From 4d6270a8fa82dff07f28bc83e3bb8b9264a8f05b Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 14 Sep 2014 15:03:21 +0200 Subject: [PATCH 01/64] testing --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 0d41e2e..83f9af2 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - stack.gl + TESTING | stack.gl From 1807eacf93938d931bcd346f41d8998bc9cca35c Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 14 Sep 2014 15:04:56 +0200 Subject: [PATCH 02/64] untest --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 83f9af2..0d41e2e 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - TESTING | stack.gl + stack.gl From 973c81028dc024fde7ce0b535d268f382f04835e Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 14 Sep 2014 15:42:04 +0200 Subject: [PATCH 03/64] testing again --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 0d41e2e..83f9af2 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - stack.gl + TESTING | stack.gl From 57d9200aaeff524c1db536e7c1c71fc5031fce74 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 14 Sep 2014 15:42:38 +0200 Subject: [PATCH 04/64] fixed! --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 83f9af2..0d41e2e 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - TESTING | stack.gl + stack.gl From f4f7840bd9e46489ce1f23c36cd103a048387678 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 14 Sep 2014 17:56:16 +0200 Subject: [PATCH 05/64] first pass at boids wanna delve deeper but should be good for now... --- splash-flock/boid.js | 1 + splash-flock/boid.png | Bin 0 -> 1309 bytes splash-flock/demo.js | 4 ++ splash-flock/index.js | 100 +++++++++++++++++++++++++++++-- splash-flock/package.json | 17 +++++- splash-flock/shaders/logic.frag | 78 ++++++++++++++++++++++++ splash-flock/shaders/logic.vert | 9 +++ splash-flock/shaders/render.frag | 14 +++++ splash-flock/shaders/render.vert | 16 +++++ 9 files changed, 230 insertions(+), 9 deletions(-) create mode 100644 splash-flock/boid.js create mode 100644 splash-flock/boid.png create mode 100644 splash-flock/shaders/logic.frag create mode 100644 splash-flock/shaders/logic.vert create mode 100644 splash-flock/shaders/render.frag create mode 100644 splash-flock/shaders/render.vert diff --git a/splash-flock/boid.js b/splash-flock/boid.js new file mode 100644 index 0000000..c57ab5d --- /dev/null +++ b/splash-flock/boid.js @@ -0,0 +1 @@ +module.exports=require('ndpack-image')(16,16,4,"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAklEQVR4AewaftIAAAHfSURBVKXBcW+aQBjA4R94vsBR72Cl1Jr1+3+qJjYuuDo3hQnIiXYjoYlpmvSPPo/3+h9f4PNFig8452ialq7ruFx6fH9CEIRoHSEiXFO887eq+LPbsS/3NHXNqT+jlCKONYlN+JamzIzhjeJKVVW8bF5YFz/ZbF4oyz3OnRARrLXk+T3OOV7xMGbGQDFyzrHb7VkXa5bLJavVit/bLceuIwgDsts7mqbB4xURIQwDRATFqGlbynLPZrNh9WPF09MTRVHQNi2RjlgsSgZaa4y1WGsRERSj7njkcDhQliXbX1uKomD5/ExVlhhjwANrLfP5PXVd4zrHQDG6XC705x7nHF3X0bYtVVmyXq8Bj7Zp6I4dzp3o+zPny5mBYjTxfdREMZUpQRAQRRHWGPDAmhlaxwRRgMgUpSZMfJ+BYiRhyM1NTGITsixjsViAB23donXEw8MDd7cZ1lriOEbCgIFipKMIaxPyPKdpGjw8rLV03ZEgCMmyjO+Pj+T5PWmSoiPNQDESEdI0xbkT4KG1Jp/nnNyJqUxJbEKe5ywWc5I0RUQYKK4YYxiITEms4VDX9H2PUlPiWJMkCWmaYsyMN4p3jDGEYUhiLUfnuJzP+L5PGIZEUYSIcE3xARFBRLB87h/fHcFMratoHAAAAABJRU5ErkJggg==") diff --git a/splash-flock/boid.png b/splash-flock/boid.png new file mode 100644 index 0000000000000000000000000000000000000000..9e2b9e65d8b69985160bacb8b6f79696891079c6 GIT binary patch literal 1309 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+n3Xd_B1$5BeXNr6bM+EIYV;~{3xK*A7;Nk-3KEmEQ%e+* zQqwc@Y?a>c-mj#PnPRIHZt82`Ti~3Uk?B!Ylp0*+7m{3+ootz+WN)WnQ(*-(AUCxn zQK2F?C$HG5!d3}vt`(3C64qBz04piUwpD^SD#ABF!8yMuRl!uxR5#hc$WX!DQqR!T z#M01EN5ROz&{*HlK;Otx*U-?)#N5izOaTg%fVLH-q*(>IxIyg#@@$ndN=gc>^!3Zj z%k|2Q_413-^$jg8E%gnI^o@*kfhu&1EAvVcD|GXUm0>2hq!uR^WfqiV=I1GZOiWD5 zFD$Tv3bSNU;+l1ennz|zM-B0$V)JVzP|XC=H|jx7ncO3BHWAB;NpiyW)Z+ZoqGVvir744~DzI`cN=+=uFAB-e&w+(vKt_H^esM;Afr7KMf`)Hma%LWg zuL;)R>ucqiS6q^qmz?V9Vygr+LN7Bj#md#m$i>aY&CS@z$;Hsn)x^Tw!obzc+{o3% z!ob+T*aD{4B|o_|H#M&WrZ)wq*VVuPr(RH6$SnZc?2=lPS(cjOR+OKs0QR$0CKk82 zxEebd8<|)b8<|>QcMC*s3NE*}xVhqVi$2gX`kGQ&7W-`!E@wbg46-srJPa!|F7?w(#0t@i}y@ZuWVeI z@2!oVYqw;bXRqJz{@iox=*uR$cE;EK3-uTVX|4Tg@on4QC0A0<6w5rXJ#>EA&%n^F zD^hRI``sw;=(i5n;^=eN9Se?5xc_2VCg0PAC-zT$>ez8>hH=Yb1D{FkG1j_k6e7;E ze(KHdk2hYPwaaAR?&(2M-JB`cmqx^M25GLCmO8WcY}xMEdC$GH`YSWF z3QkFIADTXsbJuIX<&y;-{itE7`v2t$hv0$jTN&~;S7zM4mSG$%C3xz>VTn(HUW~CK ztV)4Fulyd{*4pztHV~e+&39VL(={4P=RI!?f17Z2hQDn@yx=C5G_?n==H_-nJ&!GX zgBOIZzHp#y_ul>84^MrsJ-*bq(b2SLlFH7MB*ulM?bi^m)-yA?Xk=_ qO@{6Ew%F^gZ1Vq>*3XP*;$hf1^?q9HrK=^N0?X6Y&t;ucLK6V9J>ob3 literal 0 HcmV?d00001 diff --git a/splash-flock/demo.js b/splash-flock/demo.js index 6c48ca3..30d3f61 100644 --- a/splash-flock/demo.js +++ b/splash-flock/demo.js @@ -1,3 +1,7 @@ +document.body.style.margin = 0 +document.body.style.padding = 0 +document.body.style.overflow = 'hidden' + require('./')(document.body.appendChild( document.createElement('canvas') )) diff --git a/splash-flock/index.js b/splash-flock/index.js index 6b95ba1..70677ef 100644 --- a/splash-flock/index.js +++ b/splash-flock/index.js @@ -1,23 +1,111 @@ -var clear = require('gl-clear')({ color: [1, 0, 1, 1] }) -var debounce = require('frame-debounce') -var fit = require('canvas-fit') -var Shader = require('glslify') -var FBO = require('gl-fbo') +var clear = require('gl-clear')({ color: [1, 1, 1, 1] }) +var triangle = require('a-big-triangle') +var debounce = require('frame-debounce') +var fit = require('canvas-fit') +var createBuffer = require('gl-buffer') +var ndarray = require('ndarray') +var Shader = require('glslify') +var FBO = require('gl-fbo') +var VAO = require('gl-vao') +var SIZE = 32 +var STEPS = 2 module.exports = init function init(canvas) { - var gl = require('gl-context')(canvas, render) + var gl = require('gl-context')(canvas, render) + var boid = require('gl-texture2d')(gl, require('./boid')) + var vao = createParticleVAO(gl, SIZE) + var shaders = {} + var pdata = [] + + var starter = createStartPositions(SIZE) + for (var i = 0; i < STEPS; i++) { + pdata[i] = FBO(gl, [SIZE, SIZE], { float: true }) + pdata[i].color[0].setPixels(starter) + } window.addEventListener('resize' , debounce(fit(canvas, window)) ) + shaders.logic = Shader({ + vert: './shaders/logic.vert' + , frag: './shaders/logic.frag' + })(gl) + + shaders.render = Shader({ + vert: './shaders/render.vert' + , frag: './shaders/render.frag' + })(gl) + function render() { var width = canvas.width var height = canvas.height + gl.disable(gl.DEPTH_TEST) + gl.disable(gl.CULL_FACE) + gl.disable(gl.BLEND) + pdata[0].bind() + + gl.viewport(0, 0, width, height) + shaders.logic.bind() + shaders.logic.uniforms.positions = pdata[1].color[0].bind(0) + triangle(gl) + + gl.bindFramebuffer(gl.FRAMEBUFFER, null) gl.viewport(0, 0, width, height) clear(gl) + gl.enable(gl.BLEND) + gl.blendFunc(gl.DST_COLOR, gl.ZERO) + + shaders.render.bind() + shaders.render.uniforms.positions = pdata[0].color[0].bind(0) + shaders.render.uniforms.tex = boid.bind(1) + shaders.render.uniforms.screenSize = [width, height] + vao.bind() + vao.draw(gl.POINTS, vao.length) + + switchFrames(pdata) } } + +function switchFrames(data) { + data.push(data.shift()) + return data +} + +function createParticleVAO(gl, size) { + var data = new Float32Array(size * size) + var n = 0 + for (var x = 0; x < size; x++) + for (var y = 0; y < size; y++) { + data[n++] = x / size + data[n++] = y / size + } + + var buffer = createBuffer(gl, data) + var vao = VAO(gl, [{ + buffer: buffer + , type: gl.FLOAT + , size: 2 + }]) + + vao.length = data.length / 2 + + return vao +} + +function createStartPositions(size) { + var data = new Float32Array(size * size * 4) + for (var i = 0; i < data.length;) { + // positions + data[i++] = Math.random() - 0.5 + data[i++] = Math.random() - 0.5 + // speeds + data[i++] = Math.random() * 0.1 - 0.05 + data[i++] = Math.random() * 0.1 - 0.05 + } + + return ndarray(data, [size, size, 4]) +} diff --git a/splash-flock/package.json b/splash-flock/package.json index 7317f22..abf06b8 100644 --- a/splash-flock/package.json +++ b/splash-flock/package.json @@ -1,17 +1,28 @@ { "scripts": { - "start": "beefy index.js:bundle.js --open" + "start": "npm start glslify-live & npm run serve", + "serve": "beefy demo.js:bundle.js --open -- -t glslify-live -t glslify", + "image": "ndpack-image boid.png > boid.js" }, "dependencies": { + "a-big-triangle": "0.0.0", "canvas-fit": "^1.2.0", "frame-debounce": "0.0.0", + "gl-buffer": "^2.0.9", "gl-clear": "0.0.1", "gl-context": "^0.1.0", "gl-fbo": "^2.0.3", - "glslify": "^1.6.0" + "gl-texture2d": "^2.0.3", + "gl-vao": "^1.2.0", + "glsl-curl-noise": "0.0.4", + "glsl-square-frame": "^1.0.0", + "glslify": "^1.6.0", + "ndarray": "^1.0.15" }, "devDependencies": { "beefy": "^2.1.1", - "browserify": "^5.11.2" + "browserify": "^5.11.2", + "glslify-live": "^2.0.4", + "ndpack-image": "^1.0.3" } } diff --git a/splash-flock/shaders/logic.frag b/splash-flock/shaders/logic.frag new file mode 100644 index 0000000..2685526 --- /dev/null +++ b/splash-flock/shaders/logic.frag @@ -0,0 +1,78 @@ +precision mediump float; + +varying vec2 vuv; +uniform sampler2D positions; + +#pragma glslify: noise = require(glsl-curl-noise) + +#define CENTER_ATTRACTION 0.0045 +#define SPEED_LIMIT 0.065 +#define SEPARATION 0.0035 +#define ALIGNMENT 0.00125 +#define COHESION 0.0007 +#define WANDER 0.00035 +#define SIZE 32.0 + +vec2 alignment(vec2 speed) { + vec2 influence = vec2(0.0); + + for (float x = 0.0; x < 1.0; x += 1.0 / SIZE) + for (float y = 0.0; y < 1.0; y += 1.0 / SIZE) { + vec2 uv = vec2(x, y); + vec2 speed = texture2D(positions, uv).zw; + + influence += speed; + } + + return influence; +} +vec2 cohesion(vec2 position) { + vec2 influence = vec2(0.0); + + for (float x = 0.0; x < 1.0; x += 1.0 / SIZE) + for (float y = 0.0; y < 1.0; y += 1.0 / SIZE) { + vec2 uv = vec2(x, y); + vec2 pos = texture2D(positions, uv).xy; + + influence += pos / SIZE / SIZE; + } + + return influence - position; +} +vec2 separation(vec2 position, vec2 maxDistance, vec2 index) { + vec2 influence = vec2(0.0); + for (float x = 0.0; x < 1.0; x += 1.0 / SIZE) + for (float y = 0.0; y < 1.0; y += 1.0 / SIZE) { + vec2 uv = vec2(x, y); + vec2 pos = texture2D(positions, uv).xy; + float self = ( + x == index.x && + y == index.y + ) ? 0.0 : 1.0; + + float close = all( + greaterThanEqual(abs(position - pos), maxDistance) + ) ? 1.0 : 0.0; + + influence -= self * close * (position - pos); + } + return position - influence; +} + +void main() { + vec2 uv = gl_FragCoord.xy / vec2(SIZE); + vec2 position = texture2D(positions, uv).xy; + vec2 speed = texture2D(positions, uv).zw; + + speed += normalize(alignment(speed)) * ALIGNMENT; + speed += normalize(cohesion(position)) * COHESION; + speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION; + speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION; + speed += noise(vec3(uv * 10.2920, 1.290393)).xy * WANDER; + speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT); + + position += speed; + + gl_FragColor.xy = position; + gl_FragColor.zw = speed; +} diff --git a/splash-flock/shaders/logic.vert b/splash-flock/shaders/logic.vert new file mode 100644 index 0000000..a35398a --- /dev/null +++ b/splash-flock/shaders/logic.vert @@ -0,0 +1,9 @@ +precision mediump float; + +attribute vec2 position; +varying vec2 vuv; + +void main() { + vuv = (position + 1.0) * 0.5; + gl_Position = vec4(position.xy, 1.0, 1.0); +} diff --git a/splash-flock/shaders/render.frag b/splash-flock/shaders/render.frag new file mode 100644 index 0000000..107f8db --- /dev/null +++ b/splash-flock/shaders/render.frag @@ -0,0 +1,14 @@ +precision mediump float; + +uniform sampler2D tex; + +void main() { + vec4 color = vec4(0.0); + + color += texture2D(tex, gl_PointCoord.xy); + color *= vec4(1.2, 1.15, 1.21, 1.0); + color += vec4(0.3, 0.3, 0.3, 0.0); + color.a = 1.0; + + gl_FragColor = color; +} diff --git a/splash-flock/shaders/render.vert b/splash-flock/shaders/render.vert new file mode 100644 index 0000000..bb644e1 --- /dev/null +++ b/splash-flock/shaders/render.vert @@ -0,0 +1,16 @@ +precision mediump float; + +attribute vec2 uv; + +uniform sampler2D positions; +uniform vec2 screenSize; + +void main() { + vec2 position = texture2D(positions, uv).xy; + + position.x += 15.0; + position *= screenSize.x / screenSize.y / screenSize.xy; + + gl_PointSize = 8.0; + gl_Position = vec4((position) * 25.0, 1.0, 1.0); +} From d7120f098c6468d433f0a50489fba9a26946cb5e Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 14 Sep 2014 18:33:45 +0200 Subject: [PATCH 06/64] update all the things! --- bundle.js | 13884 ++++++++++++++++++++---------------- data/regenerate.js | 4 +- default.jpg | Bin 0 -> 9155 bytes index.css | 13 + index.html | 10 +- index.js | 8 +- package.json | 2 +- splash-flock/package.json | 5 +- 8 files changed, 7813 insertions(+), 6113 deletions(-) create mode 100644 default.jpg diff --git a/bundle.js b/bundle.js index b1b2af6..c25af6d 100644 --- a/bundle.js +++ b/bundle.js @@ -96,7 +96,7 @@ module.exports={ "name": "gl-vao", "desc": "", "link": "http://ghub.io/gl-vao", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 0 }, @@ -112,7 +112,7 @@ module.exports={ "name": "gl-texture2d", "desc": "", "link": "http://ghub.io/gl-texture2d", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 2 }, @@ -120,7 +120,7 @@ module.exports={ "name": "gl-buffer", "desc": "", "link": "http://ghub.io/gl-buffer", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 3 } @@ -130,7 +130,7 @@ module.exports={ "name": "glslify", "desc": "", "link": "http://ghub.io/glslify", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 0 }, @@ -138,7 +138,7 @@ module.exports={ "name": "glslify-live", "desc": "", "link": "http://ghub.io/glslify-live", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 1 }, @@ -146,7 +146,7 @@ module.exports={ "name": "glslify-optimize", "desc": "", "link": "http://ghub.io/glslify-optimize", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 2 } @@ -156,7 +156,7 @@ module.exports={ "name": "gl-vec2", "desc": "", "link": "http://ghub.io/gl-vec2", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 0 }, @@ -164,7 +164,7 @@ module.exports={ "name": "gl-vec3", "desc": "", "link": "http://ghub.io/gl-vec3", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 1 }, @@ -172,7 +172,7 @@ module.exports={ "name": "gl-vec4", "desc": "", "link": "http://ghub.io/gl-vec4", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 2 }, @@ -180,7 +180,7 @@ module.exports={ "name": "gl-quat", "desc": "", "link": "http://ghub.io/gl-quat", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 3 }, @@ -188,7 +188,7 @@ module.exports={ "name": "gl-mat2", "desc": "", "link": "http://ghub.io/gl-mat2", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 4 }, @@ -196,7 +196,7 @@ module.exports={ "name": "gl-mat3", "desc": "", "link": "http://ghub.io/gl-mat3", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 5 }, @@ -204,7 +204,7 @@ module.exports={ "name": "gl-mat4", "desc": "", "link": "http://ghub.io/gl-mat4", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 6 } @@ -214,7 +214,7 @@ module.exports={ "name": "orbit-camera", "desc": "", "link": "http://ghub.io/orbit-camera", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 0 }, @@ -222,7 +222,7 @@ module.exports={ "name": "game-shell-orbit-camera", "desc": "", "link": "http://ghub.io/game-shell-orbit-camera", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 1 }, @@ -230,7 +230,7 @@ module.exports={ "name": "canvas-orbit-camera", "desc": "", "link": "http://ghub.io/canvas-orbit-camera", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 2 } @@ -240,7 +240,7 @@ module.exports={ "name": "gl-now", "desc": "", "link": "http://ghub.io/gl-now", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 0 }, @@ -248,7 +248,7 @@ module.exports={ "name": "gl-context", "desc": "", "link": "http://ghub.io/gl-context", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 1 } @@ -258,7 +258,7 @@ module.exports={ "name": "key-pressed", "desc": "", "link": "http://ghub.io/key-pressed", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 0 }, @@ -266,7 +266,7 @@ module.exports={ "name": "mouse-pressed", "desc": "", "link": "http://ghub.io/mouse-pressed", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 1 }, @@ -274,7 +274,7 @@ module.exports={ "name": "mouse-speed", "desc": "", "link": "http://ghub.io/mouse-speed", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 2 }, @@ -282,7 +282,7 @@ module.exports={ "name": "scroll-speed", "desc": "", "link": "http://ghub.io/scroll-speed", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 3 }, @@ -290,7 +290,7 @@ module.exports={ "name": "canvas-fit", "desc": "", "link": "http://ghub.io/canvas-fit", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 4 }, @@ -298,7 +298,7 @@ module.exports={ "name": "vkey", "desc": "", "link": "http://ghub.io/vkey", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 5 } @@ -324,7 +324,7 @@ module.exports={ "name": "glsl-noise", "desc": "", "link": "http://ghub.io/glsl-noise", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 2 }, @@ -350,7 +350,7 @@ module.exports={ "name": "glslify-hex", "desc": "", "link": "http://ghub.io/glslify-hex", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 0 }, @@ -358,7 +358,7 @@ module.exports={ "name": "glslify-import", "desc": "", "link": "http://ghub.io/glslify-import", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 1 } @@ -369,7 +369,7 @@ module.exports={ "name": "gl-compare", "desc": "", "link": "http://ghub.io/gl-compare", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 0 } @@ -379,7 +379,7 @@ module.exports={ "name": "glsl-parser", "desc": "", "link": "http://ghub.io/glsl-parser", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 0 }, @@ -387,7 +387,7 @@ module.exports={ "name": "glsl-tokenizer", "desc": "", "link": "http://ghub.io/glsl-tokenizer", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 1 }, @@ -395,7 +395,7 @@ module.exports={ "name": "glsl-deparser", "desc": "", "link": "http://ghub.io/glsl-deparser", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 2 }, @@ -403,7 +403,7 @@ module.exports={ "name": "glsl-extract", "desc": "", "link": "http://ghub.io/glsl-extract", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 3 }, @@ -411,7 +411,7 @@ module.exports={ "name": "glslify-stream", "desc": "", "link": "http://ghub.io/glslify-stream", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 4 }, @@ -419,7 +419,7 @@ module.exports={ "name": "gl-shader-core", "desc": "", "link": "http://ghub.io/gl-shader-core", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 5 } @@ -453,7 +453,7 @@ module.exports={ "name": "teapot", "desc": "", "link": "http://ghub.io/teapot", - "thumb": "", + "thumb": "default.jpg", "featured": false, "i": 3 }, @@ -468,14 +468,16 @@ module.exports={ ] } },{}],3:[function(require,module,exports){ -var splash = document.getElementById('splash') -var canvas = splash.querySelector('canvas') var filter = require('./lib/filter') var minstache = require('minstache') var domify = require('domify') var slice = require('sliced') +var grid = document.getElementById('grid').querySelector('canvas') +var flock = document.getElementById('community').querySelector('canvas') + require('./lib/fill')(document.querySelectorAll('[data-fill]')) -require('@stackgl/splash-grid')(canvas) +require('@stackgl/splash-grid')(grid) +require('@stackgl/splash-flock')(flock) var thumb = minstache.compile("
  • \n
    \n \n
    \n
    \n
    \n \n

    {{name}}

    \n
    \n
    \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
    \n
    \n
    \n
  • \n") @@ -509,7 +511,7 @@ pkgEl .querySelector('ul.thumb-filter') .appendChild(filter(pkgEl)) -},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,"domify":99,"minstache":103,"sliced":104}],4:[function(require,module,exports){ +},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,"domify":182,"minstache":186,"sliced":187}],4:[function(require,module,exports){ var debounce = require('frame-debounce') module.exports = fill @@ -533,7 +535,7 @@ function fill(elements) { } } -},{"frame-debounce":101}],5:[function(require,module,exports){ +},{"frame-debounce":184}],5:[function(require,module,exports){ var findup = require('findup-element') var minstache = require('minstache') var domify = require('domify') @@ -586,143 +588,111 @@ module.exports = function(thumbs) { return list } -},{"domify":99,"findup-element":100,"minstache":103,"sliced":104}],6:[function(require,module,exports){ -module.exports=require('ndpack-image')(1,256,4,"iVBORw0KGgoAAAANSUhEUgAAAQAAAAABCAYAAAAxWXB3AAAAAklEQVR4AewaftIAAADsSURBVCXBgXEEIQADsZW5/lv+DERS/dBDF3roQlkXeoj1EOshVnSxItZjoSzWQyzWb2JFF6e2WBGrLVbEaosV2YpYka0sZCti/SZWZMpClIQQ2oROQhRC6BBCUwiNRmhEobM1oqTRmdCIGp1JGlGzvokaoW9Cq9C3Yk1R3xY1QseaQqMzjajR6BCaGp0JjaizRY3QmUaq0ZnQCI02nUSh0aYRoqSzRSGEDiGKYlGsqU0IoRHLtC2EkImFItTEykIRshWhiPUjFKEs1ISyUIQi1kMoMqHoQhGKLlYkPYSiC0UXii70KPRPF3ro+gNf1gb72t6EvgAAAABJRU5ErkJggg==") - -},{"ndpack-image":94}],7:[function(require,module,exports){ -var createCamera = require("orbit-camera"); -var createTex2d = require("gl-texture2d"); -var createGeom = require("gl-geometry"); -var createFBO = require("gl-fbo"); -var createShader = require("glslify"); +},{"domify":182,"findup-element":183,"minstache":186,"sliced":187}],6:[function(require,module,exports){ +module.exports=require('ndpack-image')(16,16,4,"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAklEQVR4AewaftIAAAHfSURBVKXBcW+aQBjA4R94vsBR72Cl1Jr1+3+qJjYuuDo3hQnIiXYjoYlpmvSPPo/3+h9f4PNFig8452ialq7ruFx6fH9CEIRoHSEiXFO887eq+LPbsS/3NHXNqT+jlCKONYlN+JamzIzhjeJKVVW8bF5YFz/ZbF4oyz3OnRARrLXk+T3OOV7xMGbGQDFyzrHb7VkXa5bLJavVit/bLceuIwgDsts7mqbB4xURIQwDRATFqGlbynLPZrNh9WPF09MTRVHQNi2RjlgsSgZaa4y1WGsRERSj7njkcDhQliXbX1uKomD5/ExVlhhjwANrLfP5PXVd4zrHQDG6XC705x7nHF3X0bYtVVmyXq8Bj7Zp6I4dzp3o+zPny5mBYjTxfdREMZUpQRAQRRHWGPDAmhlaxwRRgMgUpSZMfJ+BYiRhyM1NTGITsixjsViAB23donXEw8MDd7cZ1lriOEbCgIFipKMIaxPyPKdpGjw8rLV03ZEgCMmyjO+Pj+T5PWmSoiPNQDESEdI0xbkT4KG1Jp/nnNyJqUxJbEKe5ywWc5I0RUQYKK4YYxiITEms4VDX9H2PUlPiWJMkCWmaYsyMN4p3jDGEYUhiLUfnuJzP+L5PGIZEUYSIcE3xARFBRLB87h/fHcFMratoHAAAAABJRU5ErkJggg==") +},{"ndpack-image":88}],7:[function(require,module,exports){ var clear = require("gl-clear")({ color: [1, 1, 1, 1] }); -var mat4 = require("gl-matrix").mat4; -var quat = require("gl-matrix").quat; var triangle = require("a-big-triangle"); var debounce = require("frame-debounce"); -var unindex = require("unindex-mesh"); -var normals = require("face-normals"); -var combine = require("mesh-combine"); var fit = require("canvas-fit"); -var qbqb = require("cube-cube"); -var getTime = require("right-now"); -var clone = require("clone"); -var TIMESCALE = 0.5; -var SIZE = 16; -var RES = [1 / SIZE, 1 / SIZE]; - -module.exports = function(canvas) { +var createBuffer = require("gl-buffer"); +var ndarray = require("ndarray"); +var Shader = require("glslify"); +var FBO = require("gl-fbo"); +var VAO = require("gl-vao"); +var SIZE = 32; +var STEPS = 2; +module.exports = init; + +function init(canvas) { var gl = require("gl-context")(canvas, render); + var boid = require("gl-texture2d")(gl, require("./boid")); + var vao = createParticleVAO(gl, SIZE); + var shaders = {}; + var pdata = []; + var starter = createStartPositions(SIZE); + + for (var i = 0; i < STEPS; i++) { + pdata[i] = FBO(gl, [SIZE, SIZE], { + float: true + }); + + pdata[i].color[0].setPixels(starter); + } - var heightmap = createFBO(gl, [SIZE, SIZE], { - float: true - }); - - var gradient = createTex2d(gl, require("./gradient-map")); - var voxels = createMesh(); - var projection = mat4.create(); - var viewrot = mat4.create(); - var view = mat4.create(); - var model = mat4.create(); - var camera = createCamera([0, 10, 30], [0, 0, 0], [0, 1, 0]); - var shader = require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}", "\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}", [{"name":"tHeightmap","type":"sampler2D"},{"name":"uResolution","type":"vec2"},{"name":"uProjection","type":"mat4"},{"name":"uModel","type":"mat4"},{"name":"uView","type":"mat4"},{"name":"tGradient","type":"sampler2D"},{"name":"uViewRotation","type":"mat4"}], [{"name":"aPosition","type":"vec3"},{"name":"aCentroid","type":"vec3"},{"name":"aNormal","type":"vec3"},{"name":"aEdge","type":"vec3"}])(gl); - var heightShader = require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}", "\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}", [{"name":"uResolution","type":"vec2"},{"name":"uTime","type":"float"}], [{"name":"position","type":"vec2"}])(gl); - var geom = createGeom(gl).attr("aPosition", voxels.positions).attr("aCentroid", voxels.centroids).attr("aNormal", voxels.normals).attr("aEdge", voxels.edges); - camera.distance = 1.5; - heightmap.color[0].wrap = gl.CLAMP_TO_EDGE; - heightmap.color[0].minFilter = gl.NEAREST; - heightmap.color[0].maxFilter = gl.NEAREST; - mat4.translate(model, model, [-0.5, 0, -0.5]); - window.addEventListener("resize", debounce(fit(canvas)), false); + window.addEventListener("resize", debounce(fit(canvas, window))); + shaders.logic = require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}", "\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}", [{"name":"positions","type":"sampler2D"}], [{"name":"position","type":"vec2"}])(gl); + shaders.render = require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}", "\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}", [{"name":"positions","type":"sampler2D"},{"name":"screenSize","type":"vec2"},{"name":"tex","type":"sampler2D"}], [{"name":"uv","type":"vec2"}])(gl); function render() { var width = canvas.width; var height = canvas.height; - - if (window.scrollY > height) - return; - - var now = getTime() * TIMESCALE; - heightmap.bind(); - gl.viewport(0, 0, SIZE, SIZE); gl.disable(gl.DEPTH_TEST); gl.disable(gl.CULL_FACE); - heightShader.bind(); - heightShader.uniforms.uTime = now; - heightShader.uniforms.uResolution = RES; + gl.disable(gl.BLEND); + pdata[0].bind(); + gl.viewport(0, 0, width, height); + shaders.logic.bind(); + shaders.logic.uniforms.positions = pdata[1].color[0].bind(0); triangle(gl); gl.bindFramebuffer(gl.FRAMEBUFFER, null); gl.viewport(0, 0, width, height); - gl.enable(gl.DEPTH_TEST); - gl.enable(gl.CULL_FACE); clear(gl); - mat4.perspective(projection, Math.PI / 4, width / height, 0.001, 100); - quat.identity(camera.rotation); - quat.rotateY(camera.rotation, camera.rotation, now * 0.0002); - quat.rotateX(camera.rotation, camera.rotation, -0.5); - camera.view(view); - quat.identity(camera.rotation); - quat.rotateY(camera.rotation, camera.rotation, now * 0.0002); - geom.bind(shader); - shader.uniforms.uResolution = RES; - shader.uniforms.uViewRotation = mat4.fromQuat(viewrot, camera.rotation); - shader.uniforms.uProjection = projection; - shader.uniforms.uModel = model; - shader.uniforms.uView = view; - shader.uniforms.tHeightmap = heightmap.color[0].bind(0); - shader.uniforms.tGradient = gradient.bind(1); - geom.draw(); - geom.unbind(); + gl.enable(gl.BLEND); + gl.blendFunc(gl.DST_COLOR, gl.ZERO); + shaders.render.bind(); + shaders.render.uniforms.positions = pdata[0].color[0].bind(0); + shaders.render.uniforms.tex = boid.bind(1); + shaders.render.uniforms.screenSize = [width, height]; + vao.bind(); + vao.draw(gl.POINTS, vao.length); + switchFrames(pdata); } -}; - -function createMesh() { - var voxels = qbqb(SIZE, 1, SIZE); - var positions = unindex(combine(voxels)); - var edges = unindex(combine(getEdges(voxels))); - var centroids = unindex(combine(getCentroids(voxels))); +} - return { - positions: positions, - centroids: centroids, - normals: normals(positions), - edges: edges - }; +function switchFrames(data) { + data.push(data.shift()); + return data; } -function getCentroids(meshes) { - return meshes.map(function(mesh) { - mesh = clone(mesh); +function createParticleVAO(gl, size) { + var data = new Float32Array(size * size); + var n = 0; - for (var i = 0; i < mesh.positions.length; i++) { - mesh.positions[i] = mesh.centroid; - } + for (var x = 0; x < size; x++) for (var y = 0; y < size; y++) { + data[n++] = x / size; + data[n++] = y / size; + } - return mesh; - }); + var buffer = createBuffer(gl, data); + + var vao = VAO(gl, [{ + buffer: buffer, + type: gl.FLOAT, + size: 2 + }]); + + vao.length = data.length / 2; + return vao; } -function getEdges(meshes) { - return meshes.map(function(mesh) { - mesh = clone(mesh); - var idx = mesh.index; +function createStartPositions(size) { + var data = new Float32Array(size * size * 4); - for (var i = 0; i < mesh.positions.length; i++) { - var pos = mesh.positions[i]; - mesh.positions[i] = mesh.positions[i].slice(); - mesh.positions[i][0] = (pos[0] * SIZE - idx[0] - 0.5) * 2; - mesh.positions[i][2] = (pos[2] * SIZE - idx[2] - 0.5) * 2; - mesh.positions[i][1] = (pos[1] - idx[1] - 0.5) * 2; - } + for (var i = 0; i < data.length; ) { + data[i++] = Math.random() - 0.5; + data[i++] = Math.random() - 0.5; + data[i++] = Math.random() * 0.1 - 0.05; + data[i++] = Math.random() * 0.1 - 0.05; + } - return mesh; - }); + return ndarray(data, [size, size, 4]); } -},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,"clone":27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,"glslify":83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":96,"right-now":97,"unindex-mesh":98}],8:[function(require,module,exports){ +},{"./boid":6,"a-big-triangle":24,"canvas-fit":25,"frame-debounce":27,"gl-buffer":31,"gl-clear":45,"gl-context":46,"gl-fbo":48,"gl-texture2d":72,"gl-vao":78,"glslify":80,"glslify/adapter.js":79,"ndarray":86}],8:[function(require,module,exports){ "use strict" var pool = require("typedarray-pool") @@ -2254,7 +2224,7 @@ function wrappedNDArrayCtor(data, shape, stride, offset) { module.exports = wrappedNDArrayCtor }).call(this,require("buffer").Buffer) -},{"buffer":106,"iota-array":15}],15:[function(require,module,exports){ +},{"buffer":189,"iota-array":15}],15:[function(require,module,exports){ "use strict" function iota(n) { @@ -3015,16 +2985,19 @@ var size = require('element-size') module.exports = fit -function fit(canvas) { +function fit(canvas, parent, scale) { canvas.style.position = canvas.style.position || 'absolute' canvas.style.top = 0 canvas.style.left = 0 + scale = parseFloat(scale || 1) + return resize() function resize() { - if (canvas.parentNode && canvas.parentNode !== document.body) { - var psize = size(canvas.parentNode) + var p = parent || canvas.parentNode + if (p && p !== document.body) { + var psize = size(p) var width = psize[0]|0 var height = psize[1]|0 } else { @@ -3032,8 +3005,8 @@ function fit(canvas) { var height = window.innerHeight } - canvas.width = width - canvas.height = height + canvas.width = width * scale + canvas.height = height * scale canvas.style.width = width + 'px' canvas.style.height = height + 'px' @@ -3048,6 +3021,10 @@ function getSize(element) { // Handle cases where the element is not already // attached to the DOM by briefly appending it // to document.body, and removing it again later. + if (element === window || element === document.body) { + return [window.innerWidth, window.innerHeight] + } + if (!element.parentNode) { var temporary = true document.body.appendChild(element) @@ -3074,875 +3051,660 @@ function parse(prop) { } },{}],27:[function(require,module,exports){ -(function (Buffer){ -'use strict'; +(function (process){ +var slice = require('sliced') -function objectToString(o) { - return Object.prototype.toString.call(o); +if (process.browser) { + var raf = require('raf-component') +} else { + var raf = typeof setImmediate !== 'undefined' + ? setImmediate + : process.nextTick } -// shim for Node's 'util' package -// DO NOT REMOVE THIS! It is required for compatibility with EnderJS (http://enderjs.com/). -var util = { - isArray: function (ar) { - return Array.isArray(ar) || (typeof ar === 'object' && objectToString(ar) === '[object Array]'); - }, - isDate: function (d) { - return typeof d === 'object' && objectToString(d) === '[object Date]'; - }, - isRegExp: function (re) { - return typeof re === 'object' && objectToString(re) === '[object RegExp]'; - }, - getRegExpFlags: function (re) { - var flags = ''; - re.global && (flags += 'g'); - re.ignoreCase && (flags += 'i'); - re.multiline && (flags += 'm'); - return flags; +module.exports = debounce + +function debounce(fn, now) { + var args = null + var ctx = null + + return debounced + + function debounced() { + if (args !== null) return + args = slice(arguments) + ctx = this + if (now) fn.apply(ctx, args) + raf(next) } -}; + function next() { + if (!now) fn.apply(ctx, args) + args = null + ctx = null + } +} -if (typeof module === 'object') - module.exports = clone; +}).call(this,require('_process')) +},{"_process":192,"raf-component":28,"sliced":29}],28:[function(require,module,exports){ +/** + * Expose `requestAnimationFrame()`. + */ + +exports = module.exports = window.requestAnimationFrame + || window.webkitRequestAnimationFrame + || window.mozRequestAnimationFrame + || window.oRequestAnimationFrame + || window.msRequestAnimationFrame + || fallback; /** - * Clones (copies) an Object using deep copying. - * - * This function supports circular references by default, but if you are certain - * there are no circular references in your object, you can save some CPU time - * by calling clone(obj, false). - * - * Caution: if `circular` is false and `parent` contains circular references, - * your program may enter an infinite loop and crash. - * - * @param `parent` - the object to be cloned - * @param `circular` - set to true if the object to be cloned may contain - * circular references. (optional - true by default) - * @param `depth` - set to a number if the object is only to be cloned to - * a particular depth. (optional - defaults to Infinity) - * @param `prototype` - sets the prototype to be used when cloning an object. - * (optional - defaults to parent prototype). -*/ + * Fallback implementation. + */ -function clone(parent, circular, depth, prototype) { - // maintain two arrays for circular references, where corresponding parents - // and children have the same index - var allParents = []; - var allChildren = []; +var prev = new Date().getTime(); +function fallback(fn) { + var curr = new Date().getTime(); + var ms = Math.max(0, 16 - (curr - prev)); + var req = setTimeout(fn, ms); + prev = curr; + return req; +} - var useBuffer = typeof Buffer != 'undefined'; +/** + * Cancel. + */ - if (typeof circular == 'undefined') - circular = true; +var cancel = window.cancelAnimationFrame + || window.webkitCancelAnimationFrame + || window.mozCancelAnimationFrame + || window.oCancelAnimationFrame + || window.msCancelAnimationFrame + || window.clearTimeout; - if (typeof depth == 'undefined') - depth = Infinity; +exports.cancel = function(id){ + cancel.call(window, id); +}; - // recurse this function so we don't reset allParents and allChildren - function _clone(parent, depth) { - // cloning null always returns null - if (parent === null) - return null; +},{}],29:[function(require,module,exports){ +module.exports = exports = require('./lib/sliced'); - if (depth == 0) - return parent; +},{"./lib/sliced":30}],30:[function(require,module,exports){ - var child; - if (typeof parent != 'object') { - return parent; - } +/** + * An Array.prototype.slice.call(arguments) alternative + * + * @param {Object} args something with a length + * @param {Number} slice + * @param {Number} sliceEnd + * @api public + */ - if (util.isArray(parent)) { - child = []; - } else if (util.isRegExp(parent)) { - child = new RegExp(parent.source, util.getRegExpFlags(parent)); - if (parent.lastIndex) child.lastIndex = parent.lastIndex; - } else if (util.isDate(parent)) { - child = new Date(parent.getTime()); - } else if (useBuffer && Buffer.isBuffer(parent)) { - child = new Buffer(parent.length); - parent.copy(child); - return child; - } else { - if (typeof prototype == 'undefined') child = Object.create(Object.getPrototypeOf(parent)); - else child = Object.create(prototype); - } +module.exports = function (args, slice, sliceEnd) { + var ret = []; + var len = args.length; - if (circular) { - var index = allParents.indexOf(parent); + if (0 === len) return ret; - if (index != -1) { - return allChildren[index]; - } - allParents.push(parent); - allChildren.push(child); - } + var start = slice < 0 + ? Math.max(0, slice + len) + : slice || 0; - for (var i in parent) { - child[i] = _clone(parent[i], depth - 1); - } + if (sliceEnd !== undefined) { + len = sliceEnd < 0 + ? sliceEnd + len + : sliceEnd + } - return child; + while (len-- > start) { + ret[len - start] = args[len]; } - return _clone(parent, depth); + return ret; } -/** - * Simple flat clone using prototype, accepts only objects, usefull for property - * override on FLAT configuration object (no nested props). - * - * USE WITH CAUTION! This may not behave as you wish if you do not know how this - * works. - */ -clone.clonePrototype = function(parent) { - if (parent === null) - return null; - - var c = function () {}; - c.prototype = parent; - return new c(); -}; - -}).call(this,require("buffer").Buffer) -},{"buffer":106}],28:[function(require,module,exports){ -var prism = require('rectangular-prism') -var truthy = function() { return true } -module.exports = cubecube +},{}],31:[function(require,module,exports){ +"use strict" -function cubecube(w, h, d, filter) { - filter = filter || truthy +var pool = require("typedarray-pool") +var ops = require("ndarray-ops") +var ndarray = require("ndarray") +var webglew = require("webglew") - var size = [1/w, 1/h, 1/d] - var cubes = [] +var SUPPORTED_TYPES = [ + "uint8", + "uint8_clamped", + "uint16", + "uint32", + "int8", + "int16", + "int32", + "float32" ] - for (var x = 0; x < w; x++) - for (var y = 0; y < h; y++) - for (var z = 0; z < d; z++) { - if (filter(x, y, z)) { - var cube = prism(size, [x/w, y/h, z/d]) +function GLBuffer(gl, type, handle, length, usage) { + this.gl = gl + this.type = type + this.handle = handle + this.length = length + this.usage = usage +} - cubes.push(cube) - cube.centroid = [(x+0.5)/w, (y+0.5)/h, (z+0.5)/d] - cube.index = [x, y, z] - } - } +var proto = GLBuffer.prototype - return cubes +proto.bind = function() { + this.gl.bindBuffer(this.type, this.handle) } -},{"rectangular-prism":30}],29:[function(require,module,exports){ -module.exports = { - cells: [ - [1, 0, 2], - [3, 1, 2], - [4, 5, 6], - [5, 7, 6], - [0, 1, 5], - [4, 0, 5], - [1, 3, 5], - [3, 7, 5], - [2, 0, 4], - [2, 4, 6], - [2, 6, 3], - [6, 7, 3] - ], - positions: [ - [0, 0, 0], - [0, 0, 1], - [1, 0, 0], - [1, 0, 1], - [0, 1, 0], - [0, 1, 1], - [1, 1, 0], - [1, 1, 1] - ] +proto.dispose = function() { + this.gl.deleteBuffer(this.handle) } -},{}],30:[function(require,module,exports){ -var prism = require('./cube') - -module.exports = createPrism - -function createPrism(size, pos) { - pos = pos || [0,0,0] - size = size || [1,1,1] - - if (!Array.isArray(size)) { - size = [size, size, size] +function updateTypeArray(gl, type, len, usage, data, offset) { + var dataLen = data.length * data.BYTES_PER_ELEMENT + if(offset < 0) { + gl.bufferData(type, data, usage) + return dataLen } - - var prism = clonePrism() - - for (var i = 0; i < prism.positions.length; i++) { - prism.positions[i][0] *= size[0] - prism.positions[i][1] *= size[1] - prism.positions[i][2] *= size[2] - prism.positions[i][0] += pos[0] - prism.positions[i][1] += pos[1] - prism.positions[i][2] += pos[2] + if(dataLen + offset > len) { + throw new Error("gl-buffer: If resizing buffer, must not specify offset") } - - return prism + gl.bufferSubData(type, offset, data) + return len } -function clonePrism() { - return { - cells: prism.cells.map(function(d) { - return d.slice() - }), - positions: prism.positions.map(function(d) { - return d.slice() - }) +function makeScratchTypeArray(array, dtype) { + var res = pool.malloc(array.length, dtype) + var n = array.length + for(var i=0; i=0; --i) { + if(stride[i] !== n) { + return false } + n *= shape[i] } - - return output -} - -},{}],32:[function(require,module,exports){ -(function (process){ -var slice = require('sliced') - -if (process.browser) { - var raf = require('raf-component') -} else { - var raf = typeof setImmediate !== 'undefined' - ? setImmediate - : process.nextTick + return true } -module.exports = debounce - -function debounce(fn, now) { - var args = null - var ctx = null - - return debounced - - function debounced() { - if (args !== null) return - args = slice(arguments) - ctx = this - if (now) fn.apply(ctx, args) - raf(next) +proto.update = function(array, offset) { + if(typeof offset !== "number") { + offset = -1 } - - function next() { - if (!now) fn.apply(ctx, args) - args = null - ctx = null + this.bind() + if(typeof array === "object" && typeof array.shape !== "undefined") { //ndarray + var dtype = array.dtype + if(SUPPORTED_TYPES.indexOf(dtype) < 0) { + dtype = "float32" + } + if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) { + var wgl = webglew(this.gl) + var ext = wgl.OES_element_index_uint + if(ext && dtype !== "uint16") { + dtype = "uint32" + } else { + dtype = "uint16" + } + } + if(dtype === array.dtype && isPacked(array.shape, array.stride)) { + if(array.offset === 0 && array.data.length === array.shape[0]) { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data, offset) + } else { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data.subarray(array.offset, array.shape[0]), offset) + } + } else { + var tmp = pool.malloc(array.size, dtype) + var ndt = ndarray(tmp, array.shape) + ops.assign(ndt, array) + if(offset < 0) { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, tmp, offset) + } else { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, tmp.subarray(0, array.size), offset) + } + pool.free(tmp) + } + } else if(Array.isArray(array)) { //Vanilla array + var t + if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) { + t = makeScratchTypeArray(array, "uint16") + } else { + t = makeScratchTypeArray(array, "float32") + } + if(offset < 0) { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t, offset) + } else { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t.subarray(0, array.length), offset) + } + pool.free(t) + } else if(typeof array === "object" && typeof array.length === "number") { //Typed array + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array, offset) + } else if(typeof array === "number" || array === undefined) { //Number/default + if(offset >= 0) { + throw new Error("gl-buffer: Cannot specify offset when resizing buffer") + } + array = array | 0 + if(array <= 0) { + array = 1 + } + this.gl.bufferData(this.type, array|0, this.usage) + this.length = array + } else { //Error, case should not happen + throw new Error("gl-buffer: Invalid data type") } } -}).call(this,require('_process')) -},{"_process":109,"raf-component":33,"sliced":34}],33:[function(require,module,exports){ -/** - * Expose `requestAnimationFrame()`. - */ - -exports = module.exports = window.requestAnimationFrame - || window.webkitRequestAnimationFrame - || window.mozRequestAnimationFrame - || window.oRequestAnimationFrame - || window.msRequestAnimationFrame - || fallback; +function createBuffer(gl, data, type, usage) { + webglew(gl) + type = type || gl.ARRAY_BUFFER + usage = usage || gl.DYNAMIC_DRAW + if(type !== gl.ARRAY_BUFFER && type !== gl.ELEMENT_ARRAY_BUFFER) { + throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER") + } + if(usage !== gl.DYNAMIC_DRAW && usage !== gl.STATIC_DRAW && usage !== gl.STREAM_DRAW) { + throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW") + } + var handle = gl.createBuffer() + var result = new GLBuffer(gl, type, handle, 0, usage) + result.update(data) + return result +} -/** - * Fallback implementation. - */ +module.exports = createBuffer +},{"ndarray":37,"ndarray-ops":32,"typedarray-pool":41,"webglew":43}],32:[function(require,module,exports){ +arguments[4][9][0].apply(exports,arguments) +},{"cwise-compiler":33}],33:[function(require,module,exports){ +arguments[4][10][0].apply(exports,arguments) +},{"./lib/thunk.js":35}],34:[function(require,module,exports){ +arguments[4][11][0].apply(exports,arguments) +},{"uniq":36}],35:[function(require,module,exports){ +arguments[4][12][0].apply(exports,arguments) +},{"./compile.js":34}],36:[function(require,module,exports){ +module.exports=require(13) +},{}],37:[function(require,module,exports){ +arguments[4][14][0].apply(exports,arguments) +},{"buffer":189,"iota-array":38}],38:[function(require,module,exports){ +module.exports=require(15) +},{}],39:[function(require,module,exports){ +module.exports=require(16) +},{}],40:[function(require,module,exports){ +module.exports=require(17) +},{}],41:[function(require,module,exports){ +(function (global,Buffer){ +var bits = require("bit-twiddle") +var dup = require("dup") +if(!global.__TYPEDARRAY_POOL) { + global.__TYPEDARRAY_POOL = { + UINT8 : dup([32, 0]) + , UINT16 : dup([32, 0]) + , UINT32 : dup([32, 0]) + , INT8 : dup([32, 0]) + , INT16 : dup([32, 0]) + , INT32 : dup([32, 0]) + , FLOAT : dup([32, 0]) + , DOUBLE : dup([32, 0]) + , DATA : dup([32, 0]) + , UINT8C : dup([32, 0]) + , BUFFER : dup([32, 0]) + } +} +var hasUint8C = (typeof Uint8ClampedArray) !== "undefined" +var POOL = global.__TYPEDARRAY_POOL +if(!POOL.UINT8C) { + POOL.UINT8C = dup([32, 0]) +} +if(!POOL.BUFFER) { + POOL.BUFFER = dup([32, 0]) +} +var UINT8 = POOL.UINT8 + , UINT16 = POOL.UINT16 + , UINT32 = POOL.UINT32 + , INT8 = POOL.INT8 + , INT16 = POOL.INT16 + , INT32 = POOL.INT32 + , FLOAT = POOL.FLOAT + , DOUBLE = POOL.DOUBLE + , DATA = POOL.DATA + , UINT8C = POOL.UINT8C + , BUFFER = POOL.BUFFER -var prev = new Date().getTime(); -function fallback(fn) { - var curr = new Date().getTime(); - var ms = Math.max(0, 16 - (curr - prev)); - var req = setTimeout(fn, ms); - prev = curr; - return req; +exports.free = function free(array) { + var n = array.length|0 + , log_n = bits.log2(n) + if(Buffer.isBuffer(array)) { + BUFFER[log_n].push(array) + } else { + switch(Object.prototype.toString.call(array)) { + case "[object Uint8Array]": + UINT8[log_n].push(array) + break + case "[object Uint16Array]": + UINT16[log_n].push(array) + break + case "[object Uint32Array]": + UINT32[log_n].push(array) + break + case "[object Int8Array]": + INT8[log_n].push(array) + break + case "[object Int16Array]": + INT16[log_n].push(array) + break + case "[object Int32Array]": + INT32[log_n].push(array) + break + case "[object Uint8ClampedArray]": + UINT8C[log_n].push(array) + break + case "[object Float32Array]": + FLOAT[log_n].push(array) + break + case "[object Float64Array]": + DOUBLE[log_n].push(array) + break + case "[object ArrayBuffer]": + DATA[log_n].push(array) + break + default: + throw new Error("typedarray-pool: Unspecified array type") + } + } } -/** - * Cancel. - */ +exports.freeUint8 = function freeUint8(array) { + UINT8[bits.log2(array.length)].push(array) +} -var cancel = window.cancelAnimationFrame - || window.webkitCancelAnimationFrame - || window.mozCancelAnimationFrame - || window.oCancelAnimationFrame - || window.msCancelAnimationFrame - || window.clearTimeout; +exports.freeUint16 = function freeUint16(array) { + UINT16[bits.log2(array.length)].push(array) +} -exports.cancel = function(id){ - cancel.call(window, id); -}; +exports.freeUint32 = function freeUint32(array) { + UINT32[bits.log2(array.length)].push(array) +} -},{}],34:[function(require,module,exports){ -module.exports = exports = require('./lib/sliced'); +exports.freeInt8 = function freeInt8(array) { + INT8[bits.log2(array.length)].push(array) +} -},{"./lib/sliced":35}],35:[function(require,module,exports){ +exports.freeInt16 = function freeInt16(array) { + INT16[bits.log2(array.length)].push(array) +} -/** - * An Array.prototype.slice.call(arguments) alternative - * - * @param {Object} args something with a length - * @param {Number} slice - * @param {Number} sliceEnd - * @api public - */ +exports.freeInt32 = function freeInt32(array) { + INT32[bits.log2(array.length)].push(array) +} -module.exports = function (args, slice, sliceEnd) { - var ret = []; - var len = args.length; +exports.freeFloat32 = exports.freeFloat = function freeFloat(array) { + FLOAT[bits.log2(array.length)].push(array) +} - if (0 === len) return ret; +exports.freeFloat64 = exports.freeDouble = function freeDouble(array) { + DOUBLE[bits.log2(array.length)].push(array) +} - var start = slice < 0 - ? Math.max(0, slice + len) - : slice || 0; +exports.freeArrayBuffer = function freeArrayBuffer(array) { + DATA[bits.log2(array.length)].push(array) +} - if (sliceEnd !== undefined) { - len = sliceEnd < 0 - ? sliceEnd + len - : sliceEnd +if(hasUint8C) { + exports.freeUint8Clamped = function freeUint8Clamped(array) { + UINT8C[bits.log2(array.length)].push(array) } +} else { + exports.freeUint8Clamped = exports.freeUint8 +} - while (len-- > start) { - ret[len - start] = args[len]; - } - - return ret; +exports.freeBuffer = function freeBuffer(array) { + BUFFER[bits.log2(array.length)].push(array) } +exports.malloc = function malloc(n, dtype) { + n = bits.nextPow2(n) + var log_n = bits.log2(n) + if(dtype === undefined || dtype === "arraybuffer") { + var d = DATA[log_n] + if(d.length > 0) { + var r = d[d.length-1] + d.pop() + return r + } + return new ArrayBuffer(n) + } else { + switch(dtype) { + case "uint8": + var u8 = UINT8[log_n] + if(u8.length > 0) { + return u8.pop() + } + return new Uint8Array(n) + break -},{}],36:[function(require,module,exports){ -module.exports = defaults + case "uint16": + var u16 = UINT16[log_n] + if(u16.length > 0) { + return u16.pop() + } + return new Uint16Array(n) + break -function defaults(opts) { - return { - color: array(opts.color, [0, 0, 0, 1]) - , depth: number(opts.depth, 1) - , stencil: number(opts.stencil, false) - } -} + case "uint32": + var u32 = UINT32[log_n] + if(u32.length > 0) { + return u32.pop() + } + return new Uint32Array(n) + break -function number(n, def) { - return n === false - ? false - : typeof n === 'undefined' - ? def - : n + 0 -} + case "int8": + var i8 = INT8[log_n] + if(i8.length > 0) { + return i8.pop() + } + return new Int8Array(n) + break -function array(a, def) { - return a === false - ? false - : Array.isArray(a) - ? a || def - : def -} + case "int16": + var i16 = INT16[log_n] + if(i16.length > 0) { + return i16.pop() + } + return new Int16Array(n) + break -},{}],37:[function(require,module,exports){ -var defaults = require('./defaults') + case "int32": + var i32 = INT32[log_n] + if(i32.length > 0) { + return i32.pop() + } + return new Int32Array(n) + break -module.exports = clear + case "float": + case "float32": + var f = FLOAT[log_n] + if(f.length > 0) { + return f.pop() + } + return new Float32Array(n) + break -function clear(opts) { - opts = defaults(opts || {}) + case "double": + case "float64": + var dd = DOUBLE[log_n] + if(dd.length > 0) { + return dd.pop() + } + return new Float64Array(n) + break - var stencil = opts.stencil - var color = opts.color - var depth = opts.depth + case "uint8_clamped": + if(hasUint8C) { + var u8c = UINT8C[log_n] + if(u8c.length > 0) { + return u8c.pop() + } + return new Uint8ClampedArray(n) + } else { + var u8 = UINT8[log_n] + if(u8.length > 0) { + return u8.pop() + } + return new Uint8Array(n) + } + break - return function clear(gl) { - var flags = 0 + case "buffer": + var buf = BUFFER[log_n] + if(buf.length > 0) { + return buf.pop() + } + return new Buffer(n) + break - if (color !== false) { - gl.clearColor(color[0], color[1], color[2], color[3]) - flags |= gl.COLOR_BUFFER_BIT - } - if (depth !== false) { - gl.clearDepth(depth) - flags |= gl.DEPTH_BUFFER_BIT - } - if (stencil !== false) { - gl.clearStencil(stencil) - flags |= gl.STENCIL_BUFFER_BIT + default: + return null } - - gl.clear(flags) - - return gl } + return null } -},{"./defaults":36}],38:[function(require,module,exports){ -var raf = require('raf-component') - -module.exports = createContext - -function createContext(canvas, opts, render) { - if (typeof opts === 'function') { - render = opts - opts = {} - } else { - opts = opts || {} +exports.mallocUint8 = function mallocUint8(n) { + n = bits.nextPow2(n) + var log_n = bits.log2(n) + var cache = UINT8[log_n] + if(cache.length > 0) { + return cache.pop() } + return new Uint8Array(n) +} - var gl = ( - canvas.getContext('webgl', opts) || - canvas.getContext('webgl-experimental', opts) - ) - - if (!gl) { - throw new Error('Unable to initialize WebGL') +exports.mallocUint16 = function mallocUint16(n) { + n = bits.nextPow2(n) + var log_n = bits.log2(n) + var cache = UINT16[log_n] + if(cache.length > 0) { + return cache.pop() } + return new Uint16Array(n) +} - if (render) raf(tick) - - return gl - - function tick() { - render(gl) - raf(tick) +exports.mallocUint32 = function mallocUint32(n) { + n = bits.nextPow2(n) + var log_n = bits.log2(n) + var cache = UINT32[log_n] + if(cache.length > 0) { + return cache.pop() } + return new Uint32Array(n) } -},{"raf-component":39}],39:[function(require,module,exports){ -module.exports=require(33) -},{}],40:[function(require,module,exports){ -"use strict"; - -var webglew = require("webglew") -var createTexture = require("gl-texture2d") - -module.exports = createFBO - -var colorAttachmentArrays = null -var FRAMEBUFFER_UNSUPPORTED -var FRAMEBUFFER_INCOMPLETE_ATTACHMENT -var FRAMEBUFFER_INCOMPLETE_DIMENSIONS -var FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT +exports.mallocInt8 = function mallocInt8(n) { + n = bits.nextPow2(n) + var log_n = bits.log2(n) + var cache = INT8[log_n] + if(cache.length > 0) { + return cache.pop() + } + return new Int8Array(n) +} -function lazyInitColorAttachments(gl, ext) { - var maxColorAttachments = gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL); - colorAttachmentArrays = new Array(maxColorAttachments + 1) - for(var i=0; i<=maxColorAttachments; ++i) { - var x = new Array(maxColorAttachments) - for(var j=0; j 0) { + return cache.pop() } + return new Int16Array(n) } -//Throw an appropriate error -function throwFBOError(status) { - switch(status){ - case FRAMEBUFFER_UNSUPPORTED: - throw new Error("gl-fbo: Framebuffer unsupported") - case FRAMEBUFFER_INCOMPLETE_ATTACHMENT: - throw new Error("gl-fbo: Framebuffer incomplete attachment") - case FRAMEBUFFER_INCOMPLETE_DIMENSIONS: - throw new Error("gl-fbo: Framebuffer incomplete dimensions") - case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: - throw new Error("gl-fbo: Framebuffer incomplete missing attachment") - default: - throw new Error("gl-fbo: Framebuffer failed for unspecified reason") +exports.mallocInt32 = function mallocInt32(n) { + n = bits.nextPow2(n) + var log_n = bits.log2(n) + var cache = INT32[log_n] + if(cache.length > 0) { + return cache.pop() } + return new Int32Array(n) } -//Initialize a texture object -function initTexture(gl, width, height, type, format, attachment) { - if(!type) { - return null +exports.mallocFloat32 = exports.mallocFloat = function mallocFloat(n) { + n = bits.nextPow2(n) + var log_n = bits.log2(n) + var cache = FLOAT[log_n] + if(cache.length > 0) { + return cache.pop() } - var result = createTexture(gl, width, height, format, type) - result.magFilter = gl.NEAREST - result.minFilter = gl.NEAREST - result.mipSamples = 1 - gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, result.handle, 0) - gl.bindTexture(gl.TEXTURE_2D, null) - return result -} - -//Initialize a render buffer object -function initRenderBuffer(gl, width, height, component, attachment) { - var result = gl.createRenderbuffer() - gl.bindRenderbuffer(gl.RENDERBUFFER, result) - gl.renderbufferStorage(gl.RENDERBUFFER, component, width, height) - gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, result) - return result + return new Float32Array(n) } -//Rebuild the frame buffer -function rebuildFBO(fbo) { - var gl = fbo.gl - var handle = fbo.handle = gl.createFramebuffer() - var height = fbo._shape[0] - var width = fbo._shape[1] - var numColors = fbo.color.length - var ext = fbo._ext - var useStencil = fbo._useStencil - var useDepth = fbo._useDepth - var colorType = fbo._colorType - var extensions = webglew(gl) - - //Bind the fbo - gl.bindFramebuffer(gl.FRAMEBUFFER, handle) - - //Allocate color buffers - for(var i=0; i 1) { - ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]) +exports.mallocFloat64 = exports.mallocDouble = function mallocDouble(n) { + n = bits.nextPow2(n) + var log_n = bits.log2(n) + var cache = DOUBLE[log_n] + if(cache.length > 0) { + return cache.pop() } + return new Float64Array(n) +} - //Allocate depth/stencil buffers - if(extensions.WEBGL_depth_texture) { - if(useStencil) { - fbo.depth = initTexture(gl, width, height, - extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL, - gl.DEPTH_STENCIL, - gl.DEPTH_STENCIL_ATTACHMENT) - } else if(useDepth) { - fbo.depth = initTexture(gl, width, height, - gl.UNSIGNED_SHORT, - gl.DEPTH_COMPONENT, - gl.DEPTH_ATTACHMENT) - } - } else { - if(useDepth && useStencil) { - fbo._depth_rb = initRenderBuffer(gl, width, height, gl.DEPTH_STENCIL, gl.DEPTH_STENCIL_ATTACHMENT) - } else if(useDepth) { - fbo._depth_rb = initRenderBuffer(gl, width, height, gl.DEPTH_COMPONENT16, gl.DEPTH_ATTACHMENT) - } else if(useStencil) { - fbo._depth_rb = initRenderBuffer(gl, width, height, gl.STENCIL_INDEX, gl.STENCIL_ATTACHMENT) - } +exports.mallocArrayBuffer = function mallocArrayBuffer(n) { + n = bits.nextPow2(n) + var log_n = bits.log2(n) + var cache = DATA[log_n] + if(cache.length > 0) { + return cache.pop() } + return new ArrayBuffer(n) +} - //Check frame buffer state - var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER) - if(status !== gl.FRAMEBUFFER_COMPLETE) { - - //Release all partially allocated resources - fbo._destroyed = true - - //Release all resources - gl.bindFramebuffer(gl.FRAMEBUFFER, null) - gl.deleteFramebuffer(fbo.handle) - fbo.handle = null - if(fbo.depth) { - fbo.depth.dispose() - fbo.depth = null - } - if(fbo._depth_rb) { - gl.deleteRenderbuffer(fbo._depth_rb) - fbo._depth_rb = null - } - for(var i=0; i 0) { + return cache.pop() } - - //Throw the frame buffer error - throwFBOError(status) + return new Uint8ClampedArray(n) } - - //Everything ok, let's get on with life - gl.bindFramebuffer(gl.FRAMEBUFFER, null) -} - -function Framebuffer(gl, width, height, colorType, numColors, useDepth, useStencil, ext) { - var extensions = webglew(gl) - - //Handle and set properties - this.gl = gl - this._shape = [height|0, width|0] - this._destroyed = false - this._ext = ext - - //Allocate buffers - this.color = new Array(numColors) - this._color_rb = null - this.depth = null - this._depth_rb = null - - //Save depth and stencil flags - this._colorType = colorType - this._useDepth = useDepth - this._useStencil = useStencil - - //Initialize all attachments - rebuildFBO(this) +} else { + exports.mallocUint8Clamped = exports.mallocUint8 } -var proto = Framebuffer.prototype - -Object.defineProperty(proto, "valid", { - get: function() { - return !this._destroyed - } -}); - -Object.defineProperty(proto, "shape", { - get: function() { - if(this._destroyed) { - return [0,0] - } - return this._shape - }, - set: function(x) { - //If fbo is invalid, just skip this - if(this._destroyed) { - throw new Error("gl-fbo: Can't resize destroyed FBO") - } - - if (this._shape[0] === x[0]|0 && - this._shape[1] === x[1]|0) return - - var gl = this.gl - - //Check parameter ranges - var maxFBOSize = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE) - if(!Array.isArray(x) || x.length !== 2 || - x[0] < 0 || x[0] > maxFBOSize || - x[1] < 0 || x[1] > maxFBOSize) { - throw new Error("gl-fbo: Can't resize FBO, invalid dimensions") - } - - //Update shape - this._shape[0] = x[0]|0 - this._shape[1] = x[1]|0 - - //Resize framebuffer attachments - for(var i=0; i 0) { + return cache.pop() } -}) + return new Buffer(n) +} -proto.bind = function() { - if(this._destroyed) { - return +exports.clearCache = function clearCache() { + for(var i=0; i<32; ++i) { + UINT8[i].length = 0 + UINT16[i].length = 0 + UINT32[i].length = 0 + INT8[i].length = 0 + INT16[i].length = 0 + INT32[i].length = 0 + FLOAT[i].length = 0 + DOUBLE[i].length = 0 + DATA[i].length = 0 + UINT8C[i].length = 0 + BUFFER[i].length = 0 } - var gl = this.gl - gl.bindFramebuffer(gl.FRAMEBUFFER, this.handle) - gl.viewport(0, 0, this._shape[1], this._shape[0]) } - -proto.dispose = function() { - if(this._destroyed) { - return - } - this._destroyed = true - var gl = this.gl - gl.deleteFramebuffer(this.handle) - this.handle = null - if(this.depth) { - this.depth.dispose() - this.depth = null - } - if(this._depth_rb) { - gl.deleteRenderbuffer(this._depth_rb) - this._depth_rb = null - } - for(var i=0; i maxFBOSize || height < 0 || height > maxFBOSize) { - throw new Error("gl-fbo: Parameters are too large for FBO") - } - - //Handle each option type - options = options || {} - - //Figure out number of color buffers to use - var numColors = 1 - if("color" in options) { - numColors = Math.max(options.color|0, 0) - if(numColors < 0) { - throw new Error("gl-fbo: Must specify a nonnegative number of colors") - } - if(numColors > 1) { - //Check if multiple render targets supported - var mrtext = extensions.WEBGL_draw_buffers - if(!mrtext) { - throw new Error("gl-fbo: Multiple draw buffer extension not supported") - } else if(numColors > gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL)) { - throw new Error("gl-fbo: Context does not support " + numColors + " draw buffers") - } - } - } - - //Determine whether to use floating point textures - var colorType = gl.UNSIGNED_BYTE - if(options.float && numColors > 0) { - if(!extensions.OES_texture_float) { - throw new Error("gl-fbo: Context does not support floating point textures") - } - colorType = gl.FLOAT - } else if(options.preferFloat && numColors > 0) { - if(extensions.OES_texture_float) { - colorType = gl.FLOAT - } - } - - //Check if we should use depth buffer - var useDepth = true - if("depth" in options) { - useDepth = !!options.depth - } - - //Check if we should use a stencil buffer - var useStencil = false - if("stencil" in options) { - useStencil = !!options.stencil - } - - return new Framebuffer( - gl, - width, - height, - colorType, - numColors, - useDepth, - useStencil, - extensions.WEBGL_draw_buffers) -} -},{"gl-texture2d":81,"webglew":42}],41:[function(require,module,exports){ +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) +},{"bit-twiddle":39,"buffer":189,"dup":40}],42:[function(require,module,exports){ /* (The MIT License) * * Copyright (c) 2012 Brandon Benvie @@ -4184,7 +3946,7 @@ void function(global, undefined_, undefined){ global.WeakMap.createStorage = createStorage; }((0, eval)('this')); -},{}],42:[function(require,module,exports){ +},{}],43:[function(require,module,exports){ "use strict"; var weakMap = typeof WeakMap === "undefined" ? require("weakmap") : WeakMap @@ -4221,5921 +3983,7853 @@ function initWebGLEW(gl) { return extensions } module.exports = initWebGLEW -},{"weakmap":41}],43:[function(require,module,exports){ -var normalize = require('./normalize') -var createVAO = require('gl-vao') +},{"weakmap":42}],44:[function(require,module,exports){ +module.exports = defaults -module.exports = GLGeometry +function defaults(opts) { + return { + color: array(opts.color, [0, 0, 0, 1]) + , depth: number(opts.depth, 1) + , stencil: number(opts.stencil, false) + } +} -function GLGeometry(gl) { - if (!(this instanceof GLGeometry)) - return new GLGeometry(gl) +function number(n, def) { + return n === false + ? false + : typeof n === 'undefined' + ? def + : n + 0 +} - this._attributes = [] - this._dirty = true - this._length = 0 - this._index = null - this._vao = null - this._keys = [] - this.gl = gl +function array(a, def) { + return a === false + ? false + : Array.isArray(a) + ? a || def + : def } -GLGeometry.prototype.faces = function faces(attr, opts) { - var size = opts && opts.size || 3 - attr = attr.cells ? attr.cells : attr +},{}],45:[function(require,module,exports){ +var defaults = require('./defaults') - this._dirty = true - this._index = normalize(this.gl - , attr - , size - , this.gl.ELEMENT_ARRAY_BUFFER - , 'uint16' - ) +module.exports = clear - this._length = this._index.length * size - this._index = this._index.buffer +function clear(opts) { + opts = defaults(opts || {}) - return this -} + var stencil = opts.stencil + var color = opts.color + var depth = opts.depth -GLGeometry.prototype.attr = function attr(name, attr, opts) { - opts = opts || {} - this._dirty = true + return function clear(gl) { + var flags = 0 - var gl = this.gl - var first = !this._attributes.length - var size = opts.size || 3 + if (color !== false) { + gl.clearColor(color[0], color[1], color[2], color[3]) + flags |= gl.COLOR_BUFFER_BIT + } + if (depth !== false) { + gl.clearDepth(depth) + flags |= gl.DEPTH_BUFFER_BIT + } + if (stencil !== false) { + gl.clearStencil(stencil) + flags |= gl.STENCIL_BUFFER_BIT + } - var attribute = normalize(gl, attr, size) - if (!attribute) { - throw new Error( - 'Unexpected attribute format: needs an ndarray, array, typed array, ' - + 'gl-buffer or simplicial complex' - ) + gl.clear(flags) + + return gl } +} - var buffer = attribute.buffer - var length = attribute.length - var index = attribute.index +},{"./defaults":44}],46:[function(require,module,exports){ +var raf = require('raf-component') - this._keys.push(name) - this._attributes.push({ - size: size - , buffer: buffer - }) +module.exports = createContext - if (first) { - this._length = length +function createContext(canvas, opts, render) { + if (typeof opts === 'function') { + render = opts + opts = {} + } else { + opts = opts || {} } - if (first && index) { - this._index = index - } + var gl = ( + canvas.getContext('webgl', opts) || + canvas.getContext('webgl-experimental', opts) + ) - return this -} + if (!gl) { + throw new Error('Unable to initialize WebGL') + } -GLGeometry.prototype.bind = function bind(shader) { - this.update() - this._vao.bind() + if (render) raf(tick) - if (!shader) return - shader.bind() + return gl - if (!this._keys) return - for (var i = 0; i < this._keys.length; i++) { - var attr = shader.attributes[this._keys[i]] - if (attr) attr.location = i + function tick() { + render(gl) + raf(tick) } } -GLGeometry.prototype.draw = function draw(mode) { - this.update() - this._vao.draw(mode || this.gl.TRIANGLES, this._length) -} +},{"raf-component":47}],47:[function(require,module,exports){ +module.exports=require(28) +},{}],48:[function(require,module,exports){ +'use strict' -GLGeometry.prototype.unbind = function unbind() { - this.update() - this._vao.unbind() -} +var webglew = require('webglew') +var createTexture = require('gl-texture2d') -GLGeometry.prototype.update = function update() { - if (!this._dirty) return - this._dirty = false - if (this._vao) this._vao.dispose() - - this._vao = createVAO( - this.gl - , this._attributes - , this._index - ) -} +module.exports = createFBO -},{"./normalize":67,"gl-vao":64}],44:[function(require,module,exports){ -var dtype = require('dtype') +var colorAttachmentArrays = null +var FRAMEBUFFER_UNSUPPORTED +var FRAMEBUFFER_INCOMPLETE_ATTACHMENT +var FRAMEBUFFER_INCOMPLETE_DIMENSIONS +var FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT -module.exports = pack +function saveFBOState(gl) { + var fbo = gl.getParameter(gl.FRAMEBUFFER_BINDING) + var rbo = gl.getParameter(gl.RENDERBUFFER_BINDING) + var tex = gl.getParameter(gl.TEXTURE_BINDING_2D) + return [fbo, rbo, tex] +} -function pack(arr, type) { - type = type || 'float32' +function restoreFBOState(gl, data) { + gl.bindFramebuffer(gl.FRAMEBUFFER, data[0]) + gl.bindRenderbuffer(gl.RENDERBUFFER, data[1]) + gl.bindTexture(gl.TEXTURE_2D, data[2]) +} - if (!arr[0] || !arr[0].length) { - return arr +function lazyInitColorAttachments(gl, ext) { + var maxColorAttachments = gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL) + colorAttachmentArrays = new Array(maxColorAttachments + 1) + for(var i=0; i<=maxColorAttachments; ++i) { + var x = new Array(maxColorAttachments) + for(var j=0; j len) { - throw new Error("gl-buffer: If resizing buffer, must not specify offset") + if(numColors === 0) { + fbo._color_rb = initRenderBuffer(gl, width, height, gl.RGBA4, gl.COLOR_ATTACHMENT0) + if(ext) { + ext.drawBuffersWEBGL(colorAttachmentArrays[0]) + } + } else if(numColors > 1) { + ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]) } - gl.bufferSubData(type, offset, data) - return len -} -function makeScratchTypeArray(array, dtype) { - var res = pool.malloc(array.length, dtype) - var n = array.length - for(var i=0; i=0; --i) { - if(stride[i] !== n) { - return false + //Check frame buffer state + var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER) + if(status !== gl.FRAMEBUFFER_COMPLETE) { + + //Release all partially allocated resources + fbo._destroyed = true + + //Release all resources + gl.bindFramebuffer(gl.FRAMEBUFFER, null) + gl.deleteFramebuffer(fbo.handle) + fbo.handle = null + if(fbo.depth) { + fbo.depth.dispose() + fbo.depth = null } - n *= shape[i] + if(fbo._depth_rb) { + gl.deleteRenderbuffer(fbo._depth_rb) + fbo._depth_rb = null + } + for(var i=0; i= 0) { - throw new Error("gl-buffer: Cannot specify offset when resizing buffer") - } - array = array | 0 - if(array <= 0) { - array = 1 - } - this.gl.bufferData(this.type, array|0, this.usage) - this.length = array - } else { //Error, case should not happen - throw new Error("gl-buffer: Invalid data type") - } -} + }) + this._shapeVector = shapeVector -function createBuffer(gl, data, type, usage) { - webglew(gl) - type = type || gl.ARRAY_BUFFER - usage = usage || gl.DYNAMIC_DRAW - if(type !== gl.ARRAY_BUFFER && type !== gl.ELEMENT_ARRAY_BUFFER) { - throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER") - } - if(usage !== gl.DYNAMIC_DRAW && usage !== gl.STATIC_DRAW && usage !== gl.STREAM_DRAW) { - throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW") - } - var handle = gl.createBuffer() - var result = new GLBuffer(gl, type, handle, 0, usage) - result.update(data) - return result + //Initialize all attachments + rebuildFBO(this) } -module.exports = createBuffer -},{"ndarray":52,"ndarray-ops":47,"typedarray-pool":56,"webglew":58}],47:[function(require,module,exports){ -arguments[4][9][0].apply(exports,arguments) -},{"cwise-compiler":48}],48:[function(require,module,exports){ -arguments[4][10][0].apply(exports,arguments) -},{"./lib/thunk.js":50}],49:[function(require,module,exports){ -arguments[4][11][0].apply(exports,arguments) -},{"uniq":51}],50:[function(require,module,exports){ -arguments[4][12][0].apply(exports,arguments) -},{"./compile.js":49}],51:[function(require,module,exports){ -module.exports=require(13) -},{}],52:[function(require,module,exports){ -arguments[4][14][0].apply(exports,arguments) -},{"buffer":106,"iota-array":53}],53:[function(require,module,exports){ -module.exports=require(15) -},{}],54:[function(require,module,exports){ -module.exports=require(16) -},{}],55:[function(require,module,exports){ -module.exports=require(17) -},{}],56:[function(require,module,exports){ -(function (global,Buffer){ -var bits = require("bit-twiddle") -var dup = require("dup") -if(!global.__TYPEDARRAY_POOL) { - global.__TYPEDARRAY_POOL = { - UINT8 : dup([32, 0]) - , UINT16 : dup([32, 0]) - , UINT32 : dup([32, 0]) - , INT8 : dup([32, 0]) - , INT16 : dup([32, 0]) - , INT32 : dup([32, 0]) - , FLOAT : dup([32, 0]) - , DOUBLE : dup([32, 0]) - , DATA : dup([32, 0]) - , UINT8C : dup([32, 0]) - , BUFFER : dup([32, 0]) +var proto = Framebuffer.prototype + +function reshapeFBO(fbo, w, h) { + //If fbo is invalid, just skip this + if(fbo._destroyed) { + throw new Error('gl-fbo: Can\'t resize destroyed FBO') } -} -var hasUint8C = (typeof Uint8ClampedArray) !== "undefined" -var POOL = global.__TYPEDARRAY_POOL -if(!POOL.UINT8C) { - POOL.UINT8C = dup([32, 0]) -} -if(!POOL.BUFFER) { - POOL.BUFFER = dup([32, 0]) -} -var UINT8 = POOL.UINT8 - , UINT16 = POOL.UINT16 - , UINT32 = POOL.UINT32 - , INT8 = POOL.INT8 - , INT16 = POOL.INT16 - , INT32 = POOL.INT32 - , FLOAT = POOL.FLOAT - , DOUBLE = POOL.DOUBLE - , DATA = POOL.DATA - , UINT8C = POOL.UINT8C - , BUFFER = POOL.BUFFER -exports.free = function free(array) { - var n = array.length|0 - , log_n = bits.log2(n) - if(Buffer.isBuffer(array)) { - BUFFER[log_n].push(array) - } else { - switch(Object.prototype.toString.call(array)) { - case "[object Uint8Array]": - UINT8[log_n].push(array) - break - case "[object Uint16Array]": - UINT16[log_n].push(array) - break - case "[object Uint32Array]": - UINT32[log_n].push(array) - break - case "[object Int8Array]": - INT8[log_n].push(array) - break - case "[object Int16Array]": - INT16[log_n].push(array) - break - case "[object Int32Array]": - INT32[log_n].push(array) - break - case "[object Uint8ClampedArray]": - UINT8C[log_n].push(array) - break - case "[object Float32Array]": - FLOAT[log_n].push(array) - break - case "[object Float64Array]": - DOUBLE[log_n].push(array) - break - case "[object ArrayBuffer]": - DATA[log_n].push(array) - break - default: - throw new Error("typedarray-pool: Unspecified array type") - } + //Don't resize if no change in shape + if( (fbo._shape[0] === w) && + (fbo._shape[1] === h) ) { + return } -} -exports.freeUint8 = function freeUint8(array) { - UINT8[bits.log2(array.length)].push(array) -} + var gl = fbo.gl + + //Check parameter ranges + var maxFBOSize = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE) + if( w < 0 || w > maxFBOSize || + h < 0 || h > maxFBOSize) { + throw new Error('gl-fbo: Can\'t resize FBO, invalid dimensions') + } -exports.freeUint16 = function freeUint16(array) { - UINT16[bits.log2(array.length)].push(array) -} + //Update shape + fbo._shape[0] = w + fbo._shape[1] = h -exports.freeUint32 = function freeUint32(array) { - UINT32[bits.log2(array.length)].push(array) -} + //Save framebuffer state + var state = saveFBOState(gl) -exports.freeInt8 = function freeInt8(array) { - INT8[bits.log2(array.length)].push(array) -} + //Resize framebuffer attachments + for(var i=0; i 0) { - var r = d[d.length-1] - d.pop() - return r - } - return new ArrayBuffer(n) - } else { - switch(dtype) { - case "uint8": - var u8 = UINT8[log_n] - if(u8.length > 0) { - return u8.pop() - } - return new Uint8Array(n) - break - - case "uint16": - var u16 = UINT16[log_n] - if(u16.length > 0) { - return u16.pop() - } - return new Uint16Array(n) - break - - case "uint32": - var u32 = UINT32[log_n] - if(u32.length > 0) { - return u32.pop() - } - return new Uint32Array(n) - break - - case "int8": - var i8 = INT8[log_n] - if(i8.length > 0) { - return i8.pop() - } - return new Int8Array(n) - break - - case "int16": - var i16 = INT16[log_n] - if(i16.length > 0) { - return i16.pop() - } - return new Int16Array(n) - break +function createFBO(gl, width, height, options) { - case "int32": - var i32 = INT32[log_n] - if(i32.length > 0) { - return i32.pop() - } - return new Int32Array(n) - break + //Update frame buffer error code values + if(!FRAMEBUFFER_UNSUPPORTED) { + FRAMEBUFFER_UNSUPPORTED = gl.FRAMEBUFFER_UNSUPPORTED + FRAMEBUFFER_INCOMPLETE_ATTACHMENT = gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT + FRAMEBUFFER_INCOMPLETE_DIMENSIONS = gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS + FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT + } - case "float": - case "float32": - var f = FLOAT[log_n] - if(f.length > 0) { - return f.pop() - } - return new Float32Array(n) - break + var extensions = webglew(gl) + + //Lazily initialize color attachment arrays + if(!colorAttachmentArrays && extensions.WEBGL_draw_buffers) { + lazyInitColorAttachments(gl, extensions.WEBGL_draw_buffers) + } - case "double": - case "float64": - var dd = DOUBLE[log_n] - if(dd.length > 0) { - return dd.pop() - } - return new Float64Array(n) - break + //Special case: Can accept an array as argument + if(Array.isArray(width)) { + options = height + height = width[1]|0 + width = width[0]|0 + } + + if(typeof width !== 'number') { + throw new Error('gl-fbo: Missing shape parameter') + } - case "uint8_clamped": - if(hasUint8C) { - var u8c = UINT8C[log_n] - if(u8c.length > 0) { - return u8c.pop() - } - return new Uint8ClampedArray(n) - } else { - var u8 = UINT8[log_n] - if(u8.length > 0) { - return u8.pop() - } - return new Uint8Array(n) - } - break + //Validate width/height properties + var maxFBOSize = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE) + if(width < 0 || width > maxFBOSize || height < 0 || height > maxFBOSize) { + throw new Error('gl-fbo: Parameters are too large for FBO') + } - case "buffer": - var buf = BUFFER[log_n] - if(buf.length > 0) { - return buf.pop() - } - return new Buffer(n) - break + //Handle each option type + options = options || {} - default: - return null + //Figure out number of color buffers to use + var numColors = 1 + if('color' in options) { + numColors = Math.max(options.color|0, 0) + if(numColors < 0) { + throw new Error('gl-fbo: Must specify a nonnegative number of colors') + } + if(numColors > 1) { + //Check if multiple render targets supported + var mrtext = extensions.WEBGL_draw_buffers + if(!mrtext) { + throw new Error('gl-fbo: Multiple draw buffer extension not supported') + } else if(numColors > gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL)) { + throw new Error('gl-fbo: Context does not support ' + numColors + ' draw buffers') + } } } - return null -} -exports.mallocUint8 = function mallocUint8(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = UINT8[log_n] - if(cache.length > 0) { - return cache.pop() + //Determine whether to use floating point textures + var colorType = gl.UNSIGNED_BYTE + if(options.float && numColors > 0) { + if(!extensions.OES_texture_float) { + throw new Error('gl-fbo: Context does not support floating point textures') + } + colorType = gl.FLOAT + } else if(options.preferFloat && numColors > 0) { + if(extensions.OES_texture_float) { + colorType = gl.FLOAT + } } - return new Uint8Array(n) -} -exports.mallocUint16 = function mallocUint16(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = UINT16[log_n] - if(cache.length > 0) { - return cache.pop() + //Check if we should use depth buffer + var useDepth = true + if('depth' in options) { + useDepth = !!options.depth } - return new Uint16Array(n) -} -exports.mallocUint32 = function mallocUint32(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = UINT32[log_n] - if(cache.length > 0) { - return cache.pop() + //Check if we should use a stencil buffer + var useStencil = false + if('stencil' in options) { + useStencil = !!options.stencil } - return new Uint32Array(n) + + return new Framebuffer( + gl, + width, + height, + colorType, + numColors, + useDepth, + useStencil, + extensions.WEBGL_draw_buffers) } +},{"gl-texture2d":59,"webglew":61}],49:[function(require,module,exports){ +arguments[4][9][0].apply(exports,arguments) +},{"cwise-compiler":50}],50:[function(require,module,exports){ +arguments[4][10][0].apply(exports,arguments) +},{"./lib/thunk.js":52}],51:[function(require,module,exports){ +arguments[4][11][0].apply(exports,arguments) +},{"uniq":53}],52:[function(require,module,exports){ +arguments[4][12][0].apply(exports,arguments) +},{"./compile.js":51}],53:[function(require,module,exports){ +module.exports=require(13) +},{}],54:[function(require,module,exports){ +arguments[4][14][0].apply(exports,arguments) +},{"buffer":189,"iota-array":55}],55:[function(require,module,exports){ +module.exports=require(15) +},{}],56:[function(require,module,exports){ +module.exports=require(16) +},{}],57:[function(require,module,exports){ +module.exports=require(17) +},{}],58:[function(require,module,exports){ +module.exports=require(41) +},{"bit-twiddle":56,"buffer":189,"dup":57}],59:[function(require,module,exports){ +'use strict' -exports.mallocInt8 = function mallocInt8(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = INT8[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Int8Array(n) +var ndarray = require('ndarray') +var ops = require('ndarray-ops') +var pool = require('typedarray-pool') +var webglew = require('webglew') + +module.exports = createTexture2D + +var linearTypes = null +var filterTypes = null +var wrapTypes = null + +function lazyInitLinearTypes(gl) { + linearTypes = [ + gl.LINEAR, + gl.NEAREST_MIPMAP_LINEAR, + gl.LINEAR_MIPMAP_NEAREST, + gl.LINEAR_MIPMAP_NEAREST + ] + filterTypes = [ + gl.NEAREST, + gl.LINEAR, + gl.NEAREST_MIPMAP_NEAREST, + gl.NEAREST_MIPMAP_LINEAR, + gl.LINEAR_MIPMAP_NEAREST, + gl.LINEAR_MIPMAP_LINEAR + ] + wrapTypes = [ + gl.REPEAT, + gl.CLAMP_TO_EDGE, + gl.MIRRORED_REPEAT + ] } -exports.mallocInt16 = function mallocInt16(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = INT16[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Int16Array(n) +var convertFloatToUint8 = function(out, inp) { + ops.muls(out, inp, 255.0) } -exports.mallocInt32 = function mallocInt32(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = INT32[log_n] - if(cache.length > 0) { - return cache.pop() +function reshapeTexture(tex, w, h) { + var gl = tex.gl + var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) + if(w < 0 || w > maxSize || h < 0 || h > maxSize) { + throw new Error("gl-texture2d: Invalid texture size") } - return new Int32Array(n) + tex._shape = [w, h] + tex.bind() + gl.texImage2D(gl.TEXTURE_2D, 0, tex.format, w, h, 0, tex.format, tex.type, null) + tex._mipLevels = [0] + return tex } -exports.mallocFloat32 = exports.mallocFloat = function mallocFloat(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = FLOAT[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Float32Array(n) -} +function Texture2D(gl, handle, width, height, format, type) { + this.gl = gl + this.handle = handle + this.format = format + this.type = type + this._shape = [width, height] + this._mipLevels = [0] + this._magFilter = gl.NEAREST + this._minFilter = gl.NEAREST + this._wrapS = gl.CLAMP_TO_EDGE + this._wrapT = gl.CLAMP_TO_EDGE + this._anisoSamples = 1 -exports.mallocFloat64 = exports.mallocDouble = function mallocDouble(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = DOUBLE[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Float64Array(n) + var parent = this + var wrapVector = [this._wrapS, this._wrapT] + Object.defineProperties(wrapVector, { + "0": { + get: function() { + return parent._wrapS + }, + set: function(v) { + return parent.wrapS = v + } + }, + "1": { + get: function() { + return parent._wrapT + }, + set: function(v) { + return parent.wrapT = v + } + } + }) + this._wrapVector = wrapVector + + var shapeVector = [this._shape[0], this._shape[1]] + Object.defineProperties(shapeVector, { + "0": { + get: function() { + return parent._shape[0] + }, + set: function(v) { + return parent.width = v + } + }, + "1" : { + get: function() { + return parent._shape[1] + }, + set: function(v) { + return parent.height = v + } + } + }) + this._shapeVector = shapeVector } -exports.mallocArrayBuffer = function mallocArrayBuffer(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = DATA[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new ArrayBuffer(n) -} +var proto = Texture2D.prototype -if(hasUint8C) { - exports.mallocUint8Clamped = function mallocUint8Clamped(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = UINT8C[log_n] - if(cache.length > 0) { - return cache.pop() +Object.defineProperties(proto, { + "minFilter": { + get: function() { + return this._minFilter + }, + set: function(v) { + this.bind() + var gl = this.gl + if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) { + if(!webglew(gl).OES_texture_float_linear) { + v = gl.NEAREST + } + } + if(filterTypes.indexOf(v) < 0) { + throw new Error("gl-texture2d: Unknown filter mode " + v) + } + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, v) + return this._minFilter = v } - return new Uint8ClampedArray(n) - } -} else { - exports.mallocUint8Clamped = exports.mallocUint8 -} - -exports.mallocBuffer = function mallocBuffer(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = BUFFER[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Buffer(n) -} + }, + "magFilter": { + get: function() { + return this._magFilter + }, + set: function(v) { + this.bind() + var gl = this.gl + if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) { + if(!webglew(gl).OES_texture_float_linear) { + v = gl.NEAREST + } + } + if(filterTypes.indexOf(v) < 0) { + throw new Error("gl-texture2d: Unknown filter mode " + v) + } + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, v) + return this._magFilter = v + } + }, + "mipSamples": { + get: function() { + return this._anisoSamples + }, + set: function(i) { + var psamples = this._anisoSamples + this._anisoSamples = Math.max(i, 1)|0 + if(psamples !== this._anisoSamples) { + var ext = webglew(this.gl).EXT_texture_filter_anisotropic + if(ext) { + this.gl.texParameterf(this.gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, this._anisoSamples) + } + } + return this._anisoSamples + } + }, + "wrapS": { + get: function() { + return this._wrapS + }, + set: function(v) { + this.bind() + if(wrapTypes.indexOf(v) < 0) { + throw new Error("gl-texture2d: Unknown wrap mode " + v) + } + this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, v) + return this._wrapS = v + } + }, + "wrapT": { + get: function() { + return this._wrapT + }, + set: function(v) { + this.bind() + if(wrapTypes.indexOf(v) < 0) { + throw new Error("gl-texture2d: Unknown wrap mode " + v) + } + this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, v) + return this._wrapT = v + } + }, + "wrap": { + get: function() { + return this._wrapVector + }, + set: function(v) { + if(!Array.isArray(v)) { + v = [v,v] + } + if(v.length !== 2) { + throw new Error("gl-texture2d: Must specify wrap mode for rows and columns") + } + for(var i=0; i<2; ++i) { + if(wrapTypes.indexOf(v[i]) < 0) { + throw new Error("gl-texture2d: Unknown wrap mode " + v) + } + } + this._wrapS = v[0] + this._wrapT = v[1] -exports.clearCache = function clearCache() { - for(var i=0; i<32; ++i) { - UINT8[i].length = 0 - UINT16[i].length = 0 - UINT32[i].length = 0 - INT8[i].length = 0 - INT16[i].length = 0 - INT32[i].length = 0 - FLOAT[i].length = 0 - DOUBLE[i].length = 0 - DATA[i].length = 0 - UINT8C[i].length = 0 - BUFFER[i].length = 0 - } -} -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) -},{"bit-twiddle":54,"buffer":106,"dup":55}],57:[function(require,module,exports){ -module.exports=require(41) -},{}],58:[function(require,module,exports){ -module.exports=require(42) -},{"weakmap":57}],59:[function(require,module,exports){ -"use strict" + var gl = this.gl + this.bind() + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this._wrapS) + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this._wrapT) -function doBind(gl, elements, attributes) { - if(elements) { - elements.bind() - } else { - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null) - } - var nattribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS)|0 - if(attributes) { - if(attributes.length > nattribs) { - throw new Error("gl-vao: Too many vertex attributes") + return v } - for(var i=0; i0; ++i, l>>>=1) { + if(this._mipLevels.indexOf(i) < 0) { + this._mipLevels.push(i) + } + } } -VAOEmulated.prototype.dispose = function() { } -VAOEmulated.prototype.unbind = function() { } - -VAOEmulated.prototype.draw = function(mode, count, offset) { - offset = offset || 0 +proto.setPixels = function(data, x_off, y_off, mip_level) { var gl = this.gl - if(this._elements) { - gl.drawElements(mode, count, gl.UNSIGNED_SHORT, offset) + this.bind() + if(Array.isArray(x_off)) { + mip_level = y_off + y_off = x_off[1]|0 + x_off = x_off[0]|0 } else { - gl.drawArrays(mode, offset, count) + x_off = x_off || 0 + y_off = y_off || 0 + } + mip_level = mip_level || 0 + if(data instanceof HTMLCanvasElement || + data instanceof ImageData || + data instanceof HTMLImageElement || + data instanceof HTMLVideoElement) { + var needsMip = this._mipLevels.indexOf(mip_level) < 0 + if(needsMip) { + gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, data) + this._mipLevels.push(mip_level) + } else { + gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, this.format, this.type, data) + } + } else if(data.shape && data.stride && data.data) { + if(data.shape.length < 2 || + x_off + data.shape[1] > this._shape[1]>>>mip_level || + y_off + data.shape[0] > this._shape[0]>>>mip_level || + x_off < 0 || + y_off < 0) { + throw new Error("gl-texture2d: Texture dimensions are out of bounds") + } + texSubImageArray(gl, x_off, y_off, mip_level, this.format, this.type, this._mipLevels, data) + } else { + throw new Error("gl-texture2d: Unsupported data type") } } -function createVAOEmulated(gl) { - return new VAOEmulated(gl) -} - -module.exports = createVAOEmulated -},{"./do-bind.js":59}],61:[function(require,module,exports){ -"use strict" -var bindAttribs = require("./do-bind.js") +function isPacked(shape, stride) { + if(shape.length === 3) { + return (stride[2] === 1) && + (stride[1] === shape[0]*shape[2]) && + (stride[0] === shape[2]) + } + return (stride[0] === 1) && + (stride[1] === shape[0]) +} -function VertexAttribute(location, dimension, a, b, c, d) { - this.location = location - this.dimension = dimension - this.a = a - this.b = b - this.c = c - this.d = d -} - -VertexAttribute.prototype.bind = function(gl) { - switch(this.dimension) { - case 1: - gl.vertexAttrib1f(this.location, this.a) - break - case 2: - gl.vertexAttrib2f(this.location, this.a, this.b) - break - case 3: - gl.vertexAttrib3f(this.location, this.a, this.b, this.c) - break - case 4: - gl.vertexAttrib4f(this.location, this.a, this.b, this.c, this.d) - break +function texSubImageArray(gl, x_off, y_off, mip_level, cformat, ctype, mipLevels, array) { + var dtype = array.dtype + var shape = array.shape.slice() + if(shape.length < 2 || shape.length > 3) { + throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d") + } + var type = 0, format = 0 + var packed = isPacked(shape, array.stride.slice()) + if(dtype === "float32") { + type = gl.FLOAT + } else if(dtype === "float64") { + type = gl.FLOAT + packed = false + dtype = "float32" + } else if(dtype === "uint8") { + type = gl.UNSIGNED_BYTE + } else { + type = gl.UNSIGNED_BYTE + packed = false + dtype = "uint8" + } + var channels = 1 + if(shape.length === 2) { + format = gl.LUMINANCE + shape = [shape[0], shape[1], 1] + array = ndarray(array.data, shape, [array.stride[0], array.stride[1], 1], array.offset) + } else if(shape.length === 3) { + if(shape[2] === 1) { + format = gl.ALPHA + } else if(shape[2] === 2) { + format = gl.LUMINANCE_ALPHA + } else if(shape[2] === 3) { + format = gl.RGB + } else if(shape[2] === 4) { + format = gl.RGBA + } else { + throw new Error("gl-texture2d: Invalid shape for pixel coords") + } + channels = shape[2] + } else { + throw new Error("gl-texture2d: Invalid shape for texture") + } + //For 1-channel textures allow conversion between formats + if((format === gl.LUMINANCE || format === gl.ALPHA) && + (cformat === gl.LUMINANCE || cformat === gl.ALPHA)) { + format = cformat + } + if(format !== cformat) { + throw new Error("gl-texture2d: Incompatible texture format for setPixels") + } + var size = array.size + var needsMip = mipLevels.indexOf(mip_level) < 0 + if(needsMip) { + mipLevels.push(mip_level) + } + if(type === ctype && packed) { + //Array data types are compatible, can directly copy into texture + if(array.offset === 0 && array.data.length === size) { + if(needsMip) { + gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[0], shape[1], 0, cformat, ctype, array.data) + } else { + gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[0], shape[1], cformat, ctype, array.data) + } + } else { + if(needsMip) { + gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[0], shape[1], 0, cformat, ctype, array.data.subarray(array.offset, array.offset+size)) + } else { + gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[0], shape[1], cformat, ctype, array.data.subarray(array.offset, array.offset+size)) + } + } + } else { + //Need to do type conversion to pack data into buffer + var pack_buffer + if(ctype === gl.FLOAT) { + pack_buffer = pool.mallocFloat32(size) + } else { + pack_buffer = pool.mallocUint8(size) + } + var pack_view = ndarray(pack_buffer, shape, [shape[2], shape[2]*shape[0], 1]) + if(type === gl.FLOAT && ctype === gl.UNSIGNED_BYTE) { + convertFloatToUint8(pack_view, array) + } else { + ops.assign(pack_view, array) + } + if(needsMip) { + gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[0], shape[1], 0, cformat, ctype, pack_buffer.subarray(0, size)) + } else { + gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[0], shape[1], cformat, ctype, pack_buffer.subarray(0, size)) + } + if(ctype === gl.FLOAT) { + pool.freeFloat32(pack_buffer) + } else { + pool.freeUint8(pack_buffer) + } } } -function VAONative(gl, ext, handle) { - this.gl = gl - this._ext = ext - this.handle = handle - this._attribs = [] - this._useElements = false +function initTexture(gl) { + var tex = gl.createTexture() + gl.bindTexture(gl.TEXTURE_2D, tex) + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) + return tex } -VAONative.prototype.bind = function() { - this._ext.bindVertexArrayOES(this.handle) - for(var i=0; i maxTextureSize || height < 0 || height > maxTextureSize) { + throw new Error("gl-texture2d: Invalid texture shape") } + var tex = initTexture(gl) + gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, type, null) + return new Texture2D(gl, tex, width, height, format, type) } -VAONative.prototype.unbind = function() { - this._ext.bindVertexArrayOES(null) -} - -VAONative.prototype.dispose = function() { - this._ext.deleteVertexArrayOES(this.handle) +function createTextureDOM(gl, element, format, type) { + var tex = initTexture(gl) + gl.texImage2D(gl.TEXTURE_2D, 0, format, format, type, element) + return new Texture2D(gl, tex, element.width|0, element.height|0, format, type) } -VAONative.prototype.update = function(attributes, elements) { - this.bind() - bindAttribs(this.gl, elements, attributes) - this.unbind() - this._attribs.length = 0 - if(attributes) - for(var i=0; i maxSize || shape[1] < 0 || shape[1] > maxSize) { + throw new Error("gl-texture2d: Invalid texture size") + } + var packed = isPacked(shape, array.stride.slice()) + var type = 0 + if(dtype === "float32") { + type = gl.FLOAT + } else if(dtype === "float64") { + type = gl.FLOAT + packed = false + dtype = "float32" + } else if(dtype === "uint8") { + type = gl.UNSIGNED_BYTE + } else { + type = gl.UNSIGNED_BYTE + packed = false + dtype = "uint8" + } + var format = 0 + if(shape.length === 2) { + format = gl.LUMINANCE + shape = [shape[0], shape[1], 1] + array = ndarray(array.data, shape, [array.stride[0], array.stride[1], 1], array.offset) + } else if(shape.length === 3) { + if(shape[2] === 1) { + format = gl.ALPHA + } else if(shape[2] === 2) { + format = gl.LUMINANCE_ALPHA + } else if(shape[2] === 3) { + format = gl.RGB + } else if(shape[2] === 4) { + format = gl.RGBA + } else { + throw new Error("Invalid shape for pixel coords") } + } else { + throw new Error("Invalid shape for texture") } - this._useElements = !!elements -} - -VAONative.prototype.draw = function(mode, count, offset) { - offset = offset || 0 - var gl = this.gl - if(this._useElements) { - gl.drawElements(mode, count, gl.UNSIGNED_SHORT, offset) + if(type === gl.FLOAT && !webglew(gl).texture_float) { + type = gl.UNSIGNED_BYTE + packed = false + } + var buffer, buf_store + var size = array.size + if(!packed) { + var stride = [shape[2], shape[2]*shape[0], 1] + buf_store = pool.malloc(size, dtype) + var buf_array = ndarray(buf_store, shape, stride, 0) + if((dtype === "float32" || dtype === "float64") && type === gl.UNSIGNED_BYTE) { + convertFloatToUint8(buf_array, array) + } else { + ops.assign(buf_array, array) + } + buffer = buf_store.subarray(0, size) + } else if (array.offset === 0 && array.data.length === size) { + buffer = array.data } else { - gl.drawArrays(mode, offset, count) + buffer = array.data.subarray(array.offset, array.offset + size) + } + var tex = initTexture(gl) + gl.texImage2D(gl.TEXTURE_2D, 0, format, shape[0], shape[1], 0, format, type, buffer) + if(!packed) { + pool.free(buf_store) } + return new Texture2D(gl, tex, shape[1], shape[0], format, type) } -function createVAONative(gl, ext) { - return new VAONative(gl, ext, ext.createVertexArrayOES()) +function createTexture2D(gl) { + if(arguments.length <= 1) { + throw new Error("Missing arguments for texture2d constructor") + } + if(!linearTypes) { + lazyInitLinearTypes(gl) + } + if(typeof arguments[1] === "number") { + return createTextureShape(gl, arguments[1], arguments[2], arguments[3]||gl.RGBA, arguments[4]||gl.UNSIGNED_BYTE) + } + if(Array.isArray(arguments[1])) { + return createTextureShape(gl, arguments[1][0]|0, arguments[1][1]|0, arguments[2]||gl.RGBA, arguments[4]||gl.UNSIGNED_BYTE) + } + if(typeof arguments[1] === "object") { + var obj = arguments[1] + if(obj instanceof HTMLCanvasElement || + obj instanceof HTMLImageElement || + obj instanceof HTMLVideoElement || + obj instanceof ImageData) { + return createTextureDOM(gl, obj, arguments[2]||gl.RGBA, arguments[3]||gl.UNSIGNED_BYTE) + } else if(obj.shape && obj.data && obj.stride) { + return createTextureArray(gl, obj) + } + } + throw new Error("Invalid arguments for texture2d constructor") } - -module.exports = createVAONative -},{"./do-bind.js":59}],62:[function(require,module,exports){ +},{"ndarray":54,"ndarray-ops":49,"typedarray-pool":58,"webglew":61}],60:[function(require,module,exports){ +module.exports=require(42) +},{}],61:[function(require,module,exports){ +module.exports=require(43) +},{"weakmap":60}],62:[function(require,module,exports){ +arguments[4][9][0].apply(exports,arguments) +},{"cwise-compiler":63}],63:[function(require,module,exports){ +arguments[4][10][0].apply(exports,arguments) +},{"./lib/thunk.js":65}],64:[function(require,module,exports){ +arguments[4][11][0].apply(exports,arguments) +},{"uniq":66}],65:[function(require,module,exports){ +arguments[4][12][0].apply(exports,arguments) +},{"./compile.js":64}],66:[function(require,module,exports){ +module.exports=require(13) +},{}],67:[function(require,module,exports){ +module.exports=require(16) +},{}],68:[function(require,module,exports){ +module.exports=require(17) +},{}],69:[function(require,module,exports){ module.exports=require(41) -},{}],63:[function(require,module,exports){ +},{"bit-twiddle":67,"buffer":189,"dup":68}],70:[function(require,module,exports){ module.exports=require(42) -},{"weakmap":62}],64:[function(require,module,exports){ +},{}],71:[function(require,module,exports){ +module.exports=require(43) +},{"weakmap":70}],72:[function(require,module,exports){ +arguments[4][59][0].apply(exports,arguments) +},{"ndarray":86,"ndarray-ops":62,"typedarray-pool":69,"webglew":71}],73:[function(require,module,exports){ "use strict" -var webglew = require("webglew") -var createVAONative = require("./lib/vao-native.js") -var createVAOEmulated = require("./lib/vao-emulated.js") - -function createVAO(gl, attributes, elements) { - var ext = webglew(gl).OES_vertex_array_object - var vao - if(ext) { - vao = createVAONative(gl, ext) +function doBind(gl, elements, attributes) { + if(elements) { + elements.bind() } else { - vao = createVAOEmulated(gl) + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null) + } + var nattribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS)|0 + if(attributes) { + if(attributes.length > nattribs) { + throw new Error("gl-vao: Too many vertex attributes") + } + for(var i=0; i= 0) { + var d = type.charCodeAt(type.length-1) - 48 + if(d < 2 || d > 4) { + throw new Error("Invalid data type for attribute " + name + ": " + type) + } + addVectorAttribute(gl, program, location, d, obj, name, doLink) + } else { + throw new Error("Unknown data type for attribute " + name + ": " + type) + } + break + } + } + return obj +} - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +},{}],82:[function(require,module,exports){ +"use strict" -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +var dup = require("dup") +var coallesceUniforms = require("./reflect.js") -/** - * @class 2 Dimensional Vector - * @name vec2 - */ +module.exports = createUniformWrapper -var vec2 = {}; +//Binds a function and returns a value +function identity(x) { + var c = new Function("y", "return function(){return y}") + return c(x) +} -/** - * Creates a new, empty vec2 - * - * @returns {vec2} a new 2D vector - */ -vec2.create = function() { - var out = new GLMAT_ARRAY_TYPE(2); - out[0] = 0; - out[1] = 0; - return out; -}; +//Create shims for uniforms +function createUniformWrapper(gl, program, uniforms, locations) { -/** - * Creates a new vec2 initialized with values from an existing vector - * - * @param {vec2} a vector to clone - * @returns {vec2} a new 2D vector - */ -vec2.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(2); - out[0] = a[0]; - out[1] = a[1]; - return out; -}; + function makeGetter(index) { + var proc = new Function("gl", "prog", "locations", + "return function(){return gl.getUniform(prog,locations[" + index + "])}") + return proc(gl, program, locations) + } -/** - * Creates a new vec2 initialized with the given values - * - * @param {Number} x X component - * @param {Number} y Y component - * @returns {vec2} a new 2D vector - */ -vec2.fromValues = function(x, y) { - var out = new GLMAT_ARRAY_TYPE(2); - out[0] = x; - out[1] = y; - return out; -}; - -/** - * Copy the values from one vec2 to another - * - * @param {vec2} out the receiving vector - * @param {vec2} a the source vector - * @returns {vec2} out - */ -vec2.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - return out; -}; + function makePropSetter(path, index, type) { + switch(type) { + case "bool": + case "int": + case "sampler2D": + case "samplerCube": + return "gl.uniform1i(locations[" + index + "],obj" + path + ")" + case "float": + return "gl.uniform1f(locations[" + index + "],obj" + path + ")" + default: + var vidx = type.indexOf("vec") + if(0 <= vidx && vidx <= 1 && type.length === 4 + vidx) { + var d = type.charCodeAt(type.length-1) - 48 + if(d < 2 || d > 4) { + throw new Error("Invalid data type") + } + switch(type.charAt(0)) { + case "b": + case "i": + return "gl.uniform" + d + "iv(locations[" + index + "],obj" + path + ")" + case "v": + return "gl.uniform" + d + "fv(locations[" + index + "],obj" + path + ")" + default: + throw new Error("Unrecognized data type for vector " + name + ": " + type) + } + } else if(type.indexOf("mat") === 0 && type.length === 4) { + var d = type.charCodeAt(type.length-1) - 48 + if(d < 2 || d > 4) { + throw new Error("Invalid uniform dimension type for matrix " + name + ": " + type) + } + return "gl.uniformMatrix" + d + "fv(locations[" + index + "],false,obj" + path + ")" + } else { + throw new Error("Unknown uniform data type for " + name + ": " + type) + } + break + } + } -/** - * Set the components of a vec2 to the given values - * - * @param {vec2} out the receiving vector - * @param {Number} x X component - * @param {Number} y Y component - * @returns {vec2} out - */ -vec2.set = function(out, x, y) { - out[0] = x; - out[1] = y; - return out; -}; + function enumerateIndices(prefix, type) { + if(typeof type !== "object") { + return [ [prefix, type] ] + } + var indices = [] + for(var id in type) { + var prop = type[id] + var tprefix = prefix + if(parseInt(id) + "" === id) { + tprefix += "[" + id + "]" + } else { + tprefix += "." + id + } + if(typeof prop === "object") { + indices.push.apply(indices, enumerateIndices(tprefix, prop)) + } else { + indices.push([tprefix, prop]) + } + } + return indices + } -/** - * Adds two vec2's - * - * @param {vec2} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {vec2} out - */ -vec2.add = function(out, a, b) { - out[0] = a[0] + b[0]; - out[1] = a[1] + b[1]; - return out; -}; + function makeSetter(type) { + var code = [ "return function updateProperty(obj){" ] + var indices = enumerateIndices("", type) + for(var i=0; i 4) { + throw new Error("Invalid data type") + } + if(type.charAt(0) === "b") { + return dup(d, false) + } + return dup(d) + } else if(type.indexOf("mat") === 0 && type.length === 4) { + var d = type.charCodeAt(type.length-1) - 48 + if(d < 2 || d > 4) { + throw new Error("Invalid uniform dimension type for matrix " + name + ": " + type) + } + return dup([d,d]) + } else { + throw new Error("Unknown uniform data type for " + name + ": " + type) + } + break + } + } -/** - * Alias for {@link vec2.subtract} - * @function - */ -vec2.sub = vec2.subtract; + function storeProperty(obj, prop, type) { + if(typeof type === "object") { + var child = processObject(type) + Object.defineProperty(obj, prop, { + get: identity(child), + set: makeSetter(type), + enumerable: true, + configurable: false + }) + } else { + if(locations[type]) { + Object.defineProperty(obj, prop, { + get: makeGetter(type), + set: makeSetter(type), + enumerable: true, + configurable: false + }) + } else { + obj[prop] = defaultValue(uniforms[type].type) + } + } + } -/** - * Multiplies two vec2's - * - * @param {vec2} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {vec2} out - */ -vec2.multiply = function(out, a, b) { - out[0] = a[0] * b[0]; - out[1] = a[1] * b[1]; - return out; -}; + function processObject(obj) { + var result + if(Array.isArray(obj)) { + result = new Array(obj.length) + for(var i=0; i 1) { + if(!(x[0] in o)) { + o[x[0]] = [] + } + o = o[x[0]] + for(var k=1; k 0) { - //TODO: evaluate use of glm_invsqrt here? - len = 1 / Math.sqrt(len); - out[0] = a[0] * len; - out[1] = a[1] * len; - } - return out; -}; +//Relinks all uniforms +function relinkUniforms(gl, program, locations, uniforms) { + for(var i=0; i height) + return; -/** - * Creates a new, empty vec3 - * - * @returns {vec3} a new 3D vector - */ -vec3.create = function() { - var out = new GLMAT_ARRAY_TYPE(3); - out[0] = 0; - out[1] = 0; - out[2] = 0; - return out; + var now = getTime() * TIMESCALE; + heightmap.bind(); + gl.viewport(0, 0, SIZE, SIZE); + gl.disable(gl.DEPTH_TEST); + gl.disable(gl.CULL_FACE); + heightShader.bind(); + heightShader.uniforms.uTime = now; + heightShader.uniforms.uResolution = RES; + triangle(gl); + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + gl.viewport(0, 0, width, height); + gl.enable(gl.DEPTH_TEST); + gl.enable(gl.CULL_FACE); + clear(gl); + mat4.perspective(projection, Math.PI / 4, width / height, 0.001, 100); + quat.identity(camera.rotation); + quat.rotateY(camera.rotation, camera.rotation, now * 0.0002); + quat.rotateX(camera.rotation, camera.rotation, -0.5); + camera.view(view); + quat.identity(camera.rotation); + quat.rotateY(camera.rotation, camera.rotation, now * 0.0002); + geom.bind(shader); + shader.uniforms.uResolution = RES; + shader.uniforms.uViewRotation = mat4.fromQuat(viewrot, camera.rotation); + shader.uniforms.uProjection = projection; + shader.uniforms.uModel = model; + shader.uniforms.uView = view; + shader.uniforms.tHeightmap = heightmap.color[0].bind(0); + shader.uniforms.tGradient = gradient.bind(1); + geom.draw(); + geom.unbind(); + } }; -/** - * Creates a new vec3 initialized with values from an existing vector - * - * @param {vec3} a vector to clone - * @returns {vec3} a new 3D vector - */ -vec3.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(3); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - return out; -}; +function createMesh() { + var voxels = qbqb(SIZE, 1, SIZE); + var positions = unindex(combine(voxels)); + var edges = unindex(combine(getEdges(voxels))); + var centroids = unindex(combine(getCentroids(voxels))); -/** - * Creates a new vec3 initialized with the given values - * - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @returns {vec3} a new 3D vector - */ -vec3.fromValues = function(x, y, z) { - var out = new GLMAT_ARRAY_TYPE(3); - out[0] = x; - out[1] = y; - out[2] = z; - return out; -}; + return { + positions: positions, + centroids: centroids, + normals: normals(positions), + edges: edges + }; +} -/** - * Copy the values from one vec3 to another - * - * @param {vec3} out the receiving vector - * @param {vec3} a the source vector - * @returns {vec3} out - */ -vec3.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - return out; -}; +function getCentroids(meshes) { + return meshes.map(function(mesh) { + mesh = clone(mesh); -/** - * Set the components of a vec3 to the given values - * - * @param {vec3} out the receiving vector - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @returns {vec3} out - */ -vec3.set = function(out, x, y, z) { - out[0] = x; - out[1] = y; - out[2] = z; - return out; -}; + for (var i = 0; i < mesh.positions.length; i++) { + mesh.positions[i] = mesh.centroid; + } -/** - * Adds two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.add = function(out, a, b) { - out[0] = a[0] + b[0]; - out[1] = a[1] + b[1]; - out[2] = a[2] + b[2]; - return out; -}; + return mesh; + }); +} -/** - * Subtracts two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.subtract = function(out, a, b) { - out[0] = a[0] - b[0]; - out[1] = a[1] - b[1]; - out[2] = a[2] - b[2]; - return out; -}; +function getEdges(meshes) { + return meshes.map(function(mesh) { + mesh = clone(mesh); + var idx = mesh.index; -/** - * Alias for {@link vec3.subtract} - * @function - */ -vec3.sub = vec3.subtract; + for (var i = 0; i < mesh.positions.length; i++) { + var pos = mesh.positions[i]; + mesh.positions[i] = mesh.positions[i].slice(); + mesh.positions[i][0] = (pos[0] * SIZE - idx[0] - 0.5) * 2; + mesh.positions[i][2] = (pos[2] * SIZE - idx[2] - 0.5) * 2; + mesh.positions[i][1] = (pos[1] - idx[1] - 0.5) * 2; + } -/** - * Multiplies two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.multiply = function(out, a, b) { - out[0] = a[0] * b[0]; - out[1] = a[1] * b[1]; - out[2] = a[2] * b[2]; - return out; -}; + return mesh; + }); +} +},{"./gradient-map":89,"a-big-triangle":107,"canvas-fit":108,"clone":110,"cube-cube":111,"face-normals":114,"frame-debounce":115,"gl-clear":120,"gl-context":121,"gl-fbo":123,"gl-geometry":126,"gl-matrix":151,"gl-texture2d":164,"glslify":166,"glslify/adapter.js":165,"mesh-combine":172,"orbit-camera":179,"right-now":180,"unindex-mesh":181}],91:[function(require,module,exports){ +arguments[4][8][0].apply(exports,arguments) +},{"ndarray":97,"ndarray-ops":92,"typedarray-pool":101}],92:[function(require,module,exports){ +arguments[4][9][0].apply(exports,arguments) +},{"cwise-compiler":93}],93:[function(require,module,exports){ +arguments[4][10][0].apply(exports,arguments) +},{"./lib/thunk.js":95}],94:[function(require,module,exports){ +arguments[4][11][0].apply(exports,arguments) +},{"uniq":96}],95:[function(require,module,exports){ +arguments[4][12][0].apply(exports,arguments) +},{"./compile.js":94}],96:[function(require,module,exports){ +module.exports=require(13) +},{}],97:[function(require,module,exports){ +arguments[4][14][0].apply(exports,arguments) +},{"buffer":189,"iota-array":98}],98:[function(require,module,exports){ +module.exports=require(15) +},{}],99:[function(require,module,exports){ +module.exports=require(16) +},{}],100:[function(require,module,exports){ +module.exports=require(17) +},{}],101:[function(require,module,exports){ +module.exports=require(18) +},{"bit-twiddle":99,"dup":100}],102:[function(require,module,exports){ +module.exports=require(19) +},{}],103:[function(require,module,exports){ +module.exports=require(20) +},{"./do-bind.js":102}],104:[function(require,module,exports){ +module.exports=require(21) +},{"./do-bind.js":102}],105:[function(require,module,exports){ +module.exports=require(22) +},{}],106:[function(require,module,exports){ +module.exports=require(23) +},{"./lib/vao-emulated.js":103,"./lib/vao-native.js":104,"webglew":105}],107:[function(require,module,exports){ +module.exports=require(24) +},{"gl-buffer":91,"gl-vao":106}],108:[function(require,module,exports){ +var size = require('element-size') -/** - * Alias for {@link vec3.multiply} - * @function - */ -vec3.mul = vec3.multiply; +module.exports = fit -/** - * Divides two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.divide = function(out, a, b) { - out[0] = a[0] / b[0]; - out[1] = a[1] / b[1]; - out[2] = a[2] / b[2]; - return out; -}; +function fit(canvas) { + canvas.style.position = canvas.style.position || 'absolute' + canvas.style.top = 0 + canvas.style.left = 0 -/** - * Alias for {@link vec3.divide} - * @function - */ -vec3.div = vec3.divide; + return resize() -/** - * Returns the minimum of two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.min = function(out, a, b) { - out[0] = Math.min(a[0], b[0]); - out[1] = Math.min(a[1], b[1]); - out[2] = Math.min(a[2], b[2]); - return out; -}; + function resize() { + if (canvas.parentNode && canvas.parentNode !== document.body) { + var psize = size(canvas.parentNode) + var width = psize[0]|0 + var height = psize[1]|0 + } else { + var width = window.innerWidth + var height = window.innerHeight + } -/** - * Returns the maximum of two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.max = function(out, a, b) { - out[0] = Math.max(a[0], b[0]); - out[1] = Math.max(a[1], b[1]); - out[2] = Math.max(a[2], b[2]); - return out; -}; + canvas.width = width + canvas.height = height + canvas.style.width = width + 'px' + canvas.style.height = height + 'px' -/** - * Scales a vec3 by a scalar number - * - * @param {vec3} out the receiving vector - * @param {vec3} a the vector to scale - * @param {Number} b amount to scale the vector by - * @returns {vec3} out - */ -vec3.scale = function(out, a, b) { - out[0] = a[0] * b; - out[1] = a[1] * b; - out[2] = a[2] * b; - return out; -}; + return resize + } +} -/** - * Calculates the euclidian distance between two vec3's - * - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {Number} distance between a and b - */ -vec3.distance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2]; - return Math.sqrt(x*x + y*y + z*z); -}; +},{"element-size":109}],109:[function(require,module,exports){ +module.exports = getSize -/** - * Alias for {@link vec3.distance} - * @function - */ -vec3.dist = vec3.distance; +function getSize(element) { + // Handle cases where the element is not already + // attached to the DOM by briefly appending it + // to document.body, and removing it again later. + if (!element.parentNode) { + var temporary = true + document.body.appendChild(element) + } -/** - * Calculates the squared euclidian distance between two vec3's - * - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {Number} squared distance between a and b - */ -vec3.squaredDistance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2]; - return x*x + y*y + z*z; -}; + var bounds = element.getBoundingClientRect() + var styles = getComputedStyle(element) + var height = (bounds.height|0) + + parse(styles.getPropertyValue('margin-top')) + + parse(styles.getPropertyValue('margin-bottom')) + var width = (bounds.width|0) + + parse(styles.getPropertyValue('margin-left')) + + parse(styles.getPropertyValue('margin-right')) -/** - * Alias for {@link vec3.squaredDistance} - * @function - */ -vec3.sqrDist = vec3.squaredDistance; + if (temporary) { + document.body.removeChild(element) + } -/** - * Calculates the length of a vec3 - * - * @param {vec3} a vector to calculate length of - * @returns {Number} length of a - */ -vec3.length = function (a) { - var x = a[0], - y = a[1], - z = a[2]; - return Math.sqrt(x*x + y*y + z*z); -}; + return [width, height] +} -/** - * Alias for {@link vec3.length} - * @function - */ -vec3.len = vec3.length; +function parse(prop) { + return parseFloat(prop) || 0 +} -/** - * Calculates the squared length of a vec3 - * - * @param {vec3} a vector to calculate squared length of - * @returns {Number} squared length of a - */ -vec3.squaredLength = function (a) { - var x = a[0], - y = a[1], - z = a[2]; - return x*x + y*y + z*z; -}; +},{}],110:[function(require,module,exports){ +(function (Buffer){ +'use strict'; -/** - * Alias for {@link vec3.squaredLength} - * @function - */ -vec3.sqrLen = vec3.squaredLength; +function objectToString(o) { + return Object.prototype.toString.call(o); +} -/** - * Negates the components of a vec3 - * - * @param {vec3} out the receiving vector - * @param {vec3} a vector to negate - * @returns {vec3} out - */ -vec3.negate = function(out, a) { - out[0] = -a[0]; - out[1] = -a[1]; - out[2] = -a[2]; - return out; +// shim for Node's 'util' package +// DO NOT REMOVE THIS! It is required for compatibility with EnderJS (http://enderjs.com/). +var util = { + isArray: function (ar) { + return Array.isArray(ar) || (typeof ar === 'object' && objectToString(ar) === '[object Array]'); + }, + isDate: function (d) { + return typeof d === 'object' && objectToString(d) === '[object Date]'; + }, + isRegExp: function (re) { + return typeof re === 'object' && objectToString(re) === '[object RegExp]'; + }, + getRegExpFlags: function (re) { + var flags = ''; + re.global && (flags += 'g'); + re.ignoreCase && (flags += 'i'); + re.multiline && (flags += 'm'); + return flags; + } }; -/** - * Normalize a vec3 - * - * @param {vec3} out the receiving vector - * @param {vec3} a vector to normalize - * @returns {vec3} out - */ -vec3.normalize = function(out, a) { - var x = a[0], - y = a[1], - z = a[2]; - var len = x*x + y*y + z*z; - if (len > 0) { - //TODO: evaluate use of glm_invsqrt here? - len = 1 / Math.sqrt(len); - out[0] = a[0] * len; - out[1] = a[1] * len; - out[2] = a[2] * len; - } - return out; -}; -/** - * Calculates the dot product of two vec3's - * - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {Number} dot product of a and b - */ -vec3.dot = function (a, b) { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; -}; +if (typeof module === 'object') + module.exports = clone; /** - * Computes the cross product of two vec3's + * Clones (copies) an Object using deep copying. * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.cross = function(out, a, b) { - var ax = a[0], ay = a[1], az = a[2], - bx = b[0], by = b[1], bz = b[2]; - - out[0] = ay * bz - az * by; - out[1] = az * bx - ax * bz; - out[2] = ax * by - ay * bx; - return out; -}; - -/** - * Performs a linear interpolation between two vec3's + * This function supports circular references by default, but if you are certain + * there are no circular references in your object, you can save some CPU time + * by calling clone(obj, false). * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {vec3} out - */ -vec3.lerp = function (out, a, b, t) { - var ax = a[0], - ay = a[1], - az = a[2]; - out[0] = ax + t * (b[0] - ax); - out[1] = ay + t * (b[1] - ay); - out[2] = az + t * (b[2] - az); - return out; -}; - -/** - * Transforms the vec3 with a mat4. - * 4th vector component is implicitly '1' - * - * @param {vec3} out the receiving vector - * @param {vec3} a the vector to transform - * @param {mat4} m matrix to transform with - * @returns {vec3} out - */ -vec3.transformMat4 = function(out, a, m) { - var x = a[0], y = a[1], z = a[2]; - out[0] = m[0] * x + m[4] * y + m[8] * z + m[12]; - out[1] = m[1] * x + m[5] * y + m[9] * z + m[13]; - out[2] = m[2] * x + m[6] * y + m[10] * z + m[14]; - return out; -}; - -/** - * Transforms the vec3 with a quat + * Caution: if `circular` is false and `parent` contains circular references, + * your program may enter an infinite loop and crash. * - * @param {vec3} out the receiving vector - * @param {vec3} a the vector to transform - * @param {quat} q quaternion to transform with - * @returns {vec3} out - */ -vec3.transformQuat = function(out, a, q) { - var x = a[0], y = a[1], z = a[2], - qx = q[0], qy = q[1], qz = q[2], qw = q[3], + * @param `parent` - the object to be cloned + * @param `circular` - set to true if the object to be cloned may contain + * circular references. (optional - true by default) + * @param `depth` - set to a number if the object is only to be cloned to + * a particular depth. (optional - defaults to Infinity) + * @param `prototype` - sets the prototype to be used when cloning an object. + * (optional - defaults to parent prototype). +*/ - // calculate quat * vec - ix = qw * x + qy * z - qz * y, - iy = qw * y + qz * x - qx * z, - iz = qw * z + qx * y - qy * x, - iw = -qx * x - qy * y - qz * z; +function clone(parent, circular, depth, prototype) { + // maintain two arrays for circular references, where corresponding parents + // and children have the same index + var allParents = []; + var allChildren = []; - // calculate result * inverse quat - out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; - out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; - out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; - return out; -}; + var useBuffer = typeof Buffer != 'undefined'; -/** - * Perform some operation over an array of vec3s. - * - * @param {Array} a the array of vectors to iterate over - * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed - * @param {Number} offset Number of elements to skip at the beginning of the array - * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array - * @param {Function} fn Function to call for each vector in the array - * @param {Object} [arg] additional argument to pass to fn - * @returns {Array} a - * @function - */ -vec3.forEach = (function() { - var vec = vec3.create(); + if (typeof circular == 'undefined') + circular = true; - return function(a, stride, offset, count, fn, arg) { - var i, l; - if(!stride) { - stride = 3; - } + if (typeof depth == 'undefined') + depth = Infinity; - if(!offset) { - offset = 0; - } - - if(count) { - l = Math.min((count * stride) + offset, a.length); - } else { - l = a.length; - } + // recurse this function so we don't reset allParents and allChildren + function _clone(parent, depth) { + // cloning null always returns null + if (parent === null) + return null; - for(i = offset; i < l; i += stride) { - vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; - fn(vec, vec, arg); - a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; - } - - return a; - }; -})(); + if (depth == 0) + return parent; -/** - * Returns a string representation of a vector - * - * @param {vec3} vec vector to represent as a string - * @returns {String} string representation of the vector - */ -vec3.str = function (a) { - return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')'; -}; + var child; + if (typeof parent != 'object') { + return parent; + } -if(typeof(exports) !== 'undefined') { - exports.vec3 = vec3; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. + if (util.isArray(parent)) { + child = []; + } else if (util.isRegExp(parent)) { + child = new RegExp(parent.source, util.getRegExpFlags(parent)); + if (parent.lastIndex) child.lastIndex = parent.lastIndex; + } else if (util.isDate(parent)) { + child = new Date(parent.getTime()); + } else if (useBuffer && Buffer.isBuffer(parent)) { + child = new Buffer(parent.length); + parent.copy(child); + return child; + } else { + if (typeof prototype == 'undefined') child = Object.create(Object.getPrototypeOf(parent)); + else child = Object.create(prototype); + } -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: + if (circular) { + var index = allParents.indexOf(parent); - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + if (index != -1) { + return allChildren[index]; + } + allParents.push(parent); + allChildren.push(child); + } -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + for (var i in parent) { + child[i] = _clone(parent[i], depth - 1); + } -/** - * @class 4 Dimensional Vector - * @name vec4 - */ + return child; + } -var vec4 = {}; + return _clone(parent, depth); +} /** - * Creates a new, empty vec4 + * Simple flat clone using prototype, accepts only objects, usefull for property + * override on FLAT configuration object (no nested props). * - * @returns {vec4} a new 4D vector + * USE WITH CAUTION! This may not behave as you wish if you do not know how this + * works. */ -vec4.create = function() { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = 0; - out[1] = 0; - out[2] = 0; - out[3] = 0; - return out; -}; +clone.clonePrototype = function(parent) { + if (parent === null) + return null; -/** - * Creates a new vec4 initialized with values from an existing vector - * - * @param {vec4} a vector to clone - * @returns {vec4} a new 4D vector - */ -vec4.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - return out; + var c = function () {}; + c.prototype = parent; + return new c(); }; -/** - * Creates a new vec4 initialized with the given values - * - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @param {Number} w W component - * @returns {vec4} a new 4D vector - */ -vec4.fromValues = function(x, y, z, w) { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = x; - out[1] = y; - out[2] = z; - out[3] = w; - return out; -}; +}).call(this,require("buffer").Buffer) +},{"buffer":189}],111:[function(require,module,exports){ +var prism = require('rectangular-prism') +var truthy = function() { return true } -/** - * Copy the values from one vec4 to another - * - * @param {vec4} out the receiving vector - * @param {vec4} a the source vector - * @returns {vec4} out - */ -vec4.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - return out; -}; +module.exports = cubecube -/** - * Set the components of a vec4 to the given values - * - * @param {vec4} out the receiving vector - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @param {Number} w W component - * @returns {vec4} out - */ -vec4.set = function(out, x, y, z, w) { - out[0] = x; - out[1] = y; - out[2] = z; - out[3] = w; - return out; -}; +function cubecube(w, h, d, filter) { + filter = filter || truthy -/** - * Adds two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.add = function(out, a, b) { - out[0] = a[0] + b[0]; - out[1] = a[1] + b[1]; - out[2] = a[2] + b[2]; - out[3] = a[3] + b[3]; - return out; -}; + var size = [1/w, 1/h, 1/d] + var cubes = [] -/** - * Subtracts two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.subtract = function(out, a, b) { - out[0] = a[0] - b[0]; - out[1] = a[1] - b[1]; - out[2] = a[2] - b[2]; - out[3] = a[3] - b[3]; - return out; -}; + for (var x = 0; x < w; x++) + for (var y = 0; y < h; y++) + for (var z = 0; z < d; z++) { + if (filter(x, y, z)) { + var cube = prism(size, [x/w, y/h, z/d]) -/** - * Alias for {@link vec4.subtract} - * @function - */ -vec4.sub = vec4.subtract; + cubes.push(cube) + cube.centroid = [(x+0.5)/w, (y+0.5)/h, (z+0.5)/d] + cube.index = [x, y, z] + } + } -/** - * Multiplies two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.multiply = function(out, a, b) { - out[0] = a[0] * b[0]; - out[1] = a[1] * b[1]; - out[2] = a[2] * b[2]; - out[3] = a[3] * b[3]; - return out; -}; + return cubes +} -/** - * Alias for {@link vec4.multiply} - * @function - */ -vec4.mul = vec4.multiply; +},{"rectangular-prism":113}],112:[function(require,module,exports){ +module.exports = { + cells: [ + [1, 0, 2], + [3, 1, 2], + [4, 5, 6], + [5, 7, 6], + [0, 1, 5], + [4, 0, 5], + [1, 3, 5], + [3, 7, 5], + [2, 0, 4], + [2, 4, 6], + [2, 6, 3], + [6, 7, 3] + ], + positions: [ + [0, 0, 0], + [0, 0, 1], + [1, 0, 0], + [1, 0, 1], + [0, 1, 0], + [0, 1, 1], + [1, 1, 0], + [1, 1, 1] + ] +} -/** - * Divides two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.divide = function(out, a, b) { - out[0] = a[0] / b[0]; - out[1] = a[1] / b[1]; - out[2] = a[2] / b[2]; - out[3] = a[3] / b[3]; - return out; -}; +},{}],113:[function(require,module,exports){ +var prism = require('./cube') -/** - * Alias for {@link vec4.divide} - * @function - */ -vec4.div = vec4.divide; +module.exports = createPrism -/** - * Returns the minimum of two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.min = function(out, a, b) { - out[0] = Math.min(a[0], b[0]); - out[1] = Math.min(a[1], b[1]); - out[2] = Math.min(a[2], b[2]); - out[3] = Math.min(a[3], b[3]); - return out; -}; +function createPrism(size, pos) { + pos = pos || [0,0,0] + size = size || [1,1,1] -/** - * Returns the maximum of two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.max = function(out, a, b) { - out[0] = Math.max(a[0], b[0]); - out[1] = Math.max(a[1], b[1]); - out[2] = Math.max(a[2], b[2]); - out[3] = Math.max(a[3], b[3]); - return out; -}; + if (!Array.isArray(size)) { + size = [size, size, size] + } -/** - * Scales a vec4 by a scalar number - * - * @param {vec4} out the receiving vector - * @param {vec4} a the vector to scale - * @param {Number} b amount to scale the vector by - * @returns {vec4} out - */ -vec4.scale = function(out, a, b) { - out[0] = a[0] * b; - out[1] = a[1] * b; - out[2] = a[2] * b; - out[3] = a[3] * b; - return out; -}; + var prism = clonePrism() -/** - * Calculates the euclidian distance between two vec4's - * - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {Number} distance between a and b - */ -vec4.distance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2], - w = b[3] - a[3]; - return Math.sqrt(x*x + y*y + z*z + w*w); -}; + for (var i = 0; i < prism.positions.length; i++) { + prism.positions[i][0] *= size[0] + prism.positions[i][1] *= size[1] + prism.positions[i][2] *= size[2] + prism.positions[i][0] += pos[0] + prism.positions[i][1] += pos[1] + prism.positions[i][2] += pos[2] + } -/** - * Alias for {@link vec4.distance} - * @function - */ -vec4.dist = vec4.distance; + return prism +} -/** - * Calculates the squared euclidian distance between two vec4's - * - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {Number} squared distance between a and b - */ -vec4.squaredDistance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2], - w = b[3] - a[3]; - return x*x + y*y + z*z + w*w; -}; +function clonePrism() { + return { + cells: prism.cells.map(function(d) { + return d.slice() + }), + positions: prism.positions.map(function(d) { + return d.slice() + }) + } +} -/** - * Alias for {@link vec4.squaredDistance} - * @function - */ -vec4.sqrDist = vec4.squaredDistance; +},{"./cube":112}],114:[function(require,module,exports){ +module.exports = faceNormals -/** - * Calculates the length of a vec4 - * - * @param {vec4} a vector to calculate length of - * @returns {Number} length of a - */ -vec4.length = function (a) { - var x = a[0], - y = a[1], - z = a[2], - w = a[3]; - return Math.sqrt(x*x + y*y + z*z + w*w); -}; +function faceNormals(verts, output) { + var l = verts.length + if (!output) output = new Float32Array(l) -/** - * Alias for {@link vec4.length} - * @function - */ -vec4.len = vec4.length; + for (var i = 0; i < l; i += 9) { + var p1x = verts[i+3] - verts[i] + var p1y = verts[i+4] - verts[i+1] + var p1z = verts[i+5] - verts[i+2] -/** - * Calculates the squared length of a vec4 - * - * @param {vec4} a vector to calculate squared length of - * @returns {Number} squared length of a - */ -vec4.squaredLength = function (a) { - var x = a[0], - y = a[1], - z = a[2], - w = a[3]; - return x*x + y*y + z*z + w*w; -}; + var p2x = verts[i+6] - verts[i] + var p2y = verts[i+7] - verts[i+1] + var p2z = verts[i+8] - verts[i+2] -/** - * Alias for {@link vec4.squaredLength} - * @function - */ -vec4.sqrLen = vec4.squaredLength; + var p3x = p1y * p2z - p1z * p2y + var p3y = p1z * p2x - p1x * p2z + var p3z = p1x * p2y - p1y * p2x -/** - * Negates the components of a vec4 - * - * @param {vec4} out the receiving vector - * @param {vec4} a vector to negate - * @returns {vec4} out - */ -vec4.negate = function(out, a) { - out[0] = -a[0]; - out[1] = -a[1]; - out[2] = -a[2]; - out[3] = -a[3]; - return out; -}; + var mag = Math.sqrt(p3x * p3x + p3y * p3y + p3z * p3z) + if (mag === 0) { + output[i ] = 0 + output[i+1] = 0 + output[i+2] = 0 -/** - * Normalize a vec4 - * - * @param {vec4} out the receiving vector - * @param {vec4} a vector to normalize - * @returns {vec4} out - */ -vec4.normalize = function(out, a) { - var x = a[0], - y = a[1], - z = a[2], - w = a[3]; - var len = x*x + y*y + z*z + w*w; - if (len > 0) { - len = 1 / Math.sqrt(len); - out[0] = a[0] * len; - out[1] = a[1] * len; - out[2] = a[2] * len; - out[3] = a[3] * len; - } - return out; -}; + output[i+3] = 0 + output[i+4] = 0 + output[i+5] = 0 -/** - * Calculates the dot product of two vec4's - * - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {Number} dot product of a and b - */ -vec4.dot = function (a, b) { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; -}; + output[i+6] = 0 + output[i+7] = 0 + output[i+8] = 0 + } else { + p3x = p3x / mag + p3y = p3y / mag + p3z = p3z / mag -/** - * Performs a linear interpolation between two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {vec4} out - */ -vec4.lerp = function (out, a, b, t) { - var ax = a[0], - ay = a[1], - az = a[2], - aw = a[3]; - out[0] = ax + t * (b[0] - ax); - out[1] = ay + t * (b[1] - ay); - out[2] = az + t * (b[2] - az); - out[3] = aw + t * (b[3] - aw); - return out; -}; + output[i ] = p3x + output[i+1] = p3y + output[i+2] = p3z -/** - * Transforms the vec4 with a mat4. - * - * @param {vec4} out the receiving vector - * @param {vec4} a the vector to transform - * @param {mat4} m matrix to transform with - * @returns {vec4} out - */ -vec4.transformMat4 = function(out, a, m) { - var x = a[0], y = a[1], z = a[2], w = a[3]; - out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w; - out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w; - out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w; - out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w; - return out; -}; + output[i+3] = p3x + output[i+4] = p3y + output[i+5] = p3z -/** - * Transforms the vec4 with a quat - * - * @param {vec4} out the receiving vector - * @param {vec4} a the vector to transform - * @param {quat} q quaternion to transform with - * @returns {vec4} out - */ -vec4.transformQuat = function(out, a, q) { - var x = a[0], y = a[1], z = a[2], - qx = q[0], qy = q[1], qz = q[2], qw = q[3], + output[i+6] = p3x + output[i+7] = p3y + output[i+8] = p3z + } + } - // calculate quat * vec - ix = qw * x + qy * z - qz * y, - iy = qw * y + qz * x - qx * z, - iz = qw * z + qx * y - qy * x, - iw = -qx * x - qy * y - qz * z; + return output +} - // calculate result * inverse quat - out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; - out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; - out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; - return out; -}; +},{}],115:[function(require,module,exports){ +arguments[4][27][0].apply(exports,arguments) +},{"_process":192,"raf-component":116,"sliced":117}],116:[function(require,module,exports){ +module.exports=require(28) +},{}],117:[function(require,module,exports){ +arguments[4][29][0].apply(exports,arguments) +},{"./lib/sliced":118}],118:[function(require,module,exports){ +module.exports=require(30) +},{}],119:[function(require,module,exports){ +module.exports=require(44) +},{}],120:[function(require,module,exports){ +module.exports=require(45) +},{"./defaults":119}],121:[function(require,module,exports){ +var raf = require('raf-component') -/** - * Perform some operation over an array of vec4s. - * - * @param {Array} a the array of vectors to iterate over - * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed - * @param {Number} offset Number of elements to skip at the beginning of the array - * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array - * @param {Function} fn Function to call for each vector in the array - * @param {Object} [arg] additional argument to pass to fn - * @returns {Array} a - * @function - */ -vec4.forEach = (function() { - var vec = vec4.create(); +module.exports = createContext - return function(a, stride, offset, count, fn, arg) { - var i, l; - if(!stride) { - stride = 4; - } +function createContext(canvas, opts, render) { + if (typeof opts === 'function') { + render = opts + opts = {} + } else { + opts = opts || {} + } - if(!offset) { - offset = 0; - } - - if(count) { - l = Math.min((count * stride) + offset, a.length); - } else { - l = a.length; - } + var gl = ( + canvas.getContext('webgl', opts) || + canvas.getContext('webgl-experimental', opts) || + canvas.getContext('experimental-webgl', opts) + ) - for(i = offset; i < l; i += stride) { - vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3]; - fn(vec, vec, arg); - a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3]; - } - - return a; - }; -})(); + if (!gl) { + throw new Error('Unable to initialize WebGL') + } -/** - * Returns a string representation of a vector - * - * @param {vec4} vec vector to represent as a string - * @returns {String} string representation of the vector - */ -vec4.str = function (a) { - return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; -}; + if (render) raf(tick) -if(typeof(exports) !== 'undefined') { - exports.vec4 = vec4; + return gl + + function tick() { + render(gl) + raf(tick) + } } -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: +},{"raf-component":122}],122:[function(require,module,exports){ +module.exports=require(28) +},{}],123:[function(require,module,exports){ +"use strict"; - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +var webglew = require("webglew") +var createTexture = require("gl-texture2d") -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +module.exports = createFBO -/** - * @class 2x2 Matrix - * @name mat2 - */ +var colorAttachmentArrays = null +var FRAMEBUFFER_UNSUPPORTED +var FRAMEBUFFER_INCOMPLETE_ATTACHMENT +var FRAMEBUFFER_INCOMPLETE_DIMENSIONS +var FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT -var mat2 = {}; +function lazyInitColorAttachments(gl, ext) { + var maxColorAttachments = gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL); + colorAttachmentArrays = new Array(maxColorAttachments + 1) + for(var i=0; i<=maxColorAttachments; ++i) { + var x = new Array(maxColorAttachments) + for(var j=0; j 1) { + ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]) + } -/** - * Transpose the values of a mat2 - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the source matrix - * @returns {mat2} out - */ -mat2.transpose = function(out, a) { - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (out === a) { - var a1 = a[1]; - out[1] = a[2]; - out[2] = a1; - } else { - out[0] = a[0]; - out[1] = a[2]; - out[2] = a[1]; - out[3] = a[3]; + //Allocate depth/stencil buffers + if(extensions.WEBGL_depth_texture) { + if(useStencil) { + fbo.depth = initTexture(gl, width, height, + extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL, + gl.DEPTH_STENCIL, + gl.DEPTH_STENCIL_ATTACHMENT) + } else if(useDepth) { + fbo.depth = initTexture(gl, width, height, + gl.UNSIGNED_SHORT, + gl.DEPTH_COMPONENT, + gl.DEPTH_ATTACHMENT) } - - return out; -}; + } else { + if(useDepth && useStencil) { + fbo._depth_rb = initRenderBuffer(gl, width, height, gl.DEPTH_STENCIL, gl.DEPTH_STENCIL_ATTACHMENT) + } else if(useDepth) { + fbo._depth_rb = initRenderBuffer(gl, width, height, gl.DEPTH_COMPONENT16, gl.DEPTH_ATTACHMENT) + } else if(useStencil) { + fbo._depth_rb = initRenderBuffer(gl, width, height, gl.STENCIL_INDEX, gl.STENCIL_ATTACHMENT) + } + } -/** - * Inverts a mat2 - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the source matrix - * @returns {mat2} out - */ -mat2.invert = function(out, a) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + //Check frame buffer state + var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER) + if(status !== gl.FRAMEBUFFER_COMPLETE) { - // Calculate the determinant - det = a0 * a3 - a2 * a1; + //Release all partially allocated resources + fbo._destroyed = true - if (!det) { - return null; + //Release all resources + gl.bindFramebuffer(gl.FRAMEBUFFER, null) + gl.deleteFramebuffer(fbo.handle) + fbo.handle = null + if(fbo.depth) { + fbo.depth.dispose() + fbo.depth = null + } + if(fbo._depth_rb) { + gl.deleteRenderbuffer(fbo._depth_rb) + fbo._depth_rb = null + } + for(var i=0; i maxFBOSize || + x[1] < 0 || x[1] > maxFBOSize) { + throw new Error("gl-fbo: Can't resize FBO, invalid dimensions") + } - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + //Update shape + this._shape[0] = x[0]|0 + this._shape[1] = x[1]|0 -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + //Resize framebuffer attachments + for(var i=0; i - * [a, b, - * c, d, - * tx,ty] - * - * This is a short form for the 3x3 matrix: - *
    - * [a, b, 0
    - *  c, d, 0
    - *  tx,ty,1]
    - * 
    - * The last column is ignored so the array is shorter and operations are faster. - */ + //Check FBO status after resize, if something broke then die in a fire + gl.bindFramebuffer(gl.FRAMEBUFFER, this.handle) + var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER) + if(status !== gl.FRAMEBUFFER_COMPLETE) { + this.dispose() + throwFBOError(status) + } + gl.bindFramebuffer(gl.FRAMEBUFFER, null) -var mat2d = {}; + //Success! + return x + } +}) -var mat2dIdentity = new Float32Array([ - 1, 0, - 0, 1, - 0, 0 -]); +proto.bind = function() { + if(this._destroyed) { + return + } + var gl = this.gl + gl.bindFramebuffer(gl.FRAMEBUFFER, this.handle) + gl.viewport(0, 0, this._shape[1], this._shape[0]) +} -/** - * Creates a new identity mat2d - * - * @returns {mat2d} a new 2x3 matrix - */ -mat2d.create = function() { - var out = new GLMAT_ARRAY_TYPE(6); - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 1; - out[4] = 0; - out[5] = 0; - return out; -}; +proto.dispose = function() { + if(this._destroyed) { + return + } + this._destroyed = true + var gl = this.gl + gl.deleteFramebuffer(this.handle) + this.handle = null + if(this.depth) { + this.depth.dispose() + this.depth = null + } + if(this._depth_rb) { + gl.deleteRenderbuffer(this._depth_rb) + this._depth_rb = null + } + for(var i=0; i maxFBOSize || height < 0 || height > maxFBOSize) { + throw new Error("gl-fbo: Parameters are too large for FBO") + } + + //Handle each option type + options = options || {} + + //Figure out number of color buffers to use + var numColors = 1 + if("color" in options) { + numColors = Math.max(options.color|0, 0) + if(numColors < 0) { + throw new Error("gl-fbo: Must specify a nonnegative number of colors") } - det = 1.0 / det; + if(numColors > 1) { + //Check if multiple render targets supported + var mrtext = extensions.WEBGL_draw_buffers + if(!mrtext) { + throw new Error("gl-fbo: Multiple draw buffer extension not supported") + } else if(numColors > gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL)) { + throw new Error("gl-fbo: Context does not support " + numColors + " draw buffers") + } + } + } - out[0] = ad * det; - out[1] = -ab * det; - out[2] = -ac * det; - out[3] = aa * det; - out[4] = (ac * aty - ad * atx) * det; - out[5] = (ab * atx - aa * aty) * det; - return out; -}; + //Determine whether to use floating point textures + var colorType = gl.UNSIGNED_BYTE + if(options.float && numColors > 0) { + if(!extensions.OES_texture_float) { + throw new Error("gl-fbo: Context does not support floating point textures") + } + colorType = gl.FLOAT + } else if(options.preferFloat && numColors > 0) { + if(extensions.OES_texture_float) { + colorType = gl.FLOAT + } + } -/** - * Calculates the determinant of a mat2d - * - * @param {mat2d} a the source matrix - * @returns {Number} determinant of a - */ -mat2d.determinant = function (a) { - return a[0] * a[3] - a[1] * a[2]; -}; + //Check if we should use depth buffer + var useDepth = true + if("depth" in options) { + useDepth = !!options.depth + } -/** - * Multiplies two mat2d's - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the first operand - * @param {mat2d} b the second operand - * @returns {mat2d} out - */ -mat2d.multiply = function (out, a, b) { - var aa = a[0], ab = a[1], ac = a[2], ad = a[3], - atx = a[4], aty = a[5], - ba = b[0], bb = b[1], bc = b[2], bd = b[3], - btx = b[4], bty = b[5]; + //Check if we should use a stencil buffer + var useStencil = false + if("stencil" in options) { + useStencil = !!options.stencil + } - out[0] = aa*ba + ab*bc; - out[1] = aa*bb + ab*bd; - out[2] = ac*ba + ad*bc; - out[3] = ac*bb + ad*bd; - out[4] = ba*atx + bc*aty + btx; - out[5] = bb*atx + bd*aty + bty; - return out; -}; + return new Framebuffer( + gl, + width, + height, + colorType, + numColors, + useDepth, + useStencil, + extensions.WEBGL_draw_buffers) +} +},{"gl-texture2d":164,"webglew":125}],124:[function(require,module,exports){ +module.exports=require(42) +},{}],125:[function(require,module,exports){ +module.exports=require(43) +},{"weakmap":124}],126:[function(require,module,exports){ +var normalize = require('./normalize') +var createVAO = require('gl-vao') -/** - * Alias for {@link mat2d.multiply} - * @function - */ -mat2d.mul = mat2d.multiply; +module.exports = GLGeometry +function GLGeometry(gl) { + if (!(this instanceof GLGeometry)) + return new GLGeometry(gl) -/** - * Rotates a mat2d by the given angle - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat2d} out - */ -mat2d.rotate = function (out, a, rad) { - var aa = a[0], - ab = a[1], - ac = a[2], - ad = a[3], - atx = a[4], - aty = a[5], - st = Math.sin(rad), - ct = Math.cos(rad); + this._attributes = [] + this._dirty = true + this._length = 0 + this._index = null + this._vao = null + this._keys = [] + this.gl = gl +} - out[0] = aa*ct + ab*st; - out[1] = -aa*st + ab*ct; - out[2] = ac*ct + ad*st; - out[3] = -ac*st + ct*ad; - out[4] = ct*atx + st*aty; - out[5] = ct*aty - st*atx; - return out; -}; +GLGeometry.prototype.faces = function faces(attr, opts) { + var size = opts && opts.size || 3 + attr = attr.cells ? attr.cells : attr -/** - * Scales the mat2d by the dimensions in the given vec2 - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the matrix to translate - * @param {mat2d} v the vec2 to scale the matrix by - * @returns {mat2d} out - **/ -mat2d.scale = function(out, a, v) { - var vx = v[0], vy = v[1]; - out[0] = a[0] * vx; - out[1] = a[1] * vy; - out[2] = a[2] * vx; - out[3] = a[3] * vy; - out[4] = a[4] * vx; - out[5] = a[5] * vy; - return out; -}; + this._dirty = true + this._index = normalize(this.gl + , attr + , size + , this.gl.ELEMENT_ARRAY_BUFFER + , 'uint16' + ) -/** - * Translates the mat2d by the dimensions in the given vec2 - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the matrix to translate - * @param {mat2d} v the vec2 to translate the matrix by - * @returns {mat2d} out - **/ -mat2d.translate = function(out, a, v) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4] + v[0]; - out[5] = a[5] + v[1]; - return out; -}; - -/** - * Returns a string representation of a mat2d - * - * @param {mat2d} a matrix to represent as a string - * @returns {String} string representation of the matrix - */ -mat2d.str = function (a) { - return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + - a[3] + ', ' + a[4] + ', ' + a[5] + ')'; -}; + this._length = this._index.length * size + this._index = this._index.buffer -if(typeof(exports) !== 'undefined') { - exports.mat2d = mat2d; + return this } -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: +GLGeometry.prototype.attr = function attr(name, attr, opts) { + opts = opts || {} + this._dirty = true - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + var gl = this.gl + var first = !this._attributes.length + var size = opts.size || 3 -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + var attribute = normalize(gl, attr, size) + if (!attribute) { + throw new Error( + 'Unexpected attribute format: needs an ndarray, array, typed array, ' + + 'gl-buffer or simplicial complex' + ) + } -/** - * @class 3x3 Matrix - * @name mat3 - */ + var buffer = attribute.buffer + var length = attribute.length + var index = attribute.index -var mat3 = {}; + this._keys.push(name) + this._attributes.push({ + size: size + , buffer: buffer + }) -var mat3Identity = new Float32Array([ - 1, 0, 0, - 0, 1, 0, - 0, 0, 1 -]); + if (first) { + this._length = length + } -/** - * Creates a new identity mat3 - * - * @returns {mat3} a new 3x3 matrix - */ -mat3.create = function() { - var out = new GLMAT_ARRAY_TYPE(9); - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 1; - out[5] = 0; - out[6] = 0; - out[7] = 0; - out[8] = 1; - return out; -}; + if (first && index) { + this._index = index + } -/** - * Creates a new mat3 initialized with values from an existing matrix - * - * @param {mat3} a matrix to clone - * @returns {mat3} a new 3x3 matrix - */ -mat3.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(9); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - return out; -}; + return this +} -/** - * Copy the values from one mat3 to another - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - return out; -}; +GLGeometry.prototype.bind = function bind(shader) { + this.update() + this._vao.bind() -/** - * Set a mat3 to the identity matrix - * - * @param {mat3} out the receiving matrix - * @returns {mat3} out - */ -mat3.identity = function(out) { - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 1; - out[5] = 0; - out[6] = 0; - out[7] = 0; - out[8] = 1; - return out; -}; + if (!shader) return + shader.bind() -/** - * Transpose the values of a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.transpose = function(out, a) { - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (out === a) { - var a01 = a[1], a02 = a[2], a12 = a[5]; - out[1] = a[3]; - out[2] = a[6]; - out[3] = a01; - out[5] = a[7]; - out[6] = a02; - out[7] = a12; - } else { - out[0] = a[0]; - out[1] = a[3]; - out[2] = a[6]; - out[3] = a[1]; - out[4] = a[4]; - out[5] = a[7]; - out[6] = a[2]; - out[7] = a[5]; - out[8] = a[8]; - } - - return out; -}; + if (!this._keys) return + for (var i = 0; i < this._keys.length; i++) { + var attr = shader.attributes[this._keys[i]] + if (attr) attr.location = i + } +} -/** - * Inverts a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.invert = function(out, a) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], +GLGeometry.prototype.draw = function draw(mode) { + this.update() + this._vao.draw(mode || this.gl.TRIANGLES, this._length) +} - b01 = a22 * a11 - a12 * a21, - b11 = -a22 * a10 + a12 * a20, - b21 = a21 * a10 - a11 * a20, +GLGeometry.prototype.unbind = function unbind() { + this.update() + this._vao.unbind() +} - // Calculate the determinant - det = a00 * b01 + a01 * b11 + a02 * b21; +GLGeometry.prototype.update = function update() { + if (!this._dirty) return + this._dirty = false + if (this._vao) this._vao.dispose() - if (!det) { - return null; - } - det = 1.0 / det; + this._vao = createVAO( + this.gl + , this._attributes + , this._index + ) +} - out[0] = b01 * det; - out[1] = (-a22 * a01 + a02 * a21) * det; - out[2] = (a12 * a01 - a02 * a11) * det; - out[3] = b11 * det; - out[4] = (a22 * a00 - a02 * a20) * det; - out[5] = (-a12 * a00 + a02 * a10) * det; - out[6] = b21 * det; - out[7] = (-a21 * a00 + a01 * a20) * det; - out[8] = (a11 * a00 - a01 * a10) * det; - return out; -}; +},{"./normalize":150,"gl-vao":147}],127:[function(require,module,exports){ +var dtype = require('dtype') -/** - * Calculates the adjugate of a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.adjoint = function(out, a) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8]; - - out[0] = (a11 * a22 - a12 * a21); - out[1] = (a02 * a21 - a01 * a22); - out[2] = (a01 * a12 - a02 * a11); - out[3] = (a12 * a20 - a10 * a22); - out[4] = (a00 * a22 - a02 * a20); - out[5] = (a02 * a10 - a00 * a12); - out[6] = (a10 * a21 - a11 * a20); - out[7] = (a01 * a20 - a00 * a21); - out[8] = (a00 * a11 - a01 * a10); - return out; -}; - -/** - * Calculates the determinant of a mat3 - * - * @param {mat3} a the source matrix - * @returns {Number} determinant of a - */ -mat3.determinant = function (a) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8]; - - return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); -}; - -/** - * Multiplies two mat3's - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the first operand - * @param {mat3} b the second operand - * @returns {mat3} out - */ -mat3.multiply = function (out, a, b) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], - - b00 = b[0], b01 = b[1], b02 = b[2], - b10 = b[3], b11 = b[4], b12 = b[5], - b20 = b[6], b21 = b[7], b22 = b[8]; - - out[0] = b00 * a00 + b01 * a10 + b02 * a20; - out[1] = b00 * a01 + b01 * a11 + b02 * a21; - out[2] = b00 * a02 + b01 * a12 + b02 * a22; - - out[3] = b10 * a00 + b11 * a10 + b12 * a20; - out[4] = b10 * a01 + b11 * a11 + b12 * a21; - out[5] = b10 * a02 + b11 * a12 + b12 * a22; - - out[6] = b20 * a00 + b21 * a10 + b22 * a20; - out[7] = b20 * a01 + b21 * a11 + b22 * a21; - out[8] = b20 * a02 + b21 * a12 + b22 * a22; - return out; -}; - -/** - * Alias for {@link mat3.multiply} - * @function - */ -mat3.mul = mat3.multiply; +module.exports = pack -/** - * Translate a mat3 by the given vector - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the matrix to translate - * @param {vec2} v vector to translate by - * @returns {mat3} out - */ -mat3.translate = function(out, a, v) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], - x = v[0], y = v[1]; +function pack(arr, type) { + type = type || 'float32' - out[0] = a00; - out[1] = a01; - out[2] = a02; + if (!arr[0] || !arr[0].length) { + return arr + } - out[3] = a10; - out[4] = a11; - out[5] = a12; + var Arr = typeof type === 'string' + ? dtype(type) + : type - out[6] = x * a00 + y * a10 + a20; - out[7] = x * a01 + y * a11 + a21; - out[8] = x * a02 + y * a12 + a22; - return out; -}; + var dim = arr[0].length + var out = new Arr(arr.length * dim) + var k = 0 -/** - * Rotates a mat3 by the given angle - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat3} out - */ -mat3.rotate = function (out, a, rad) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], + for (var i = 0; i < arr.length; i++) + for (var j = 0; j < dim; j++) { + out[k++] = arr[i][j] + } - s = Math.sin(rad), - c = Math.cos(rad); + return out +} - out[0] = c * a00 + s * a10; - out[1] = c * a01 + s * a11; - out[2] = c * a02 + s * a12; +},{"dtype":128}],128:[function(require,module,exports){ +module.exports = function(dtype) { + switch (dtype) { + case 'int8': + return Int8Array + case 'int16': + return Int16Array + case 'int32': + return Int32Array + case 'uint8': + return Uint8Array + case 'uint16': + return Uint16Array + case 'uint32': + return Uint32Array + case 'float32': + return Float32Array + case 'float64': + return Float64Array + case 'array': + return Array + } +} +},{}],129:[function(require,module,exports){ +"use strict" - out[3] = c * a10 - s * a00; - out[4] = c * a11 - s * a01; - out[5] = c * a12 - s * a02; +var pool = require("typedarray-pool") +var ops = require("ndarray-ops") +var ndarray = require("ndarray") +var webglew = require("webglew") - out[6] = a20; - out[7] = a21; - out[8] = a22; - return out; -}; +var SUPPORTED_TYPES = [ + "uint8", + "uint8_clamped", + "uint16", + "uint32", + "int8", + "int16", + "int32", + "float32" ] -/** - * Scales the mat3 by the dimensions in the given vec2 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the matrix to rotate - * @param {vec2} v the vec2 to scale the matrix by - * @returns {mat3} out - **/ -mat3.scale = function(out, a, v) { - var x = v[0], y = v[2]; +function GLBuffer(gl, type, handle, length, usage) { + this.gl = gl + this.type = type + this.handle = handle + this.length = length + this.usage = usage +} - out[0] = x * a[0]; - out[1] = x * a[1]; - out[2] = x * a[2]; +var proto = GLBuffer.prototype - out[3] = y * a[3]; - out[4] = y * a[4]; - out[5] = y * a[5]; +proto.bind = function() { + this.gl.bindBuffer(this.type, this.handle) +} - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - return out; -}; +proto.dispose = function() { + this.gl.deleteBuffer(this.handle) +} -/** - * Copies the values from a mat2d into a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the matrix to rotate - * @param {vec2} v the vec2 to scale the matrix by - * @returns {mat3} out - **/ -mat3.fromMat2d = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = 0; +function updateTypeArray(gl, type, len, usage, data, offset) { + var dataLen = data.length * data.BYTES_PER_ELEMENT + if(offset < 0) { + gl.bufferData(type, data, usage) + return dataLen + } + if(dataLen + offset > len) { + throw new Error("gl-buffer: If resizing buffer, must not specify offset") + } + gl.bufferSubData(type, offset, data) + return len +} - out[3] = a[2]; - out[4] = a[3]; - out[5] = 0; +function makeScratchTypeArray(array, dtype) { + var res = pool.malloc(array.length, dtype) + var n = array.length + for(var i=0; i=0; --i) { + if(stride[i] !== n) { + return false + } + n *= shape[i] + } + return true +} -/** -* Calculates a 3x3 matrix from the given quaternion -* -* @param {mat3} out mat3 receiving operation result -* @param {quat} q Quaternion to create matrix from -* -* @returns {mat3} out -*/ -mat3.fromQuat = function (out, q) { - var x = q[0], y = q[1], z = q[2], w = q[3], - x2 = x + x, - y2 = y + y, - z2 = z + z, - - xx = x * x2, - xy = x * y2, - xz = x * z2, - yy = y * y2, - yz = y * z2, - zz = z * z2, - wx = w * x2, - wy = w * y2, - wz = w * z2; +proto.update = function(array, offset) { + if(typeof offset !== "number") { + offset = -1 + } + this.bind() + if(typeof array === "object" && typeof array.shape !== "undefined") { //ndarray + var dtype = array.dtype + if(SUPPORTED_TYPES.indexOf(dtype) < 0) { + dtype = "float32" + } + if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) { + var wgl = webglew(gl) + var ext = wgl.OES_element_index_uint + if(ext && dtype !== "uint16") { + dtype = "uint32" + } else { + dtype = "uint16" + } + } + if(dtype === array.dtype && isPacked(array.shape, array.stride)) { + if(array.offset === 0 && array.data.length === array.shape[0]) { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data, offset) + } else { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data.subarray(array.offset, array.shape[0]), offset) + } + } else { + var tmp = pool.malloc(array.size, dtype) + var ndt = ndarray(tmp, array.shape) + ops.assign(ndt, array) + if(offset < 0) { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, tmp, offset) + } else { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, tmp.subarray(0, array.size), offset) + } + pool.free(tmp) + } + } else if(Array.isArray(array)) { //Vanilla array + var t + if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) { + t = makeScratchTypeArray(array, "uint16") + } else { + t = makeScratchTypeArray(array, "float32") + } + if(offset < 0) { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t, offset) + } else { + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t.subarray(0, array.length), offset) + } + pool.free(t) + } else if(typeof array === "object" && typeof array.length === "number") { //Typed array + this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array, offset) + } else if(typeof array === "number" || array === undefined) { //Number/default + if(offset >= 0) { + throw new Error("gl-buffer: Cannot specify offset when resizing buffer") + } + array = array | 0 + if(array <= 0) { + array = 1 + } + this.gl.bufferData(this.type, array|0, this.usage) + this.length = array + } else { //Error, case should not happen + throw new Error("gl-buffer: Invalid data type") + } +} - out[0] = 1 - (yy + zz); - out[1] = xy + wz; - out[2] = xz - wy; +function createBuffer(gl, data, type, usage) { + webglew(gl) + type = type || gl.ARRAY_BUFFER + usage = usage || gl.DYNAMIC_DRAW + if(type !== gl.ARRAY_BUFFER && type !== gl.ELEMENT_ARRAY_BUFFER) { + throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER") + } + if(usage !== gl.DYNAMIC_DRAW && usage !== gl.STATIC_DRAW && usage !== gl.STREAM_DRAW) { + throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW") + } + var handle = gl.createBuffer() + var result = new GLBuffer(gl, type, handle, 0, usage) + result.update(data) + return result +} - out[3] = xy - wz; - out[4] = 1 - (xx + zz); - out[5] = yz + wx; +module.exports = createBuffer +},{"ndarray":135,"ndarray-ops":130,"typedarray-pool":139,"webglew":141}],130:[function(require,module,exports){ +arguments[4][9][0].apply(exports,arguments) +},{"cwise-compiler":131}],131:[function(require,module,exports){ +arguments[4][10][0].apply(exports,arguments) +},{"./lib/thunk.js":133}],132:[function(require,module,exports){ +arguments[4][11][0].apply(exports,arguments) +},{"uniq":134}],133:[function(require,module,exports){ +arguments[4][12][0].apply(exports,arguments) +},{"./compile.js":132}],134:[function(require,module,exports){ +module.exports=require(13) +},{}],135:[function(require,module,exports){ +arguments[4][14][0].apply(exports,arguments) +},{"buffer":189,"iota-array":136}],136:[function(require,module,exports){ +module.exports=require(15) +},{}],137:[function(require,module,exports){ +module.exports=require(16) +},{}],138:[function(require,module,exports){ +module.exports=require(17) +},{}],139:[function(require,module,exports){ +module.exports=require(41) +},{"bit-twiddle":137,"buffer":189,"dup":138}],140:[function(require,module,exports){ +module.exports=require(42) +},{}],141:[function(require,module,exports){ +module.exports=require(43) +},{"weakmap":140}],142:[function(require,module,exports){ +module.exports=require(73) +},{}],143:[function(require,module,exports){ +"use strict" - out[6] = xz + wy; - out[7] = yz - wx; - out[8] = 1 - (xx + yy); +var bindAttribs = require("./do-bind.js") - return out; -}; +function VAOEmulated(gl) { + this.gl = gl + this._elements = null + this._attributes = null +} -/** - * Returns a string representation of a mat3 - * - * @param {mat3} mat matrix to represent as a string - * @returns {String} string representation of the matrix - */ -mat3.str = function (a) { - return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + - a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + - a[6] + ', ' + a[7] + ', ' + a[8] + ')'; -}; +VAOEmulated.prototype.bind = function() { + bindAttribs(this.gl, this._elements, this._attributes) +} -if(typeof(exports) !== 'undefined') { - exports.mat3 = mat3; +VAOEmulated.prototype.update = function(attributes, elements) { + this._elements = elements + this._attributes = attributes } -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: +VAOEmulated.prototype.dispose = function() { } +VAOEmulated.prototype.unbind = function() { } - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +VAOEmulated.prototype.draw = function(mode, count, offset) { + offset = offset || 0 + var gl = this.gl + if(this._elements) { + gl.drawElements(mode, count, gl.UNSIGNED_SHORT, offset) + } else { + gl.drawArrays(mode, offset, count) + } +} -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +function createVAOEmulated(gl) { + return new VAOEmulated(gl) +} -/** - * @class 4x4 Matrix - * @name mat4 - */ +module.exports = createVAOEmulated +},{"./do-bind.js":142}],144:[function(require,module,exports){ +"use strict" -var mat4 = {}; +var bindAttribs = require("./do-bind.js") -var mat4Identity = new Float32Array([ - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 -]); +function VertexAttribute(location, dimension, a, b, c, d) { + this.location = location + this.dimension = dimension + this.a = a + this.b = b + this.c = c + this.d = d +} -/** - * Creates a new identity mat4 - * - * @returns {mat4} a new 4x4 matrix - */ -mat4.create = function() { - var out = new GLMAT_ARRAY_TYPE(16); - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = 1; - out[6] = 0; - out[7] = 0; - out[8] = 0; - out[9] = 0; - out[10] = 1; - out[11] = 0; - out[12] = 0; - out[13] = 0; - out[14] = 0; - out[15] = 1; - return out; -}; +VertexAttribute.prototype.bind = function(gl) { + switch(this.dimension) { + case 1: + gl.vertexAttrib1f(this.location, this.a) + break + case 2: + gl.vertexAttrib2f(this.location, this.a, this.b) + break + case 3: + gl.vertexAttrib3f(this.location, this.a, this.b, this.c) + break + case 4: + gl.vertexAttrib4f(this.location, this.a, this.b, this.c, this.d) + break + } +} -/** - * Creates a new mat4 initialized with values from an existing matrix - * - * @param {mat4} a matrix to clone - * @returns {mat4} a new 4x4 matrix - */ -mat4.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(16); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - out[9] = a[9]; - out[10] = a[10]; - out[11] = a[11]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - return out; -}; +function VAONative(gl, ext, handle) { + this.gl = gl + this._ext = ext + this.handle = handle + this._attribs = [] + this._useElements = false +} -/** - * Copy the values from one mat4 to another - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the source matrix - * @returns {mat4} out - */ -mat4.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - out[9] = a[9]; - out[10] = a[10]; - out[11] = a[11]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - return out; -}; +VAONative.prototype.bind = function() { + this._ext.bindVertexArrayOES(this.handle) + for(var i=0; i 0) { + //TODO: evaluate use of glm_invsqrt here? + len = 1 / Math.sqrt(len); + out[0] = a[0] * len; + out[1] = a[1] * len; + } return out; }; /** - * Rotates a quaternion by the given angle around the Z axis + * Calculates the dot product of two vec2's * - * @param {quat} out quat receiving operation result - * @param {quat} a quat to rotate - * @param {number} rad angle (in radians) to rotate - * @returns {quat} out + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {Number} dot product of a and b */ -quat.rotateZ = function (out, a, rad) { - rad *= 0.5; - - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - bz = Math.sin(rad), bw = Math.cos(rad); - - out[0] = ax * bw + ay * bz; - out[1] = ay * bw - ax * bz; - out[2] = az * bw + aw * bz; - out[3] = aw * bw - az * bz; - return out; +vec2.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1]; }; /** - * Calculates the W component of a quat from the X, Y, and Z components. - * Assumes that quaternion is 1 unit in length. - * Any existing W component will be ignored. + * Computes the cross product of two vec2's + * Note that the cross product must by definition produce a 3D vector * - * @param {quat} out the receiving quaternion - * @param {quat} a quat to calculate W component of - * @returns {quat} out + * @param {vec3} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec3} out */ -quat.calculateW = function (out, a) { - var x = a[0], y = a[1], z = a[2]; - - out[0] = x; - out[1] = y; +vec2.cross = function(out, a, b) { + var z = a[0] * b[1] - a[1] * b[0]; + out[0] = out[1] = 0; out[2] = z; - out[3] = -Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z)); return out; }; /** - * Calculates the dot product of two quat's + * Performs a linear interpolation between two vec2's * - * @param {quat} a the first operand - * @param {quat} b the second operand - * @returns {Number} dot product of a and b - * @function + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec2} out */ -quat.dot = vec4.dot; +vec2.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + return out; +}; /** - * Performs a linear interpolation between two quat's + * Transforms the vec2 with a mat2 * - * @param {quat} out the receiving quaternion - * @param {quat} a the first operand - * @param {quat} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {quat} out - * @function + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat2} m matrix to transform with + * @returns {vec2} out */ -quat.lerp = vec4.lerp; +vec2.transformMat2 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[2] * y; + out[1] = m[1] * x + m[3] * y; + return out; +}; /** - * Performs a spherical linear interpolation between two quat + * Transforms the vec2 with a mat2d * - * @param {quat} out the receiving quaternion - * @param {quat} a the first operand - * @param {quat} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {quat} out + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat2d} m matrix to transform with + * @returns {vec2} out */ -quat.slerp = function (out, a, b, t) { - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - bx = b[0], by = b[1], bz = b[2], bw = b[3]; - - var cosHalfTheta = ax * bx + ay * by + az * bz + aw * bw, - halfTheta, - sinHalfTheta, - ratioA, - ratioB; - - if (Math.abs(cosHalfTheta) >= 1.0) { - if (out !== a) { - out[0] = ax; - out[1] = ay; - out[2] = az; - out[3] = aw; - } - return out; - } - - halfTheta = Math.acos(cosHalfTheta); - sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta); - - if (Math.abs(sinHalfTheta) < 0.001) { - out[0] = (ax * 0.5 + bx * 0.5); - out[1] = (ay * 0.5 + by * 0.5); - out[2] = (az * 0.5 + bz * 0.5); - out[3] = (aw * 0.5 + bw * 0.5); - return out; - } - - ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta; - ratioB = Math.sin(t * halfTheta) / sinHalfTheta; - - out[0] = (ax * ratioA + bx * ratioB); - out[1] = (ay * ratioA + by * ratioB); - out[2] = (az * ratioA + bz * ratioB); - out[3] = (aw * ratioA + bw * ratioB); - +vec2.transformMat2d = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[2] * y + m[4]; + out[1] = m[1] * x + m[3] * y + m[5]; return out; }; /** - * Calculates the inverse of a quat + * Transforms the vec2 with a mat3 + * 3rd vector component is implicitly '1' * - * @param {quat} out the receiving quaternion - * @param {quat} a quat to calculate inverse of - * @returns {quat} out + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat3} m matrix to transform with + * @returns {vec2} out */ -quat.invert = function(out, a) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], - dot = a0*a0 + a1*a1 + a2*a2 + a3*a3, - invDot = dot ? 1.0/dot : 0; - - // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0 - - out[0] = -a0*invDot; - out[1] = -a1*invDot; - out[2] = -a2*invDot; - out[3] = a3*invDot; +vec2.transformMat3 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[3] * y + m[6]; + out[1] = m[1] * x + m[4] * y + m[7]; return out; }; /** - * Calculates the conjugate of a quat - * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result. + * Transforms the vec2 with a mat4 + * 3rd vector component is implicitly '0' + * 4th vector component is implicitly '1' * - * @param {quat} out the receiving quaternion - * @param {quat} a quat to calculate conjugate of - * @returns {quat} out + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec2} out */ -quat.conjugate = function (out, a) { - out[0] = -a[0]; - out[1] = -a[1]; - out[2] = -a[2]; - out[3] = a[3]; +vec2.transformMat4 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[4] * y + m[12]; + out[1] = m[1] * x + m[5] * y + m[13]; return out; }; /** - * Calculates the length of a quat - * - * @param {quat} a vector to calculate length of - * @returns {Number} length of a - * @function - */ -quat.length = vec4.length; - -/** - * Alias for {@link quat.length} - * @function - */ -quat.len = quat.length; - -/** - * Calculates the squared length of a quat - * - * @param {quat} a vector to calculate squared length of - * @returns {Number} squared length of a - * @function - */ -quat.squaredLength = vec4.squaredLength; - -/** - * Alias for {@link quat.squaredLength} - * @function - */ -quat.sqrLen = quat.squaredLength; - -/** - * Normalize a quat + * Perform some operation over an array of vec2s. * - * @param {quat} out the receiving quaternion - * @param {quat} a quaternion to normalize - * @returns {quat} out + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a * @function */ -quat.normalize = vec4.normalize; +vec2.forEach = (function() { + var vec = vec2.create(); -/** - * Creates a quaternion from the given 3x3 rotation matrix. - * - * @param {quat} out the receiving quaternion - * @param {mat3} m rotation matrix - * @returns {quat} out - * @function - */ -quat.fromMat3 = (function() { - var s_iNext = [1,2,0]; - return function(out, m) { - // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes - // article "Quaternion Calculus and Fast Animation". - var fTrace = m[0] + m[4] + m[8]; - var fRoot; + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 2; + } - if ( fTrace > 0.0 ) { - // |w| > 1/2, may as well choose w > 1/2 - fRoot = Math.sqrt(fTrace + 1.0); // 2w - out[3] = 0.5 * fRoot; - fRoot = 0.5/fRoot; // 1/(4w) - out[0] = (m[7]-m[5])*fRoot; - out[1] = (m[2]-m[6])*fRoot; - out[2] = (m[3]-m[1])*fRoot; + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); } else { - // |w| <= 1/2 - var i = 0; - if ( m[4] > m[0] ) - i = 1; - if ( m[8] > m[i*3+i] ) - i = 2; - var j = s_iNext[i]; - var k = s_iNext[j]; - - fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0); - out[i] = 0.5 * fRoot; - fRoot = 0.5 / fRoot; - out[3] = (m[k*3+j] - m[j*3+k]) * fRoot; - out[j] = (m[j*3+i] + m[i*3+j]) * fRoot; - out[k] = (m[k*3+i] + m[i*3+k]) * fRoot; + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; } - return out; + return a; }; })(); /** - * Returns a string representation of a quatenion + * Returns a string representation of a vector * - * @param {quat} vec vector to represent as a string + * @param {vec2} vec vector to represent as a string * @returns {String} string representation of the vector */ -quat.str = function (a) { - return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; +vec2.str = function (a) { + return 'vec2(' + a[0] + ', ' + a[1] + ')'; }; if(typeof(exports) !== 'undefined') { - exports.quat = quat; + exports.vec2 = vec2; } ; +/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/** + * @class 3 Dimensional Vector + * @name vec3 + */ +var vec3 = {}; +/** + * Creates a new, empty vec3 + * + * @returns {vec3} a new 3D vector + */ +vec3.create = function() { + var out = new GLMAT_ARRAY_TYPE(3); + out[0] = 0; + out[1] = 0; + out[2] = 0; + return out; +}; +/** + * Creates a new vec3 initialized with values from an existing vector + * + * @param {vec3} a vector to clone + * @returns {vec3} a new 3D vector + */ +vec3.clone = function(a) { + var out = new GLMAT_ARRAY_TYPE(3); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + return out; +}; +/** + * Creates a new vec3 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @returns {vec3} a new 3D vector + */ +vec3.fromValues = function(x, y, z) { + var out = new GLMAT_ARRAY_TYPE(3); + out[0] = x; + out[1] = y; + out[2] = z; + return out; +}; +/** + * Copy the values from one vec3 to another + * + * @param {vec3} out the receiving vector + * @param {vec3} a the source vector + * @returns {vec3} out + */ +vec3.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + return out; +}; +/** + * Set the components of a vec3 to the given values + * + * @param {vec3} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @returns {vec3} out + */ +vec3.set = function(out, x, y, z) { + out[0] = x; + out[1] = y; + out[2] = z; + return out; +}; +/** + * Adds two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + return out; +}; +/** + * Subtracts two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + return out; +}; - })(shim.exports); -})(); +/** + * Alias for {@link vec3.subtract} + * @function + */ +vec3.sub = vec3.subtract; -},{}],69:[function(require,module,exports){ -arguments[4][9][0].apply(exports,arguments) -},{"cwise-compiler":70}],70:[function(require,module,exports){ -arguments[4][10][0].apply(exports,arguments) -},{"./lib/thunk.js":72}],71:[function(require,module,exports){ -arguments[4][11][0].apply(exports,arguments) -},{"uniq":73}],72:[function(require,module,exports){ -arguments[4][12][0].apply(exports,arguments) -},{"./compile.js":71}],73:[function(require,module,exports){ -module.exports=require(13) -},{}],74:[function(require,module,exports){ -arguments[4][14][0].apply(exports,arguments) -},{"buffer":106,"iota-array":75}],75:[function(require,module,exports){ -module.exports=require(15) -},{}],76:[function(require,module,exports){ -module.exports=require(16) -},{}],77:[function(require,module,exports){ -module.exports=require(17) -},{}],78:[function(require,module,exports){ -module.exports=require(56) -},{"bit-twiddle":76,"buffer":106,"dup":77}],79:[function(require,module,exports){ -module.exports=require(41) -},{}],80:[function(require,module,exports){ -module.exports=require(42) -},{"weakmap":79}],81:[function(require,module,exports){ -"use strict" +/** + * Multiplies two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.multiply = function(out, a, b) { + out[0] = a[0] * b[0]; + out[1] = a[1] * b[1]; + out[2] = a[2] * b[2]; + return out; +}; -var ndarray = require("ndarray") -var ops = require("ndarray-ops") -var pool = require("typedarray-pool") -var webglew = require("webglew") +/** + * Alias for {@link vec3.multiply} + * @function + */ +vec3.mul = vec3.multiply; -var linearTypes = null -var filterTypes = null -var wrapTypes = null +/** + * Divides two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.divide = function(out, a, b) { + out[0] = a[0] / b[0]; + out[1] = a[1] / b[1]; + out[2] = a[2] / b[2]; + return out; +}; -function lazyInitLinearTypes(gl) { - linearTypes = [ - gl.LINEAR, - gl.NEAREST_MIPMAP_LINEAR, - gl.LINEAR_MIPMAP_NEAREST, - gl.LINEAR_MIPMAP_NEAREST - ] - filterTypes = [ - gl.NEAREST, - gl.LINEAR, - gl.NEAREST_MIPMAP_NEAREST, - gl.NEAREST_MIPMAP_LINEAR, - gl.LINEAR_MIPMAP_NEAREST, - gl.LINEAR_MIPMAP_LINEAR - ] - wrapTypes = [ - gl.REPEAT, - gl.CLAMP_TO_EDGE, - gl.MIRRORED_REPEAT - ] -} +/** + * Alias for {@link vec3.divide} + * @function + */ +vec3.div = vec3.divide; -var convertFloatToUint8 = function(out, inp) { - ops.muls(out, inp, 255.0) -} +/** + * Returns the minimum of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.min = function(out, a, b) { + out[0] = Math.min(a[0], b[0]); + out[1] = Math.min(a[1], b[1]); + out[2] = Math.min(a[2], b[2]); + return out; +}; -function Texture2D(gl, handle, width, height, format, type) { - this.gl = gl - this.handle = handle - this.format = format - this.type = type - this._shape = [height, width] - this._mipLevels = [0] - this._magFilter = gl.NEAREST - this._minFilter = gl.NEAREST - this._wrapS = gl.CLAMP_TO_EDGE - this._wrapT = gl.CLAMP_TO_EDGE - this._anisoSamples = 1 -} +/** + * Returns the maximum of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.max = function(out, a, b) { + out[0] = Math.max(a[0], b[0]); + out[1] = Math.max(a[1], b[1]); + out[2] = Math.max(a[2], b[2]); + return out; +}; -Object.defineProperty(Texture2D.prototype, "minFilter", { - get: function() { - return this._minFilter - }, - set: function(v) { - this.bind() - var gl = this.gl - if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) { - if(!webglew(gl).OES_texture_float_linear) { - v = gl.NEAREST - } - } - if(filterTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown filter mode " + v) - } - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, v) - return this._minFilter = v - } -}) +/** + * Scales a vec3 by a scalar number + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec3} out + */ +vec3.scale = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + return out; +}; -var proto = Texture2D.prototype +/** + * Calculates the euclidian distance between two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} distance between a and b + */ +vec3.distance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2]; + return Math.sqrt(x*x + y*y + z*z); +}; -Object.defineProperty(proto, "magFilter", { - get: function() { - return this._magFilter - }, - set: function(v) { - this.bind() - var gl = this.gl - if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) { - if(!webglew(gl).OES_texture_float_linear) { - v = gl.NEAREST - } - } - if(filterTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown filter mode " + v) - } - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, v) - return this._magFilter = v - } -}) +/** + * Alias for {@link vec3.distance} + * @function + */ +vec3.dist = vec3.distance; -Object.defineProperty(proto, "wrapS", { - get: function() { - return this._wrapS - }, - set: function(v) { - this.bind() - if(wrapTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown wrap mode " + v) - } - this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, v) - return this._wrapS = v - } -}) +/** + * Calculates the squared euclidian distance between two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} squared distance between a and b + */ +vec3.squaredDistance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2]; + return x*x + y*y + z*z; +}; -Object.defineProperty(proto, "wrapT", { - get: function() { - return this._wrapT - }, - set: function(v) { - this.bind() - if(wrapTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown wrap mode " + v) - } - this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, v) - return this._wrapT = v - } -}) +/** + * Alias for {@link vec3.squaredDistance} + * @function + */ +vec3.sqrDist = vec3.squaredDistance; +/** + * Calculates the length of a vec3 + * + * @param {vec3} a vector to calculate length of + * @returns {Number} length of a + */ +vec3.length = function (a) { + var x = a[0], + y = a[1], + z = a[2]; + return Math.sqrt(x*x + y*y + z*z); +}; -Object.defineProperty(proto, "wrap", { - get: function() { - return [this._wrapT, this._wrapS] - }, - set: function(v) { - if(!Array.isArray(v)) { - v = [v,v] - } - if(v.length !== 2) { - throw new Error("gl-texture2d: Must specify wrap mode for rows and columns") - } - for(var i=0; i<2; ++i) { - if(wrapTypes.indexOf(v[i]) < 0) { - throw new Error("gl-texture2d: Unknown wrap mode " + v) - } - } - this._wrapT = v[0] - this._wrapS = v[1] +/** + * Alias for {@link vec3.length} + * @function + */ +vec3.len = vec3.length; - var gl = this.gl - this.bind() - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this._wrapT) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this._wrapS) +/** + * Calculates the squared length of a vec3 + * + * @param {vec3} a vector to calculate squared length of + * @returns {Number} squared length of a + */ +vec3.squaredLength = function (a) { + var x = a[0], + y = a[1], + z = a[2]; + return x*x + y*y + z*z; +}; - return v - } -}) +/** + * Alias for {@link vec3.squaredLength} + * @function + */ +vec3.sqrLen = vec3.squaredLength; -Object.defineProperty(proto, "mipSamples", { - get: function() { - return this._anisoSamples - }, - set: function(i) { - var psamples = this._anisoSamples - this._anisoSamples = Math.max(i, 1)|0 - if(psamples !== this._anisoSamples) { - var ext = webglew(this.gl).EXT_texture_filter_anisotropic - if(ext) { - this.gl.texParameterf(this.gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, this._anisoSamples) - } - } - return this._anisoSamples - } -}) +/** + * Negates the components of a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to negate + * @returns {vec3} out + */ +vec3.negate = function(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + return out; +}; -Object.defineProperty(proto, "shape", { - get: function() { - return this._shape - }, - set: function(x) { - if(!Array.isArray(x)) { - x = [x|0,x|0] - } else { - if(x.length !== 2) { - throw new Error("gl-texture2d: Invalid texture shape") - } - } - var r = x[0]|0 - var c = x[1]|0 - if(this.height === r && this.width === c) { - return x - } - var gl = this.gl - var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) - if(c < 0 || c > maxSize || r < 0 || r > maxSize) { - throw new Error("gl-texture2d: Invalid texture size") +/** + * Normalize a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to normalize + * @returns {vec3} out + */ +vec3.normalize = function(out, a) { + var x = a[0], + y = a[1], + z = a[2]; + var len = x*x + y*y + z*z; + if (len > 0) { + //TODO: evaluate use of glm_invsqrt here? + len = 1 / Math.sqrt(len); + out[0] = a[0] * len; + out[1] = a[1] * len; + out[2] = a[2] * len; } - this._shape = [r, c] - this.bind() - gl.texImage2D(gl.TEXTURE_2D, 0, this.format, c, r, 0, this.format, this.type, null) - this._mipLevels = [0] - return x - } -}) + return out; +}; -proto.bind = function bindTexture2D(unit) { - var gl = this.gl - if(unit !== undefined) { - gl.activeTexture(gl.TEXTURE0 + (unit|0)) - } - gl.bindTexture(gl.TEXTURE_2D, this.handle) - if(unit !== undefined) { - return unit - } - return gl.getParameter(gl.ACTIVE_TEXTURE) - gl.TEXTURE0 -} +/** + * Calculates the dot product of two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} dot product of a and b + */ +vec3.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; +}; -proto.dispose = function disposeTexture2D() { - this.gl.deleteTexture(this.handle) -} +/** + * Computes the cross product of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.cross = function(out, a, b) { + var ax = a[0], ay = a[1], az = a[2], + bx = b[0], by = b[1], bz = b[2]; -proto.generateMipmap = function() { - this.bind() - this.gl.generateMipmap(this.gl.TEXTURE_2D) - - //Update mip levels - var l = Math.min(this._shape[0], this._shape[1]) - for(var i=0; l>0; ++i, l>>>=1) { - if(this._mipLevels.indexOf(i) < 0) { - this._mipLevels.push(i) - } - } -} + out[0] = ay * bz - az * by; + out[1] = az * bx - ax * bz; + out[2] = ax * by - ay * bx; + return out; +}; -proto.setPixels = function(data, x_off, y_off, mip_level) { - var gl = this.gl - this.bind() - if(Array.isArray(x_off)) { - mip_level = y_off - y_off = x_off[0]|0 - x_off = x_off[1]|0 - } else { - x_off = x_off || 0 - y_off = y_off || 0 - } - mip_level = mip_level || 0 - if(data instanceof HTMLCanvasElement || - data instanceof ImageData || - data instanceof HTMLImageElement || - data instanceof HTMLVideoElement) { - var needsMip = this._mipLevels.indexOf(mip_level) < 0 - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, data) - this._mipLevels.push(mip_level) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, this.format, this.type, data) - } - } else if(data.shape && data.stride && data.data) { - if(data.shape.length < 2 || - x_off + data.shape[1] > this._shape[1]>>>mip_level || - y_off + data.shape[0] > this._shape[0]>>>mip_level || - x_off < 0 || - y_off < 0) { - throw new Error("gl-texture2d: Texture dimensions are out of bounds") - } - texSubImageArray(gl, x_off, y_off, mip_level, this.format, this.type, this._mipLevels, data) - } else { - throw new Error("gl-texture2d: Unsupported data type") - } -} +/** + * Performs a linear interpolation between two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec3} out + */ +vec3.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1], + az = a[2]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + out[2] = az + t * (b[2] - az); + return out; +}; -function texSubImageArray(gl, x_off, y_off, mip_level, cformat, ctype, mipLevels, array) { - var dtype = array.dtype - var shape = array.shape - var packed = isPacked(array) - var type = 0, format = 0 - if(dtype === "float32") { - type = gl.FLOAT - } else if(dtype === "float64") { - type = gl.FLOAT - packed = false - dtype = "float32" - } else if(dtype === "uint8") { - type = gl.UNSIGNED_BYTE - } else { - type = gl.UNSIGNED_BYTE - packed = false - dtype = "uint8" - } - if(shape.length === 2) { - format = gl.LUMINANCE - } else if(shape.length === 3) { - if(shape[2] === 1) { - format = gl.ALPHA - } else if(shape[2] === 2) { - format = gl.LUMINANCE_ALPHA - } else if(shape[2] === 3) { - format = gl.RGB - } else if(shape[2] === 4) { - format = gl.RGBA - } else { - throw new Error("gl-texture2d: Invalid shape for pixel coords") +/** + * Transforms the vec3 with a mat4. + * 4th vector component is implicitly '1' + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec3} out + */ +vec3.transformMat4 = function(out, a, m) { + var x = a[0], y = a[1], z = a[2]; + out[0] = m[0] * x + m[4] * y + m[8] * z + m[12]; + out[1] = m[1] * x + m[5] * y + m[9] * z + m[13]; + out[2] = m[2] * x + m[6] * y + m[10] * z + m[14]; + return out; +}; + +/** + * Transforms the vec3 with a quat + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {quat} q quaternion to transform with + * @returns {vec3} out + */ +vec3.transformQuat = function(out, a, q) { + var x = a[0], y = a[1], z = a[2], + qx = q[0], qy = q[1], qz = q[2], qw = q[3], + + // calculate quat * vec + ix = qw * x + qy * z - qz * y, + iy = qw * y + qz * x - qx * z, + iz = qw * z + qx * y - qy * x, + iw = -qx * x - qy * y - qz * z; + + // calculate result * inverse quat + out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; + out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; + out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; + return out; +}; + +/** + * Perform some operation over an array of vec3s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ +vec3.forEach = (function() { + var vec = vec3.create(); + + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 3; + } + + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); + } else { + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; + } + + return a; + }; +})(); + +/** + * Returns a string representation of a vector + * + * @param {vec3} vec vector to represent as a string + * @returns {String} string representation of the vector + */ +vec3.str = function (a) { + return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')'; +}; + +if(typeof(exports) !== 'undefined') { + exports.vec3 = vec3; +} +; +/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +/** + * @class 4 Dimensional Vector + * @name vec4 + */ + +var vec4 = {}; + +/** + * Creates a new, empty vec4 + * + * @returns {vec4} a new 4D vector + */ +vec4.create = function() { + var out = new GLMAT_ARRAY_TYPE(4); + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 0; + return out; +}; + +/** + * Creates a new vec4 initialized with values from an existing vector + * + * @param {vec4} a vector to clone + * @returns {vec4} a new 4D vector + */ +vec4.clone = function(a) { + var out = new GLMAT_ARRAY_TYPE(4); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; +}; + +/** + * Creates a new vec4 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {vec4} a new 4D vector + */ +vec4.fromValues = function(x, y, z, w) { + var out = new GLMAT_ARRAY_TYPE(4); + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = w; + return out; +}; + +/** + * Copy the values from one vec4 to another + * + * @param {vec4} out the receiving vector + * @param {vec4} a the source vector + * @returns {vec4} out + */ +vec4.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; +}; + +/** + * Set the components of a vec4 to the given values + * + * @param {vec4} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {vec4} out + */ +vec4.set = function(out, x, y, z, w) { + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = w; + return out; +}; + +/** + * Adds two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + out[3] = a[3] + b[3]; + return out; +}; + +/** + * Subtracts two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + out[3] = a[3] - b[3]; + return out; +}; + +/** + * Alias for {@link vec4.subtract} + * @function + */ +vec4.sub = vec4.subtract; + +/** + * Multiplies two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.multiply = function(out, a, b) { + out[0] = a[0] * b[0]; + out[1] = a[1] * b[1]; + out[2] = a[2] * b[2]; + out[3] = a[3] * b[3]; + return out; +}; + +/** + * Alias for {@link vec4.multiply} + * @function + */ +vec4.mul = vec4.multiply; + +/** + * Divides two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.divide = function(out, a, b) { + out[0] = a[0] / b[0]; + out[1] = a[1] / b[1]; + out[2] = a[2] / b[2]; + out[3] = a[3] / b[3]; + return out; +}; + +/** + * Alias for {@link vec4.divide} + * @function + */ +vec4.div = vec4.divide; + +/** + * Returns the minimum of two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.min = function(out, a, b) { + out[0] = Math.min(a[0], b[0]); + out[1] = Math.min(a[1], b[1]); + out[2] = Math.min(a[2], b[2]); + out[3] = Math.min(a[3], b[3]); + return out; +}; + +/** + * Returns the maximum of two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.max = function(out, a, b) { + out[0] = Math.max(a[0], b[0]); + out[1] = Math.max(a[1], b[1]); + out[2] = Math.max(a[2], b[2]); + out[3] = Math.max(a[3], b[3]); + return out; +}; + +/** + * Scales a vec4 by a scalar number + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec4} out + */ +vec4.scale = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + out[3] = a[3] * b; + return out; +}; + +/** + * Calculates the euclidian distance between two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} distance between a and b + */ +vec4.distance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2], + w = b[3] - a[3]; + return Math.sqrt(x*x + y*y + z*z + w*w); +}; + +/** + * Alias for {@link vec4.distance} + * @function + */ +vec4.dist = vec4.distance; + +/** + * Calculates the squared euclidian distance between two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} squared distance between a and b + */ +vec4.squaredDistance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2], + w = b[3] - a[3]; + return x*x + y*y + z*z + w*w; +}; + +/** + * Alias for {@link vec4.squaredDistance} + * @function + */ +vec4.sqrDist = vec4.squaredDistance; + +/** + * Calculates the length of a vec4 + * + * @param {vec4} a vector to calculate length of + * @returns {Number} length of a + */ +vec4.length = function (a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + return Math.sqrt(x*x + y*y + z*z + w*w); +}; + +/** + * Alias for {@link vec4.length} + * @function + */ +vec4.len = vec4.length; + +/** + * Calculates the squared length of a vec4 + * + * @param {vec4} a vector to calculate squared length of + * @returns {Number} squared length of a + */ +vec4.squaredLength = function (a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + return x*x + y*y + z*z + w*w; +}; + +/** + * Alias for {@link vec4.squaredLength} + * @function + */ +vec4.sqrLen = vec4.squaredLength; + +/** + * Negates the components of a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to negate + * @returns {vec4} out + */ +vec4.negate = function(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = -a[3]; + return out; +}; + +/** + * Normalize a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to normalize + * @returns {vec4} out + */ +vec4.normalize = function(out, a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + var len = x*x + y*y + z*z + w*w; + if (len > 0) { + len = 1 / Math.sqrt(len); + out[0] = a[0] * len; + out[1] = a[1] * len; + out[2] = a[2] * len; + out[3] = a[3] * len; + } + return out; +}; + +/** + * Calculates the dot product of two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} dot product of a and b + */ +vec4.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; +}; + +/** + * Performs a linear interpolation between two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec4} out + */ +vec4.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1], + az = a[2], + aw = a[3]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + out[2] = az + t * (b[2] - az); + out[3] = aw + t * (b[3] - aw); + return out; +}; + +/** + * Transforms the vec4 with a mat4. + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec4} out + */ +vec4.transformMat4 = function(out, a, m) { + var x = a[0], y = a[1], z = a[2], w = a[3]; + out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w; + out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w; + out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w; + out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w; + return out; +}; + +/** + * Transforms the vec4 with a quat + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to transform + * @param {quat} q quaternion to transform with + * @returns {vec4} out + */ +vec4.transformQuat = function(out, a, q) { + var x = a[0], y = a[1], z = a[2], + qx = q[0], qy = q[1], qz = q[2], qw = q[3], + + // calculate quat * vec + ix = qw * x + qy * z - qz * y, + iy = qw * y + qz * x - qx * z, + iz = qw * z + qx * y - qy * x, + iw = -qx * x - qy * y - qz * z; + + // calculate result * inverse quat + out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; + out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; + out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; + return out; +}; + +/** + * Perform some operation over an array of vec4s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ +vec4.forEach = (function() { + var vec = vec4.create(); + + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 4; + } + + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); + } else { + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3]; + } + + return a; + }; +})(); + +/** + * Returns a string representation of a vector + * + * @param {vec4} vec vector to represent as a string + * @returns {String} string representation of the vector + */ +vec4.str = function (a) { + return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; +}; + +if(typeof(exports) !== 'undefined') { + exports.vec4 = vec4; +} +; +/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +/** + * @class 2x2 Matrix + * @name mat2 + */ + +var mat2 = {}; + +var mat2Identity = new Float32Array([ + 1, 0, + 0, 1 +]); + +/** + * Creates a new identity mat2 + * + * @returns {mat2} a new 2x2 matrix + */ +mat2.create = function() { + var out = new GLMAT_ARRAY_TYPE(4); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; +}; + +/** + * Creates a new mat2 initialized with values from an existing matrix + * + * @param {mat2} a matrix to clone + * @returns {mat2} a new 2x2 matrix + */ +mat2.clone = function(a) { + var out = new GLMAT_ARRAY_TYPE(4); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; +}; + +/** + * Copy the values from one mat2 to another + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ +mat2.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; +}; + +/** + * Set a mat2 to the identity matrix + * + * @param {mat2} out the receiving matrix + * @returns {mat2} out + */ +mat2.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; +}; + +/** + * Transpose the values of a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ +mat2.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a1 = a[1]; + out[1] = a[2]; + out[2] = a1; + } else { + out[0] = a[0]; + out[1] = a[2]; + out[2] = a[1]; + out[3] = a[3]; + } + + return out; +}; + +/** + * Inverts a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ +mat2.invert = function(out, a) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + + // Calculate the determinant + det = a0 * a3 - a2 * a1; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = a3 * det; + out[1] = -a1 * det; + out[2] = -a2 * det; + out[3] = a0 * det; + + return out; +}; + +/** + * Calculates the adjugate of a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ +mat2.adjoint = function(out, a) { + // Caching this value is nessecary if out == a + var a0 = a[0]; + out[0] = a[3]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = a0; + + return out; +}; + +/** + * Calculates the determinant of a mat2 + * + * @param {mat2} a the source matrix + * @returns {Number} determinant of a + */ +mat2.determinant = function (a) { + return a[0] * a[3] - a[2] * a[1]; +}; + +/** + * Multiplies two mat2's + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the first operand + * @param {mat2} b the second operand + * @returns {mat2} out + */ +mat2.multiply = function (out, a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3]; + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + out[0] = a0 * b0 + a1 * b2; + out[1] = a0 * b1 + a1 * b3; + out[2] = a2 * b0 + a3 * b2; + out[3] = a2 * b1 + a3 * b3; + return out; +}; + +/** + * Alias for {@link mat2.multiply} + * @function + */ +mat2.mul = mat2.multiply; + +/** + * Rotates a mat2 by the given angle + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat2} out + */ +mat2.rotate = function (out, a, rad) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + s = Math.sin(rad), + c = Math.cos(rad); + out[0] = a0 * c + a1 * s; + out[1] = a0 * -s + a1 * c; + out[2] = a2 * c + a3 * s; + out[3] = a2 * -s + a3 * c; + return out; +}; + +/** + * Scales the mat2 by the dimensions in the given vec2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the matrix to rotate + * @param {vec2} v the vec2 to scale the matrix by + * @returns {mat2} out + **/ +mat2.scale = function(out, a, v) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + v0 = v[0], v1 = v[1]; + out[0] = a0 * v0; + out[1] = a1 * v1; + out[2] = a2 * v0; + out[3] = a3 * v1; + return out; +}; + +/** + * Returns a string representation of a mat2 + * + * @param {mat2} mat matrix to represent as a string + * @returns {String} string representation of the matrix + */ +mat2.str = function (a) { + return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; +}; + +if(typeof(exports) !== 'undefined') { + exports.mat2 = mat2; +} +; +/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +/** + * @class 2x3 Matrix + * @name mat2d + * + * @description + * A mat2d contains six elements defined as: + *
    + * [a, b,
    + *  c, d,
    + *  tx,ty]
    + * 
    + * This is a short form for the 3x3 matrix: + *
    + * [a, b, 0
    + *  c, d, 0
    + *  tx,ty,1]
    + * 
    + * The last column is ignored so the array is shorter and operations are faster. + */ + +var mat2d = {}; + +var mat2dIdentity = new Float32Array([ + 1, 0, + 0, 1, + 0, 0 +]); + +/** + * Creates a new identity mat2d + * + * @returns {mat2d} a new 2x3 matrix + */ +mat2d.create = function() { + var out = new GLMAT_ARRAY_TYPE(6); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + out[4] = 0; + out[5] = 0; + return out; +}; + +/** + * Creates a new mat2d initialized with values from an existing matrix + * + * @param {mat2d} a matrix to clone + * @returns {mat2d} a new 2x3 matrix + */ +mat2d.clone = function(a) { + var out = new GLMAT_ARRAY_TYPE(6); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + return out; +}; + +/** + * Copy the values from one mat2d to another + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the source matrix + * @returns {mat2d} out + */ +mat2d.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + return out; +}; + +/** + * Set a mat2d to the identity matrix + * + * @param {mat2d} out the receiving matrix + * @returns {mat2d} out + */ +mat2d.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + out[4] = 0; + out[5] = 0; + return out; +}; + +/** + * Inverts a mat2d + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the source matrix + * @returns {mat2d} out + */ +mat2d.invert = function(out, a) { + var aa = a[0], ab = a[1], ac = a[2], ad = a[3], + atx = a[4], aty = a[5]; + + var det = aa * ad - ab * ac; + if(!det){ + return null; + } + det = 1.0 / det; + + out[0] = ad * det; + out[1] = -ab * det; + out[2] = -ac * det; + out[3] = aa * det; + out[4] = (ac * aty - ad * atx) * det; + out[5] = (ab * atx - aa * aty) * det; + return out; +}; + +/** + * Calculates the determinant of a mat2d + * + * @param {mat2d} a the source matrix + * @returns {Number} determinant of a + */ +mat2d.determinant = function (a) { + return a[0] * a[3] - a[1] * a[2]; +}; + +/** + * Multiplies two mat2d's + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the first operand + * @param {mat2d} b the second operand + * @returns {mat2d} out + */ +mat2d.multiply = function (out, a, b) { + var aa = a[0], ab = a[1], ac = a[2], ad = a[3], + atx = a[4], aty = a[5], + ba = b[0], bb = b[1], bc = b[2], bd = b[3], + btx = b[4], bty = b[5]; + + out[0] = aa*ba + ab*bc; + out[1] = aa*bb + ab*bd; + out[2] = ac*ba + ad*bc; + out[3] = ac*bb + ad*bd; + out[4] = ba*atx + bc*aty + btx; + out[5] = bb*atx + bd*aty + bty; + return out; +}; + +/** + * Alias for {@link mat2d.multiply} + * @function + */ +mat2d.mul = mat2d.multiply; + + +/** + * Rotates a mat2d by the given angle + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat2d} out + */ +mat2d.rotate = function (out, a, rad) { + var aa = a[0], + ab = a[1], + ac = a[2], + ad = a[3], + atx = a[4], + aty = a[5], + st = Math.sin(rad), + ct = Math.cos(rad); + + out[0] = aa*ct + ab*st; + out[1] = -aa*st + ab*ct; + out[2] = ac*ct + ad*st; + out[3] = -ac*st + ct*ad; + out[4] = ct*atx + st*aty; + out[5] = ct*aty - st*atx; + return out; +}; + +/** + * Scales the mat2d by the dimensions in the given vec2 + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the matrix to translate + * @param {mat2d} v the vec2 to scale the matrix by + * @returns {mat2d} out + **/ +mat2d.scale = function(out, a, v) { + var vx = v[0], vy = v[1]; + out[0] = a[0] * vx; + out[1] = a[1] * vy; + out[2] = a[2] * vx; + out[3] = a[3] * vy; + out[4] = a[4] * vx; + out[5] = a[5] * vy; + return out; +}; + +/** + * Translates the mat2d by the dimensions in the given vec2 + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the matrix to translate + * @param {mat2d} v the vec2 to translate the matrix by + * @returns {mat2d} out + **/ +mat2d.translate = function(out, a, v) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4] + v[0]; + out[5] = a[5] + v[1]; + return out; +}; + +/** + * Returns a string representation of a mat2d + * + * @param {mat2d} a matrix to represent as a string + * @returns {String} string representation of the matrix + */ +mat2d.str = function (a) { + return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + + a[3] + ', ' + a[4] + ', ' + a[5] + ')'; +}; + +if(typeof(exports) !== 'undefined') { + exports.mat2d = mat2d; +} +; +/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +/** + * @class 3x3 Matrix + * @name mat3 + */ + +var mat3 = {}; + +var mat3Identity = new Float32Array([ + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 +]); + +/** + * Creates a new identity mat3 + * + * @returns {mat3} a new 3x3 matrix + */ +mat3.create = function() { + var out = new GLMAT_ARRAY_TYPE(9); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 1; + out[5] = 0; + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; +}; + +/** + * Creates a new mat3 initialized with values from an existing matrix + * + * @param {mat3} a matrix to clone + * @returns {mat3} a new 3x3 matrix + */ +mat3.clone = function(a) { + var out = new GLMAT_ARRAY_TYPE(9); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; +}; + +/** + * Copy the values from one mat3 to another + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ +mat3.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; +}; + +/** + * Set a mat3 to the identity matrix + * + * @param {mat3} out the receiving matrix + * @returns {mat3} out + */ +mat3.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 1; + out[5] = 0; + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; +}; + +/** + * Transpose the values of a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ +mat3.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a01 = a[1], a02 = a[2], a12 = a[5]; + out[1] = a[3]; + out[2] = a[6]; + out[3] = a01; + out[5] = a[7]; + out[6] = a02; + out[7] = a12; + } else { + out[0] = a[0]; + out[1] = a[3]; + out[2] = a[6]; + out[3] = a[1]; + out[4] = a[4]; + out[5] = a[7]; + out[6] = a[2]; + out[7] = a[5]; + out[8] = a[8]; + } + + return out; +}; + +/** + * Inverts a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ +mat3.invert = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + b01 = a22 * a11 - a12 * a21, + b11 = -a22 * a10 + a12 * a20, + b21 = a21 * a10 - a11 * a20, + + // Calculate the determinant + det = a00 * b01 + a01 * b11 + a02 * b21; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = b01 * det; + out[1] = (-a22 * a01 + a02 * a21) * det; + out[2] = (a12 * a01 - a02 * a11) * det; + out[3] = b11 * det; + out[4] = (a22 * a00 - a02 * a20) * det; + out[5] = (-a12 * a00 + a02 * a10) * det; + out[6] = b21 * det; + out[7] = (-a21 * a00 + a01 * a20) * det; + out[8] = (a11 * a00 - a01 * a10) * det; + return out; +}; + +/** + * Calculates the adjugate of a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ +mat3.adjoint = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8]; + + out[0] = (a11 * a22 - a12 * a21); + out[1] = (a02 * a21 - a01 * a22); + out[2] = (a01 * a12 - a02 * a11); + out[3] = (a12 * a20 - a10 * a22); + out[4] = (a00 * a22 - a02 * a20); + out[5] = (a02 * a10 - a00 * a12); + out[6] = (a10 * a21 - a11 * a20); + out[7] = (a01 * a20 - a00 * a21); + out[8] = (a00 * a11 - a01 * a10); + return out; +}; + +/** + * Calculates the determinant of a mat3 + * + * @param {mat3} a the source matrix + * @returns {Number} determinant of a + */ +mat3.determinant = function (a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8]; + + return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); +}; + +/** + * Multiplies two mat3's + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the first operand + * @param {mat3} b the second operand + * @returns {mat3} out + */ +mat3.multiply = function (out, a, b) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + b00 = b[0], b01 = b[1], b02 = b[2], + b10 = b[3], b11 = b[4], b12 = b[5], + b20 = b[6], b21 = b[7], b22 = b[8]; + + out[0] = b00 * a00 + b01 * a10 + b02 * a20; + out[1] = b00 * a01 + b01 * a11 + b02 * a21; + out[2] = b00 * a02 + b01 * a12 + b02 * a22; + + out[3] = b10 * a00 + b11 * a10 + b12 * a20; + out[4] = b10 * a01 + b11 * a11 + b12 * a21; + out[5] = b10 * a02 + b11 * a12 + b12 * a22; + + out[6] = b20 * a00 + b21 * a10 + b22 * a20; + out[7] = b20 * a01 + b21 * a11 + b22 * a21; + out[8] = b20 * a02 + b21 * a12 + b22 * a22; + return out; +}; + +/** + * Alias for {@link mat3.multiply} + * @function + */ +mat3.mul = mat3.multiply; + +/** + * Translate a mat3 by the given vector + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to translate + * @param {vec2} v vector to translate by + * @returns {mat3} out + */ +mat3.translate = function(out, a, v) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + x = v[0], y = v[1]; + + out[0] = a00; + out[1] = a01; + out[2] = a02; + + out[3] = a10; + out[4] = a11; + out[5] = a12; + + out[6] = x * a00 + y * a10 + a20; + out[7] = x * a01 + y * a11 + a21; + out[8] = x * a02 + y * a12 + a22; + return out; +}; + +/** + * Rotates a mat3 by the given angle + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat3} out + */ +mat3.rotate = function (out, a, rad) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + s = Math.sin(rad), + c = Math.cos(rad); + + out[0] = c * a00 + s * a10; + out[1] = c * a01 + s * a11; + out[2] = c * a02 + s * a12; + + out[3] = c * a10 - s * a00; + out[4] = c * a11 - s * a01; + out[5] = c * a12 - s * a02; + + out[6] = a20; + out[7] = a21; + out[8] = a22; + return out; +}; + +/** + * Scales the mat3 by the dimensions in the given vec2 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to rotate + * @param {vec2} v the vec2 to scale the matrix by + * @returns {mat3} out + **/ +mat3.scale = function(out, a, v) { + var x = v[0], y = v[2]; + + out[0] = x * a[0]; + out[1] = x * a[1]; + out[2] = x * a[2]; + + out[3] = y * a[3]; + out[4] = y * a[4]; + out[5] = y * a[5]; + + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; +}; + +/** + * Copies the values from a mat2d into a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to rotate + * @param {vec2} v the vec2 to scale the matrix by + * @returns {mat3} out + **/ +mat3.fromMat2d = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = 0; + + out[3] = a[2]; + out[4] = a[3]; + out[5] = 0; + + out[6] = a[4]; + out[7] = a[5]; + out[8] = 1; + return out; +}; + +/** +* Calculates a 3x3 matrix from the given quaternion +* +* @param {mat3} out mat3 receiving operation result +* @param {quat} q Quaternion to create matrix from +* +* @returns {mat3} out +*/ +mat3.fromQuat = function (out, q) { + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - (yy + zz); + out[1] = xy + wz; + out[2] = xz - wy; + + out[3] = xy - wz; + out[4] = 1 - (xx + zz); + out[5] = yz + wx; + + out[6] = xz + wy; + out[7] = yz - wx; + out[8] = 1 - (xx + yy); + + return out; +}; + +/** + * Returns a string representation of a mat3 + * + * @param {mat3} mat matrix to represent as a string + * @returns {String} string representation of the matrix + */ +mat3.str = function (a) { + return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + + a[6] + ', ' + a[7] + ', ' + a[8] + ')'; +}; + +if(typeof(exports) !== 'undefined') { + exports.mat3 = mat3; +} +; +/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +/** + * @class 4x4 Matrix + * @name mat4 + */ + +var mat4 = {}; + +var mat4Identity = new Float32Array([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 +]); + +/** + * Creates a new identity mat4 + * + * @returns {mat4} a new 4x4 matrix + */ +mat4.create = function() { + var out = new GLMAT_ARRAY_TYPE(16); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; +}; + +/** + * Creates a new mat4 initialized with values from an existing matrix + * + * @param {mat4} a matrix to clone + * @returns {mat4} a new 4x4 matrix + */ +mat4.clone = function(a) { + var out = new GLMAT_ARRAY_TYPE(16); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; +}; + +/** + * Copy the values from one mat4 to another + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ +mat4.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; +}; + +/** + * Set a mat4 to the identity matrix + * + * @param {mat4} out the receiving matrix + * @returns {mat4} out + */ +mat4.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; +}; + +/** + * Transpose the values of a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ +mat4.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a01 = a[1], a02 = a[2], a03 = a[3], + a12 = a[6], a13 = a[7], + a23 = a[11]; + + out[1] = a[4]; + out[2] = a[8]; + out[3] = a[12]; + out[4] = a01; + out[6] = a[9]; + out[7] = a[13]; + out[8] = a02; + out[9] = a12; + out[11] = a[14]; + out[12] = a03; + out[13] = a13; + out[14] = a23; + } else { + out[0] = a[0]; + out[1] = a[4]; + out[2] = a[8]; + out[3] = a[12]; + out[4] = a[1]; + out[5] = a[5]; + out[6] = a[9]; + out[7] = a[13]; + out[8] = a[2]; + out[9] = a[6]; + out[10] = a[10]; + out[11] = a[14]; + out[12] = a[3]; + out[13] = a[7]; + out[14] = a[11]; + out[15] = a[15]; } - } else { - throw new Error("gl-texture2d: Invalid shape for texture") - } - //For 1-channel textures allow conversion between formats - if((format === gl.LUMINANCE || format === gl.ALPHA) && - (cformat === gl.LUMINANCE || cformat === gl.ALPHA)) { - format = cformat - } - if(format !== cformat) { - throw new Error("gl-texture2d: Incompatible texture format for setPixels") - } - var size = array.size - var needsMip = mipLevels.indexOf(mip_level) < 0 - if(needsMip) { - mipLevels.push(mip_level) - } - if(type === ctype && packed) { - //Array data types are compatible, can directly copy into texture - if(array.offset === 0 && array.data.length === size) { - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[1], shape[0], 0, cformat, ctype, array.data) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[1], shape[0], cformat, ctype, array.data) - } + + return out; +}; + +/** + * Inverts a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ +mat4.invert = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32, + + // Calculate the determinant + det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; + out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; + out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; + out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; + out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; + out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; + out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; + out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; + out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; + out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; + out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; + out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; + out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; + out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; + out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; + out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; + + return out; +}; + +/** + * Calculates the adjugate of a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ +mat4.adjoint = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; + + out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22)); + out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22)); + out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12)); + out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12)); + out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22)); + out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22)); + out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12)); + out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12)); + out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21)); + out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21)); + out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11)); + out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11)); + out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21)); + out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21)); + out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11)); + out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11)); + return out; +}; + +/** + * Calculates the determinant of a mat4 + * + * @param {mat4} a the source matrix + * @returns {Number} determinant of a + */ +mat4.determinant = function (a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32; + + // Calculate the determinant + return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; +}; + +/** + * Multiplies two mat4's + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @returns {mat4} out + */ +mat4.multiply = function (out, a, b) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; + + // Cache only the current line of the second matrix + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7]; + out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11]; + out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15]; + out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + return out; +}; + +/** + * Alias for {@link mat4.multiply} + * @function + */ +mat4.mul = mat4.multiply; + +/** + * Translate a mat4 by the given vector + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to translate + * @param {vec3} v vector to translate by + * @returns {mat4} out + */ +mat4.translate = function (out, a, v) { + var x = v[0], y = v[1], z = v[2], + a00, a01, a02, a03, + a10, a11, a12, a13, + a20, a21, a22, a23; + + if (a === out) { + out[12] = a[0] * x + a[4] * y + a[8] * z + a[12]; + out[13] = a[1] * x + a[5] * y + a[9] * z + a[13]; + out[14] = a[2] * x + a[6] * y + a[10] * z + a[14]; + out[15] = a[3] * x + a[7] * y + a[11] * z + a[15]; } else { - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[1], shape[0], 0, cformat, ctype, array.data.subarray(array.offset, array.offset+size)) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[1], shape[0], cformat, ctype, array.data.subarray(array.offset, array.offset+size)) - } + a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; + a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; + a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; + + out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03; + out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13; + out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23; + + out[12] = a00 * x + a10 * y + a20 * z + a[12]; + out[13] = a01 * x + a11 * y + a21 * z + a[13]; + out[14] = a02 * x + a12 * y + a22 * z + a[14]; + out[15] = a03 * x + a13 * y + a23 * z + a[15]; + } + + return out; +}; + +/** + * Scales the mat4 by the dimensions in the given vec3 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to scale + * @param {vec3} v the vec3 to scale the matrix by + * @returns {mat4} out + **/ +mat4.scale = function(out, a, v) { + var x = v[0], y = v[1], z = v[2]; + + out[0] = a[0] * x; + out[1] = a[1] * x; + out[2] = a[2] * x; + out[3] = a[3] * x; + out[4] = a[4] * y; + out[5] = a[5] * y; + out[6] = a[6] * y; + out[7] = a[7] * y; + out[8] = a[8] * z; + out[9] = a[9] * z; + out[10] = a[10] * z; + out[11] = a[11] * z; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; +}; + +/** + * Rotates a mat4 by the given angle + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @param {vec3} axis the axis to rotate around + * @returns {mat4} out + */ +mat4.rotate = function (out, a, rad, axis) { + var x = axis[0], y = axis[1], z = axis[2], + len = Math.sqrt(x * x + y * y + z * z), + s, c, t, + a00, a01, a02, a03, + a10, a11, a12, a13, + a20, a21, a22, a23, + b00, b01, b02, + b10, b11, b12, + b20, b21, b22; + + if (Math.abs(len) < GLMAT_EPSILON) { return null; } + + len = 1 / len; + x *= len; + y *= len; + z *= len; + + s = Math.sin(rad); + c = Math.cos(rad); + t = 1 - c; + + a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; + a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; + a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; + + // Construct the elements of the rotation matrix + b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s; + b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s; + b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c; + + // Perform rotation-specific matrix multiplication + out[0] = a00 * b00 + a10 * b01 + a20 * b02; + out[1] = a01 * b00 + a11 * b01 + a21 * b02; + out[2] = a02 * b00 + a12 * b01 + a22 * b02; + out[3] = a03 * b00 + a13 * b01 + a23 * b02; + out[4] = a00 * b10 + a10 * b11 + a20 * b12; + out[5] = a01 * b10 + a11 * b11 + a21 * b12; + out[6] = a02 * b10 + a12 * b11 + a22 * b12; + out[7] = a03 * b10 + a13 * b11 + a23 * b12; + out[8] = a00 * b20 + a10 * b21 + a20 * b22; + out[9] = a01 * b20 + a11 * b21 + a21 * b22; + out[10] = a02 * b20 + a12 * b21 + a22 * b22; + out[11] = a03 * b20 + a13 * b21 + a23 * b22; + + if (a !== out) { // If the source and destination differ, copy the unchanged last row + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + return out; +}; + +/** + * Rotates a matrix by the given angle around the X axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ +mat4.rotateX = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7], + a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + + if (a !== out) { // If the source and destination differ, copy the unchanged rows + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[4] = a10 * c + a20 * s; + out[5] = a11 * c + a21 * s; + out[6] = a12 * c + a22 * s; + out[7] = a13 * c + a23 * s; + out[8] = a20 * c - a10 * s; + out[9] = a21 * c - a11 * s; + out[10] = a22 * c - a12 * s; + out[11] = a23 * c - a13 * s; + return out; +}; + +/** + * Rotates a matrix by the given angle around the Y axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ +mat4.rotateY = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3], + a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + + if (a !== out) { // If the source and destination differ, copy the unchanged rows + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[0] = a00 * c - a20 * s; + out[1] = a01 * c - a21 * s; + out[2] = a02 * c - a22 * s; + out[3] = a03 * c - a23 * s; + out[8] = a00 * s + a20 * c; + out[9] = a01 * s + a21 * c; + out[10] = a02 * s + a22 * c; + out[11] = a03 * s + a23 * c; + return out; +}; + +/** + * Rotates a matrix by the given angle around the Z axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ +mat4.rotateZ = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3], + a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7]; + + if (a !== out) { // If the source and destination differ, copy the unchanged last row + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[0] = a00 * c + a10 * s; + out[1] = a01 * c + a11 * s; + out[2] = a02 * c + a12 * s; + out[3] = a03 * c + a13 * s; + out[4] = a10 * c - a00 * s; + out[5] = a11 * c - a01 * s; + out[6] = a12 * c - a02 * s; + out[7] = a13 * c - a03 * s; + return out; +}; + +/** + * Creates a matrix from a quaternion rotation and vector translation + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * var quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @returns {mat4} out + */ +mat4.fromRotationTranslation = function (out, q, v) { + // Quaternion math + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - (yy + zz); + out[1] = xy + wz; + out[2] = xz - wy; + out[3] = 0; + out[4] = xy - wz; + out[5] = 1 - (xx + zz); + out[6] = yz + wx; + out[7] = 0; + out[8] = xz + wy; + out[9] = yz - wx; + out[10] = 1 - (xx + yy); + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + + return out; +}; + +/** +* Calculates a 4x4 matrix from the given quaternion +* +* @param {mat4} out mat4 receiving operation result +* @param {quat} q Quaternion to create matrix from +* +* @returns {mat4} out +*/ +mat4.fromQuat = function (out, q) { + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - (yy + zz); + out[1] = xy + wz; + out[2] = xz - wy; + out[3] = 0; + + out[4] = xy - wz; + out[5] = 1 - (xx + zz); + out[6] = yz + wx; + out[7] = 0; + + out[8] = xz + wy; + out[9] = yz - wx; + out[10] = 1 - (xx + yy); + out[11] = 0; + + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + + return out; +}; + +/** + * Generates a frustum matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {Number} left Left bound of the frustum + * @param {Number} right Right bound of the frustum + * @param {Number} bottom Bottom bound of the frustum + * @param {Number} top Top bound of the frustum + * @param {Number} near Near bound of the frustum + * @param {Number} far Far bound of the frustum + * @returns {mat4} out + */ +mat4.frustum = function (out, left, right, bottom, top, near, far) { + var rl = 1 / (right - left), + tb = 1 / (top - bottom), + nf = 1 / (near - far); + out[0] = (near * 2) * rl; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = (near * 2) * tb; + out[6] = 0; + out[7] = 0; + out[8] = (right + left) * rl; + out[9] = (top + bottom) * tb; + out[10] = (far + near) * nf; + out[11] = -1; + out[12] = 0; + out[13] = 0; + out[14] = (far * near * 2) * nf; + out[15] = 0; + return out; +}; + +/** + * Generates a perspective projection matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} fovy Vertical field of view in radians + * @param {number} aspect Aspect ratio. typically viewport width/height + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ +mat4.perspective = function (out, fovy, aspect, near, far) { + var f = 1.0 / Math.tan(fovy / 2), + nf = 1 / (near - far); + out[0] = f / aspect; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = f; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = (far + near) * nf; + out[11] = -1; + out[12] = 0; + out[13] = 0; + out[14] = (2 * far * near) * nf; + out[15] = 0; + return out; +}; + +/** + * Generates a orthogonal projection matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} left Left bound of the frustum + * @param {number} right Right bound of the frustum + * @param {number} bottom Bottom bound of the frustum + * @param {number} top Top bound of the frustum + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ +mat4.ortho = function (out, left, right, bottom, top, near, far) { + var lr = 1 / (left - right), + bt = 1 / (bottom - top), + nf = 1 / (near - far); + out[0] = -2 * lr; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = -2 * bt; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 2 * nf; + out[11] = 0; + out[12] = (left + right) * lr; + out[13] = (top + bottom) * bt; + out[14] = (far + near) * nf; + out[15] = 1; + return out; +}; + +/** + * Generates a look-at matrix with the given eye position, focal point, and up axis + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {vec3} eye Position of the viewer + * @param {vec3} center Point the viewer is looking at + * @param {vec3} up vec3 pointing up + * @returns {mat4} out + */ +mat4.lookAt = function (out, eye, center, up) { + var x0, x1, x2, y0, y1, y2, z0, z1, z2, len, + eyex = eye[0], + eyey = eye[1], + eyez = eye[2], + upx = up[0], + upy = up[1], + upz = up[2], + centerx = center[0], + centery = center[1], + centerz = center[2]; + + if (Math.abs(eyex - centerx) < GLMAT_EPSILON && + Math.abs(eyey - centery) < GLMAT_EPSILON && + Math.abs(eyez - centerz) < GLMAT_EPSILON) { + return mat4.identity(out); } - } else { - //Need to do type conversion to pack data into buffer - var pack_buffer - if(ctype === gl.FLOAT) { - pack_buffer = pool.mallocFloat32(size) + + z0 = eyex - centerx; + z1 = eyey - centery; + z2 = eyez - centerz; + + len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); + z0 *= len; + z1 *= len; + z2 *= len; + + x0 = upy * z2 - upz * z1; + x1 = upz * z0 - upx * z2; + x2 = upx * z1 - upy * z0; + len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2); + if (!len) { + x0 = 0; + x1 = 0; + x2 = 0; } else { - pack_buffer = pool.mallocUint8(size) + len = 1 / len; + x0 *= len; + x1 *= len; + x2 *= len; } - var pack_view = ndarray(pack_buffer, shape) - if(type === gl.FLOAT && ctype === gl.UNSIGNED_BYTE) { - convertFloatToUint8(pack_view, array) + + y0 = z1 * x2 - z2 * x1; + y1 = z2 * x0 - z0 * x2; + y2 = z0 * x1 - z1 * x0; + + len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2); + if (!len) { + y0 = 0; + y1 = 0; + y2 = 0; } else { - ops.assign(pack_view, array) + len = 1 / len; + y0 *= len; + y1 *= len; + y2 *= len; } - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[1], shape[0], 0, cformat, ctype, pack_buffer.subarray(0, size)) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[1], shape[0], cformat, ctype, pack_buffer.subarray(0, size)) + + out[0] = x0; + out[1] = y0; + out[2] = z0; + out[3] = 0; + out[4] = x1; + out[5] = y1; + out[6] = z1; + out[7] = 0; + out[8] = x2; + out[9] = y2; + out[10] = z2; + out[11] = 0; + out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez); + out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez); + out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez); + out[15] = 1; + + return out; +}; + +/** + * Returns a string representation of a mat4 + * + * @param {mat4} mat matrix to represent as a string + * @returns {String} string representation of the matrix + */ +mat4.str = function (a) { + return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' + + a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' + + a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')'; +}; + +if(typeof(exports) !== 'undefined') { + exports.mat4 = mat4; +} +; +/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +/** + * @class Quaternion + * @name quat + */ + +var quat = {}; + +var quatIdentity = new Float32Array([0, 0, 0, 1]); + +/** + * Creates a new identity quat + * + * @returns {quat} a new quaternion + */ +quat.create = function() { + var out = new GLMAT_ARRAY_TYPE(4); + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; +}; + +/** + * Creates a new quat initialized with values from an existing quaternion + * + * @param {quat} a quaternion to clone + * @returns {quat} a new quaternion + * @function + */ +quat.clone = vec4.clone; + +/** + * Creates a new quat initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {quat} a new quaternion + * @function + */ +quat.fromValues = vec4.fromValues; + +/** + * Copy the values from one quat to another + * + * @param {quat} out the receiving quaternion + * @param {quat} a the source quaternion + * @returns {quat} out + * @function + */ +quat.copy = vec4.copy; + +/** + * Set the components of a quat to the given values + * + * @param {quat} out the receiving quaternion + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {quat} out + * @function + */ +quat.set = vec4.set; + +/** + * Set a quat to the identity quaternion + * + * @param {quat} out the receiving quaternion + * @returns {quat} out + */ +quat.identity = function(out) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; +}; + +/** + * Sets a quat from the given angle and rotation axis, + * then returns it. + * + * @param {quat} out the receiving quaternion + * @param {vec3} axis the axis around which to rotate + * @param {Number} rad the angle in radians + * @returns {quat} out + **/ +quat.setAxisAngle = function(out, axis, rad) { + rad = rad * 0.5; + var s = Math.sin(rad); + out[0] = s * axis[0]; + out[1] = s * axis[1]; + out[2] = s * axis[2]; + out[3] = Math.cos(rad); + return out; +}; + +/** + * Adds two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {quat} out + * @function + */ +quat.add = vec4.add; + +/** + * Multiplies two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {quat} out + */ +quat.multiply = function(out, a, b) { + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = b[0], by = b[1], bz = b[2], bw = b[3]; + + out[0] = ax * bw + aw * bx + ay * bz - az * by; + out[1] = ay * bw + aw * by + az * bx - ax * bz; + out[2] = az * bw + aw * bz + ax * by - ay * bx; + out[3] = aw * bw - ax * bx - ay * by - az * bz; + return out; +}; + +/** + * Alias for {@link quat.multiply} + * @function + */ +quat.mul = quat.multiply; + +/** + * Scales a quat by a scalar number + * + * @param {quat} out the receiving vector + * @param {quat} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {quat} out + * @function + */ +quat.scale = vec4.scale; + +/** + * Rotates a quaternion by the given angle around the X axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ +quat.rotateX = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw + aw * bx; + out[1] = ay * bw + az * bx; + out[2] = az * bw - ay * bx; + out[3] = aw * bw - ax * bx; + return out; +}; + +/** + * Rotates a quaternion by the given angle around the Y axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ +quat.rotateY = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + by = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw - az * by; + out[1] = ay * bw + aw * by; + out[2] = az * bw + ax * by; + out[3] = aw * bw - ay * by; + return out; +}; + +/** + * Rotates a quaternion by the given angle around the Z axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ +quat.rotateZ = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bz = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw + ay * bz; + out[1] = ay * bw - ax * bz; + out[2] = az * bw + aw * bz; + out[3] = aw * bw - az * bz; + return out; +}; + +/** + * Calculates the W component of a quat from the X, Y, and Z components. + * Assumes that quaternion is 1 unit in length. + * Any existing W component will be ignored. + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate W component of + * @returns {quat} out + */ +quat.calculateW = function (out, a) { + var x = a[0], y = a[1], z = a[2]; + + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = -Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z)); + return out; +}; + +/** + * Calculates the dot product of two quat's + * + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {Number} dot product of a and b + * @function + */ +quat.dot = vec4.dot; + +/** + * Performs a linear interpolation between two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {quat} out + * @function + */ +quat.lerp = vec4.lerp; + +/** + * Performs a spherical linear interpolation between two quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {quat} out + */ +quat.slerp = function (out, a, b, t) { + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = b[0], by = b[1], bz = b[2], bw = b[3]; + + var cosHalfTheta = ax * bx + ay * by + az * bz + aw * bw, + halfTheta, + sinHalfTheta, + ratioA, + ratioB; + + if (Math.abs(cosHalfTheta) >= 1.0) { + if (out !== a) { + out[0] = ax; + out[1] = ay; + out[2] = az; + out[3] = aw; + } + return out; } - if(ctype === gl.FLOAT) { - pool.freeFloat32(pack_buffer) - } else { - pool.freeUint8(pack_buffer) + + halfTheta = Math.acos(cosHalfTheta); + sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta); + + if (Math.abs(sinHalfTheta) < 0.001) { + out[0] = (ax * 0.5 + bx * 0.5); + out[1] = (ay * 0.5 + by * 0.5); + out[2] = (az * 0.5 + bz * 0.5); + out[3] = (aw * 0.5 + bw * 0.5); + return out; } - } -} -function initTexture(gl) { - var tex = gl.createTexture() - gl.bindTexture(gl.TEXTURE_2D, tex) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) - return tex -} + ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta; + ratioB = Math.sin(t * halfTheta) / sinHalfTheta; -function createTextureShape(gl, width, height, format, type) { - var maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) - if(width < 0 || width > maxTextureSize || height < 0 || height > maxTextureSize) { - throw new Error("gl-texture2d: Invalid texture shape") - } - var tex = initTexture(gl) - gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, type, null) - return new Texture2D(gl, tex, width, height, format, type) -} + out[0] = (ax * ratioA + bx * ratioB); + out[1] = (ay * ratioA + by * ratioB); + out[2] = (az * ratioA + bz * ratioB); + out[3] = (aw * ratioA + bw * ratioB); -function createTextureDOM(gl, element, format, type) { - var tex = initTexture(gl) - gl.texImage2D(gl.TEXTURE_2D, 0, format, format, type, element) - return new Texture2D(gl, tex, element.width|0, element.height|0, format, type) -} + return out; +}; -function isPacked(array) { - var shape = array.shape - var stride = array.stride - var s = 1 - for(var i=shape.length-1; i>=0; --i) { - if(stride[i] !== s) { - return false - } - s *= shape[i] - } - return true -} +/** + * Calculates the inverse of a quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate inverse of + * @returns {quat} out + */ +quat.invert = function(out, a) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + dot = a0*a0 + a1*a1 + a2*a2 + a3*a3, + invDot = dot ? 1.0/dot : 0; + + // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0 + + out[0] = -a0*invDot; + out[1] = -a1*invDot; + out[2] = -a2*invDot; + out[3] = a3*invDot; + return out; +}; + +/** + * Calculates the conjugate of a quat + * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result. + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate conjugate of + * @returns {quat} out + */ +quat.conjugate = function (out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = a[3]; + return out; +}; + +/** + * Calculates the length of a quat + * + * @param {quat} a vector to calculate length of + * @returns {Number} length of a + * @function + */ +quat.length = vec4.length; + +/** + * Alias for {@link quat.length} + * @function + */ +quat.len = quat.length; + +/** + * Calculates the squared length of a quat + * + * @param {quat} a vector to calculate squared length of + * @returns {Number} squared length of a + * @function + */ +quat.squaredLength = vec4.squaredLength; + +/** + * Alias for {@link quat.squaredLength} + * @function + */ +quat.sqrLen = quat.squaredLength; + +/** + * Normalize a quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a quaternion to normalize + * @returns {quat} out + * @function + */ +quat.normalize = vec4.normalize; + +/** + * Creates a quaternion from the given 3x3 rotation matrix. + * + * @param {quat} out the receiving quaternion + * @param {mat3} m rotation matrix + * @returns {quat} out + * @function + */ +quat.fromMat3 = (function() { + var s_iNext = [1,2,0]; + return function(out, m) { + // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes + // article "Quaternion Calculus and Fast Animation". + var fTrace = m[0] + m[4] + m[8]; + var fRoot; -//Creates a texture from an ndarray -function createTextureArray(gl, array) { - var dtype = array.dtype - var shape = array.shape.slice() - var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) - if(shape[0] < 0 || shape[0] > maxSize || shape[1] < 0 || shape[1] > maxSize) { - throw new Error("gl-texture2d: Invalid texture size") - } + if ( fTrace > 0.0 ) { + // |w| > 1/2, may as well choose w > 1/2 + fRoot = Math.sqrt(fTrace + 1.0); // 2w + out[3] = 0.5 * fRoot; + fRoot = 0.5/fRoot; // 1/(4w) + out[0] = (m[7]-m[5])*fRoot; + out[1] = (m[2]-m[6])*fRoot; + out[2] = (m[3]-m[1])*fRoot; + } else { + // |w| <= 1/2 + var i = 0; + if ( m[4] > m[0] ) + i = 1; + if ( m[8] > m[i*3+i] ) + i = 2; + var j = s_iNext[i]; + var k = s_iNext[j]; + + fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0); + out[i] = 0.5 * fRoot; + fRoot = 0.5 / fRoot; + out[3] = (m[k*3+j] - m[j*3+k]) * fRoot; + out[j] = (m[j*3+i] + m[i*3+j]) * fRoot; + out[k] = (m[k*3+i] + m[i*3+k]) * fRoot; + } + + return out; + }; +})(); - var packed = isPacked(array) - var type = 0 - if(dtype === "float32") { - type = gl.FLOAT - } else if(dtype === "float64") { - type = gl.FLOAT - packed = false - dtype = "float32" - } else if(dtype === "uint8") { - type = gl.UNSIGNED_BYTE - } else { - type = gl.UNSIGNED_BYTE - packed = false - dtype = "uint8" - } - var format = 0 - if(shape.length === 2) { - format = gl.LUMINANCE - } else if(shape.length === 3) { - if(shape[2] === 1) { - format = gl.ALPHA - } else if(shape[2] === 2) { - format = gl.LUMINANCE_ALPHA - } else if(shape[2] === 3) { - format = gl.RGB - } else if(shape[2] === 4) { - format = gl.RGBA - } else { - throw new Error("Invalid shape for pixel coords") - } - } else { - throw new Error("Invalid shape for texture") - } - if(type === gl.FLOAT && !!webglew(gl).texture_float) { - type = gl.UNSIGNED_BYTE - packed = false - } - var buffer, buf_store - if(!packed) { - var sz = 1 - var stride = new Array(shape.length) - for(var i=shape.length-1; i>=0; --i) { - stride[i] = sz - sz *= shape[i] - } - buf_store = pool.malloc(sz, dtype) - var buf_array = ndarray(buf_store, array.shape, stride, 0) - if((dtype === "float32" || dtype === "float64") && type === gl.UNSIGNED_BYTE) { - convertFloatToUint8(buf_array, array) - } else { - ops.assign(buf_array, array) - } - buffer = buf_store.subarray(0, sz) - } else { - var array_size = array.size - buffer = array.data.subarray(array.offset, array.offset + array_size) - } - var tex = initTexture(gl) - gl.texImage2D(gl.TEXTURE_2D, 0, format, shape[1], shape[0], 0, format, type, buffer) - if(!packed) { - pool.free(buf_store) - } - return new Texture2D(gl, tex, shape[1], shape[0], format, type) -} +/** + * Returns a string representation of a quatenion + * + * @param {quat} vec vector to represent as a string + * @returns {String} string representation of the vector + */ +quat.str = function (a) { + return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; +}; -function createTexture2D(gl) { - if(arguments.length <= 1) { - throw new Error("Missing arguments for texture2d constructor") - } - if(!linearTypes) { - lazyInitLinearTypes(gl) - } - if(typeof arguments[1] === "number") { - return createTextureShape(gl, arguments[1], arguments[2], arguments[3]||gl.RGBA, arguments[4]||gl.UNSIGNED_BYTE) - } - if(Array.isArray(arguments[1])) { - return createTextureShape(gl, arguments[1][1]|0, arguments[1][0]|0, arguments[2]||gl.RGBA, arguments[4]||gl.UNSIGNED_BYTE) - } - if(typeof arguments[1] === "object") { - var obj = arguments[1] - if(obj instanceof HTMLCanvasElement || - obj instanceof HTMLImageElement || - obj instanceof HTMLVideoElement || - obj instanceof ImageData) { - return createTextureDOM(gl, obj, arguments[2]||gl.RGBA, arguments[3]||gl.UNSIGNED_BYTE) - } else if(obj.shape && obj.data && obj.stride) { - return createTextureArray(gl, obj) - } - } - throw new Error("Invalid arguments for texture2d constructor") +if(typeof(exports) !== 'undefined') { + exports.quat = quat; } -module.exports = createTexture2D - -},{"ndarray":74,"ndarray-ops":69,"typedarray-pool":78,"webglew":80}],82:[function(require,module,exports){ -module.exports = programify +; -var shader = require('gl-shader-core') -function programify(vertex, fragment, uniforms, attributes) { - return function(gl) { - return shader(gl, vertex, fragment, uniforms, attributes) - } -} -},{"gl-shader-core":88}],83:[function(require,module,exports){ -module.exports = noop -function noop() { - throw new Error( - 'You should bundle your code ' + - 'using `glslify` as a transform.' - ) -} -},{}],84:[function(require,module,exports){ -"use strict" -module.exports = createAttributeWrapper -//Shader attribute class -function ShaderAttribute(gl, program, location, dimension, name, constFunc, relink) { - this._gl = gl - this._program = program - this._location = location - this._dimension = dimension - this._name = name - this._constFunc = constFunc - this._relink = relink -} -var proto = ShaderAttribute.prototype -proto.pointer = function setAttribPointer(type, normalized, stride, offset) { - var gl = this._gl - gl.vertexAttribPointer(this._location, this._dimension, type||gl.FLOAT, normalized?gl.TRUE:gl.FALSE, stride||0, offset||0) - this._gl.enableVertexAttribArray(this._location) -} -Object.defineProperty(proto, "location", { - get: function() { - return this._location - } - , set: function(v) { - if(v !== this._location) { - this._location = v - this._gl.bindAttribLocation(this._program, v, this._name) - this._gl.linkProgram(this._program) - this._relink() - } - } -}) -//Adds a vector attribute to obj -function addVectorAttribute(gl, program, location, dimension, obj, name, doLink) { - var constFuncArgs = [ "gl", "v" ] - var varNames = [] - for(var i=0; i= 0) { - var d = type.charCodeAt(type.length-1) - 48 - if(d < 2 || d > 4) { - throw new Error("Invalid data type for attribute " + name + ": " + type) - } - addVectorAttribute(gl, program, location, d, obj, name, doLink) - } else { - throw new Error("Unknown data type for attribute " + name + ": " + type) - } - break - } - } - return obj -} + })(shim.exports); +})(); -},{}],85:[function(require,module,exports){ +},{}],152:[function(require,module,exports){ +arguments[4][9][0].apply(exports,arguments) +},{"cwise-compiler":153}],153:[function(require,module,exports){ +arguments[4][10][0].apply(exports,arguments) +},{"./lib/thunk.js":155}],154:[function(require,module,exports){ +arguments[4][11][0].apply(exports,arguments) +},{"uniq":156}],155:[function(require,module,exports){ +arguments[4][12][0].apply(exports,arguments) +},{"./compile.js":154}],156:[function(require,module,exports){ +module.exports=require(13) +},{}],157:[function(require,module,exports){ +arguments[4][14][0].apply(exports,arguments) +},{"buffer":189,"iota-array":158}],158:[function(require,module,exports){ +module.exports=require(15) +},{}],159:[function(require,module,exports){ +module.exports=require(16) +},{}],160:[function(require,module,exports){ +module.exports=require(17) +},{}],161:[function(require,module,exports){ +module.exports=require(41) +},{"bit-twiddle":159,"buffer":189,"dup":160}],162:[function(require,module,exports){ +module.exports=require(42) +},{}],163:[function(require,module,exports){ +module.exports=require(43) +},{"weakmap":162}],164:[function(require,module,exports){ "use strict" -var dup = require("dup") -var coallesceUniforms = require("./reflect.js") +var ndarray = require("ndarray") +var ops = require("ndarray-ops") +var pool = require("typedarray-pool") +var webglew = require("webglew") -module.exports = createUniformWrapper +var linearTypes = null +var filterTypes = null +var wrapTypes = null -//Binds a function and returns a value -function identity(x) { - var c = new Function("y", "return function(){return y}") - return c(x) +function lazyInitLinearTypes(gl) { + linearTypes = [ + gl.LINEAR, + gl.NEAREST_MIPMAP_LINEAR, + gl.LINEAR_MIPMAP_NEAREST, + gl.LINEAR_MIPMAP_NEAREST + ] + filterTypes = [ + gl.NEAREST, + gl.LINEAR, + gl.NEAREST_MIPMAP_NEAREST, + gl.NEAREST_MIPMAP_LINEAR, + gl.LINEAR_MIPMAP_NEAREST, + gl.LINEAR_MIPMAP_LINEAR + ] + wrapTypes = [ + gl.REPEAT, + gl.CLAMP_TO_EDGE, + gl.MIRRORED_REPEAT + ] } -//Create shims for uniforms -function createUniformWrapper(gl, program, uniforms, locations) { +var convertFloatToUint8 = function(out, inp) { + ops.muls(out, inp, 255.0) +} - function makeGetter(index) { - var proc = new Function("gl", "prog", "locations", - "return function(){return gl.getUniform(prog,locations[" + index + "])}") - return proc(gl, program, locations) - } +function Texture2D(gl, handle, width, height, format, type) { + this.gl = gl + this.handle = handle + this.format = format + this.type = type + this._shape = [height, width] + this._mipLevels = [0] + this._magFilter = gl.NEAREST + this._minFilter = gl.NEAREST + this._wrapS = gl.CLAMP_TO_EDGE + this._wrapT = gl.CLAMP_TO_EDGE + this._anisoSamples = 1 +} - function makePropSetter(path, index, type) { - switch(type) { - case "bool": - case "int": - case "sampler2D": - case "samplerCube": - return "gl.uniform1i(locations[" + index + "],obj" + path + ")" - case "float": - return "gl.uniform1f(locations[" + index + "],obj" + path + ")" - default: - var vidx = type.indexOf("vec") - if(0 <= vidx && vidx <= 1 && type.length === 4 + vidx) { - var d = type.charCodeAt(type.length-1) - 48 - if(d < 2 || d > 4) { - throw new Error("Invalid data type") - } - switch(type.charAt(0)) { - case "b": - case "i": - return "gl.uniform" + d + "iv(locations[" + index + "],obj" + path + ")" - case "v": - return "gl.uniform" + d + "fv(locations[" + index + "],obj" + path + ")" - default: - throw new Error("Unrecognized data type for vector " + name + ": " + type) - } - } else if(type.indexOf("mat") === 0 && type.length === 4) { - var d = type.charCodeAt(type.length-1) - 48 - if(d < 2 || d > 4) { - throw new Error("Invalid uniform dimension type for matrix " + name + ": " + type) - } - return "gl.uniformMatrix" + d + "fv(locations[" + index + "],false,obj" + path + ")" - } else { - throw new Error("Unknown uniform data type for " + name + ": " + type) - } - break +Object.defineProperty(Texture2D.prototype, "minFilter", { + get: function() { + return this._minFilter + }, + set: function(v) { + this.bind() + var gl = this.gl + if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) { + if(!webglew(gl).OES_texture_float_linear) { + v = gl.NEAREST + } + } + if(filterTypes.indexOf(v) < 0) { + throw new Error("gl-texture2d: Unknown filter mode " + v) } + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, v) + return this._minFilter = v } +}) - function enumerateIndices(prefix, type) { - if(typeof type !== "object") { - return [ [prefix, type] ] - } - var indices = [] - for(var id in type) { - var prop = type[id] - var tprefix = prefix - if(parseInt(id) + "" === id) { - tprefix += "[" + id + "]" - } else { - tprefix += "." + id - } - if(typeof prop === "object") { - indices.push.apply(indices, enumerateIndices(tprefix, prop)) - } else { - indices.push([tprefix, prop]) +var proto = Texture2D.prototype + +Object.defineProperty(proto, "magFilter", { + get: function() { + return this._magFilter + }, + set: function(v) { + this.bind() + var gl = this.gl + if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) { + if(!webglew(gl).OES_texture_float_linear) { + v = gl.NEAREST } } - return indices + if(filterTypes.indexOf(v) < 0) { + throw new Error("gl-texture2d: Unknown filter mode " + v) + } + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, v) + return this._magFilter = v } +}) - function makeSetter(type) { - var code = [ "return function updateProperty(obj){" ] - var indices = enumerateIndices("", type) - for(var i=0; i 4) { - throw new Error("Invalid data type") - } - if(type.charAt(0) === "b") { - return dup(d, false) - } - return dup(d) - } else if(type.indexOf("mat") === 0 && type.length === 4) { - var d = type.charCodeAt(type.length-1) - 48 - if(d < 2 || d > 4) { - throw new Error("Invalid uniform dimension type for matrix " + name + ": " + type) - } - return dup([d,d]) - } else { - throw new Error("Unknown uniform data type for " + name + ": " + type) - } - break +Object.defineProperty(proto, "wrapT", { + get: function() { + return this._wrapT + }, + set: function(v) { + this.bind() + if(wrapTypes.indexOf(v) < 0) { + throw new Error("gl-texture2d: Unknown wrap mode " + v) } + this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, v) + return this._wrapT = v } +}) - function storeProperty(obj, prop, type) { - if(typeof type === "object") { - var child = processObject(type) - Object.defineProperty(obj, prop, { - get: identity(child), - set: makeSetter(type), - enumerable: true, - configurable: false - }) - } else { - if(locations[type]) { - Object.defineProperty(obj, prop, { - get: makeGetter(type), - set: makeSetter(type), - enumerable: true, - configurable: false - }) - } else { - obj[prop] = defaultValue(uniforms[type].type) + +Object.defineProperty(proto, "wrap", { + get: function() { + return [this._wrapT, this._wrapS] + }, + set: function(v) { + if(!Array.isArray(v)) { + v = [v,v] + } + if(v.length !== 2) { + throw new Error("gl-texture2d: Must specify wrap mode for rows and columns") + } + for(var i=0; i<2; ++i) { + if(wrapTypes.indexOf(v[i]) < 0) { + throw new Error("gl-texture2d: Unknown wrap mode " + v) + } + } + this._wrapT = v[0] + this._wrapS = v[1] + + var gl = this.gl + this.bind() + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this._wrapT) + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this._wrapS) + + return v + } +}) + +Object.defineProperty(proto, "mipSamples", { + get: function() { + return this._anisoSamples + }, + set: function(i) { + var psamples = this._anisoSamples + this._anisoSamples = Math.max(i, 1)|0 + if(psamples !== this._anisoSamples) { + var ext = webglew(this.gl).EXT_texture_filter_anisotropic + if(ext) { + this.gl.texParameterf(this.gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, this._anisoSamples) } } + return this._anisoSamples } +}) - function processObject(obj) { - var result - if(Array.isArray(obj)) { - result = new Array(obj.length) - for(var i=0; i maxSize || r < 0 || r > maxSize) { + throw new Error("gl-texture2d: Invalid texture size") + } + this._shape = [r, c] + this.bind() + gl.texImage2D(gl.TEXTURE_2D, 0, this.format, c, r, 0, this.format, this.type, null) + this._mipLevels = [0] + return x } +}) - //Return data - var coallesced = coallesceUniforms(uniforms, true) - return { - get: identity(processObject(coallesced)), - set: makeSetter(coallesced), - enumerable: true, - configurable: true +proto.bind = function bindTexture2D(unit) { + var gl = this.gl + if(unit !== undefined) { + gl.activeTexture(gl.TEXTURE0 + (unit|0)) + } + gl.bindTexture(gl.TEXTURE_2D, this.handle) + if(unit !== undefined) { + return unit } + return gl.getParameter(gl.ACTIVE_TEXTURE) - gl.TEXTURE0 } -},{"./reflect.js":86,"dup":87}],86:[function(require,module,exports){ -"use strict" +proto.dispose = function disposeTexture2D() { + this.gl.deleteTexture(this.handle) +} -module.exports = makeReflectTypes +proto.generateMipmap = function() { + this.bind() + this.gl.generateMipmap(this.gl.TEXTURE_2D) + + //Update mip levels + var l = Math.min(this._shape[0], this._shape[1]) + for(var i=0; l>0; ++i, l>>>=1) { + if(this._mipLevels.indexOf(i) < 0) { + this._mipLevels.push(i) + } + } +} -//Construct type info for reflection. -// -// This iterates over the flattened list of uniform type values and smashes them into a JSON object. -// -// The leaves of the resulting object are either indices or type strings representing primitive glslify types -function makeReflectTypes(uniforms, useIndex) { - var obj = {} - for(var i=0; i 1) { - if(!(x[0] in o)) { - o[x[0]] = [] - } - o = o[x[0]] - for(var k=1; k this._shape[1]>>>mip_level || + y_off + data.shape[0] > this._shape[0]>>>mip_level || + x_off < 0 || + y_off < 0) { + throw new Error("gl-texture2d: Texture dimensions are out of bounds") + } + texSubImageArray(gl, x_off, y_off, mip_level, this.format, this.type, this._mipLevels, data) + } else { + throw new Error("gl-texture2d: Unsupported data type") + } +} + +function texSubImageArray(gl, x_off, y_off, mip_level, cformat, ctype, mipLevels, array) { + var dtype = array.dtype + var shape = array.shape + var packed = isPacked(array) + var type = 0, format = 0 + if(dtype === "float32") { + type = gl.FLOAT + } else if(dtype === "float64") { + type = gl.FLOAT + packed = false + dtype = "float32" + } else if(dtype === "uint8") { + type = gl.UNSIGNED_BYTE + } else { + type = gl.UNSIGNED_BYTE + packed = false + dtype = "uint8" + } + if(shape.length === 2) { + format = gl.LUMINANCE + } else if(shape.length === 3) { + if(shape[2] === 1) { + format = gl.ALPHA + } else if(shape[2] === 2) { + format = gl.LUMINANCE_ALPHA + } else if(shape[2] === 3) { + format = gl.RGB + } else if(shape[2] === 4) { + format = gl.RGBA + } else { + throw new Error("gl-texture2d: Invalid shape for pixel coords") + } + } else { + throw new Error("gl-texture2d: Invalid shape for texture") + } + //For 1-channel textures allow conversion between formats + if((format === gl.LUMINANCE || format === gl.ALPHA) && + (cformat === gl.LUMINANCE || cformat === gl.ALPHA)) { + format = cformat + } + if(format !== cformat) { + throw new Error("gl-texture2d: Incompatible texture format for setPixels") + } + var size = array.size + var needsMip = mipLevels.indexOf(mip_level) < 0 + if(needsMip) { + mipLevels.push(mip_level) + } + if(type === ctype && packed) { + //Array data types are compatible, can directly copy into texture + if(array.offset === 0 && array.data.length === size) { + if(needsMip) { + gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[1], shape[0], 0, cformat, ctype, array.data) } else { - if(useIndex) { - o[x[0]] = i - } else { - o[x[0]] = uniforms[i].type - } + gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[1], shape[0], cformat, ctype, array.data) + } + } else { + if(needsMip) { + gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[1], shape[0], 0, cformat, ctype, array.data.subarray(array.offset, array.offset+size)) + } else { + gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[1], shape[0], cformat, ctype, array.data.subarray(array.offset, array.offset+size)) } } + } else { + //Need to do type conversion to pack data into buffer + var pack_buffer + if(ctype === gl.FLOAT) { + pack_buffer = pool.mallocFloat32(size) + } else { + pack_buffer = pool.mallocUint8(size) + } + var pack_view = ndarray(pack_buffer, shape) + if(type === gl.FLOAT && ctype === gl.UNSIGNED_BYTE) { + convertFloatToUint8(pack_view, array) + } else { + ops.assign(pack_view, array) + } + if(needsMip) { + gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[1], shape[0], 0, cformat, ctype, pack_buffer.subarray(0, size)) + } else { + gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[1], shape[0], cformat, ctype, pack_buffer.subarray(0, size)) + } + if(ctype === gl.FLOAT) { + pool.freeFloat32(pack_buffer) + } else { + pool.freeUint8(pack_buffer) + } } - return obj } -},{}],87:[function(require,module,exports){ -module.exports=require(17) -},{}],88:[function(require,module,exports){ -"use strict" - -var createUniformWrapper = require("./lib/create-uniforms.js") -var createAttributeWrapper = require("./lib/create-attributes.js") -var makeReflect = require("./lib/reflect.js") -//Shader object -function Shader(gl, prog, vertShader, fragShader) { - this.gl = gl - this.handle = prog - this.attributes = null - this.uniforms = null - this.types = null - this.vertexShader = vertShader - this.fragmentShader = fragShader +function initTexture(gl) { + var tex = gl.createTexture() + gl.bindTexture(gl.TEXTURE_2D, tex) + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) + return tex } -//Binds the shader -Shader.prototype.bind = function() { - this.gl.useProgram(this.handle) +function createTextureShape(gl, width, height, format, type) { + var maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) + if(width < 0 || width > maxTextureSize || height < 0 || height > maxTextureSize) { + throw new Error("gl-texture2d: Invalid texture shape") + } + var tex = initTexture(gl) + gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, type, null) + return new Texture2D(gl, tex, width, height, format, type) } -//Destroy shader, release resources -Shader.prototype.dispose = function() { - var gl = this.gl - gl.deleteShader(this.vertexShader) - gl.deleteShader(this.fragmentShader) - gl.deleteProgram(this.handle) +function createTextureDOM(gl, element, format, type) { + var tex = initTexture(gl) + gl.texImage2D(gl.TEXTURE_2D, 0, format, format, type, element) + return new Texture2D(gl, tex, element.width|0, element.height|0, format, type) } -Shader.prototype.updateExports = function(uniforms, attributes) { - var locations = new Array(uniforms.length) - var program = this.handle - var gl = this.gl - - var doLink = relinkUniforms.bind(void 0, - gl, - program, - locations, - uniforms - ) - doLink() - - this.types = { - uniforms: makeReflect(uniforms), - attributes: makeReflect(attributes) +function isPacked(array) { + var shape = array.shape + var stride = array.stride + var s = 1 + for(var i=shape.length-1; i>=0; --i) { + if(stride[i] !== s) { + return false + } + s *= shape[i] } - - this.attributes = createAttributeWrapper( - gl, - program, - attributes, - doLink - ) - - Object.defineProperty(this, "uniforms", createUniformWrapper( - gl, - program, - uniforms, - locations - )) + return true } -//Relinks all uniforms -function relinkUniforms(gl, program, locations, uniforms) { - for(var i=0; i maxSize || shape[1] < 0 || shape[1] > maxSize) { + throw new Error("gl-texture2d: Invalid texture size") } -} -//Compiles and links a shader program with the given attribute and vertex list -function createShader( - gl - , vertSource - , fragSource - , uniforms - , attributes) { - - //Compile vertex shader - var vertShader = gl.createShader(gl.VERTEX_SHADER) - gl.shaderSource(vertShader, vertSource) - gl.compileShader(vertShader) - if(!gl.getShaderParameter(vertShader, gl.COMPILE_STATUS)) { - var errLog = gl.getShaderInfoLog(vertShader) - console.error("Error compling vertex shader:", errLog) - throw new Error("Error compiling vertex shader:" + errLog) + var packed = isPacked(array) + var type = 0 + if(dtype === "float32") { + type = gl.FLOAT + } else if(dtype === "float64") { + type = gl.FLOAT + packed = false + dtype = "float32" + } else if(dtype === "uint8") { + type = gl.UNSIGNED_BYTE + } else { + type = gl.UNSIGNED_BYTE + packed = false + dtype = "uint8" } - - //Compile fragment shader - var fragShader = gl.createShader(gl.FRAGMENT_SHADER) - gl.shaderSource(fragShader, fragSource) - gl.compileShader(fragShader) - if(!gl.getShaderParameter(fragShader, gl.COMPILE_STATUS)) { - var errLog = gl.getShaderInfoLog(fragShader) - console.error("Error compiling fragment shader:", errLog) - throw new Error("Error compiling fragment shader:" + errLog) + var format = 0 + if(shape.length === 2) { + format = gl.LUMINANCE + } else if(shape.length === 3) { + if(shape[2] === 1) { + format = gl.ALPHA + } else if(shape[2] === 2) { + format = gl.LUMINANCE_ALPHA + } else if(shape[2] === 3) { + format = gl.RGB + } else if(shape[2] === 4) { + format = gl.RGBA + } else { + throw new Error("Invalid shape for pixel coords") + } + } else { + throw new Error("Invalid shape for texture") } - - //Link program - var program = gl.createProgram() - gl.attachShader(program, fragShader) - gl.attachShader(program, vertShader) - gl.linkProgram(program) - if(!gl.getProgramParameter(program, gl.LINK_STATUS)) { - var errLog = gl.getProgramInfoLog(program) - console.error("Error linking shader program:", errLog) - throw new Error("Error linking shader program:" + errLog) + if(type === gl.FLOAT && !!webglew(gl).texture_float) { + type = gl.UNSIGNED_BYTE + packed = false } - - //Return final linked shader object - var shader = new Shader( - gl, - program, - vertShader, - fragShader - ) - shader.updateExports(uniforms, attributes) - - return shader + var buffer, buf_store + if(!packed) { + var sz = 1 + var stride = new Array(shape.length) + for(var i=shape.length-1; i>=0; --i) { + stride[i] = sz + sz *= shape[i] + } + buf_store = pool.malloc(sz, dtype) + var buf_array = ndarray(buf_store, array.shape, stride, 0) + if((dtype === "float32" || dtype === "float64") && type === gl.UNSIGNED_BYTE) { + convertFloatToUint8(buf_array, array) + } else { + ops.assign(buf_array, array) + } + buffer = buf_store.subarray(0, sz) + } else { + var array_size = array.size + buffer = array.data.subarray(array.offset, array.offset + array_size) + } + var tex = initTexture(gl) + gl.texImage2D(gl.TEXTURE_2D, 0, format, shape[1], shape[0], 0, format, type, buffer) + if(!packed) { + pool.free(buf_store) + } + return new Texture2D(gl, tex, shape[1], shape[0], format, type) } -module.exports = createShader +function createTexture2D(gl) { + if(arguments.length <= 1) { + throw new Error("Missing arguments for texture2d constructor") + } + if(!linearTypes) { + lazyInitLinearTypes(gl) + } + if(typeof arguments[1] === "number") { + return createTextureShape(gl, arguments[1], arguments[2], arguments[3]||gl.RGBA, arguments[4]||gl.UNSIGNED_BYTE) + } + if(Array.isArray(arguments[1])) { + return createTextureShape(gl, arguments[1][1]|0, arguments[1][0]|0, arguments[2]||gl.RGBA, arguments[4]||gl.UNSIGNED_BYTE) + } + if(typeof arguments[1] === "object") { + var obj = arguments[1] + if(obj instanceof HTMLCanvasElement || + obj instanceof HTMLImageElement || + obj instanceof HTMLVideoElement || + obj instanceof ImageData) { + return createTextureDOM(gl, obj, arguments[2]||gl.RGBA, arguments[3]||gl.UNSIGNED_BYTE) + } else if(obj.shape && obj.data && obj.stride) { + return createTextureArray(gl, obj) + } + } + throw new Error("Invalid arguments for texture2d constructor") +} +module.exports = createTexture2D -},{"./lib/create-attributes.js":84,"./lib/create-uniforms.js":85,"./lib/reflect.js":86}],89:[function(require,module,exports){ +},{"ndarray":157,"ndarray-ops":152,"typedarray-pool":161,"webglew":163}],165:[function(require,module,exports){ +arguments[4][79][0].apply(exports,arguments) +},{"gl-shader-core":171}],166:[function(require,module,exports){ +module.exports=require(80) +},{}],167:[function(require,module,exports){ +module.exports=require(81) +},{}],168:[function(require,module,exports){ +arguments[4][82][0].apply(exports,arguments) +},{"./reflect.js":169,"dup":170}],169:[function(require,module,exports){ +module.exports=require(83) +},{}],170:[function(require,module,exports){ +module.exports=require(17) +},{}],171:[function(require,module,exports){ +module.exports=require(85) +},{"./lib/create-attributes.js":167,"./lib/create-uniforms.js":168,"./lib/reflect.js":169}],172:[function(require,module,exports){ var slice = require('sliced') module.exports = combine @@ -10172,33 +11866,17 @@ function combine(meshes) { } } -},{"sliced":90}],90:[function(require,module,exports){ -arguments[4][34][0].apply(exports,arguments) -},{"./lib/sliced":91}],91:[function(require,module,exports){ -module.exports=require(35) -},{}],92:[function(require,module,exports){ +},{"sliced":173}],173:[function(require,module,exports){ +arguments[4][29][0].apply(exports,arguments) +},{"./lib/sliced":174}],174:[function(require,module,exports){ +module.exports=require(30) +},{}],175:[function(require,module,exports){ arguments[4][14][0].apply(exports,arguments) -},{"buffer":106,"iota-array":93}],93:[function(require,module,exports){ +},{"buffer":189,"iota-array":176}],176:[function(require,module,exports){ module.exports=require(15) -},{}],94:[function(require,module,exports){ -"use strict" - -module.exports = unpackPNG - -var ndarray = require("ndarray") - -function unpackPNG(w, h, c, str) { - var canvas = document.createElement("canvas") - canvas.width = h - canvas.height = w - var img = new Image() - img.src = "data:image/png;base64," + str - var context = canvas.getContext("2d") - context.drawImage(img, 0, 0) - var pixels = context.getImageData(0, 0, h, w) - return ndarray(pixels.data, [h, w, c], [4*w, 4, 1], 0) -} -},{"ndarray":92}],95:[function(require,module,exports){ +},{}],177:[function(require,module,exports){ +module.exports=require(88) +},{"ndarray":175}],178:[function(require,module,exports){ /** * @fileoverview gl-matrix - High performance matrix and vector operations * @author Brandon Jones @@ -14448,7 +16126,7 @@ if(typeof(exports) !== 'undefined') { })(shim.exports); })(this); -},{}],96:[function(require,module,exports){ +},{}],179:[function(require,module,exports){ "use strict" var glm = require("gl-matrix") @@ -14543,7 +16221,7 @@ function createOrbitCamera(eye, target, up) { module.exports = createOrbitCamera -},{"gl-matrix":95}],97:[function(require,module,exports){ +},{"gl-matrix":178}],180:[function(require,module,exports){ (function (global){ module.exports = global.performance && @@ -14554,7 +16232,7 @@ module.exports = } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],98:[function(require,module,exports){ +},{}],181:[function(require,module,exports){ module.exports = unindex function unindex(positions, cells, out) { @@ -14580,7 +16258,7 @@ function unindex(positions, cells, out) { return out } -},{}],99:[function(require,module,exports){ +},{}],182:[function(require,module,exports){ /** * Expose `parse`. @@ -14675,7 +16353,7 @@ function parse(html, doc) { return fragment; } -},{}],100:[function(require,module,exports){ +},{}],183:[function(require,module,exports){ module.exports = findup function findup(child, check) { @@ -14705,11 +16383,11 @@ function byExact(el) { } } -},{}],101:[function(require,module,exports){ -arguments[4][32][0].apply(exports,arguments) -},{"_process":109,"raf-component":102,"sliced":104}],102:[function(require,module,exports){ -module.exports=require(33) -},{}],103:[function(require,module,exports){ +},{}],184:[function(require,module,exports){ +arguments[4][27][0].apply(exports,arguments) +},{"_process":192,"raf-component":185,"sliced":187}],185:[function(require,module,exports){ +module.exports=require(28) +},{}],186:[function(require,module,exports){ /** * Expose `render()`.` @@ -14861,11 +16539,11 @@ function escape(html) { .replace(/>/g, '>'); } -},{}],104:[function(require,module,exports){ -arguments[4][34][0].apply(exports,arguments) -},{"./lib/sliced":105}],105:[function(require,module,exports){ -module.exports=require(35) -},{}],106:[function(require,module,exports){ +},{}],187:[function(require,module,exports){ +arguments[4][29][0].apply(exports,arguments) +},{"./lib/sliced":188}],188:[function(require,module,exports){ +module.exports=require(30) +},{}],189:[function(require,module,exports){ /*! * The buffer module from node.js, for the browser. * @@ -16036,7 +17714,7 @@ function assert (test, message) { if (!test) throw new Error(message || 'Failed assertion') } -},{"base64-js":107,"ieee754":108}],107:[function(require,module,exports){ +},{"base64-js":190,"ieee754":191}],190:[function(require,module,exports){ var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; ;(function (exports) { @@ -16158,7 +17836,7 @@ var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; exports.fromByteArray = uint8ToBase64 }(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) -},{}],108:[function(require,module,exports){ +},{}],191:[function(require,module,exports){ exports.read = function(buffer, offset, isLE, mLen, nBytes) { var e, m, eLen = nBytes * 8 - mLen - 1, @@ -16244,7 +17922,7 @@ exports.write = function(buffer, value, offset, isLE, mLen, nBytes) { buffer[offset + i - d] |= s * 128; }; -},{}],109:[function(require,module,exports){ +},{}],192:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; diff --git a/data/regenerate.js b/data/regenerate.js index f2bf62e..48ab09a 100644 --- a/data/regenerate.js +++ b/data/regenerate.js @@ -16,7 +16,7 @@ var examples = tree( var tokens = example.tokens.slice() tokens.links = {} - var thumb = null + var thumb = 'default.jpg' var $ = cheerio.load( marked.Parser.parse(tokens) ) @@ -69,7 +69,7 @@ var packages = tree( var name = unhtml(pkg.text) var html = marked.Parser.parse(pkg.tokens) - var thumb + var thumb = 'default.jpg' var $ = cheerio.load(html) diff --git a/default.jpg b/default.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a7d3dd3e66a9a6d3132544a899e17e8736632f81 GIT binary patch literal 9155 zcmd^E`CpUA){mmLRI3F91x2|aAiL}mS+2?=fdpBSKmtLQ07*z9OIX5o+p5T3c7XsD z1tbemAcUPNA_4+s3CJdeum)rg`|@Jn-rL*udjEj;{r-^5ndh7{=bZV@eCC;F|NZ_b z;H*gy#sdH_H&+CF3HTlRa{wV@k{d1Z(`N0QyEjcU|0YXn!eJv?qpOAiYpsFD->}H;{&FgRg+^-b8z0ZjpV_ zwq%H%8yV-O=PqqzD5W0+48q^Vqy1f^g7Dr1KVXo7^sml=2klSYYSL1_s`%p!q_2M( zRmvWGTk0m!7cHf&s;%O7MMGUmS5H-4TT4$}U0F)win^wn`V}<|Jr#9zpq4IBT}SFS zNFR*m>+S)xF*f~etOLnF`nRM40|Qk9HC2heo@(lPdU|SCG}JUSR1P#${DKMoE4QlBHwFCNf4TjSwfZ+jF!;Z#;_;sf@T*%t ze;f4g@%~50es;lk(P}nmKO)K34Sk?4^U3%w@TM=?#h>VFML9i2g)BFXCOP zn>VE{gI(M(gio@St{~aRGn#U}R&oFD3x(Zt6?K zOZ}QN5cBz1v_I?bH(U45$D;FDTeX8=)IQDZzs>YNyAJ5{srfJ79ti(pKALbqci#hE z@6Q8H{>oN>`%ee!=g|Hj;2z-czaVhX5;$`3D{$oKkxw{!?C7sJcI=BUzWm~gV}gQT zeI+P(;*U5aARut`$Wg&##{|DVE_nRwQzs8_>eR1Fzx|!~U+Ir_|C0890tkJ12z3Z0 za7YMnSm=;|(4qa;fXIVIE^z1ozpwv;xDFjXCitoI6Mlbi=u^bUzBx$ckicPqF9ePP z4jujU_>j=yzo`ogT(@@dk^VOEMW=?yk;gA@ERHVO$hi7`r+M?}X`$a-3H&66y~F-UJ-X4S%3XB2T%4!avol$TL= zlKO8s9(vOSW(#6}imscEb}D=_&>B@FmzgpiJq-Zd=reEPc;>_M6SX70I9f?riD-?( zIkv8?nqFJrZ+>*puC=KF_a(#^qkedyDx!z4#|1|R?*k;AP}|`nvf(+#lP+G1`4Zfk zeZZIlT^mn-#&UEBz}d3UUH>JbFI3QoYQy`<#uY(urI9vtc`^Ll-NL3y;4FVxnArQV z6Fh`1PbgNux5YLRi4U1YbZpu&u=@b%7~nFLWNtxh`FbC4jmM&J4vo!k+IQ;tm^zRu$}2FQ`SsNaAE>-aa09O$P77x}DlcX&sGqxA zlH1sv#cMj(kHm);)g30QfJdSxH2{oN(eQ0cr>J({0=)h2I=GvGokfpIp9puh5H7_yTKXvDKn!* zZ?=X42l4=6^WDA(H~;-EUU`ASgj=5$HKLVOAKR%UBfdw}(>)%&vK!Z)`I zMVN|EKRedPNo4Qq#M!=hPM%$HpC&IjXCt|dJUCk*Yd(ks^72^)q1v)o>Edjivf)6) z-Jz`vzn&gDnqHd=eix)yR~`){_&0jpA=&(L1l+CJ-GtdqYS;QMq~?~hB0Q8!tsG|$NN zsh^c3bEaUsUzH3vwI{g=Ldi(#pz&yb$nJNXn4qp9?gleqLla60*0D6;I74A>!;iDt zi>o2n4_A{(gOPB-^0dSvH61c&9?P3`><9Bo#|-0#D zbE~~&$E&g^5k=b((Te5I`l{!*vsjW+pUvZ&?G)$sy5$M5X{t)``!roe|YM$}IG4Mab zv=90QPvn~zw;a+@{kHpzs!o0UH7}3Vijo?!n%cOaJ8cUmNOzx3 zELnuvCXB3|VQxAiL6wnqT*d)&@-TW(M6Fonx+b+csm3mkb+Mao>e&v=NE_sFL}>%r ztXU_`F+z{^=6On}f@jYnHO{AP23Vr0wCv!Tbq>+L*JK$xgHkN4++yr?tetrxCjQx= z0nD`agQYP9A3%BZ6vK)zkjgRkY(1%dWk)GOm_h7!{HJ$A2#K zr{2>@PP3%K{Yk#Aek_Ce-74b*C(cm|9_Xj~;vToMgBEAPE2;p=^T;mZEEvtkW^i3` z#oi`)<>z*2z$)9cn-EZ_CO-RE7AXSe_>5CD+dKEP1gpTcUm|a2&d6BG zLVs~7$N_Gh$=6v?Th-%-VO1S{bP0h-c&=JcTmAjUsQ&&o9Qqt7jx^mIovJ!Hm>lAx zWFX&Bq$~tB0(E8P=c;}4x3^^__N6UYtHg=oOK=zk2__YyyT(Q z`vmIqhPF008F;CeF$Jr7RFAkBca3OnLGT^bmmNdZ$WR%`M9bQiGojL6ERGLH`#3hT z%W^)RjE4h-D@Yk2ioosvmM*2QCPOz8Asg_IPkZsnyzEG+ht~Q{72I)=J4cGmSrct|O z2fwZv<(ZoqrhK?E$_dYTe>n0a&B#tRF!E|ku7Fn(wePp-hb9a?@HW;$v2Eb zX;d-dZWpf&6rF9;{R{3kG^3-;i=y~LKuwTMer>2Ac5JvPge+p5dM-@H22oK`2C=n} zxSnNc*oAfJ`^EWvBYYG#qh9Fm(0lgrJa?TQ#0c%ZSYGaKmn~DS9 zp_t&62I3vKpv^Nw>~pxU213Mxmz2`#8pZtfn3MN1t9WT?L#k=P5kCsCCR5`O;J^eU z;btE8gZ(y{T`d|OZW_GBN^%LaIy;z<*qI`lwMCH|4LT##Th>v3`){6hRUNJ`(^bj` z+aa-)aiqf-$g|8Mri#{gf^cYpG!)cozI#OMrq8M73^ALMUVm9?dD}CLC3oCIu^LWG z*#{&m=Vken6`VIL$hUN7UA*8`P>Zd1qgV4OB49a6;S;HY^YXvr0&ySk`1Jr&v8&?6 z$OeDItzx{+qzpr8l5po9cGvJ$nm4*C@&ip2in#j zL7?y={-%gDt(K+$fg$#sY73syf82DI2rz$I`pfS9UH>76S09@}1Jqi2;jNj+IW@HN zp^RGQ@q{i)=<%&gW-^hZu!^5DI4&eAd4@mqxUwKMM}|9gq+V!L?_|}gIu-~ zgN%1X$cN=T>f5;x(o~$wj#q^kQ?uFCdc%44ySH~;=l|gI#cQFt znUAmuLY(-)Ylq-zLiU;~$RVFy$mR#r%)rjP=29~AUE?y9X8TQ!?Ze=`=U7{Dm0PLrXOxt!O9p}Z-K{VB z7U+N3W$tgxyv^goR+M=iQ64qNnd}gtF5=zwxttEiI_*VdLL!V^OGEGYu=XMiCvwGf zffMMmq=BrI+Smz3RdVV2)MG=z-Z%&v5_5#*!(p}3-JXll2CKqO7v=V}D^c4KRjH%z zGxkmrhH>~HO1-P?clkp z+&U(o_QE-4+MAM<#Uv2sX>S}z3-|{{005_sHCH>R&heXsDHxVvMh_|$&mDSv?HW|s zytRO9HUv87fH1Wjqtn2i$Els-FK(A2DOy|4rtPDa2C=cPW_!|Vv z(QBVJ@a!L|?g#=JK?QS&@I*Yf6CgkPa@Uv6_e$Z)1_ zeK&q+$Mqk7%oeb;575cdTUXILy=`T+Tz$SOr-;^&Q$RPN_TH{C&yr?oD_rU^IHAQQ zoUdFw7R53M-E)nny<@?DdGjT~@1eO1soCc|TQ(hMNWHdg{Ge)6B>zQP4oQ55R9#cunK zy5pZ}aqMD8!MrG%c`nzbZ)1oas2{925Ojg!hoDcQUs9l}ENWrEIdu=Z#k@{W{yrdm zLr#_MfKxJ*NQ77bCpDJ7eb-eKNGQJYL}*1@2KXJGYZtBj1l;7kF8e+4B9+xHc8)io z=X@?k1ZpA7C@kyXfPpUj&MjvfvKp1vf`t=uxH@GeftPtp=q1g?8=O!Ac8pnQ+^YJh zj@juXQPSG&d?KSB3dZv09?vqrrCB?{`tUHHiJ#d$PDs!eNegQ{N{tFy5TKrqY8okLnK!=ef&zjnV5FacTnr0Z!c#UISSQkcSk~+k6VH_?sGOzom2@keDD4rRoH_TEF z7Va=%YCf_kN=0N=fmNFMWbt>_a`c5tuEeWv_W_4n5pBk^5AWxaFMSspKw3p|z7m-| z!oxPE;dqNJJdYdItxczCv(B`^-6ma5X`^U}%ghkRG?PDTZ~_`*n_+dbmYmV(Y}YlY z=M?gYp+p|k$jRxL$B2FqGfIv$>PvKmXKxyTvw9X9B(MId768%ZC3sqV8e)1|Vv5$* zQ;PaRO|*hAL&!9o=CAbd^c>=$#q~v4WmpSlE0F@_b#;R@^2HlDYz(I|Js~QCkBx-& zs!PZq9!-qxV03xKXTJ4Jp{M$g3|7}9m6y_sENx<5dh+$xXMLInQy)<5DybiX<;D7T z>wQtSa02U`zYow9W;wYFZOv)@CKCa*+?$Mma%w`88IFB3%yrEk2iP@vRs#ekPJy<> z@Gw@lG-)y2BNn!%-KNBJggZ1{e5twH9-kL|xzpcFiC-~UUS>pmeteiBSF$8|!ZmLd zNin+-J(uUbrCN}uv0_VpK+zVN^q=JFXhLgfuAIg?58kD}|EVrV^@p@3iwBig*><=b zrh-RJII(eJ)bAX%tYo*t%BahKD!5UB&%=u;)y1|S*HwZ=-0-j-_(;ybMEy9O2M6B) zU0J>yQl%@8a-eN&5>cgRA9xm{9pJld{SOz_x5j2!n7UUnHhzv7P~HsoN#ofUBs6{o zEdL=y`~_kt^QcJ405_R)@8v)r*22Qnq)N*N1aXv4>5R{e z(n=%O!k!AJJXR6A_2fYpfxHj+hf;YO5t1ulEp%@N&B=G?7Mo3+-Spa2sbZ0E!fAD$ zD1t2CcI4K`YORXUg7(Bl%U{mY0CnHJGiNSUMYMmAkPO}{*9;CGs!wQrHOU!vUNa+v zWb1wKzRjQ*fX7s6Hl@irN+7;`wWQ3usigu)xHfF2bFvVE)49woeH8XJUnq}p_BmL; zS;CRtNs&cl;w{J9U^Fxc!Sjogb;!sTgg!eTD+SzZ1)PoKoiL57z*!{d9YZE{oF!ks6PP@QMp!-IKFS5Pic1&++E z?2UDw2G9lN40#kIL5D`*=^EjyI?^IT_9~zL<+bYY`84Y7<+&HAiA1HT1+%6Q=q&vE ze$}RnQS#za9MC+H7JH|$V#q9+1EVKlM%T{g2M-|6CRZ!L;IH3i21#|AX`?1xS!aAI zO2EP5^iIp`#kAVkkuPhlVL+Ew^{TD`U6pN-y*HRMz4HDY=~0676jdpYX@7Wq0Eg!p)Fep@e0{EXQn# zfstsSPlTXDPg7z!GANT8qb$q6-oZpX^o5nD(UU*QrhoO)|AS3uHrh2cwXn?Eqf(0f zV9+TUK^H&Rl{jS%4&!Y(iko4vTJ`s}7+!sXr3T8FJRjhivrIN7uSn(mm`u}_hhi}m z>N|#_xAC25NDBYwlqiF+Z=Gnt1h+AeXvu@V$A)`fsn3g@GD`aB8`e@W{P3Fj1LR0uV~~ zZ%b+pE>F{R!29U2yV_nCD|vU>ajgO~ygRW8kT`86HuwaMLODGFcEXcvkpa1j@&TdB zeR0iZO`aD1os5f#yvaG=Qqd;Y7{#S*bCW0n-(S`d1jfa}@*eMeq;NJ}g`eJMAWWR4qpRBZ8Dc~e(F=p@qY>!BKGeixF5 z^330O*|e#ja&H$`x|z)sexYJYjcVg_Mp5@|<5pMVx{tT*GF) zk-S@HcFO7OX7C!Yl^9Vd%30A zQ>V?MYE62AqJD0>=QZY6{obwM3E0L~!oZO-dvIlwVB0#2YBH?F%Br@tm&?B-!|=wQ zG>sy>Pw{+}2wVsjrll&K0|6m$p7#|Buzs$H6`jEl25PJDLFwYPg;;GE8v#|@VK6Jt ze~eQe_{bmbk0^eawI_(V|J{GMBD8IOiL$WSLd9tlRb%@M`o|oKmSH;?tS%xP(KK)F zu0~&23Y3R8D{!sm2@%G-b`d+Fsn#eHY~eMB`h9>ygy0tEe5n<+8voS5U~-e6nSN2* z&gO24TywAkGH4yoO3kwET)pQzJ8O-$EhYN-#IiFqVR|0Vt7KE`Qxnpcx{*aQi_`6t z^}SNJm?$8%iCq-oc6zJAySG-qErKWirkXH1F$TkOhEnHpPEY&guB9?l%h&s7XkZ4! z21goc3J6ULMAoX0QYCj}uyi!H#Pb{?(MoA?rZ^JCnp(bcL! z9Itdy5=Ayw#&%vx?Fq7PfH=4yqW1xTbWX$K+uW5!$zXa4=koNU{!_OHo8j@-tWf#= z*3R;0R48@&1};U)yc;dqimNQuq(y=`MwsO{Ga_k+95;tC8I|x(`;~k30UmFQ>Z>F6 fAf|m=bm?Hjn>|V9H*TjrjQ-OW|NlWW+VB4#67IG_ literal 0 HcmV?d00001 diff --git a/index.css b/index.css index 5621f97..8dbb581 100644 --- a/index.css +++ b/index.css @@ -78,6 +78,19 @@ h1 .lighter { z-index: 1; } +#community { + position: relative; +} + +#community-content { + position: relative; + z-index: 2; +} + +#community-canvas { + z-index: 1; +} + /** * Section Layout */ diff --git a/index.html b/index.html index 0d41e2e..3f90e00 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@
    -
    +

    #stackgl

    @@ -50,8 +50,12 @@

    packages

      -
      -

      community

      +
      +
      +

      community

      +
      + +
      diff --git a/index.js b/index.js index db8d231..d51be74 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,15 @@ -var splash = document.getElementById('splash') -var canvas = splash.querySelector('canvas') var filter = require('./lib/filter') var minstache = require('minstache') var domify = require('domify') var slice = require('sliced') var fs = require('fs') +var grid = document.getElementById('grid').querySelector('canvas') +var flock = document.getElementById('community').querySelector('canvas') + require('./lib/fill')(document.querySelectorAll('[data-fill]')) -require('@stackgl/splash-grid')(canvas) +require('@stackgl/splash-grid')(grid) +require('@stackgl/splash-flock')(flock) var thumb = minstache.compile(fs.readFileSync( __dirname + '/lib/thumb.html' diff --git a/package.json b/package.json index a1bb636..6081f76 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "scripts": { "prestart": "npm run links && node data/regenerate", "start": "beefy index.js:bundle.js --open", - "postinstall": "npm run links && scoped-bulk stackgl npm install", + "postinstall": "npm run links && scoped-bulk stackgl npm install && npm dedupe", "bundle": "npm run prestart && browserify index.js -o bundle.js", "links": "district stackgl splash-grid splash-flock" }, diff --git a/splash-flock/package.json b/splash-flock/package.json index abf06b8..0690b9c 100644 --- a/splash-flock/package.json +++ b/splash-flock/package.json @@ -1,9 +1,12 @@ { "scripts": { "start": "npm start glslify-live & npm run serve", - "serve": "beefy demo.js:bundle.js --open -- -t glslify-live -t glslify", + "serve": "beefy demo.js:bundle.js --open", "image": "ndpack-image boid.png > boid.js" }, + "browserify": { + "transform": ["glslify"] + }, "dependencies": { "a-big-triangle": "0.0.0", "canvas-fit": "^1.2.0", From 3fbab5da8e18962396efa34f2be1bdb10af5ba7d Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 14 Sep 2014 18:51:23 +0200 Subject: [PATCH 07/64] update packages --- data/packages.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/data/packages.md b/data/packages.md index f61b37d..a56162a 100644 --- a/data/packages.md +++ b/data/packages.md @@ -10,11 +10,13 @@ To add a new package: ## WebGL Core ### gl-vao +![gl-vao](http://imgur.com/iv3pOSh.png) ### gl-fbo ![gl-fbo](http://imgur.com/xiXCQGN.png) - ### gl-texture2d +![gl-texture2d](http://imgur.com/ZkcCvzx.jpg) ### gl-buffer +![gl-buffer](http://imgur.com/JFZGJBx.png) ## Tools @@ -24,13 +26,10 @@ To add a new package: ## Math -### gl-vec2 -### gl-vec3 -### gl-vec4 -### gl-quat ### gl-mat2 ### gl-mat3 ### gl-mat4 +### gl-matrix ## Camera Controls From b8c0b7bb80f0828e38bffc90cad78345e404c7d0 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 14 Sep 2014 19:08:59 +0200 Subject: [PATCH 08/64] update thumbs for packages --- bundle.js | 90 ++++++++++++++++++++---------------------------- data/packages.md | 8 +++++ 2 files changed, 45 insertions(+), 53 deletions(-) diff --git a/bundle.js b/bundle.js index c25af6d..2c281ec 100644 --- a/bundle.js +++ b/bundle.js @@ -94,9 +94,9 @@ module.exports={ "WebGL Core": [ { "name": "gl-vao", - "desc": "", + "desc": "\n", "link": "http://ghub.io/gl-vao", - "thumb": "default.jpg", + "thumb": "http://imgur.com/iv3pOSh.png", "featured": false, "i": 0 }, @@ -110,17 +110,17 @@ module.exports={ }, { "name": "gl-texture2d", - "desc": "", + "desc": "\n", "link": "http://ghub.io/gl-texture2d", - "thumb": "default.jpg", + "thumb": "http://imgur.com/ZkcCvzx.jpg", "featured": false, "i": 2 }, { "name": "gl-buffer", - "desc": "", + "desc": "\n", "link": "http://ghub.io/gl-buffer", - "thumb": "default.jpg", + "thumb": "http://imgur.com/JFZGJBx.png", "featured": false, "i": 3 } @@ -128,111 +128,95 @@ module.exports={ "Tools": [ { "name": "glslify", - "desc": "", + "desc": "\n", "link": "http://ghub.io/glslify", - "thumb": "default.jpg", + "thumb": "http://imgur.com/ThMYeUx.png", "featured": false, "i": 0 }, { "name": "glslify-live", - "desc": "", + "desc": "\n", "link": "http://ghub.io/glslify-live", - "thumb": "default.jpg", + "thumb": "http://imgur.com/9mmysos.png", "featured": false, "i": 1 }, { "name": "glslify-optimize", - "desc": "", + "desc": "\n", "link": "http://ghub.io/glslify-optimize", - "thumb": "default.jpg", + "thumb": "http://imgur.com/pF9tmNg.png", "featured": false, "i": 2 } ], "Math": [ { - "name": "gl-vec2", + "name": "gl-mat2", "desc": "", - "link": "http://ghub.io/gl-vec2", + "link": "http://ghub.io/gl-mat2", "thumb": "default.jpg", "featured": false, "i": 0 }, { - "name": "gl-vec3", + "name": "gl-mat3", "desc": "", - "link": "http://ghub.io/gl-vec3", + "link": "http://ghub.io/gl-mat3", "thumb": "default.jpg", "featured": false, "i": 1 }, { - "name": "gl-vec4", + "name": "gl-mat4", "desc": "", - "link": "http://ghub.io/gl-vec4", + "link": "http://ghub.io/gl-mat4", "thumb": "default.jpg", "featured": false, "i": 2 }, { - "name": "gl-quat", + "name": "gl-matrix", "desc": "", - "link": "http://ghub.io/gl-quat", + "link": "http://ghub.io/gl-matrix", "thumb": "default.jpg", "featured": false, "i": 3 - }, - { - "name": "gl-mat2", - "desc": "", - "link": "http://ghub.io/gl-mat2", - "thumb": "default.jpg", - "featured": false, - "i": 4 - }, - { - "name": "gl-mat3", - "desc": "", - "link": "http://ghub.io/gl-mat3", - "thumb": "default.jpg", - "featured": false, - "i": 5 - }, - { - "name": "gl-mat4", - "desc": "", - "link": "http://ghub.io/gl-mat4", - "thumb": "default.jpg", - "featured": false, - "i": 6 } ], "Camera Controls": [ + { + "name": "turntable-camera", + "desc": "\n", + "link": "http://ghub.io/turntable-camera", + "thumb": "http://imgur.com/3wiGD3K.png", + "featured": false, + "i": 0 + }, { "name": "orbit-camera", - "desc": "", + "desc": "\n", "link": "http://ghub.io/orbit-camera", - "thumb": "default.jpg", + "thumb": "http://imgur.com/BPkl0Yh.png", "featured": false, - "i": 0 + "i": 1 }, { "name": "game-shell-orbit-camera", - "desc": "", + "desc": "\n", "link": "http://ghub.io/game-shell-orbit-camera", - "thumb": "default.jpg", + "thumb": "http://imgur.com/BPkl0Yh.png", "featured": false, - "i": 1 + "i": 2 }, { "name": "canvas-orbit-camera", - "desc": "", + "desc": "\n", "link": "http://ghub.io/canvas-orbit-camera", - "thumb": "default.jpg", + "thumb": "http://imgur.com/BPkl0Yh.png", "featured": false, - "i": 2 + "i": 3 } ], "Initialization": [ diff --git a/data/packages.md b/data/packages.md index a56162a..d660909 100644 --- a/data/packages.md +++ b/data/packages.md @@ -21,8 +21,11 @@ To add a new package: ## Tools ### glslify +![glslify](http://imgur.com/ThMYeUx.png) ### glslify-live +![glslify-live](http://imgur.com/9mmysos.png) ### glslify-optimize +![glslify-optimize](http://imgur.com/pF9tmNg.png) ## Math @@ -33,9 +36,14 @@ To add a new package: ## Camera Controls +### turntable-camera +![turntable-camera](http://imgur.com/3wiGD3K.png) ### orbit-camera +![orbit-camera](http://imgur.com/BPkl0Yh.png) ### game-shell-orbit-camera +![game-shell-orbit-camera](http://imgur.com/BPkl0Yh.png) ### canvas-orbit-camera +![canvas-orbit-camera](http://imgur.com/BPkl0Yh.png) ## Initialization From b2d5b0a05fa83b3a5eec8be6e0b0116fec4e6956 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 14 Sep 2014 19:16:07 +0200 Subject: [PATCH 09/64] noise images --- bundle.js | 16 ++++++++++++---- data/packages.md | 5 +++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bundle.js b/bundle.js index 2c281ec..e0ad944 100644 --- a/bundle.js +++ b/bundle.js @@ -306,19 +306,27 @@ module.exports={ }, { "name": "glsl-noise", - "desc": "", + "desc": "\n", "link": "http://ghub.io/glsl-noise", - "thumb": "default.jpg", + "thumb": "http://imgur.com/BFITCvl.jpg", "featured": false, "i": 2 }, + { + "name": "glsl-curl-noise", + "desc": "\n", + "link": "http://ghub.io/glsl-curl-noise", + "thumb": "http://imgur.com/ABlBkoE.png", + "featured": false, + "i": 3 + }, { "name": "glsl-random", "desc": "\n", "link": "http://ghub.io/glsl-random", "thumb": "http://imgur.com/9EOo2or.png", "featured": false, - "i": 3 + "i": 4 }, { "name": "glsl-fog", @@ -326,7 +334,7 @@ module.exports={ "link": "http://ghub.io/glsl-fog", "thumb": "http://imgur.com/8l0otem.png", "featured": false, - "i": 4 + "i": 5 } ], "Shader Transforms": [ diff --git a/data/packages.md b/data/packages.md index d660909..6998819 100644 --- a/data/packages.md +++ b/data/packages.md @@ -68,6 +68,11 @@ To add a new package: ![glsl-dither](http://imgur.com/D4ccYiJ.png) ### glsl-noise +![glsl-noise](http://imgur.com/BFITCvl.jpg) + +### glsl-curl-noise +![glsl-curl-noise](http://imgur.com/ABlBkoE.png) + ### glsl-random ![glsl-random](http://imgur.com/9EOo2or.png) From 996e242600cefa5f0c1fa5a36574762e7bca3a8f Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 14 Sep 2014 21:04:37 +0200 Subject: [PATCH 10/64] more thumbs --- bundle.js | 13 ++++++------- data/packages.md | 4 +++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bundle.js b/bundle.js index e0ad944..76094ab 100644 --- a/bundle.js +++ b/bundle.js @@ -340,28 +340,27 @@ module.exports={ "Shader Transforms": [ { "name": "glslify-hex", - "desc": "", + "desc": "\n", "link": "http://ghub.io/glslify-hex", - "thumb": "default.jpg", + "thumb": "http://imgur.com/Dh8CPE9.png", "featured": false, "i": 0 }, { "name": "glslify-import", - "desc": "", + "desc": "\n", "link": "http://ghub.io/glslify-import", - "thumb": "default.jpg", + "thumb": "http://imgur.com/7trTmBF.png", "featured": false, "i": 1 } ], - "File Parsers": [], "Visualisation": [ { "name": "gl-compare", - "desc": "", + "desc": "\n", "link": "http://ghub.io/gl-compare", - "thumb": "default.jpg", + "thumb": "http://imgur.com/z8BkmZl.jpg", "featured": false, "i": 0 } diff --git a/data/packages.md b/data/packages.md index 6998819..582a0fc 100644 --- a/data/packages.md +++ b/data/packages.md @@ -82,12 +82,14 @@ To add a new package: ## Shader Transforms ### glslify-hex +![glslify-hex](http://imgur.com/Dh8CPE9.png) ### glslify-import +![glslify-import](http://imgur.com/7trTmBF.png) -## File Parsers ## Visualisation ### gl-compare +![gl-compare](http://imgur.com/z8BkmZl.jpg) ## Internals From 5be19ec29062d64efc969de329e66cd669a63038 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 15 Sep 2014 03:11:18 +0200 Subject: [PATCH 11/64] image fallback, minification --- bg.jpg | Bin 0 -> 112507 bytes bundle.js | 17988 +------------------------------------ index.css | 5 + index.js | 9 +- package.json | 5 +- splash-grid/index.js | 2 +- splash-grid/package.json | 2 +- 7 files changed, 24 insertions(+), 17987 deletions(-) create mode 100644 bg.jpg diff --git a/bg.jpg b/bg.jpg new file mode 100644 index 0000000000000000000000000000000000000000..9f1d0917f0bcfec6264467fb5d2a4492a2e7b549 GIT binary patch literal 112507 zcmeFacUY6#wl5rYDRvhk9V`@)8UX`@>RM6+1f+(}l2C*Y0tvlZQCbj?&_P29Bm|^{ zUQ~LQ5&{WDdhb>0jqbJf-sd}a-}BEs<$jOzkN2JL%q(O6<`}b#G3Jw_{-aRicLL zKz(3Punmur;&pj1SueN?+}7>UbuYM+GfLJ=f#*l%vh?`(WFXJ=A6eXB3Ov7kZ}qyd z*2C-f5J=nWATf|A^tOcfb!o7eI0z&yEg^DU;EF5lclmp@|68p7DWjIw|2Zoh{vCiH)uP<= zZ2v*;|F&Y3fwzk-P|p^Ha7RLI>DhU|7j}`ohqQgZ-Dr_NkBcjnxMOBd_xG=(j{wHg zzt}RIK5>i@aGdej3C3ebbpQfg&X4_a;@CfC006_Wlc!G8i92)bZ{eSQI)02!^RECp zE%e_Rz7u`wGoJWSnJd#H2|XU( z$lrgtazq83r~gF%g%O|x*xUIhvVKN?BJdM|p9uU!;3on<5%`I~PXvA<@DqWb2>e9g zCjvha_=&(z1b!m$6M>%y{6yd<0zVP>iNH?;ej@M_fu9KcMBpa^KN0wez)u8zBJdM| zp9uU!;3oqA|3l!cq1?x;|EIfk_Nm6ZD|5$sPYS)$BMj5K0(L)UihWA=P5yr{T)}%j znY%04ds6o8Nl4|{fArui`Qh13&!??%|490OA$HaffYSra9glg){P5PlC)fzjAoPy; z->3f%Okvhu5i~fSd{_2KhQUdLe;S#8M=Nq}`8esW(7#LnAC&MXn~`UZbCP{$-xnzs zzfzu~Wq&BNFs}85Cq{w%WBA>|?oav(&Gh9=P0WtBpN%h;eo<)aZy#0k>Ry zM|X>Y>6S81cU&{73dzcz(=*<9@*j8dm}wUC+=(~;amN3K9C}&DvrfuZ0fZPj;Yw4} z3b;)%U*?>AcyEHodD4UwnDdI0^wx^R=%O_^B%7|4W5C+S zhpXP;hVYZCntKsx`BfD}Ma-}Xp>wZTxMtymrqptWD(?+$Qp&_=^0U&&>?1(lILEhz zz9MWZLzRf148DY@pr#oyY9-q6$?^PET;n}V&j8H4Pij<{c`}I@6G~Gt!guMDSVOpW zG*r-TSXeLrY z=jCh6s=L2@_VQ;up75EN*WwFQgpdWk z0={R|9eEp?$ZqY!|Kyit%lizULuXmc(RvV|UTdJ+CUR?2dsD8QMY^Q4V%{%BY-^l7 zstBn_x#7V3J^`eyINzUD-EkM*G2~s@+pmLbSmJ-ROJJjlql)1+U^dz(VLr{N?B!$>X#PlIFAy&oCqm4%;#d$}AFU~jy^A9EydWc)yJk=m8jB#It z^)A=zbd%2};3q#A{#chQ3hr<%)YFwYN4-NmrBC{mqL{&nUs|0TsE?S^wEsRebkPUr6wSqoLnfK-Aau+c^ zH}!M^-hQKfR;7|#1*CUN4?5q!<UR zYm5EGcw*C-YkF}SuGF8US)~cv-%Bvn)6(>upIn)N;c> z84Ehl+GIiri}-VYNemCAcmZa~Ybajd4$5#kCO~PVib{w}hTBvI%X8%{5qp6_C zVfzIhv=PWQN(B~~EMjV?|I+ZW)?jF-Heoy{?~81$ik12)?C16qVmE!L6QYsMqV|w7 z^I)zV6%|YQ7)E~vza?0YduXb2rO^m%VNprt%eTQOxwn!15BdU!@As7~3&)}LJcL`X zZcG|Cvpz5z;|=VLst)4UG2>meOnsETzvhtan3$M@PzE)S;m@yw<5D_=)eW=WrqRxBR0T?41*iK6#gdqO z=bG4AcQj0x@By5c-fQA;*(pfwhG9|sqNBLHAVo zo|YG=)7$SGrcxWD$IwEpmGG>UbZo?B`@c$)P1qRC8Qg4JW)j6POD zhHaB`f)?kqXABW_DX$C_PF<*?&nYJRR!<`aoirRdZ*~z<8%S@4Nix3OX82<8DA0=CnN8IrNGc@U@IW*g;DK zJeI1iw`>JV#N)8Op$>La`GEnR%CGH(lR4DD2x(VR?gO#cK0?S;UY`bOYE#@1VC$7o z>JcFITh7_}wubp>tI@9_A|gpgfTwYLXYx|Fsw_kId1E?~IuX*rQz!^N&nU}=$pb6N zdV%#B?w6Mi^B2Z*1247)idGPlBl$ZgL_}p{vpbtc+WmQe3*y&QHU(epPWjk-51(i07N!}1`c#Ca7e74oj!!n1t*$caM77Kov zj+z}fdytVtdyl}T(eRnvNe$dJ|3eO;xYi-g`WN}3jIZh+jTsu}8@ZT#-c;7k{KN@W z!6NZ@C<)&xa|hcsl5d^73pf#i-I9I6gs;@6GF<=r%)RjU*neL{FMIezHUI~C$DsH0 z+LCisDBR6|>qA+iI)>EH?$nxi%d&sMcsf2G+y>!iHbvukx{ER%(x-H^=_TZb-6XU| zx7#~z86$-q9=AD6o-D|-S&h02K72Z@vUR+K{u+M2q+o8VuO1EP+X5?g(f z4ud`hyn;ztZ8%Z-Y%h1AWBw@FH5p$u57*d8OL~ou$~KqqZ=&4WyjppSb4>HYMV`p_eXF~%Jyirs`M6Wq~a^Sg&YJkgN3bx$24#Y@mrml z!|;x$9W&?k#>CtYAtuy(qHUBN`&nXvbOD$xg{L^_)^>UF3$x}nd*pys`>JjFOQrK7 zuz*e8(0x2Ya`mDkP?QG27e>vA3=1v!5owhV-hLQrcW%uFdqqnKfS7wV3=$4T#UPsn;(0-x(Uc|@dY19$G8zSKTV6Oayh#6Pv(oXFyZLL5J6+t#l(|W5SEz{K!hDL#;b)-zzL2_!e1K8$Qui5XSuE&H ze7jM>EXCn+ert2Pjgu--4ug{$!Z~eDy%U8^)*3r3bF4pTN~mF}gLpBLc$!p`W}sdpl1HA025c(jxFX|mQTP&%jTJ?gqobK zzR%S5VD981qe$GXui^R93)VcpAUC}XO)EmS^M36xkGk{Qr`A{v4kVGORQ#d1g+BHU zrnqodRR2j~+vni>=_z+stvBk0bQi1!49<4s`d?S`e)#1GV0CA8YF)IUO!tp^zDUF5 z*>M7MOG>q3w2XW5W}NkY72HVNG`D*`DyCBJL3rCXmwpM3NZfl4gx6#Xv!)eQvlE?p zwZ>MnI$y#Ud0;i6nKfQ2lmXwgdbwbqp$j* z@dJ)!rnsz|m|s+a7qH1E4|574FqKiX8@9sO$YiORkQm2RmAosa*sb?oM#e!@?@uY$ zaCJ*DufjQWg9-Whd3pgbf+}`bXr|@~E#hk#;_5l27ri^JP8}&NG&@%aT@hdg+&jX+w=M2Pa{M5`o5}q4LNRT-)a>z$s7S%J zxeH*9u3f~fZFNr0#+OBdHZQ$alnH@?5Q*Z(FQP^3=SudXJ{aHgD)-cD3MS)_&M-dT z3gYC~=IAX5p(+bimME>%lS3= z&D7rl!z-WPfVvG=z*-$RMf5gB1~~`Td$Y#l2|13jkezoIQwhtJTf4? zbMNEHoj9}g8n}Gluo=kcTw_%?Zx|3(i#~ zV6;=v&dM6M;Puf79lzfN=<2d27+mBQNJ_y~~JZz9$Gz!D#B!C&(&(L-}|D4z*0 zD;&c(Yt%C~I|b>K#H{qgU<4S=3n7xrQ(07ItqylTLE}S;Hyfa?k`0hRYiv}b7hAw+ zKHnFP(a_$Qk2YQ;y0T0(-N3+LEW~L`tz$8LU7g@&E+rHGM>I@SqA#CV<~#qk$o5tW z7uxhe?>^8nciMwn3~U&I^^vrg)%sLd2uff7brQ}JEDt9LJe^B|rm*U+mdV8^sL9Fb zoG<-!{#(!y;6Si6^{`Fn2w*CSTFhT(LToFUE`}cg`W)m5??{mcp8cHYY!NX?)Xp2S zti`vutYwYloJk|aV7OJh1#77@sdm!v4w{GwvlClVHuJ^xM05{|a?JHS=T`H%GKsQw za`F~&iQUT%d^FO}@YxJQS|1{{tAU*P@xc9hxpFBcC;1jwRh6cnorW4rRP=IMpjLIH z(b`b3at5gfU!<&kK8m#U!H}5cAMPc%u zLS8YDYvQI|_az#J>OJA|;^wqY?)sudwNI{0k*igNdM*mckeRjWwEd-2OZS_wO_mW= zvdV0um3n8sZE$7PEA8S24EL3^1ayX8k%3X3qmZkL%7Vf238)99t*_=wpbomVrJSav zqI$r*AG-NPoRRVJ@S-FBb?~PG-srN2q46frK#z5wJ1kRogXwBU7L%O0@}AhNH&$vR z_sI@C0%PIkujE8@&e3&c6HvRhB_Ven@D5J7ccW=b@~|s$(h3+?&Wa=z(<}~*-gIa_ zI+0991z`$}bw-K4z5}(2-ze=mvP0T_O=9AIvl9ZLU zY-8Avz@;{v+>3tNX}h2)wp`IE+xp5ywOV;+wfse-As2;TS682O8v5b8ykfDy+p<>Y zEC%#{%$??;A6vO^_8;^Kvf#t9k;wU!I$NR?MRVRP@Pz&&>*~m0O}}WR4DU<(6+t*X zA58X)gjuR~<#YhmpIBMs_&~PR8@qG_AhTS+AI2&vgHQ1UT-9w~n6>(CL}6`jWimH$ zr*FQ(jBqYH2eD|EUtMgO7%ChjD`;F3k5)F2(`*fW_vQFOCP_QJtL#e4?1RbSQ-@gv znhrdqD6EI(Wpb3j`*wZ$%xO2`-58m2N(tqXtiF<)St}0N&MY)E9H-`&1=@s0j4FwC zckk9}&Obm&l|6Nk8jpUO74W(5%bM2ZL8c ziD_xpd5azS2St)G9pSuAxWwQjvh%rn>CWG5n}#8aXcpk!y_k-OsWiX5_~hOu;qLBf z*5~1aiS`a-3JN-{`0*At+J%|E3Nu%ZKM>KpILl4<;h0KP z^5esd?c}o=7AFowMy-PJ?q!oL9aidF6@GWL=gbPYEV{=?oNRfO-IQFIb6ogN@?~6w zq>?24C@q)51eNb=LU;LmBH@gfuE)?tQ1nJL?b@%RnBoIf2D2o?sA$J^l@m4|6>S|QU#@9|bSP@sXIRf#n_8$J2K3$02#hWBtb3gl&+mWH zfmNcQ@yms46|z8=eALLSQ=wSjE%W(7o9t0bYMw^d&8LuT1qY*DZP_EhG!2Ee;=Vbq z(6Zf0->u1}JnehDVKOu{o+nx$Ghenkz$vhU@jhq5eSQ@zXTr{Q0PluwM-#TR_=h|}5=z$_elVs(|a|>bxb?{srok?OLTZvYb z8^ownO+c^UiUHCEWhkfH6ry7#KMXnNd-!!W zRa+9(LbBZmLI(qmwMaLg?=t_5_iJehQgL`nK$va=X>Rj1{8y7xHfRvqC~bVpOJ{s3-bX z?Cv?)LftwZS-nc`o*(iCoG!pd^9p$&`0f|;3fHAv0%%&etB-+c#UH2GZeZ4y*#IRgZ* zX7%AncR$m$z$IRMR%B8N54owxxO)zKHFT(pqin>*ydf_u40&iPm0532gH;B>n+-UK;(5J_0;$<+ist)Lrb@bGCf% z)A+pB#MFKN{D%*i#lyy?T$Q~u-_Qjv;U!GW6+WTt7d;IgNerAbW1!4UkiuEm$Si~& zPCaFN;;omP=B=OQZ1azk+L4BMwDyJqP?B!rH~%n@)R5HF7~3;oR(Vwq`0TI+qQWni z-1Dh<1}Wrop7VK0wadE9#B=U4nHTNU;;?Xoo~P>}W7XJ<13 z&nbw5=;HPA;`Sli0IXCC%~wuvh*!6HrJ@eTf!6NL?$|MyBde9^NbMN!(w=vfog3Lk z4RZ%9H7ocB@FrQOkB-CG zIxaYZHFSHahtG&5!BH(snVTq5L_8+&`9TUArLK@A?s)ySP%oVtr zda_yH<74LX9GGGips^v_?Wz%lD$bG&acv4ri|qq~u(N zc-)lSbH2(1SZqnfko^m?bd;M8HN1d!P+{VRf*53qfhMm?QQ4RkbWoN@fJ$T;IesU6 zEg@RZo-422Q6$sQ&@mh3DM{NGT1qXgZx+aSnXlaWOscq&%=jy)A8?^!Ejn~nf=ZDh z=Jimi#^MLV!Xv_wN>49DDEY7Qdd?&_RJJ^!bLUy03(L2)egZ5`Bo~RnY{%-{CldKm zq*{3?(Z=;i;n-JvcZY?(vH<`Lf6%l4mj#3G4o43!z7sS&W_bL`pUs*esi6$d%suB# zH2q9%b7_yzQIoTr{AIr8Q=cO|e?dhOlnuw5Wr8Owfr{JjPn-pMo%LKjro43goqP2i zktb-J?teVBdZK7Ka4`x4$C373%{a@_Mb{zhSE?p~01CeMFsb*pct<~Cu zy-EXJQi;~$s&!P({Qk`As!dtz!8HG9%e4BCwd7(pbz+{8`Ig3EhiW_AV?UIb%oRR{ zw(pVRM^NEI53*x#z&!a2bEZlY=Ez+lm+K|V_wSRdga()c6w|+wrd%s4#;122(Bs~Z zOA_ZKD%_@^OH9Mj8s=cVq4{>bK6^u`<&@IUl7TGU9>(EZp0SQep2*4jFmPrS>?^n$ zZ)We-8D3^xV3)T5WY(V4X26>G%Ws)1dNn*gut=JHpcvg|ds+K}v4}m2b({Qpq|)q0 zqhR5&_wt|nXCF*OmwX;Hn>DXbk2H7KPg*H?Z>UQqK~wU==dzn`kr(e_O3>bJ9n!Uy zc_Pc=C9!P#F-bf7FVo7!a-5B4GQx*CppncM3)ZInqbc7?uMjeQlik(9{Ax*gtIiwWvl%WseYoyw5My|)c)4A=5gtW(|qH6!i|%Lh{>B% zM#e*J42cRQbQ9nnuLGvemIo=Zd>V5E(3?PJz__~b;)@%38r$z%^@FB!=eyfu)?J^y zBHpIT-SF1f(DHS?K=Ah$S%vJKne2A6n&h_lmN95vi@Bimq`{=DC9Cr|XV{AxBj-YRJo0%oIF4QTZWgBPSVYP6k>IkqBxtd~9+)|t2yjWm@ zD@hm{2Im-V6kG`xoDo-AG?`LzbYtOW+Nin~LNeM1u3Ux)ENk}Fc;!bI=K()9GWlG$ zHp>S~@Xa9lsW({9C6gUunOvF5`FP}nT4oCXE;g*j0osW&q}s~DPRis$)`+xu;`gz_o~C9BUW zurGGhjMiE}l-7c%Q)NPAB1`Cu!BmJl$^dZ1QsY#h<8Y{%T>x9+!K;KlpY=Jpwue8& z_?WV?_UX5OIt(4#U}(t|El%`}Y9<)+w@umm##Uh#&@2aw`q1W)z+I=V-0SpGA3?*c zmXk!LgL66Wy0^ouNh?Ffji@UvRnjI_!*vDqK7S< zpN`DaSa&k&s;k?ITReW`5;)b!d@TC9!KMHi!n^6!mRORGkp2B(|w zy*_x?GZchmP&@B%Didt>?s#orF;A8%!lL3MX6r;na{fCerpTox1N>EypflGEnnb)6D8Zgyn>PE%vY$?3T9vd+AOqUqQ!M|9~MH~?av14GMoJiILG(Tiv! zU}a+oDOcHmr{mYAFplw(YUoBWzGLE!N9O&F6heNJdB2&2C)UJDgh^J)iwUfsv81ds zTODfk(%i7s$;nlOjvoUnh`Wueva=vaCzv(DlWsF2qa(Uj@g#qOjpa5z?;z8!;Rujf z6T|(ow%ltemf3E;G%m8yZHCt^+*(vOYts?W?<-`GbaQURx%D;I7QrW3<(p&C-kE&; z2X@QM6ibXy-g_aH)?#1AfYN~lsZr{IBI@k+Py-nrggmR_i5Th<+Sl68!=FE}@5w9) z*AX>IY;G7kBq)$_eb4O5F|*Kwk+WvP)T)SQQi^D8O*LJe2Meo{Q^ly!*zx^1ug8?> zl4DB-V>9BI)4f(|=4(LOJ>Vnxf;}tYM2E0h_d&4v_&|LCezhw<(BVzm<&+*wh1+t{ zl{%i*)G}W?x2flcmEWh z^V@f)@7QtjO~Hr?fytlE%R;uto%^U`L;BCk*xst^r2_RKW%v8MjXY7a8whw2CH6r7 zkHO3rwWBD-%ODD)IjG0dtW5vyig{V5b%sNI(Gu8vrF9^0Qg&cmB!A)lf(U#8s{Noi z_zkYV?j9qIHcA;Y-4GnsXpRP8x zk-9ML`m|^g-H~xuJJ(rD8waWh)>S0Gf2ORA<<*bYWmI?-|6Nzj!0gMB6*8d)yh#b! z15_CQQCJ26l~!K8$CJBbbk5-_`Cus}wGws8Gh%?)*py}-$1)yQ1KMA$-6x@{#{$N^ z?6xe;H?MS6QOZNFIRG_wTvg8Z2tcgC!;?(CA@&2GCCFxooDGCQS=gP3MxL&+#5*R7 zhH|ngy#xgvWg$!b){`n~JYalCXgxDnkVs!L3{^7>bs53e^Z;4^) z7Q%w{E%r=lr_Do1Mqjz!uFOb%p#`XT0q1XPls9PKD`W390xa*CH7(=Zx8o$<5@E>eeYMf<+5;|SvM;enP!?q*DC#bUI|z#%Lxc63%3aVfHKszj#}c6${zSa z5w8B49U90OVAj?^9*il}Tm_1c%r>?0;2 z4Y$@W+;z#H->?0l5aVi$Pwr|W9HOV$pS;v{q-h$&G^M;6l+{__D%VbGSXfjpYb928 zm+WE=ol+12HnEhF=#4bWoOwY56+~2?g(kdJ22G7zgS-g(^^#*5HZnE+3oisjSgC7THePyUp-|Fjq0lYSNCVmjSPUk`tr zFnsdgH*~Q?{EBq!Gnfq$c!K%PClLB|54Dp~>XN=Swgs9_NP`^=JPNdVqmiS{54uK)>nIAkP^Bm z+v+G4-4+lz*#EV`yjoNthog6OMWO|5Tdyc6GKJ*}rhO^$@dQe^E9y(OP8EM`sH2om z@jJR@`WzU(og~X8B`J{Z<@!sbnWnnD-}n05C@$rGOba*3fU2q>e94rkd}~n!ib7zU zc=lSEPjr53Q!Cm8I#V4>PC%KCF0NCpL{CAPQJ-RO%Y~XJ4e+v{q0!%$N$|jDMnwF% zL5$>M&`rpt$kMurRsHd$oC2vRSwXBX@WvQLx{6s>*GtI7^3*iVnu)3-RqPpF@^Pu4 zF}!M&yEy-8vQ)Iu>)wjstm<>It0jY$!%?|PLH$Fe0?+2ya^aciDe7o2A1fpHYGXd# z0%T66TX`n3P?|;OHBDgt;CJF414Kig(m}2E4Ytji8Ps@)*-L})?hP!#!~k3VR(tqV zb5k?XnV1KES6NUNverEr%unjQwHU)jCvK^5^WZ^mVY2mApC0+esu*kB%KEN1@8sO-qHHD$U^MK%1;;4h^dM*~445 z8j8|Brs*9hZ}echwy-AX2!I(}Vrp!D96Zq**T7S?<4|t)=4E!h9_Z^p7gITULvVz< zdk;y`+J`AeHlHt`buxV|ecIBzIO$k$e=v!<1!mOsKl{p_mFe!^govSn{cZE8#ILp= z;)Qb*^~k#LH7UJv_C)QDOuV67mt*MQAA?oJ>rbOTtcd%jMwn+{b%|t|{;m=cWo=Iu zVw%;go10Zr`gdqUc-r)OM z<9G`J6e(_}3#*J1L8}3rn^&RdY;m)Hvq9XnN|&6geJlIZ{W6bEYgURJZ<_n(X7|8g z4@t3X<<4=AH*JK0F%r{XE24dOE-Et?79QU@BZo1s;E(7SHIvkz7oA4SWzj6Jg3?m* zbTmq`FRm9m2DZk`737HXE?w(Ea4uO^roGIK9D(W@Ol?RkIFHPS)oAoPJO~R5tQCp$ zI={K8ks~q3C0QBp8P-}ZI-g&P$=hq*x5q8jg&w3IG^})rSDU>jSYXJKojch4Vkh{P zECd`dx@|Ig9qPgG8`Z7c$+k~Vc_-Nyx#@T~;eR>^WwLo$N*HmckDqCyT{^tL;M)M4 zqk_^qfuvAnNYVuoJ0Ch!(`3?=j=SjO|MD3D8@YNRyFJ4XyOqm0#*1i4eN=O+Dgq|n zm1cGedXHq-IAjTqoFQG01I2lC6F|d zk5fT`nPA$g`IyL-#E4lf=F@>P{_1ygD>r|X(I{5~ziucz%1UwxJ>SqXbT2^H_v*}Q zB+lADXdk<{fbPoAt619pGR)-O!abM_tOTFxM7;xT7~R%2EDta<{v$f}*0PT!=^$N) zdaj{xkAsyiYui9>zj@J5mA#DSHP6kW%HmfvVsIOSlpLVWfd18_{gDS3@*C$kDf&ew!XRCM@{p&>uQ@hi zH^D|#NnxXfntnU|hAd%ocp)LV5Fy|l1Ix#@EmQMnwRoR5@EpcIYlK3wEzHdBKeEg) z#goHS^3uaK=EGNBNekP#b<{v}#m3B4u_20y7WW(*c0!f6&5#{uB$;}a1+2rI$9LWP z?2Z7%&*uGW$ejLfG`Ur5dk}Il;sbF)dz$Im{SynGzT9dz<{GA|S`lT#^a)iY|C4f`b8;h6;J34 zd6wsC7oVu7E!~fk2w}N3VR{22tCincY3*vDA;gGWOvZBi7Rg$<7}pTSCL+Z8x@ixM zLF`@~6R50g;XvW}1@^we*&Zv|t=^oGm}E+Rb4D)fHF#=+Cd6zq*_Am}Q#XKpJidwO zE{6~8_dyMatdCCiM(tGQ?i>LGO%H8g>+B0+?3F`Y&X_eFNNJx`bvME(JZ{pb>6@;f zOf!TtXUH|tzUrLVq8W4AOzLq0*LHCgdVKbGrIF6K`9no{qYrcb0@-)$?rpT|1Sc{h z=MLl}(%vOAO$FJJBXsmARTsbYQgGaM)3mFC-#ZLAzKJ8eNJ)Z1QNCKqwX0@eAxPTn zBHfS^=sem*KNZoh1*nA_iIc!lbsw z%x)$7J5Sh7T!Ow&Zi+BKf|-RPR8(|+UlEo}NFL@1q@_y84Eo#)@7wh_$JQP0jQwa@ zAjIR>LltLQ3=edJrR|`SDVya!j_W$G^KRbBk_n_$ zLseU@h~(vzu}g0)DdqC!4*f6vG8gA^FS2he-lrx9t#p|0>eC%d z>3_vDfobToch9-s%$gLgA+)>KHYViUcxs?nu?~6hQm$oCT?_L3WPiA$2S=ljfD3)R zS0?hk2HTTL7pfIU1Rlxi!RUJl5oaAu%aEr9D}5FYlduPq^00Q+H_@6Sa>LHDj)TTv z-$;BlpTnM*!G5O8V#=NZ31|WjDF5Q@yLs`f(KvNZ66A1b-QL_!;Jutf1S@brt35%p z*U}Ou)IhrJmf9-#lj&OT>m?P+s6wBKey%nqzAhc^=q?ubJW|$E&YFD+S*ne)nytfn z@yo}H+0)Oc(psoH9xEkd7zi&%3JHllcGb=^(CNcPH*Zl`m{U9PkCNCq8@z|x#|YEi zRP>w>_s2Z ztR&*XwlZ30EZjGC10VKJI772GQ>K=*m-rB-^V!D>UV?0So6hTJ2xBe`ExnikV`B&tUkku1mPl; z@Y()KFD%YFgIVtMx574$BY^p8y`%QKwZKRZi?!KyeFyZ%R>;9sm8d~;8a{8^$?tJ6 zuWwAR3+d`k%f#WC%pm27nF&WM z$zS!tFcl%S{*itP?L&kzR4^A86-NvsY!UD5l^#Umh*jUW^!cS6p`fs~8H;<~Vb#xX zpqswtjo1gmd2K^fMT?S*xA0i{)y$H~RXwsG+&Q_6q*!8==X5aGhm!$Qlf`4HhhjPh6)2o(0a@WvDMy7fG8EIz z?m2E7ql?I~OySSy7HE|}TP1doo)(?2S%|3)f$PK%-N>_mz3jc;evNR`04--SVkTVD za|F2HGN)?@Q&mJS&CwNniJVfJ-}(1=NU!B%hHGaP12|#B*$;=!56*m&dn4XA)Agy6 zxIRE4W0|a{Fy|^AMg6Hh>SgX7{m#BxP?QnVSfMe^uUKMyZ=N%gFU(4VXVr1nG%MXZ z1zOZwEv&t{jWKy|vS#M(Rwx-dlnI>J?&*RfE4gQ!k^;qP3P*rl6h-II6!)faLR`9M zT%u2MT*8RZgL>pvPd`azBTXZi4sRRn=Xg$TtJ6244^38P~+UToIKi z(U|EAjS$LQSIoLe?$RzT_|xdhg5fq_!~RYhJrlGssHQDmLL zBI3(a1Xpks=ia7!YOO0VHr%@r*?NB#Sti_;j^0W3b`{y&+(EmBM!yQqfnE;#%a9HL zhzvA#H|NlAg9r!4Fl)|lP0|9tS=)Oidw!fdzZBD~7T;qMTFIiPc*fVBr(s%PG_ulk zYnLk|$fRkoy>dMibzCK4a6yS&oYmXg@6~l}zO>K~yKBUM@L5dhMgI^{oUqYQ)F>&M zfx^Vo81(Tl6ULT$)4c-8=W$Day1B7G`GFtc*j17fM935h!6HgsO1U$wn@ zdYk{AO-T<^t#kFroX7$P;#k&byKOFSf*Xp%+aQj6hRa{IlB(FMqSucAle~`;xlWm#4DXx`(--%uOyj<(5P*?0>AP9g zrUuTT>nh2n?nv-H#cZJQMLdjo1CDJT6A~!TTi(F4f?dcl$DI`?mOUbNgGKM00+l|V z@5zFvDr$v00_*vlRxG#!B^_pOb%+O=R>h3K$sHLseflQ9S6-I4aW&15D~}@wuCp!5 z7Ai63s_{m(-JdP^CfAk|v6JfU%J+RtUCfi@MPa6IVY=Ca!FMUt%c(Md!}I^w$^W^|i?KUzzs~tQY{=Pu*tB7ZD{CIaXBy8Y^!a~XJ9suI)frotBO3_WSgoEp z0towSKd6N2r@Dn}r!V3;lLz-UD!}&=-K(iIJ4vNI---7*d@U|}O9?p$xSWxo?gW4{_6HCjAFj{WSoZ*h9UP)(r_VWF7$1N~n8+d1d7kxEs z$qIgbutrRJ2d5K9n`(aB=<2s?t>$j=F^MvpQZoWlI=eSJ(CgXgIhC~Cvxg}g-x$tl zy`OKrF>H22*gOYyy&(BOOa)77?NT&Pg*@nkn zbadUm0og2b=nvLYqA0a|-%p6sm4RCdxi*nyCL#zGSi%&MIoGjESJxYhd3gaKX>p^} zH1A%0WZ@?p!_u%yrr)AJb)@j;WXn5;cdGhDD0?zUg^uWf;xpTgKeP2hIqJs3{ugcM z8P#Og?tP}HV;@C8sv}jYLkU&D83|QDgb->_LJy&Z9?Ce53WS6Kr8fmbAR+Vsp{jI3 zkrp7KNUsUfJH9vboU`6~-cQfj9}?CIYu|VFy|c@8{r|tMqf`90QtdlEP?5)}?s`mM z$S~)b7Aq(P>0Wgg8C@5DK+tbv=kYCl z$Pk3j5Y@Z(-j!WghAQwFE#w5OCbO<<4Ta$QLx+$h3~H%cx2a^MYNmAdLBJU1)88g* z>@iYDg8Ao#i#SfW`!^2O?1R&8^L9vMmq}r1 zRTny`^i@|AUGB}@ci!jCG)CJtGS|oD8n4(al@BM?kTp`b+(Gu%R+V_6?IRL(YQ zzAsqj+BNryfE8c%5u5DJfUTWL#60&dd~Y>Tum{V&$f)lDKR7$f zn#?ddbO4YSUJ~0sJ;vIb#W*Tkm}qV7Wbm;&3q7(+z-?dCli2R|uK0ikHH8{eKlXa{shgpZRkz@-Wt})ph1P`Z2UHf$k2SP69*g!@U9^zca<=Vum=a7RuOw zFFRV_inPbZ>r5>pZqS1DoaR+p8Qab|Ag+}~!*3i<%j$*&)HnE&zkBJ}k=g@a_w;~R zvghwKEU4WW3>$P#-n?8fl2l7D7l-M7<9HtXr){Exd3=8Fya3UE`9%1rE!|Vp-t&Xo z;oP)+M8SyxyG%gy19%DzdfK?LwgJ&Bz2?n z>JW9;^$JUU*TEIuFTw_o=sgfUxmC4rU7xkArSLt();bMwk6!ht0}luUj(8Hq?OW7G;LPo~eSrXdtG+|Pq!ZkVYc<%7R zpD_0&k0BD{r4edrm}xNTS}SA?l46%!I5y2KE8l8Rok6dzq0{e~<&Go$qB~e$8dFsT z^UABSj;)aStG33)72MD0!G*fs#^X;=<}ysLFKP4zLFp2S2TVy&!!osCK*SA0`}3 z5kr86jIbqWI>2@%k6NUfC)hW~L<>ha<-V>r?sab4s(180bc2?9kTrt!K(!*<95nfamR)M8WRQdC&!P3ZEiDJE!GL9$Qe1xbW7uA5U};1XP4 zGj?gfY_FRum5O~_ph$MOs2yYRR3#*9IZtN$W@a~~JF&YZkyTL%t&Fo`7cMxqNqd_h z(E?HVc(Hyrj_-8HX!Hjlj?~DN)cK@Lc|S~Ccjnrg3LEAmL%+0r0)#hDhf+uuut6Yp zWnUb`saC!DWsP#faw*}{s8**D&1KKs5BIv+K=9V5wm>=4GYcOwrd|6f#d+V)Q`*UX zB58G8q?Q{M1XkfDSCR7Y(t7fB4a+6f`oWK|&H_*^0`Lw~{nWY%@LQI<{{L8__?Y#h zef-&uRq76s!xNtvlTX<0m$z$nwm*>|rdN`*-pI~aM}G{${@{ zF(QLb4Iv8mafQ1U%=(^gvCcZYFth?i-iUKJyds!2kyU(9)U3|oi()VW)c9fgq^^sZ zxLfjXP}Z?clTLPPua;P|@jScn6^Csi8f~8J8K?Ln<9pRR8gceVeIIqUDvN@~OvhAR zt-f){j*f=fCk_T$>K8!uke8CLnCh9=@VPRBPd}7n{638LQyH}@BPgvP%b}xufRtZe zJD^V27soXIA=;8$^rp-oI|mxD_c_=lb`}{Pp06QK%kg6G;a2(ZIDMbrq%+H1szD!UN0Qe=ZcCx3Hre{~o&TzqeFBuh9a@vgmK@mFN)>rLOb|r)QXSW{?I~=5NzvKN$nk49EF;OLLhu2j&)i|;Ub!UE-5@;Db-otID&K-G4 z^C$01Q&E})Qgj275~jr|9>RufQHLH4-3KbYl&&+)qg}X_bv@C`NXA{DeuCdwuft)? zG^rXeU$WRp$hYjF$b z@FvJ+EqK&seMvA<^TdpyXampfKYWI`&{aKO@8JCU88N>qm^yCC4Z_>CoV*Xq%E%!7 zmTdv03dvxwx4?>&R z!y1#NQgr;2(|)53NxOH`oOb0JCilFivn7i~Dglw(LPPdgN#?uBV`~aZFRI3q@k&om zxD7?{5+GNXZXHg8WV#v*&!jT;h;XorV(OHfbY4{oJjl3T&}AJy4<$2 z0P-?;cmm5}fp;LP8J<)3K*@^phHKs`7|X?D`1iB^c0t_iwpkXCpi#jYkY_@3QwC2e z> zGNsdZJ|jOc#vxUT+s44X>+Y;PCzn84B{5u zZ4xC+Zi-Lp4(P&ks@jyPg&R9cKJ%~tEhv$@ph3pXSgq>(^{jbR|KHoWl024SQZvr1TogHUK8|?+N8;) zl62BJ%mx3pD`jQa(AQY05YJ}z{N4b4qW?53G*M{cz?Id;bS|OthZQNT*9Q*M%apCM zvR;88s)6sir4nykf-_CyNC=$|OnP-DbQ;TbXfiXOkxLS8cLpyuZ0CnPC| z+0!=LZlA_xx`=iPV8tNq#iE3~{D;ajx@6z9I}nFNl6KsXe5AuWWwmU@WP`p)#81gx zfvja{FrS_-^HcH3vJpa~@cB26xUo340O<&&Im`n;q9ZO8?y5;kU)`%&ptLC9z7!1b zY~Njc6uJNDmUQUKuUpv=1i}eb-9D_fAR;HUU^rg^$XE-rQk~-xk7bb50tLI*yfVdeWQI@dD<*Q* zH`F13cesjJztineE9k?H*fMApgY2g^)#GPs7Fss2Tiv1Vm4$t2*$*bgUJ{x+aA7e8 zh~PH~^eG^17I;{+jaqv!lxZ9qLP^i|d;%;lzf)l~jJs_2sPUW&kNL(SU1ZcQUaLdJ z#HNtevNVqhlf6P2#Og}oWcZcH$ghik`!+cEgUTqw z%Dej^oZmP)t1U~zJ)>`Chh$qE#EVP^G7TL=p@R7J%3|-k5t#{E^~aAz-t@>Aug1~^ z6w?Ob;jMm)j{by^jLUn*EcEmzl~>hJS|-a*q^b4I?$48NCfe}TDUlZd?E&Ff64&&h zpe1_eYDy$N82{0h7#W!TRQsBFW#R5kW##%iWbr9_Un$8?9kEgqKh%-TJOIPP|4np19PKNsB+se$$f z^+uj#P=N4rQpv3R{w3qpkufs1Rq?i0MOy2!3Rud0-@aS(?uWJi4E1)F$lwc$kNo-k19y%g$ z7`c3)(~-s=2nk*d%*ojR#XMW6sjVoDcCD{@+4JLq(uT4!fzlcEBO-mGp8P>Nww`Xu z*((@HvsN2UkR&*Y{Lw_xfYz+aqksRP{gWeAViDHA;np;%UNdS+>G_$TX)l##{< zL-ks08`b0wH5RkXR*>p$aP*plx0%%{b$xGqMtyUca;SrpNYUiYvTMjF$2=U@nTwf6 zkQO77*viFC(lV$zx8XDh#ia8t(>|q~_E(E-(60W9)waOFu10hfjwXk66*5`ll`4`! z7QKrWM!^;+#c(?^3DRNGi6hfgp)S%Jp8{!t+b;)a?E?r!wgJ&Kp&C+oMHzDy)zgV+ zGu0L`HOkWZIrd=#ZH>nzmD!`vSC55#64W=)!9jh& z0!6{b8Dj98bm_=cX>k=lipw~nJ?DeCqV(azvv|kaC9&vkcrI>@Na9>x4mi5V9AG+V zsd-;cN2KjgR{b>NbO7iCQBv-P1z;vI68Ph^No76m2pJ$B>%e|;y^uDAOg{Tsa$BD+ zyenpr{-S3>=x#-z_{Mpb-(}lFqde&#OFs(cMj;H?8^y$Am9BFE90@L=(U8#5I=kX5 z=6!fxVy`v-HbRDGMWp2NN{!KT0)=l6EK@hSga@oLEF!oiuEJxm1?M2LzWX+w{962gKa+C#E(v8br}tTUOmtLB*E2?_if*PP&5sA+yc znYu%&{7$Bc!$H+m$jKvM#W5|qYMNwR(nbrYq@U3B zz)FaH*bsQfPhp=wpi0Q2$kXx?Y<>oM*X<1)WT~!XlqaS(#uVe1!}s+~CYnHr5mM|b z!b2DT*5a0y)c#S79b3Wcat$R^10Q*jQGpW3Bm-f`%}-t{caZOqtG|7U$n3btS>n@U z*GD#KvhJ)f`679m&IY74mji-%KjCc_N)YkEypHoJ$8>pBqS#N=z@EMx^5@VX=;-m; zyiXq!UqtJRhx+$k*lp5q+mS19Ula$h6B*rTcXstgcY15^FoSP9;7q#5TAv(Ose`;) z|6Nr*m3KV&iSh>Y!Z(i5UVH5(>tY$%^8dKppi7}ZhKjA}@jg2YS zOXb%mGQw_U7p$<%Umn+MMsC{~_@9nzz!v>KnL0o2mWE~Xg8E;!#D?9QNsU0IJgWH#-|_N}rRN zueCHC?BY&sbsVASb_a=8`AG!T3`OG={7naKQztLedwiX^-ho~-v=eEll%8s8faVPQX=%NAG5=d@1c9sl<7 z-Q%|b8~Oy7ae{LPbdRoh|Y=dqj?Rp}|>)x!(EO;33*FXdk;qhi}`7s%nic(7p zHE46+ICzR}wIWUStc($S0fmj@OeZ^rl&ueWy5oA*DtTtFcEGnbo2P$u?k`|6=<12> z&_M2%Rw*aUz?io727yDi7-upcZF_&lVow4Y90oBBUP1My%=k^J0->^;tn=1Nod2&- z*$4pVm0J9+`3x8O{+H6y2+`tq4??creEkLqUd#C*S?4pLryhYjTY0UTwKuFOc-f=! z?uKI#Gii4noxYk3;etgyG~?jaQm|p++<0{2l|W5ircsa{EqywmC&=p;sA6n#nr6>* zCb3dBNPFMQVHDPMx=+Jyoy-xFc=qkJlb(yj*4BJ-_1PqT47gsyj|s7=vzfJ#3{opH zloNZ<$65&gfnln&cdSc8YF2waKbJq8C-rdCys2$cBSB=D^u@5A#+KZ$nDv_o-aMa# z_g=B7Z7H_bv9yDM#iRyf;;OI_8|xu7&*`rnfzP|Nh|F`g(+Wbegg#?fVw2&)*eE50 z{H7T8Q#O07UUOW0Y$N^F!!57M0rkW4XCn>ggga*Da}2RIMnAsU&B+4o=AzMN;Tcyf zeO_8ViKY~-FCpuO7(ov`S|SvB&8=y^&iP~cm7i%huvo`xo!wkSO+wsWB$rycA}!dk zq?@bR%+9v6<4Yzs;rxuBS{yuqjIv7vgTX|}n{7{k&h#Bv2lm9@;DVZ(MT=p@*r;&M z*LmlRB6qC)43#K$B~W9*&DA$B&XD~hLfmGY&Rab?fXH9%BU6!T$`%$&snKI=j&FO| znzHlAccF)#AlSI+P+BFD&IjGH_Ruh_p@U(@;la(ovici`W5IHp(Zp7`b&WCi-KjdY_aD+tE5) znWjm8S#ml#{|jz`sFs4p+yR35Sxx~(EnDY zN(_?HrzR$8#UfAU-N;>S5%2H{-P8o}oJmKQ_s~jW#gx(oVnOe;AqCB466llm_nnug zs;<-QSKWujgd2W-@{domU-51)t*CjL0a!4ZGnz+sl%YZAyJ~`vx;3z^B`lpGpM$4- z8cOC~Zd6iKnQ$Zo$!?vFmkpqM6~zuAs6j@6Yr8v72k~nmDXBAR?9F8pDXYF~<-$Sb zadVnC*~ycy1pP->X!hLs3#ILa2`W-f*mmHFW%PC1NJ<9X9dG{iG7n3UND+_iR8hn$ zLRF;`%tX^h0nH1zSf@|DFuviHaH^|FsPaJf2@uR%TGz;S8WWuE!wzvjM6Ei(AX$>s zuf?GR^GGLv)+9bh9XWdO(x!7#3{(GHB(B!c01^I=@}?L8Yq7A{{y7(fpGEQLa3 z;*VcSTJmRhErs#Jj_B`N9n%;@{7{!!?JE={G zQ0(@->dXsl3^z#_tM2Gn{5ThV&Hhuxn(TyuYKB_MXJA?&VyB5wnak&Ldipni*^0a6 z>KiG%fvhl1KK|>GVx8BZmykKW&pmZ@I_Pe37R}{24pv;9o$vFve1knjU@Op8JFblq z(&E`63(Kx6;D31NeTmzAXh8PPazwcw_t1yYzGzPEQC%!l_UJ_FNwD8NW4+8lvjIvY8#nD?@`=B~iE72Z_EomjE@Gmj;SYt`A+K7W^H*(*NYs+G@QU1c;1DEn#!5pv1LmlaucqIS?^GC!h! zWyvq3fHRGzaKGia-3GIpx^3O%WNrN7GZi7uU^)sutH$ztY#-6=kU`HHaCOIPUfhZH z@S1T52>gKPRvMLEPwE~@$%D|eG)dcL6b+|J2lOkCQak^|*SS{iXCmNjo# z*5gdvfUG*t=XXzlXMLz;zHs`?|NSKgfB(z>UF(x!=JP*V5E(AdX!=K9P;JMm8b7xG zQe^{5Xx_2hO#Ga|F4?XB0?mF2Vx!UTr5{hY(S+pPDKWLt_t%aftNcYQqpUP^;&x$nR* zxw1sWl-#U?FFHOr8AX$x+hYFar4>I`sP5vQXI$l5hHWTGh#zO@7dTv*<|CG(lL0Pt zM&Xoz;%nfEoE~tHX|VDGxf^PUJ$&dbCz>QBj!vrmO#evuVOT%-tq$-$pdeg7ZQg4O zDJW=h7oQ37rA^)QEc(lT^vE_eTk8S@+*swUy(ITzW_}jopl6T0(3%l6(3V06gArM6 zl&%B`DKYFK86_}rVfa)@!H5YJxDSl$?3Ou&;Ct9g`1yEhvvVQ6k}74ueK!^61`G-H z`4lkg!P!luLwfc5gD}~Z-dk!eKXKOYT5Mv@rP(?~(z<%Mq<-$6RXPzY4uq@W zTI36$;r3l-GMXlSl7~Rn&2IT!?8FAr1!Nb$>@eiyEk5&0!c0t%7S?-0kJguN(^8|} zhNKKad467`EtbbR9xD?J94TpJ6Cou}z4zTy9Y^Rlb>XgC6E11hi8;`0_mvRfq^L`4 zzp-5^nYO*eel@Bz`F*I?=0$~Iy2_1(>HBjzk|*N+wZOR|hhIkhKa{j zxxB1`j2e?n3)_@UZ?C9R*~h)2nW^4{8Ykl|OV!8Vlc${vdYfi}@UEW4*~E^gT8iKC z6QgLh7O9JveYU`f)*BsxBL8{euAVQ5`rmOb2&=iZ+#ppgd>^n$54!pwVn$G0bo-`X zY0O-Fx1N5TrJk=}aVT;95#d)3GYDr4nX~T7iY+>Q;eDWT`J{ebDw1=~p)~5Pt5tX5 zm~^obK*CTi)t<`Qw)N}`I$Xx=a&BL_epZpzN~m56v{k{iQX=lW^-MN3^$_9TP2HKe zE~H2+N`8*_v%Z&S|BXY@X5LnDNWZV=ufE|pPkLkJM22u7CM-JTJZ89WN1OUy-UqMR z3Ac%;R*l2#F6>9u>Krhi_{&xp6pgyoAk-x44;tjjj+*0}w#8eMJHiLXQ{|P-HoelS z0_vhvqt&c;*gAVrS!B7UVS67et0rSRKqxlQ^&#yd<=_^7|H@@4__V~{W~rB`O&|#m z_1(U$<-v*skUj0!f^zliksq^tI2o#Tv(C(%X`u|`i>_#G7(@qUmN2o?^+tIP^}l>Z z=aBVTe%-S)+qu1`bsj#`6|d8L7b;Qn0?N`!z|dv#e(n22Hu%w*p5sd65>lqr(%X2nAvr(+ZNc4iMc zsWn0mGMXyCS=%LR%85WnH8{2fVEx@jGBAv&PJgOeZaNq&(p6NpIrT1W0TGbZ;p#Zd z3`wYcefgWOz66@=F{Z?2}T+wBgw6&u%%YX4d-)BC4@ zIQ-*>l@v#CxqnK%A2rQtQf{Q$(1vqw$sYW=}B$Fr-#h2 z`V4Py5<{<46z=S*ybUrlgQyaIk$rO7&Q}PnF&VL*B>R>ebyB}GCJmmPa^jD?fk_Ty z@gOqm2Wl4hs=M``&g?;KFU49o0|J}*moWde{}9-O;3|!K<+9VU6$i;)UI#^1tF779 zk>Ho_DzTwl&^M^oM635(a%c7}w&7)n!;q?B)UkZ5$*W=BD&1Atzq=<$c5yM&{06zY zRBkfb$xr?|ro$|lD?p+qHT|*6%$MD~wTDZG#~+(a1Dx@rpgP_Flti7AB8lf{S!Y3p zuTaN;OWR$)wY2xeiuz3F1u$60!UmAEJ|Ly-5(2~{_2&RHI$Xy0FB;Paw=o`}OeYBx z+EnVw0f;6*pnV`;p5=sePdk zP}`f7gKkaHaS%LDy@}`4EjO9LJ|_0y4PT_#K;ow{V`S1tyBxisAKu0HsU35{@`t*2 zVT_yuo@bU;)}M5jOc({RcQQX%04;82cH^paiAcOh)&Lg}X?Fx7?Z&jcz*cr?XQCyZ zOZ6Q$uv=E~-ElBN%qFm><@!K;5?d6mTu$=JNV5D_&+e__x=fskX7a6mN^~PD$7aSW z05&ncr*$5HkDiXJX1QF8F7ON|v@{J+D(I(3|M~&$im%Z451M!gLBdJ&{Q`oyw)mHc$$FG1m zZ$H0DZXSi&kSus|1p6KYHng=3?$vSV)yPT&Xn6}JjHFm%Z-8#1H0w z-d;ML*8z0Co-p7^9Qu-9_vZX7uU&-iRydi?W4cVjcs|G}4CE}+$g?GfF!#D6Uo3lH z{jIk&JUFcZda1Q;nD5VmG&(POM{@XMz`#u030n*vF@xy?R36QcSm++kLmfO_CdUJ% z*ZrRH0k{;0Adlj)^mRLb(X0z1brO;}8Zl^M0od^1a@RZo8clnu+-SY(Wwukvn4~`#NWVPr}sUsyEctPZP;x<7{p}nA1fEO|412kD! zyDD;6&YZ7j_I%(L!ME_Vmvb})1Wqm<2Ozc>+2_3fMm_!;)(59zsPN1;X!miO(C^D@ zvyGvHTISyA;nVKM=A5P85U9=UG^)taq!}@t>$H<=P^^od+gWPcM>gB&V|!fuRQf5A z1>ToDDXs-PlYWE>3~^2R#I`*k?91r|{~Ll*q@#cY0v0pitr5fM0dhqYeAU6dBy)X6ami=C?rp0YwC~|Vc z#xlA&RSgjO5QiznPEk9W*8qkn7Z*>Aq$CP_-fzj&>a-7^F$BW$ZuxL$TZu|?Fu>6t z5UMRhFm|ZG%Cg8a*6&mZZDunIyAYGXbpxXs(3AF{wgKi+k!5dR`KVz65u#PJVq~k) z6ej1m9j>dkn4eF!D1PNI!d9QD+DKbj=+fuEHZKRtwza=qEWbOfrc`J(4(EE`aEUmW z0}lV(lk)yc!L*+r01I5O%?R;Loqw0PGI&t#U9~1txJ6kV3E7}0DKPE)iHu3GfV5Ld z=g_XRhh~O(dI+8;+CC5=L)Qwkob{YPb|(*0jCgW=)LR)^B$kF$Uzmjldca20eYy=` zn?*RWtm(n1QjLTUr%z~l9?+s}YW1jTi8(yYP+9t1oqo>O|Ge-?07P+K$CL&orxgK*Lvpht;|paME7Jon`j!L6QpesZI){((mhwl|ASftmk!+M)msp zHBz>kJ9ZpD{$jlQ#c^S!%8s8jGzogiYAzbclL6;HXew-MhK7s{`bpVE&BEOBuqljU z1)F4D^2@819m@Fr&uXPjfxA*0%JRdr@w8(Xkd_|V{cCN>Tth>+l(MNC*J$mLSAPAV z4f?JxwjoX;Cb9(=;ZAOc-j!L_`9n zEab0iTqMZ-xIU0rJA{rnv*s<535e18GloGd0BD64`ez?v0lSl5(DfJbw1oj>s@v@4 zIj^j~V(>qfGXAQ>hn}1`4&L-MZ=Tl3H)@P+}J{;V%E!yc*XHoZvj( zy3A1KSy3Sx5=>jRJ9tPo@t# zPaB7q`@1@?*)93#-2z(qI+L&+pON|D^aGBImhQ*OS50^0;1LJkI7S>Csoq`aQB_-Y&P!q9xfcf+g zU6kpK?KC*S48Arax6V3w4?H|sLDztA#c=!nwcmPXUczievB>KgX2CfLS-{Bsuku}s z6{am=_pLzq&Q5^DTTo8{^CSArKcVUG?#r*v=k$+Qjn%wT!M1{;ZD4j_&ibeY;p3MO z7l&3ukNf{o$-n#UhZus}Y5d@SFK4RcUbVWeCy&_CwFHVJBrcLSZXUiAjW^;Sz}Nvk z@V)!Py~v}_p-tWu7HN*>=Z7>P+`1RL&KwWWZO6W+*bS9sb`r~M>jetvD^V-HxQ zm=0EBdLhmsoGul$FWUEJu}g!)rQJkHNg1<8v&nByZ#w50y>uJ(2vBQ}d|Hd!0?i3pX(D^%c*tM z49*OXOAJljp#7Mc@KM+oK2Wb|WFc;w-W9N3&=Phqrdc$^Zg;*-kjcs5iS zQ)-G-gc6l|`&xO;OU=iFTzyZoB0HOb0b}1dj4MX3Dk)RvO8Yeu?^zw+-`4j{duJw6 z(E#~EH_5op3r&nTS1gH&EAG9$wPF6=KVFwIrb})Wmq@=%vt{vpr@o@6es>pUV^$tQhv)w@!pU7T1Ly)Nxa_HU$;2kv}~L z%|CyjvkQLl!5O6>cUH^cLSIY+L29D$sWPA%ETX2vOm<s95$?5Bi1vec6&W)kO2%?3!;$vCs| zbk}>J`XW6soBV=_SNQqUm6&t268?4ay5So2=c#}6Sam-y|I6ZJp|kc#138t&TH?yM zK4D1G!JSoyLI;~4DSCR1u+Liat=P*1-7vvR)Gk)K3T-F0H~OkP7O)J*Z5$Gd)a_q) z!Q~%1M8_8B9`?RqVcN^`u-H>`Jn8xwUle>**M|D?=ET4!U6@vcGCBMZAYq z{CUjE2%kg6&4X}8(fGv8s!auOfYt1(#RIMFi>a<$WWGaMQqZ}X*{z5D9-c;$yVFif z4`VNzXtC~$_G!xqE}Hk@_QUr=b_ZPZDyc;{1L1gFjGJ9y8ZRFiEs(*OuZfAt>&0qov!u2s2&{ykK{X~*RdFzZIeV_{XrKf;5l(9hA$SGn_A=4IrQ zl6S4rnRZU)lH$K3LPTB>GdRiJI$)cfO!d9Fw%Wm`60ZLc=Oi3Y~45u52=iNIz@6p?nj-i{F_=Rl=7hoL{Yto$7Sc} zkyw*+qV`e?{ToNMBpf=ZL(NvIMaAirb0HH4IaR(`$(&?KL>zxAjeOH%FQFT+<=UO~ zKAT(+YjpzWb9T#~z3<~=BNEtHfP&K^=s7F_7mkC`gY z5gvk;OaPY6>RL*9^uWYei|fURy96}cF?4KB2b3WqJ+Z@bIn#^Vv>LTD={*9yvY(-6 zaB+S>46I!^J)Z+mEz=B{Qlozis6A{-$R91T7tDaHO_yn9*SN~Q&N<2P>`g;9H9}Rc z#Wg<>CT`V>gpUm#7YNXyyXRzI=W6GtgQ$m?d`lf*UszZ|TW5S!U^E^59PH*euc&>K zKP@iaC84aVZayBe<}eXpA+z%rq354&@!#k=bn!hIOQB4;cOK?^TFQ>WfKKitQeJ_z$oZ{>60PA;P`awNNj57(K{azIZ zC-fr%h)OT&lGSZU;(FH^4W39SCY7ps869d%U78tT9np~XgH~Y# zOzLMIzW_UU>RR`c1+pbty_lOwwik4(V}cikt>-@VIGFv)cz!j1-BPXYtnQ^EIf?5= zaSbnkGyRHX@AV-*nmx|1qB2}jzCkM0cgHWECs`Y3Qr5y^ESY^j%$^0Z`S-oFPG1xdfAvd)&L&}RAGtEUdkg7H+#zpDYF$=bHUJsk19(;pBMiw*D-c+@A>)+Ae`wdH5`%gW zO6f6Pn8#QVhIf%tmKVfk)g3NyI_5DM#n#sT#30Nd0|HQ)QH#*jb^ z)}watCCDqSbJ}A|7h61S@j!YG^;m|}otg)+mQCf8Jd*aHMhxYgX7px{tTz}^mlNCU z9Z|~IF1R=UK!CH~pue}tfv}Ios)fzll$kE*p}h!GFoPMc-M?xX-Kr-VdAVy{ri)}^ zSd{4iQL!01_R@;{OQS}}L0&!83uOcTWq=XyvAN^S=Umm;`Fmg8ZgqSrW!zmEdg@uOTorI}aqCh%uq~B$NUZ`cI&qMb;H;H|ML9)A zX^-6wCC=odLgeGKFj4*J@u?9YN78e(h`Ow4sb&7Q4&@c#QrFOFXIZAexZz+gM)fZ` zyms!)+KI4XbBH&i@UaBuMRj+5U1mZ}f^IQ6e$Vsp)lc<|0-jqrN)6Yd#$?l5;bsN8 zh1{i}$!0P%eBPR--CtX@P7(`Egw_y&*dhAn*2vQBAPWxw-Y{h1s*xPF16uP_<~Kor zvL#~lw;J+7Nt2O3Mgp6+#uEz}0@sme&hB7c;Mn0NZxOW^CZz{*!40N~h*sAd$Ajfx%t9h;xZz8(|V1k8_ewvdZ*$}{TF6F8u4zgJZ zmqFem<0a~#V~yW9@`>5LSqRx#eY(|8g(D+{taoMD>ru2|=5_PkYv($>Jr=tpH8AmZ zBnCcAc&GmEAJHKtVG_qg+(4bRE;V{l#bKooKZyLQ|tdbU;CMy#pt23r?d6U^--l9U{cGf#b}!;gvw(dlv|N3j=4)0h%fBY`#Chndimv)~oIfuh+8= zEwgt7R9H*P-#Cbi58nQRH^%u17yk%`NuD|6%>&80+oWK%At3itJK9udO1S~ z?AN=I&tFDjM`aq@{0plQvE>8vjn!dThcVX&5z}536T(rOVeNwP8o4+8-}tbn=&2z=gQ5iZn?aYDHk=p>rzmE56T zWcRTCF&rPHu96Nc2gqBu7u&+Kj;g(L9E^V-;?sM)SUcOc9Hui;kVV=WXq>3}51<)% zOD6mr0XP^P=xbUdQxAc-4rNIXB#^PUOA!0vN#$f$(iH0($H0jFxNPZwuYc86Mh4C{ zD&>u#?Rc>{Q^(|TqGU$j^&2$Ln- z> zq{dbzSP~CJL*=u(fOQA~!Z{zt{EAYVj|r`vt?sm=6tH4`j68(@bK;iga0-h~%N;#y z)BD54mE(H>B(ue=XbEfkrusVoM_(<9AWsa?ed|}NQJ|0-03lY+FGCgguC+Js+{V3D z2!*fWlzrfQy`wt!hkxaOT#K0(jVi(vG)S4Jl{IWg;2&L1sNWPz#*$x|E@6!Bzb2A6i2}y}*k$W#r z9>_@%XilNT~EAc-IXa$#AuvyHr6WNL&s$}0a%RrB4b6+!tvRUFkx zqlY9pd_T`+qlP033^^D|%G?;e7vem%wc@f{YwAT;%+ZR~C6{1%KzXyFQm@O~svt9> zCa?+QEL*8q)AcXwPo83b0N?eykL{$z%OR6)qgoP@5`Mf*F4ZB~QDp&;b?JszYVJE? zm-b^a6Xzn-CuD!U-=17*GokIaACq3ipoJhr;>`=j?|$Tm5JrHeVQ3Ahn_eW!Lsg9* z;9T_heOnxZ&b6L&+>Tc*Wv%*g%5=|b1P@L(gt1@txGFEZ&dQ9-dh55(enlajMJu5) z*EL$Jp7T(b*tMVQu0kC=hj%u;ixv*hJLqtV@_-#a0kqHJ_t~=TRufrVR?at z7ub}Bw}tXVhxW=^`W?K;rSv2ZkLZKWCUt@nN>Z{lN7&Bg-p*|UDL|D=ech4q91qjfq4Acvj>WRz+_Pi=^|d)mTSHxcC8fwVQj1FziD zb%zUbOZ)oav|2s6?n{~DEE@{?WdJHn-CE^dLnK>yzyn#GIRI1KwpWun@Z1)xnLW;PullxVS1u`{UBU-V(R+qms)OI?j1cQ0;;TX=P|~v7&?;@ zjY%7j#Yv&tE#E*z=B%@&17>%=uH}4HMch+|t!V1@JKn2fY2D=`z`>s9{v1S)KLvc8u@xsz>x6foMML+(0waMAmwHyr2`Iq8ele>X+10z^o$&>HjBc+L}Zd&mD+u1ird(zqtI711Z zRse>-F738>97gL3O!DxxF|Izb+t>q9X^Y@wjVMRy*H7@U!WXq6#eY@2XPM4y-Cb-8 z(o&jf$hy~Bwhjg~L&fmKGWmZgNZTtcEZF9?Q9q_urI(VFC#Gzp(==A4Hv%S?4&R@| zX0ma*hwGZ=6zCfvrreu z2ywL86&_;C#4L?lu;72t_TEuVrES|cb33D>A`T!R)e!`w-*iF*oRN-zlu!}~3IakX z5=wwj#zrqg@1S%DAqEINpmYoYA%xJ87JBd1cjMg8^Sz!Y{)d-XnWCDw&N#PZ@J)Gw+x%n4_9oex zX8sr6L{D%CxEf19WbhbYZD$=3z6PB$^@NB<{6G)q9x&TA`3$MFY%dkbv-HIe^g1Mv zn{a^*T;-isYCCP2wh*|RvVk? zzVn9+8fVx{ylLPqztn13x8D(=i~5@J3?m=JPPzLwr2FvLi-eLGe-YP&F>6xTQ^72H zKH2d>MC|SLo!dU^@Iy8w6nH8Z-Zu)mUnVgjkT7@zDFHS}v=+^F7p9P^C0GM`l|)IO zumVK^5jyv5(V~u2M`@uMIi}23$}ScZi?`_@`P5Cd?RqxtC=pUBG;R1qHPjKAM3v~( zlN&&v4?WY$Z;UMgFwB^@zRCQ;weJ8pvxuyB)af9%}c#qrc?LpY9K zsM;2}LWNtTl?YY*fO`;M)|6TC#nLc}Wbp^!Y!MX3*GCJ6Pi800{V=xpdu61I855?G zmEe`n754YU=V#_AmRH%H*=P{IP|3UZk_>xLeStaqp0vl!d(Li%D`^zJtJ2DEI6OnU zI-#Qz(iY|FN2$%%$CjK+`NHjYc*HA5hY$>4Y~GgS8nbAuPAZ;QT1+pMaHax;?a2@u z{T_NpzX;)_=@}|3&rbk2Ok3^vSjVXR*4N z%ZCmW36Bw|tHxb@~T1l2koTucU!i8pOu@q|D0?cr-!>rNK@ ziNf0ImBpa}XO(6`dVqIXpk<)^;8Ia|nStyWi0T!c3t2r($Z*bN$_kuHcXTvghmyib zbDMr*Jd-!?D#(h(#0h=u8fz#70PAOfc8CnWmdVDnezPcplg`Rk=d_UFgxz4@x3 zvr;K_PIkN!*=ewu1Cfh`kwqu12-(cGwluDlt2KvedqVFmEkh!7E@fHA!%B7q@P|^!61<<-qZ> zUI05j&X`+l_dF|Ee{lLMrbQ&{e9bJP`Cq5SL%v9S_1k~{xQD#!!ag)&DWiFDzASYG zAz-(O1H!Pah)YL|Y2fScaMe+=&ZIUV`ueIs! z3qG&!-|)5yC!2lIlDhMcWu@sqXaRzd_I!w?>q3McIucceV&5iM-g9?XAjYVhm7+uz z{U$Sgv;;!Cp!Rr7nF4Bk4JxnZax_4*d@VKK=qQL%t`+F zX7zPpaU)hBUwKJrro<#>C*b;#f&WDdvADCsOvYkzL?8|rEP&rhHU+9yFHKGFNgx1a6pi z<$jbd5zVqJc_T^X0Z&$h8CX)SaD_E^Or6j)u}o}gaN!EQLvaLClQ|pwyB$3Yv`0kN z>vIH(n<}Z%WWebind9<%Rm1P;Xjqu!nsD;KcK?z@!Q4$RWZUlC;UpF4BNA_Yu4^!% z(*z=pU4$0fh3xnuq9V=5q*cq=2g3KBNHYtnuc1}e_iKT8Vg<#8D_JeeR`%7709CK@ zHl||_W;3ciB7pLTG$w(Ke2biV3w(ZzFCh0}O1rBiESfrE*1g(K%>`QW1E0NPG;j@n zN?LnX3#L=dI7!@51~wc_HoQoxPMMp))@{O?Ivq#{%{|uHql5MJW~%bM9yD7%g?Xk7 zaIS#SW&-&sdh>3x5kA7o(4GVSt}Jr!ot_JKrn$uKc}JtugkG^+jDB69d~$8;bI#A( zElqP_Irs4OKdc>DWhrA()&6euQNJt-DCLjvaXpKwYNIbvu}>bx_{ca)xnO5jydfJH zmHQq;Jzg$h2#d+Pl%B+p*udf^ouRw(K})HjR` z5;L0loiq&o7U4tf$IV2j=gr#aL9S+!dc5htz6Di&T4^uNjyU_tca>NQ>7~%hHLdaB z_gODS0u7c>1qMeOz_Vd;eegE*gaqz!9Y4It{aZP)U#i2`MfdBr8}RM$gf&fS`T4!9 z48{G{+xS-Oe2wQj170cE3B20`7{e(tN-95YQ-)u_5C2(Kt|$p4&rh&_?DpC%#r$rU z4;5Br)VQ=dZJ7CEeE&OdQosGbi_A}5Oe(H>A)B)_xIW~{H6Wi9&CK9c=hwXY({zz@ z>G2>>X|!`d@$I=Q918D!>F;)c%GNf-}LHCM;(xj_OSh zZ_HpC&z*E8Uw0Trp6`xC%U=_)Yh3fH#(s-VAy{PIAuH{y(8fBWg)1>R(uK_39taPf zO+ERfy{N83$7t(Yn}#f#o>qyTe4WDBTf2?qeBxBm%ESk1y#P#mc+bj5niSfT>(w6b zUDZ#-#uX<%Ukqys-O-i0l+&J0_cxsl5w1Y*WQ<03*lrBC483cJuSpFmFLBA7KPajw z?N`ED-x2mP8sD&-XGb0<6%p83&7Q4#U(V`&l-xRJIRk}%A|QaMDE0^%|E5_fU^g>W z8foEpe=!(WuH;^BZ}L$9Fw1r|9`aqq(dJS}LGyJG&1FbUNcn6-O9LTbq?8}IP8qG@ zr_=lz`v!liYqIu8A6VHd)9>LjH!>6jiy()SVX$gk+tJ-)-|55xyor>bbwPK`ngxny^VYEC@9l}1RSS2Zpk8O3T}r5*&Bj8{X5Z%43_(jIvg_H# z#=nmuIXyOVd#+yut>ttMYl$U&B_IQQU;gm1h+Uw4LS=QAUHNqL$Hr*Es>T}h^9W6F z1Sl5BZ;L#~$~NAozI z&V6UNdLUhQswTkJdlFU$+$32Iey&MFtI03i-EuItw$*(qk(D;f0JxQu!`iBoF=7)A z=J?pu0KjqeCmourv-yXJi=~kUyHJr8zhC}G;P5a1QJa55TM<+4QEA)Gu3YVTyL)Xp z)M{reWXMFh^haWZv=D>5SVK{UwTlcg#`K9bJ~QYPq-jjiPiZ>#U3q`T;Nl%NPG8XkahQO`~XNEfVQw}41G0klxOY!ohmV}2G4d_cPg&2c&nO@7* z#UYAcV*g1*b*)RYX2K9le|SV~d^OFm2(0%`GcPIlQt^h3Y*OD%n+xsBVNA?Hj)6W!SBJ);pCQm-wavr*rmYo&HVY{IY&Jy)z`lg< zz+Jo=uhE}+RU3*gOFgE!$Mh=iix$`is)YQ=C04J)$#K8>d)ZBxJM@!gV|JYCx+&mz z#-5w-3O^3ZldnU+DOOGpE0aM2KFo+w&Y*OuZ?A5@3DrrvExvAkuZ9&w(H*KIiAUhP zjX-KdP(^M#FALxYoQb7i0hFH!TL@! z9|=7mzx*1+#p2>r`%yz<+StV_!@|wOV97k+Im*D@G%sjU-Ku^8e`Q@inL>AEC&8b; z+=#ztT2trR8q{?2$oLN$zkhPcBIj{m5v-#qIo5vnJfp<{xcPLKMF@OC+SI$*bm|aA zooI6@DR4w7fULg9TfSbD=!l~?z6AmhfSXayt55qIqA1Dto{>C!-sTZB;=RK#wuY9L zh$!d4>+^>Gyr(PW(q;Wvc=z$$TLMz+~%Z2rEH|aw*KVbh& zLFl-C-n?O5cs)}+1GvVQqRl|*-ZCMfxDy0`%UrPseAk}m!AKY#lc&i)|{C+(M|l`qHQOq2>Z5l_x0 z4a3_-A>_^aArafGu%=UEfyFtSI-^^TWBD^3MwKVcuO`Z_42=kQ9KYcks(iAvpj-j# zYGhuu$rc{KqVO+@T{HQ6S(c(M4gweuZu0aC#QEMXG2?FV+2ZeXS&D#nbWzQdls@zl zZ#NQ(P}RCLn8K{FlW#75h|#%zdE|bV%!|RfJp;z{aLwj~I&k9>b!=zm7=C9|Rg-f6j%kUSanFeMrLmW*v z{_SB-0RPb%8;QtvJ8Z-)}NCj$@X;F&SP{9TFf0{6R|5EpaNiqhxF&f}0bXLHb()Ut*Gsk(JhAueQR*}-iVg{?+j0RGX?D5 zVfxGAZCd2%+!IkCu|&BHfJg=_UN=(w&MKD2OeE95I@esZ^XYYzAfR*a= zHm%t)Dd{&x_b|O9q(?+Mh8$S{yL_wql9h+SM}0?L-x#=Ra(A7U3GP# zu0=ad%yePTA5QHh3|g-S)U728Pg?2sLfza`?jjfRQU<#Eqfc}i%Y9@p*1WGi=L+4q z6x)%f3J@mckU`tI4I7{lM7htKnn%wz>&b4ix23KaEZ0!Cb)%Omno!=YT-mdLe^NE)6#yPTxp%rX7q?#4UdU8uT~mP3WzmD7^#T9e+nW} z$D)->$Ez#bKMR;e{_L5*&3_Lj3$ee}c>S=X=TEY{=RyXp`J6T$?^ z$bVyK)t+h$pnkCyHglYj?zXQON#m8YlL$q5$%U4BJONk~3W^HSQ5`TMdsSV+75&Ok1ugx@t^H|xx# zj`y?>I87r>1UU#-zv6I3-*$`9CInGK^5aLnbbsAX%3sVOusPIJddrrUc$by0=9!vW zNMr3YUNjEi`9Xo@Jmuc>AOSEbqbw1ls=GcbD4SfKyl&n*4?pf&5Q)s@y&smz`ug%; z3_r~`p)`^x4Y{bPPva*BXJ)_p!yhu-@-*rSD*@;O{%lIQMacKuBGr73-W_lB0^or* z*s3<|A%)3h-RBZ{&PFWPQ_QiqzoJ7)4VUF=FmvVrjZ7FO ze%bSkL6@+rom7{~u1gO%7(R9_vlAO=bM-CF^|aAOq&UBNqEttAZ<}++zW9a0{jP@& zk7~1(Lb}1nUho0442!Vgq{KJvVPe9#c&uJg2W&bI<$Bi2wF|7~cVOWs(bEDmjkQJf ztCJ;Y8a*wSYO$$couwunc?$P6&L8My5(2F-Wb<$vz$E!rDc?CS?tV!-N7A(; zPh!+fOPAzG+KqVh7+V`XGn%iP2H=;*!Nx9GLwd&Y znb!A!#A2rtBh85Ape?TYnBmpl=IUqfzWRe%uvTWNov^Oa;8ZUWIgDYS6m)QbTwc@i z=nc;Sp0hi=JNz^2aOSl%Phw=E#oOsmB`M(HI*kbDfWlLtlD##Xp7`yZ2eZ#!1vz{> zqa`Ti(T`f<|7;fi|Ni&??nHjM#T0&rU%0+FyOoW<+h?VSKezW-%2q<{V+N_v_t^+f zfTFbFFN2H?)j-j~YOFU~0GKxcA(J;CQGHRQ3^Xin(&|}_SK&p3@xZ$J@n&l6xztag`Q~z&@)YDeVABfT6?Nm-&xqI5{uw0_SzYb z6s#)EBXrLtLU*!CMeAt}AAd|PeD06@AiqnU$>p*PvU%;tkkOeGu%A}imnu*GP3 zA{D7^ttnZeHLvZQ2uF8KBNbDlh>5l1g{p?v_B*_m0^All@kYRG_|kL^EeNQD^pv(NRbP+a z(66q4Eum4cKESy+ysflUx&m8d4z8=U6@@6BlpFd1C}&I3oj-+k?gH>`AM=-TgnSfd zw7g&fK{AFI{CKlnZY{!8t0u!L1`?sJYnG**`DA`);muo0&Dg5~l+;h`?YgZrf+mMsYI#WcdeQ1EauUJlsiP(7R@As>>Zl=wK}=Q|Nt1XF`Y7R{W@GE}{F2_9PHBv=3^043w;VfRdGsnxdYAEX?m- znjVKv#sG`jv8B4JLly4+2G?LN>R$Ld&h^%w_deP8%&&&(xv+J|>4trY96OR%t3bxB z2ISU~qon>(%hB8MHJf*xaHkvD8FwFS8L#kH=$^2p zVJO0H=Mby~yu%d`kVwlRrVs8*r;aV24lci4$`N?|HM!Cw--)}xSqh~KY&%Z0?SfAi zPK&dx(1!gZ{D0e-{TD7CK(LOu<=SV1yCpvKqvfO zG-Sg}YZ@O|tfaqA)w>Vi~(@& zP*DP!G7Z4L0Y$u5BTxtYsSfr>i2~hxQnd~%d0;&CKUMg z2b$O$KoeVi!Ca9;9;bnbChUm2SmB{x=$(QTJ9UF(iJmC0 zh@ov=+|NoIV>NJDNBP)!&ym%Yp~sUbffWCtW^-@xV!~-TvSuCBpd(z6b&(SUShC6L zhO0L&=*_>b$c5jM@Y=@R&(%OTzau=6<#CuqWVXl;aY4`e!AWiXXAhiKyh+g-{RptVR{wZ}jJ^Ev`Q~SDq=?M_J@vJrI2mkx6^2MFZ zz`#DfQtn1$G3eU?pG*VxH*}QyR%wTF_R>iT} z8BW)Vf~|U&i`IGSyt6p=Sm=#31eg$)DxnhD($YLZLM}-O8RBgn#{tD%PH}>4BkV(t zB@5uGv1w;)yo0dCR>ovaebsE(kRG_$diYHVj$>5jD&PjCrIq6<15KE|N&nJ!C8WQB z^Z4oawez>tv;$eoG3Qgb;$61`1*?1E0vnk_r(12sLqs)u(vqyz!d5)V*M&)p)RA0m z)*$wGx5GWd2suwzJ6x%pxzrZ(9%Nd0dcRY1ni|vTgt$HLs@9`_CsytiOZmc0d*ogczqTV>Ox#HqM>o*b?4+x5MDyo1Sye42 zjO#blr%R~u6c6bxlXio|5=y^pHLEmcGMB?u6OsJc*+jB$(>Pf9a7RTk&*>oaQvL9) z=FWjm@N=LW;k3jTDN$DbEyjH|d}UKL`&}-Tad5hGKHW*e`VH-Nk^S!3vDKJ{hkVu? zlR?^Ax$9(E^3~Z=3?J1%Z$!i3T8L$PW z3N)awh}KsMK#kmaz1z4n4DhTd|Cy0Txb51}nQMUUSO(vw)&@QtqCztvcWc#W4wKNJ znhbPw$GQ{{jhd0OeKb+LOGoH9NPbj)-95x9rZLk#%Ts0(Vqw$0in1*#@y+g8cJ}1c zcc5>X`RLq(OT81A-I}#<)C8H7D~gKZ2kBH(jokDO%MW`)g=1x>T(P=SXM(fL0>rBL z^6JLd7gPUHIx!-9$2`*1lB5&}8P%VqzzCtROhf{24&E-q z1UA)BP7<{U8J(EwBB2o=V&?8&=@6@qggSJ_&%_unZw(6}-2m-O$o*XtVxN>sZ1D-8 z9XIj%cXW?aMsEp!o=mFW;#h+SMD=Q(2Go2WNX0PFMOMBY{yXaFkDGis0C2SW!HTN2 z_%~(Wk;N6w?i0QNu~PuSQk-j%9%7Lu$0~1^&B+xTqX~XZSVIEpFl2&VlNTkcZ+kAH z1~gIoP9T_5au=Po-as&GUx#07ULUVI6&v>XCvK`QlW^^YLrpdUmioN9zS zh^CGd7!FkR>TZ?K&J;9^@Pd!$G>azfKThAZ^SJ|`@~YpGK727jb`!RIZaDs~{G6gX z>#ObCC#fJZu-Z{rUkB%XV)1DhN?fAx6Q?}Xynw15`tE!D8I!)saUymmeoiPkNMtk` z1H0JJ4~Db1>ci{=w6}aok3G3J3#u3+vWId-aujlw_&R5C<`KE|S<8h1lrw=3L+0WO zEGJjUF5|xIt^&0+*}dD;6or(>fI&^zR#oJ7BOvsNGkVf1ZZ1O*_GqjjbbF+Z1$&&@ zsK#ZTau9-I9C0_*-EB-7Zfb(RGXUuHq5}!-y6U=$y6i8kfiqQ+%F?R&- zNUF-D1jR-^*aDuT>u9h-EDC(u11kFD*WN>mgb2@xx^_u=l2d4 zL?VqdJH>97aFUA>OPf9R1!~Q136l9r&pD%CkL$dwwEBZx8QqmR!W|N`Q0fOwDwX~+ z7+a!tts%U2t*2zQy|UFx66>}qS@aQ5NVFVNCpgT^rRzoPkUpRobyL7}yY27A1swYl z#i6%>WELa>JCM+!71BNJ9>AUbCO=(#E(V6bp0eof)q4*b2FNNv;yGuL_*HLTF)ONu z#%^wQ+Jgr^J23egRY!tk1}wm>w#uiX1#c7{?_B*LpV6?l>iJ^$@G*FYXOAjXcxHCA z=!(d#xq0U}CXW0$!R19H%I<7pq8_U}tTN9&WP)$l zUGxb4o3ELY(Z4+YIlwpip!{_D52hh7?o`~r!~w-dp&_R$%GJ{zjbNKknsW}j?xWAp>xyU`tTwvL}BN9!K@-*2(IDFFzM(nrxLjV#Ry$S{WCz>vchxULSEnl$1 zuKdPeuCUF)qi?0E>78#8nvZ$_??ie6km$@$$8RdQzcaj>5HovLG0DVg4b^~U8rR3c z@g*CE4&{dlgr38UB?Dmz$F~;4@jt$Hw~%?za^PnWlZjDR-z&Z?ghK9b81R?7Th55{ zB$bJIbI+Cf_<8`pUX{M6u8qzH?YizvT~7Y&Y>n_Z=UB4nZshO@4iuICFyOt6-mEq( zMZJ-WNYyW_rffD$HxBx-6Be`18AWWKv1{qHodGE6lja17RqwQg(_u=)=r?iZ=Z1gk z%d-VOpHvHVg3dRxOcBYP1K@NS!PA>VWWrTE~S3{SSh|7^P(QI0cLLsaVL>4Pku25W4c9@F} z6qG)uCB890ga~r5065`4_n4KspC3>#L^~TlApI#55H{J_g+KjqUtgdE8j+u33^YX{ z$#gP%*$(MFi$gTsidcp? zORo&m2pn|~gNEww40{6EN`2oMPQf7P*W2}K3DcSn;H2z zJZj`dOV@5a`nt;lJ@NtVhE~y;QvG=T8PM~>2U)>1)f7wbp;KmRI>+)%s56gCnQWGX;i3uPS^8orJpmKc61e5-r;U~{FShL9W z{D%r?2;mAa!?buGf{tWS64SfGVRt+R*W0xE@mp}VWoeoUwB$AE_Y{SFN}1a$H~tvN ztKDVCutAhwNlOV-;>!IxIQij^WBm8tUYh>vuOEM%hi5dTk@e4r>^E$pt=^Y>hu&JO zq_-iH+0CnIJ{&{%DT~RDMR)N9XJwFG@D+J7{6)SB=k^h$k^2wtnv}?-HU-!ON1&*} z&^(DI7*#&+{*qX7cxS9Ta6PEJsSn37);B`iS=fqp4Ow(nDII)Fp607D;}Gp|+&zso z`;5MBzWN-iyQ`WBl7N=J8zCiSHdVaLBK z)ipW*bOu?raEAZIa18?fRAhX4v&a~C?@|PTG#et9A^sz+n?? zJlM-$xJ>o1<2EviBZMCr0mMa}YB1_W34CLfzcXN|Jfpdy8oCYg^i>b#ESq*bSkL>t zOTIC;7T&q9V9;w&ifn2k#d7omHA303KajUCY7vuSVvdqv!DsyKXgjd~b07u1WE4ph2jHKLo~zm_&Kvy@^!GyiILt=CQU z6~)!uQ9eYN2aC0hUzSe@JypPD9sKebwk*)y*t(bz&g)))Pk#fm8j4fA8I`pK3Z{1r z$@Q9_D;~6#$gl4?0^u(c$q)?%{}Fm=?`*>#qt^i>+r2Y_HIHl7-drV`OOEBHJ&>w z!S|wOuU4Hn6|wP#_TP@QG>IKlov73U@()EOCwzcK)M>Av9 z*VT1@*K3up0CBt$OSdR5i$i<@z?e%hm2xuP#CX%W0!jl(= z-&&XLwRBLC>e_2Ek_+%#+V(c>n+^00W$*p*!={9$5}fRqR{83-QqmFNeU)r#6`%1_Pkbn zV}33wsK%?x5BOvi6k9+7$qIU`W8%hyJGaV!#9o@9k&y{dQ6OKi>MoJ|0_|cVJGOEjehF9->TRIgS@g7s2^fa@$CH05Ym~q!G{^oz62jVd6d6QJ=Fl=6qL;- zta_MIzc_%o|;sr$x8v z8zu$ru0rM<>gRW35R2tG-QT=bMJb>nq|Z^5{*FJ^eJwNAE`h*7C^r}?y_hy@rxo>1 zT!*v5lnf=?qDzLINJ*@<7fhF*1`hj;9=l+?_QU3&catTZp4ETUxQJ=4_UXXk@uXY( z2ft}~B3`y%|?*3)G{kkE824W$tS{_z8<~X}e@aVY}32QNC~>r);`1 zBM<;+e%!QQ^-cya4i8nV4-F}jQEt2H8qfQi^IB23*ZUBWm3S^Mxxw)qXMF|P&z zk9e|nX8(3UBjN-v2vPHmEuFdwzF9r0cXMFXEx8k>J(z2-$St1JDFscVSFCG#u!}4X z+M>%0j0pFq@JcrmC#fys$}gvl3ysj`xA79X=mG$x*;)U!Z23S2w6i{2+?kZg zOn%3>T6ER;9ru@0?Ti2%Fgt?wk9~wbxe&iT5i@P^cPhOUK?C0e1M zy)YnZ{KZzwU^iwWwl>c9-V?%eIs5Lk-0j%aZf^+UOc}Nx z483}XV}8YG+^a!46W?CB5Hf)*aFiVRtan)txa1+Z8s5%!9RK4Svne zf5a8--Ah>{2X&H@KAx$`Q?$L=UMqkTftH{MMaG{mX*WxH#B-@H&{JQMmI3g;`1Soy zg7+?GM+cvu#M;&gxS!iHNktAc!j@Dl)_R+3G6K!-N3-#S(Mv&?Zj%TRD*1_wgcydP z8U}#s^D9wG;N#q$MP7>{^&`i3)aTe;5MyPsBF;5n>KQWFFk+k}N~f%yo7( zV#I@XzCqS5*qEU4U`BkM8LHZk+d>L|@N#OzTKbNwpSys4geFc{dKIE!X#97|MY^F~ z8WsTV&RVVR=XK2ZgE~Dux$mq3?D&)46db0sJr(JmE*?Pw(lo`p3-R2#~ zP0H# ful9mkwntxEkRu?Gmq{jsR1jk-7$RURE~lfy(nXD7V&sE)Wg@%R{2m-yjT9oR;yK=;q=EiR$|X-*e&ks?f-h zuAs?}d$iOVPc1FB&aAUICKMciHJ2wu9Lw-^zRz05No<6+6a(!n1WIg#3ueW?Y1hAj z@ZFq=h`iVm+4?#T1{Z%?+JIaU)WVg!jo4zGWI;Pc)DUM}uKxFi=2ND{yD^Jhyq^eL1^l z$%;61{fR}xoy01ezsofI7Y#cfKqdE(8O+}HW z#;KF~32*+~U@NnTMwAiYhL(2E+y|X{LZF(^@khKS?F8-P0L?rj5zV4ohDlGx-KK%yvxN?PzyF&*=cnEc`ZzK6YItYOc?S~4 zZ8q-4XK$l&w=S>)XZK$5H0G_?llNM=A zut;(`gkZ>J+mUx3W;KBgdhC;}y_-~A-KTZ1xprCic5RZrN|(n0b!8gAC=c#6z|7II z%#nv)?&cX+kdn$t0)g(jmg${P{v(wMHqvw?hhXaft<2+DY3YV<>FYXfbMA%Fn^3^K z&AOjk*1Nx6?hTP7L{k$DO2uyvRgkOTUplga5usvPfRVR%e|bY#l$=1U>+WeZgLUU; zk=EjRr9E4F!@?5Pb5XxLzc+$#B_VTxocZO-3Sw7RoLyPD42#sy_Em;S!Ev`3PdKa4 zp^1y0aw}V#%@KxwCxg9;f^|z9)`iv;LwM`JkTN;*(A4hHc63Nul*Uk%nC+~3-p^CD6bI-G?;zoULmSL>M+*%2@>e<0M$ z3KIV@iSSqr0uVGEiT+b&Q9FCP5y;2Rwxw;w>fu9XHZxd><@Fbthr}lro6hTwH3-C( z=spiT z+G;OUhJHHd9Ta1sAG*yAZVy?j6?@jhgxxbJbvj#|79tdHw`GB`(eB$#E5k%AQj`xP zxCPhob?>DdB~p~j^{m+IW2SVLLCSVDU-)-tfIXtRx@S^Q*2*EAC^o#_8ofL_(6r)~ zi;sy0+8`G_i2KFF;{2C6MJ3f`hKYk`-~slcr$GBI51JKHnIbCu@(0Y9Dg3UM=OZ9P zLM2_o*ObH|_i@6m-??f=BW47clAIbHP?K~Xg%JIUatih5g>2x5#o!YV7qIX8js z7gK56EB5%{CJFwCcXnRk*ivT5RU@F@d46fnqX41jWEL*Uk3k#k}E8!7{0o0w)_k zXhis$Ns23KDVw4oW{!bG2jvC{`{6nlqEiqTwe@jK$tF3;?xpr>OFS682Cq6iC@2h5qK9oKCrCxc~RWd$MFg=i%kwf!- zRa-WEbaMP2qV9~Fu_a6+P{_GuPpJ$NuA*N7)Q-zV1rtFdw+|jQWNtAi~U?;ov z7Y2&+DmSRJ-qM|4_CFpcK&~T!Zzd0fc@O~PEod+zZv^Iu?ELlP+xlO8W4f03pZW){ zl&wf~5~8*S_bgdix6^Hn8Sx3Qs22(*wOh`)Y)IFMDdDzgTgum0I5Vg`_=XItoMB?- z*I0N~!Te4oN+JHh&HcQowXLatgfppjWdS_^RT(!Pop$rsLoop^AZR4R~N&SK~Q{M{XHH4X>a$NWYL2{AdfzCExSD5QC#LOre`XomNZH z6P5%2bcr=!?`o8IKetKB%Cda+c8l>5P-Hb(7N3I;(PnH;R4FFjh*@qZXPzu z@`Vw7i{g~c^w)rKjvAzPm(6T)`_^{`b`G3c4|Rt6t*DYaJ+m{xvaZog-U)?zhC=+^ zIYEB*_s68l;i)mAT{S(V7O)GJHD37s zLav9Su&3j+fq&nx`0BQQ{}}8G_njPGAj%Y@-;PCmBJs)=f>HKlBc;q$pWakH%z%Qbj#_A=}^y-bgJcEs5kW zRrV584k1&F=23>PCc@?ptQX-|Fu4Eaygydvx0^Oq*MNANj~blS?|o;Wdfol{6R$%Y z|GV;R$owsR^M=CDp62%!Q6@*&ZreE3Xl0pHRasAhorPFGdK(_KeS}#*wod4t z^@kiENDWR-VMjtdY95&oTFImgoB>xd45OT*P=%p&f7+^3F?QIt_}m?2xUQG35` z4lD1<`3Rk($WT|(yz}LJrf(fW@=XI&oFtGweyUpS*P#-t_dS+w%cR# z93RU_-P5BhzD118$SVi4D5h~;_-@IJU&kM@wKta4*8G#x1|;15-<&p{fmMc|UJROp z{Go%Tb-w)kKfPH{lycvlFp)2lHZ$h$e|j9EBPx2)^|`2aIUk2b%F{F4w$25l71FF9 z$(oN_xDHGT2M^YIavWWx=Q;sZli}sa6qWQ~Jv+P+=zce@AbwpPex7>DeqlKRG}ZUW z?heb2^%{Iy9F9-mXK-XvR&B=1mo1 ziS6}9%u4)5;5XKadK6dW`r-ws-30)(v&QqKM0rBz%<7l{i1mfB*#F7Z?+i|-Z3u~q z;{g4E2GhkuD)+HqPvq=qMPpD5N~+=HCI(%vQ#YTiny@JGrGG3b^2|hMKFx1BH_%5x zSIf_N{>br_c?o8`5ehUU#FVrcS3mvu*1YsIdgSLPSfgbQ>~(?kcZ~~9fBqO>W2diC zy^{!|#DZKzlx@(?5A_njv4xIkoz?nPIHmD1dHe z?ujdnpaDID3sesJYi#0Vd&>jFg*ZtOkR+vNg>2>&6;zYe=bZge_w@g01$izR%vzF? ze!C`Sgl1R@&@Sof*skt#h{65_Y-sQkc5#UHIOIweJ~M=$8-tDnlV0G&%hSv1Dzn1x z8Ox*jI{9-GS{tV%3~7^=TQwL3t%u_^SA7Y{rIQ-5vV6E#2m~_?S=E9x<&}fWwygFj zQfJV2*_08oM4XSX(Mhzdnwz}sD1IrDBXf+7FZRBPrmm+jLv@}ltP*kHw-pGul57}i$upCM+V-m zw=ofP|MQPa7*8sV>JOO1KE2Ue)|JbcM9s@ox)ukSt`Of zT;G&tfnD64#QD6rMHYpIbV^G;+tO>;fd^< zMsbPsS)PUCn-=8$y7;&kJ}0?2^N&DQqZM?hN;l1}(5nOKvt`+K5?NB+_elV>42N<=fLn3vS@g4oj*gbtON2cubW{lEug{>FZ;S%qT~ z?%xN@dUFvGVL-&xOhoAao*Gk8`(S3Nou8d$yD7N`Yw0kPJE zYYR0+&RbcoZUv7Uqc7YZj42P$^@~G+a{&zti7Ht;*WYDxXFP_-WC*%@a_6Q$D8pBC zTC88AwYB+U%{H1Q3cD;1IV7*EN6v?-s{|Zg}Y6mP~Sb1UtmWFa%sE_`u9R=-w*41>X?6 zI4SgpzW{R%sg33Wbl){1rw9h3u0hIhYIiM z7hU&Jl|yQSiJTduXXPPMs!|EuK3Ik&hB49@N0ZH&(rNWgyDp63~TQDX*04qEv7{ zz<({0W_9p(!wedjFA!8sBy8emmNjCj(*$Unp$4N>Pj()Ui$~=*JIiJDhd^Ex&{^n= zL+MA4erISkJ@IABc`T-_Grf&M4vlB3(wR^Z}#<1ZR{g zO-krR2^~TUJs@Kj5D<{wMp_`05PGO1y(1-bf&>VJ5?TmV=D)+t^FHqvxSy;=mdoWb z)d##^V-qf)QeO*~^8!_F*hsW6On&Md5>OQy3=#aXY z(vLkDNqL+|nPm^thdG%|IJw=bZu{kZf z4cmA8c9Ol43p;z-mq*5{aSX{14-bhv(F4V!V`&E0 zille#{cnmgG%JCVm-jSPib%Ix5R%X=kmQv0{xM?JqHVBq@8Y;e%=~PNtV<%IYI!D3 ziaqm--sehVERSZ$;NidEh*vD{%Nx2R_G=!DxL;j$-Y)Z?!2FClNy0aqVnMVJ#*K9< z*vo_n{X$y1a4{-lJl}fBEfD?X>Y$Xt%3h4dLV4hky6-TL*TvcS#eeL$$&r(#$PZ-y zB~x=nv-C33j)1}OA55Y?mP`urF4l^jbA%L5y?>fnj$9QcRKr@@S}m%kaZYXuP$RIPMyMT%1)zFHUsTw%RTqXR<^!cs-ky zmG)_Ued9QL7l80j|GuCVG2lL3>dT+Dl$+L=$XEtn-CZY1e^F}l3S_x$o;m83zYpy@ z%sCaWY6$rj*WFS<>42=$&wxwxGoWG*KOZbVaWhh0(2gI^Ii|l4{d$QltnT<`tJ)hI z14o2+W2v}x?I;-dTIOLu+L6@uPCvBi4?d7V{LW1Prrv=l)R)%B6pEofWs)IxvU2VJ;1??NBQ$ zp1;TgCPI%pzZrDz)WZE7tFj+&d=KF&ySg8&(Dxy!XwTn9RZV@L4>)wzCj?&wlx%O_ zju{tNW?=BprOCZ}_g0ywGB3E)PvfffQ`G0Rt9G1oy_m{|me`44LJ z@RGtJI@8pW%N2Xe0drTUgc{R`OTL{Oq#iS%T48NJ`a-S(;g>|-M6e`UedebpEW}US zOgl)xw@N(i8!H;4D=p{#qQ(OOITQn%MgvV-BBOT5h3|$D{_c)f%cLajtDa|b@2Oz1 zDxSVM-*Gt|pxn!^3It9MwpuK%z#Wzw!jMJ(xgT5lV8s?g6zV@JA097U`s}(<<4WFc zc8KYfqcwpE`I0O+l$^J9O&gmvE3dt2|7zayJw{tf&_K@`TY01@1{y6aq*^b8>>0nW z(u6?VqmS{^1Dll*hDas&^x&;(#srM)&aM8H+3t!ttrJ{wx+uyUk=9u zMu{>Xk;>qtjbxjCYwc6Ay+_-V>kFx|3#C#PzsYA0%J8U^8NQ2fK}T127aK=ya#IX8 z&66WTtMv`b%9zd)D?PfTAt=5e$C>dNx{&Lqj+|Z!;{w6 z`yIy=LYfJLGoW7Uleucvd?QXV=g|R#XQX(*aynHxs5!L+q3AYPGJG7X=E%lWPd&lLn7K*t zO$bL9crKlhn~I%fa!PcLg0RR0I=p1i?t$M{%C*8V#T!Ek&>4Hqj_ob!VAgG~C-I4^ ze)p`m9#j^wVS(wsCn`+ZV?Ir#t}6&jg!Q;Vraptg>emNb22tK63u|r(z={iMI!4|y zXT9C&;-keKriNDtLjMWQcyy#aB0D6;Mp*4z;ai0!uKYr!bYzK_#O?4OYC3bpb8~3n z+Dz-4-pl8P8RZDU#yF>@G^;6aqayeVLe8j>%hH~|fYmtj+h3X$E$vAbY%9p*P2sX{^0pwpit~w6E zxG0+FQuAyZW}}GxpQ|~i;*_m>m7BQL>Ai>@RJG(qQ{vYF*OI0(FIJy#_|1}cG(4ob zJHv7bL}W1;S2G59CvKlthWy_;_tG$r$eoa*Z|X5^)O;v_@B-}xjCD?D;~}eH^M|bP z{+J1vsTOu`-pyh`fc{RP*sUZ(ox$WY|DSFx%rKN z$H`baPl2KuBzk=I-ino%oJvQdR4KfKvrlWa>0<=bd=OEI|ENqLO;gX``)DOGj9h@s zi(4ln5}|r*r}_za2wts?Jp1~@?9}NuQrG$p@5p>(pM#<{2;v++n3L@8d-@_`F5yuv zGpbC{En?G00g#tZHIu`XJxc?erNdJK2X5S%(Q48vT@O z%m(!JZ)%BKYpK@GX+uRERK zs8>Nt1|R1?+BChdun*vBeU?=)Bd2`LKq|QCpF;azeg5D0ZIi-V!5m-!Dq(hW6|5&w z1F+hFM9js^n5oh00}Ikq8U8eWX;9DEK1AC$RiuheR6nDFKq+7*j$~N}AX1CA75R0z zsSdmXo+PaOVI)-qTIW$2Uk1Z{lk0$JjV(21Wf(_4-ruK%{e8hp!P#zz8j&%MLr?HQ z${qoEfPNXAxVukM@!+ref{a26jAJWXN0l;HkMi}i7%FiZxmo+D9|`Y@cN?&v8@etT zOr7bZut?RpZVDDwc2j3;RL^EQ_0Kk(&E zhVv|PZDy&v(nh5UH@oTUb1DdKt0WcDi+2G_A(g;yNW}aayb&5KZnI{Dv{2^GzB;)? z?5YmRO^A@qAiyxu`eG~3$Z$y*9P{i`S%O%;l)!4|ic;9>Y;_)+RtAT#@2TX*;$Pr` z>YZOuz_yKuDFbdnhl9n(aL3VKC!~9_hm*Z*OZf9NdR)cUnk91QKnh8-kW_u+NYtR* z^(?pG{-dffS$bTfMi)2!YtJs*bs%q0VG@92wnVy;EkM`rPQO<(ounXHlEA^a8^y*D zQ1y+fseRf8Fhr?`QM(-CS+<&b$-TCY`62ib+gWWTH0HERlpUuSWXRc`YY41!`aeD| z>*h})lX*&HY`Xu+rIEtELtpZVn&Amg)~FxVvFYF{(xx24Q@d&^&=M;2R`J{SyZc3D zcQ$Igc%!@qxFy2Ivhqw;y$A*~L0aZRQqvj}`BOTlS&rm^CcWzDu(+Itqlku5qJX&V zyvutjoszqyF9n_3eD2yA3h(HR>*2kak}Kk5+aj3Rj|6;jq+4Jvuc{r!LcA^)`>?S~ zs6XkCky#;_&rzBcP$B@e+)3T=MFz2ES`+O3L5$6x$WN6=bGW*18b1m2k}ZVP%ZJn= zr%LTCvB`G^rJGbOSmtay)W0H?P5@`9HlY%DRXy~3f>EJj@ccl_eLGI-!^rW$N2Nh> z*d>v_FRTl1o$>p}E_8ODXbSjt_ShpGBTaLOiIFkxX-oeA79sil=U;u&W#dJ4b?J)I z${GIRzXn17&c=do;yHlgj`B8C`d#y@;8SO1Lu=m|_rv_KX6B6w170s>7uwDyVOGZd zJt1N2Fhd^BOSE$h%HNSFv$4cI(J~}ooQNF#YS$aMzERnsah$*Rb5G14H#GS(-n;E< zH8RWZ_#Ve8K2Ie2$yW~gl}YJ32*Ysthe_<;Fv*`7>OU+9*wZdr5d0d1kuj~<;A-3T zB9;StHLpFE1FlxBj^KdNa%zKAYWK3up86G;5joqn+EM_F$u`+ekXDA~l&^J7lC6Yw zhu#p$Q3yfgx(rTr@!oithR-c|;>{p$wMjm;9Ca4MXjBnsn_tmmhn{6apFtY_S(bT>w6boj^>(i=A~VMMaE45*P?y9d z565Pvbtv~Z_#j20tPl}$(Ci-6xUUPi_X z=NlDG7J|HtKWEHH#gEojEElRP`G)IbpdLOpDr+DGt`|`U0yCP* z+|wqiyGb}E%O%U4oLv(m_GR^pj63+_%6tZ;cVeD+CulR^)pKP;8 z7J8*L7(a-9jRt$L96t1}8r1Fyvj%>P@#ARhTi#-7*b7bk=q(Jk#v@tx(Y95J-55sA zAWcs58B{9l-f`}+d7 zB(3w|O%Y|Ig3|(;q~RiGwuqf%AaL&9ikS53^(1s!$SGd|8QaG2w9M!C8jOVgr2BS3 zxT)`j%TNCKDF3_9hL8Wv!oFcr$iu7&Km?-*FUxJ24ia{z;St`DF+h1mR~hoMleAMi z8QSqNn88*F!q}Uo{CdI+jQ)c-65ee8*^iJQ6*f%a2;Agf3SdNOVC*&jX z>W^|z{JH6?^U1N&*YKs4U(zU>*tPEIxTmtdqH?LG)%P1hc6Hw5_<*nPfXdpZJ`2$K zVtDlj{c6$s&iCSSP%J<#;o}hn=tgktL~-tN)o&Lo7? zpFC@{^SbYB2F@UttV$&%@QRqoUgMFaCI9A(m8zcT;p57?Ti=BB9K0-x)#Az_@6RAg zRtH(O4oF3;l*3jTn=Nu{IZA~9q0$8ckI*xq16!NDsbpiug?wUTX zxP;l#9^a}114pnYO#GsVhoz#pKE!>@!~MkTTfLQ=curjzi;(3-m0~wM%ul#NLtT54 zhGhf{zS48(quPUBLyO~}dPg9cm%m-%Z9Nc4z{Y1E-v1BRZZ;J<88or<`>uZPPT%XO zZ_^yxMKh*F+naD`(F0E#VYfd2825#&X^;~&V~qu<5#6y+U+Gz3wd*civRxK_tKDp= z-k@sd+$O(exXR@!_3MUPPyFbQ#R9ZaA||Xl2m}?$hw5#h!N8Id>e>}%hqDMU?w1er zaHwr{JPmvJ>DIB*XKPG-R}Q9eUCwvMO^P)l=ozcq-g?RI-c%oXJaz2w8tirDn3A(F zqa9OdWVuai@uO-Nl1i~A@HAYZORY*4uF|*p-?{XzF)&_H&`BFGC&JwP#mXrBZ{L2p zwFJEu4`^l}q}5IO3Q0X99U|s#z7sH_o2Wm;)ZP8}g%lu~^fzSm8o(H-q#@KLjEZ;$ zjg~p1W}9#PxO|2H@(A7mH4DtIGpLjuuABBV7q1>^zOV7{bPFGda|kEAQPMAIH~cub zf{0hL9!K0xid#2RqL8$i!u@SVvf8gMzD^BQOhE%re|s^WCBZmtSaF;BpF4}hL zn!g5Mef37LkE#~+M`*I-dZ+jS!;(CEyZ(>mR@kyLB{4v3UrzSta(O^qh+aOZo-RCY?4zmHVU#&f934z>irteBa7yaTruEM z^1$%S`LM9e`Tl*O(fJnDXlDjNJbFKG4QO?_oUytq)EFaO`Mge@s1`?PbT~W78Mct9 zGR4`n+FXCDgzjaB)4l96Dc>bO<^!*^;rxynj0(2S5{*>F|BwutbuRRH5X*>7@c&j_WkB#f9W{`-PN<~14%XqRes z5vAEvPPuJ``gmBCLL@d99gT5NE+{Rb@398)DD*Eke_S6~SiL~*`^3;BmuXm8=0HfU zn<<;}j_g~c{v@TcV~@LbR4Qd;Q?meZtSNA+k=HR0+3a;wMyrQ<-rxEh#B^IDdWw+4uK_8F6&e zkJWbmZiJ}*4-#{cpthdEW**3k!mN*8h}8;r_-hubV!0iU&IG6%Fu2cWbf?r!zla!FBnf zf#83OBethQIo8?EVHUWCz&@Sy_k~s|FsSds4#sHBPIU0I0-AlXDUL1|EHW`!vgFk` zZ8&=8Spv^`IS~ktHPvX3x||VbSkfyU(F%bE3HI`ZG{y@K2bPw|A zd2F{OMPeNkM)KWq8%w^4w|sO{^)f!!ddfatzVAkfAL0QmH-!edL&6n<=+m!-dBD1J zH!w*4=HjK~kje*BeLgSXPJOP2!$V1}88#A4iuE^0rKG{3z~o#^LpEzyWpS+Z$Blxs z4(}5lp1PwO_6<1eEe&O$(Pubk~vG%YYi@KB&_AWAe?1k$5R+60M_eVcNko z!z__6HJq(=E4`6CK?iC&9g`Y|;8tJKUzY{A8(a58@08?6I>Z{eicyij;K&Qwup`@u zZ7st6D#B${MB(n#Y4e}(m~GcxFCWiGm?EnoQtwi?>N>A84ez#{; zi%Wa$@J+|k!ARtpvXw%9hFzQId%J2~Ke}L;qGpkAfkKoC2X@>Ww7AvMxDUNb@012( ztO0TkY8kFQKj|5UvPGwd*B$4=E8IVfPDq56wxZTj#L)GFn?;9{QKl`p&D?~M494UB ziP|J971fWMrt2;P_)3%Z-nyoT9)l%WNezf+1p<#uwGtKeSc4&r%?|2{w#{4tsZ;i2 z8?qp1MX%b8-c`!%VR=06yD~!fI%xd|$cr6&e6Qj`4C#$1w17xAMbkgb15@r*I=iXd z#yIcS5Dc3no8cmV&*Hq9bnJqFl*!pH2MZy(hcFM<{Z~R}$&XXMURY%}=2&hkSunD* zud1CgO_;*oKYf>$bz;1ORdIQX;u*D-irm{muk=%&4|gvCFIhL3-3;nZaE#tmngSCy z2znW6iGbcaq3wf|bmpL+-Ix_*sny}}=Ic_uDY0|r zCoWw5v7cs6cwfY=t*7@vqpr~)S@|wG0AVz1jTyM4db7QQ>fblERhM1w!yLftRK+Ov zX_!3jAml9e{^h*y+5xrx{h2YOI-@(mqa16|{$a|p!|{qBvslm!i|d>QA4i*%{mL!= zV&a2lL!@oN0(({QwL^nrbloM9j2M@ z! z#^a(0YkyN2(mX5g(cc%QeKvp~So915!U`^CHX6!N|NfVE{sb|_!zlMdGaoYV-mNbAjSu?NOf3S>_mr$NQpI1Mmwe{P+n0@_{lRTm8 z7Qw{icc#AS6?rzFpZ!wEK=bl5|5ZO;g)^qu8=%+$@IS~S zL6;(|>E}Y>8{ifz^n18EksK~9f{yR|eSN005{hlUc~wO;*XpCY@hckpLqbR>wyjzNm%ifs#bMP)3m;@>xK;UEQW^X+&1gB|6DfLa zz5e+nbsOL7FC_(ZA8}?yIGbT=-h_5pWHB{$A}!a*^@6>m>hDLOTnv(FYEWOJcio0u zU1N%IT9z($Hxg#7)mHQ0Xtp7|_@QNBG8qG#ZlovAiL3>sJC>ipD1NXK>YHX<{E6mC zIdKnDl0Zy&As3HnKk=jCvXZv7#vzWec}bPi1gp=%&i4WXk_~ID+zYK^W3&i~?vo^R z4qfuZ=o0eJ{h|n|zP3yRKoyb5L?>KzX%Gu6Z}e7uWxh*R8`#W@aLmr3{_>Pd^fIPy zK6K@*WG&2r+YXM!1fUMEX4oK9FThQ(ow1e-RLP3u$}zqj+kINi6F*}eBoijLWTRix z@Y;2&O_1ppeiJaINpEv4(}tw`IB*lm2=mTR2KO-ShY1bz%?J?#gECpaD?2o5G#mTF zA*hrey_b1E&$T~#kLOJG7bHw=Ydu7+ik9l}_9rg3@?+vj{?z5gZ6B$Q#s11i+0+H~ zzc09?PjT%T$;Xy;{k>v3x*q#Niz^?FvAXNd zJz`t06Tv+p$f}e}TQuEzq8cEPHbVGQ zXrHb2ZH48-T2P6;mxqdIE=8y>NmWB;mVO;Q&g3C7WCmWLnIqJ*5%^?eJ5wl z-^CYNr9k4_+;B`VE+?>1_vNRGCcS=Io{f`JehKki_459@{P{~Y^1HqciDJ{n{}d#- zr{AzV$pbWfj}T%wpK`x$7wpkTYz$3$k);c8qes88 zNvgF(Kt|ZMJytW{RRxw%VJ+F5-t&5=?gGPlUiZdpf9-+$doDY6l=Ra9T%-wXcVyK1 z!-kjn1McyFe5I~#@Bk%f@Q731*rRc9z3C_FVgKHIX;r_CIJ|WBV@s{Q_u1=FG)8U1 zqnZl&5to>x`U*~4cL^J)IL?$vahULt<3YZv%TpMi-+KZry)WwqQW7(hgxcTJrCR?- zrSF2b$)7j=SuMdJa!;Gb{jU!793tVLc^MEC{W~vXEv%w|EFrIQi#{Pc;x5A~t~UIx zU6O`!x@`w2eS-9JpB-n0*&xrr%)RCrC+2DYu(SUh_14|n(&G{{j%Gng$E_j4PWMl`k%sA3)-Q2V?B<4?tj~rHOasImov%4 zT?Vdy?G5y6gm*;Wx0U;m)ypLXoy$Kb|Ku3?%yGuq43gWouV+CpZyE1*YT%nsj+hPoWtC+l3Ws*aS+IG#facHvUS|Ig&rZyE#oZVDAXhW9DT+>d-A6Hz4 z=d!ZBW=h(0Ph=ZG^9b8I6Nh8JgzTB92-l24LUTa6GEYEPj#QadqQRzcVu;q^kmNCC zD}PEX!}F#bX+mo~mFd2d0IITZC^zMU55c-TsdvIjHkcvjbl3`;ggs%K4_1ISbI@en z{cdttuEWLPcT0%LY)yeiW=*D0laqJ#BPa&KkHl(wO?QTXIMki5Fnh1bb~QmQg+O`R zF5522!0$gS`se8`@|}Eeup}4`>0gV_;1b5pLITz{k9NWoY5rlsS<@_GFtFq|bS`Zy zcP)81_$egG(&NqCh7G%0d{IA;-d5P!>L?mC+-{kQF2TM1DP?C*=?c+c9X8#BSWN6Q z({r_jqw&MzQNWsjDB10UgsHVUOLHc$!ZQ9^deTdjG0Yn`qfypkG%z$^xwXC1$QIFa z_1|bH_5N}zwIhmC%ryH5Ce4hWGXiJ_m@e8&4N)i)Urn`km4xxPpk4j>HOM+9K`9=yJ5aQg`3^hTy7)v~{jqGL>4fK{r=06HvIsa!Gsjk9O$jP|pOuXw zw8ky)-YhwEze}gm^2HGMd>WV5JVF>dxav$xr4g7-#rn>os>uE)6&yI0>{x}DoX1nw z6p^~eD6oQlv2Qq<_!&fM3E>)GUWTV_9u!dYf0gsch)W zY|(&b+x@BW4S}MbKHBw{-?GezWgLAG*`k@)B`f4R>lm_Waj+=MF0ROO5kQ@y@ligR zBf2ktK=YW*PKgEum{B&@)D{?u4~Orx$OL58pOl5#>Dy$U2huNNIqnHPSihd$rT4za zQc4~Fx=+bAajD9d(Tyewy|LdXm9l5y965O{ZI7d{W_Y|#eAl4JPf0mn96x84Lc=In zHmz@AA&2^w&sg=<*6$T`jSL7EQweo#R?gHKONM5d<@-$$VTbcG+}Khcu9@ixK9Rw} zpL=w{!t|Xcq{KbzfS-M=IBPkFF9iBq>|R4@EvHuzF3j=$8`FH#X^wcJm)YCvR?S~= zAot@9BFp_QGzU`0ebZQl&s$r-UHp@sN94-r0R#P;eQhQ5i~DRmB*nu?Ouw^*;a!)l zF1Qb<6)knJ5^~&iXN8N_YwCgPmX*Rt&=$<=W3W5$rYcYv6J&m+B;_W40|*71>EPB^ay%Q<(DywBpBri~L@&ql=7uhtYxmXxu_tMi*-`vZUA zf9qOi8C;iTnbDChR?C9cusqZ~k+g_xYVw zRnLY2xi{KL1-wwRQyi5UT6?G{T!SDUMsB=c28p97}cO`)!uyKgk4gr#@9eM8*57mxfK zqGp4tp~VT=F8>JaQ42+MInMi_F@uj7AjcV=1Tvfj1utU>PS6)i|F3?Ra=YZNRCE}FPEpmyvt5!nEHL6~_@4aPUaJ0tpcVPy zXv`Gm5Tklr7EZcdWdg*ng(QrizNVQ1x|epqfrQ6*+73ncSm1bFKUBwk8DL3>Hm8Y- zvMY#rgc2NmvJKwNo@hFGSZT;Y&9Oy+oP35iNppqKiORFR%DY8uU|;N^@6}J3fC1`Y z0l{|7!n!@wHMRx;v)oa$5Z+G94jw?DpjVxNJItyoUP3N^qkJRql8s&OI#95EX^)QB zgvy=^MQ#pJNXu&`NSUt@GmAu)&Z2RQvz>^Vg!^ z?wr2}y%W2fbk_%XzHq?I10dxCunE&f{LggzDoc^yIKMGb${TVbG*86DF$b}|Oe5_$ z#5JVf0vn6lGC)I1*Wr-Pmf!tGB2tR5t-2Q&Oy zv1SrGr>Ubm~ovg47vfYW9+BgwDieDX(a`N1@m$HU)fJ#7N3i~ z;9NYXerqRPtO_2fHCLAP(e)Y3jV`K&0aS%s*{=wE&+yg=vt>+qXxrv;^34wQ;-5p& zaF@FF%4jZ-h$(E}r>ZhMp7=>Ya%%n#%wIm1rEc6-#Uc_P;6q)MEu7Aa_PQe(r`W98 zZtFqHP-KniizTPG&(n_9Ge0}s?X=wbAshQlLCn4?YwFa{vV|e832-!ytTS%Vbi_&b zk}QIX_+4s~jo?BS4%qcxauk_qs_EB*;n-59Q7iOzjDy-r&ur#oA#PdT_ZXY&UywdA z$)%^6Um@NN^Nf!rCGx@KS?&V>#G z_?lh*&VZpQE;#lEx;l{6)-4}oQAXu9Gx;CY>F+dODt<-$y7~_X;8@4{nj?}TZ86m42gd8|Z z%NRVzX83muRA=aCQHWyZTswNQGh8g=E26i>)p46U({oA{n!&}TUXrjC*BDLPZggh$ z7tPwu$7H4I@SiD&fdXb;W)+1zOa;(EGm_3sEj4ZTVa#R#`42*BqD~&u5dEF2j)|M) z*}NzT!bc4YtGo)n@PRtBo&CGMxY3lil}eS+HHG56<8+Z^%%K^Zk+|!OS_CUN>&7I= zguD+ffiW3IYw+!usQqaSxly^?y3(Bqq|uHY1~}+R#v!YpBW=F1ilCUr%v(R24I7**chl50;bqWRJ|=F)+w<@+;caah=vu~`dx7UUTUYrpylAZ;UW2j+wQ)DDUr}2DIzW6dFlB=&v zqQT~zxN}C}a>^oN|WegUK3V;l$3)lGGdhH&Xp|E0vg zFXTmz(duH8L#M}iMrPp`%SxP{`=z$7w`U%h{P>(M(lNl_9UC5OhdXJFZzQ zP%z6fEiuO|l2)`H%=~87^Q>y->MPGHJ5uGo%IH0vd9iF~!Qgr&E`+386A$~(uh z)eSR$9{m2ks=UrxsK8yR%&%!LuF{NT6|5)^I`lyY)r@A`GSeAc0PpZS17N2=TgZ5;+qJGKe+fb0Fb1kv#Abv#XP>wsAJhS9Wnh_TEG+lSFv|;H{h!tz z_S63OZ>OsN|4TgZ3Qhd+&tK5zy8>9CIbszZ^6?sa3kovbU5hYz04_y}M!~3JnDM*D zzg9LzPS`>}CaD_0Mi-KV5wNL&GJ_2v5E(-EErb$gqwD%Nn_b1F61{xbde7^z%yKlb zBt-bqqu!GN8tURy^gvf~5Uym;KJcQZ>-+kr{)1P!IF>elihLODYo`$uLwoy&(Q%~d(+nX`6R z#+_D@2Q#hmWT$!M>noWhi0;*L z#TC(79?L=sDB&pOl>R|Zs9k>Z>*DR+u_aOt=HX~mn23q|pdrjv_LN}Y;NkngtmuCr_P8XwXk9n?wN#fo5c_qU%C8OqRtY`GV@m99 z@x4L6Jq%>ow`tw3f0;h!w&Nfmh5$VPOh@@39FZ9%IDru+6cOwQ~*7lX9fF_MSuAvUQ4OER7Ykz7s{ z<8t4&fP6eS+m9&FsE=QL{{Ty~G##`^-=3YT_RIssJm0YPJv4$}Ci^>hSZrPU+#Lg+gQfPfAgvEaF16sfjk(vn%YSxvugS= z92~&UQUos7nwM~HdOOwG_?c8~IwDrDWF{;uPvPOEeo|u7PP}T81J-xA*3=hm)|MJU z$i5n18fYJt#Z5tL!7Gi++jl8iX)oV^!E0t`W%4ioC<93G0+!oA86J4Ekgl{(1A|v6 zrlFl~o$HV}wBpW>CP<0F7&W;AT^Yj`RaI&CqFSaJ$LzlzhK5c zdssx?`8!S}t46V=lNljlRzLSamzh(SjP-u%{sDqm=Y@)u9ktqYPP&?|)1Vw7L4oHx z)FgX1!Qw?Y8-cRS(6VUNxH8hPce!G!CsWl+0-2gReH(~=U6d)Q0$He(A zT1`z~>p2>Hiy0qR=%g}pxy<{^CPhcyEQzt3a}#}@MGUC)mQ|6e8AVM0wq~^UZJ^qj z_b4*Pt~?#b)uA1Pk>Y?T@n(+IjKl3Br(1>fsnno&KLv^qO<|eO!b5-Fs!hPG=3pvW zk1IFcDm^il_y}6^n*CkTRDU)V)$cC3?4cU2A-^Jxnv={Q8HVmQm6q07;%=pwXlcNG!Irsh81u7%|XPPRj(hxzU0UwZp~yROSiHr*m7bBI`7W~4ed z?w>J(#pjWExMXxOZ=sxQ-h$Z-?5RdRve5$F0@FS@W90oUW+?6a9sM6X85;fR{m;vM z*J1PtBaY=8>+G$xp4t1V7lRw+sjns#X3$H?lVg<5LbWaD!FSn}I{l7o$bn@6BR(m$ zFD*-PQ5|fXUv+C0Qq~uNBebdR1d%fHeq_;?wW*!puY5T}V??BG7onK6|b~*z% zLKSZ55lN_UDcdJ=xp`Gzj!8QsWDaYf3QiEkO`@c}kA&Kac^3DCw|&cgU9!6ZBlF*b zu=ntXXmdwvYVw04up2;?00>0JXkW#-V-dWCi!ak3PsErTf-e7~%2_LKdfM#WF3(aC zs2Yt9ridG_`EtmEc$09sPy%F}o9bMhES!mgB;JYtYk#R}wUImHhO?PM3fWfD zBCOC>q>eqGM))}TmId%CT!sG95Z#17yfvR1)dAU6Ntqqn-t}Tr=o`Twuoq8{V`jZW zGRrk3#v-oe$=LK38(g`hL{~9FuQ{ibmdrA==#*0N9VJqSo>HKP3S2^>$`s)>AY+W$ z-ONY_Dq(eJd;H295QukdK z?mVT+XS7n!;!x6u`)=Oxikz4;h1|@8R8l2H!@A!CgR(>)<4wTXNoCmH5R(7T46j2@ z)fkNRZjHk%KOX1-OG^mXld+A5K?XC`HPLQ4s2_fBQ%ytFHLzxkPEB|wbyy2sG_?{d z=p{Re$`AcA6sgh1b_u%PVegyEGteYSY!Ye_gJ>ZkE$n)OucP*qWU?D}15-fz5<5lY_*P?LL+T@$=h_@rhsaU1P9;RjE)e?-&pdylDe?X=sc+ z3#`nqeRp^2Y3e@5z1KAo?}_nqy4@n=1N;rpRH;eWVia~k$PT5Ca!hXe+r5jonOS@i zTBA_5R@`XGZ^a#TINgXe49*NWD59&tmiJUXb@UJWJR9JQxzz(>G}@Zhnp&{@1t*bEN)`4 zIp=3vaPnf(T}%qki;5+iF%r?}=D6LV{TRj$Ym|UGukdkK<~W-KsW){Gs=&j;+*#Np z>4p-NeU0E;!8LsM7B7ZK8&SQKHHIlkzA2h{ldX)@q~{i{p?<2TpLmo|wK*||ARhb7 z>oz;r#FM;nVaf@0ZO+(AqHj{myoI$w{+w9Prmemk4T3I2m037TlK>~w>e`db=+?8p zFR+BWCU)2vyzezv5x{m&1B#e1%Ka8WgsiVK{bXJ*chA);XkAaG9v;)WITkr%@!Md! zg^h_u{;am$Pko0ol)zjq`kMV@?_{ew4cYE6UBHmpAG#?G_g|bi$WgaPS|d!(i_@0; zxSlru$h0bP`R@x0Hp@;P3{=sM>+iNm^Z^y`z(dHqv{iAsHvd~$IBJv7GH1V;)&&9( zE5$JjKADLSMjvM_8`O1a3s7tM_yn1lSa27i7cSqi z5bQ7dp~T2Ww~?9MoXmSFq5fEaL1T<^$&vl=?nce8_ZM*8DmA63FkS$45K-_|cmw;e zyHF&#J#lAFJ6gA%Pa7Vqq5ZX+w6i_0l;byn4S_0mA{~kdlBjF8gI{GWVZxGJj~AWV zmllXMqo{U5S0}X?0P+#g$NPFZkXXSaThTAZ7cMw*-nU%KyqKg*i0jvT+w9Nf+j+8W zEq$|z?dOKsIF(Ri?BhNNY}IM(2sJX@0r##SC|}*wlhXCkKfsV{eMN_vIWnpv`VIwX zkS^sI7MMGP&N>jh{Rj9mefMNwtyHcc$8YNN+Z&$uUPk$I?LIi;FB4M#a)^!ZlaO#9 z6+>cXI9gckK=sWJF|2mFl_jn;zSO=FGX6m@$PY=Y*>{N5C(i~jvW2qD;SMTM*n2|4 zljoKkH|8OV)7Q0dCR~%vhq@Q)P^&u*$1coG5!^qvqsj`D`nA`7HGvuSt|2Lwxb=?S zrnTaZ2boDBNi%wm8)cZg-`=1q$7y78b1PmTv{KE11FX4qgUY!HjY07;1;r-(^!h^S31#SN56-N`nK zXdW-n{)p>O)|1}BIH>i8 zRievezVD8e|AyW6-xr)0-0$HgkF~lgG-R|0fFoGAy5t6OI{*ev6rm0g{O4-@^ZRRs z6t@=70vPL&g2m(m@-AD_;UP=pfWPc*uNnTdSCi|Rw?oe;@R-{U?)xSjBB{28((l7& z(3y$${9-5VrvQRH7t3h1s2qD3Rp@L#h|L`+sXu51jVvfE)5cGqgV zzQRlRJlNOSrMIi^#LcL6$7k0?7$;w8iVKRpu_9puwcQ2i_FIQo?Y233prTJKdxU`> zeaKQ$PFJT&X4P0qs~THSw>++a{-AKOy>y}1Wl0;6S$4wQ4)WG}N6xxM6fyhaO3D?;qOE14~mPfoyia99xqoK))-+Euswzs8r7c$LovsLU15?u($HkkMpz%sHF#9fZ-Bp* zHgdD(nu&={Nd~1ZBv4eHS-Qpjtz>2HQK37e37MO{?l@kO)j79cS|I(t(vhtaeRtiC zNIy^WUyX2TNE{{TNi0#IW(M8|kM^ObL(s>yM)mB&JokFwo_GV!1g z&Cp9ovg%6ebB%rt5~XMs5&p#p_L=dZq|t?3ua|rQIXa@~9F&_M_~E9MoO&!sF3_BR zBOY51sLsCM{QCkgKR?B^X%%l`AO6$5X#}4^MO&9E%hQVL$ljaVTBVB~dME7foEaKy z_&U%#wvM{zc9vlg)3I|G`#m>7klkq*aG+^FhPoJ}J~}cZAIR0Fnvpb++4d&v-iSHY zI4(of)xEB(+MSZ>i>rRK!X06G7i<)&{7dg%%9vo^8kG}*NTy$r`ZBN4%!4mZRK4S< zFG6<17f-(d+r8F}v@AFsUtv^eQC;0tBT>Lg=BFv49i-0RibFEkFoJ z2@tB%I|89MDGAbhFMd1BytB?aXPs}IwZ8AX`6G!C+3@7ae)hia>-t@k?4e&$%|1!D z^wOw}9!w3LVjuCyXZ?zhoJ6p*J1c<=EpQ?>4fnD?a$;J$2Y=i!2sTs=0Kl)gY z)8#YKj)aPL)aK_nPgxa)rSv`i9EI@b!Jy-XM^ZJz!@2F7pZL~}{^feIp^>)DoEFLQ zEt|6Z?Y2cW+e^%@&}a3tDj4V-jA6A~B4eN`9n&yjsiFwl0ErC0mAwqs8c%JnI=;@j zpPGiBs%4=ZBP(xAHju+vK+kQ8JjrJ{>|bVYcK|jQx%NO2q1E& zPiglM)A&Rf>(-{mtTPLW+s37;eCxA9cK0e}dH{3Zp35fMHnAto)5U#@U>)u6XR^Re#iv@-Pwup`X8RzB zBN}#4_*-0GCvA+T@B0*-FY|dF9hNr*MBAvy(Zf8Vj5n%SHpuB74g?KG^eFcysxcYP z9_^IR;B<}@`!TYi2a@ZmORL<4n_69q{M~hk=4Y||f?02C1JpCnY)q9xSJ|0YisefG zq$oW9JGX1RKYaRoq^pz=S>|H)3{b=>7^dH)L_dSBs>eTF)vH+dcn0IAPGV;P14}OZ zX2yFP@jn}UO=9pXLTs(i*ZfRz5AY|YK)bs?kFN|(lBYvDB|)yAPkL|{zASj_5)4Wx za^fy6CHlG$2wmQi;YlMxLaa}-`ua`2q0l~y?(Yg6jJ4)_u*Ht9ePDsqj2eW#DB2G! z-oPiwvZ;;iskNvxjdQw+voJ>(8iD#P1@VgEB!J)khLd=Kds>RsbQ2pbcIr-PSsP<7b{YnjohnBcW}Ft4ht}CtWC?qrHlvRVX{g}7Cl50`Pv8lXxjkx z>dx_+?1p*{f48`5pW%G6i6AEgzJ_-_4Hk%<6{9Na&V=5{UY`$|zS&glFK5v#^zaUv z!%JPNNa(19WPDO?z!Yqm&zFfzN3(OUahO_6-P=<+`G9I1@7Bc=mXW=AaYI6c%^h+< z$x>Jh-X}Ug7awN34-Iq8H{3z5Im*?(C*ZnAqJEcPTpX%Wg>_QNn(A?UZ1XK1Csi4c zbbe|-9!UW^$M&RF)|6Eo9)&gCdYg`MeMr1P8vR0C5eFHAe^5FcU{(9s6olK|R7p<6 z`{<&7cWPWRl`(4?7UY(^#%^xXmba-wA`c$EUq`nuW@Nw_hf<|0tJXW~5SYB_mU8-TTw2&RDbNJj2K(5l(87~wZ8lsI=x@p$GOBK?S2Z^S*mRr zk=Im^AUA($6phhJORRyQBaW%<=f*q6GNkpS)OzG2bs7h3eYu4IY|OYuAp{ja`|Y&9 z8Ml{OX)HpI0~CVQ4!n>6bD6Gp-X`!`w@st{uYa2JIj|WsvI*Buxe8*g6A|DYSJc@F z${Tr}QcWEa4BmYmwSV|ik7kRWhQ*=MD4JO(RSbkB-htVo0)u=X4YM>-at*3rIn zR3mG1Eh+m0y(wi&TRrjFQEBR}(gCQ%M*GI3h5nF?=MYSGY_v!cYV*Xb!OCU$U`y|~^r(PN4xlF4%Co^1B81jC*7@n-A##E$0g z7qZzN1@s5tDXo^44pJ$QLJ`jSabpvPF`PybUTY=+xh-7ix+@!2Bo4o~5k69> z9Iiu$`Wx!mQnA4V+T*y&p)=Y5OCX>yWgtD+zEu%#ri4iU(f=i>v>1_2)x#SBT)(m9 z1zU5|*LH;=`BOT;CT?eC;mPq-Y^v0KR7>}DHlA;3QRqqdN%lbf_Ae44Vc6}`C?B2y zmI{TF7Gxo^YZE4)zvGeJcZY32TtZOGuNQJ;nzg@L2ul~E<*wSu?Qe6)C2AM=5AEjW-8Z*+fFLh_-N44bD7 zIxV#fyPoZ;f}NgG?oUVLNkVFrQlpyYoHscshhOksHg)+&5g|M*1iPv)B;Xqdfj|Z! za72z6G7f7*Sp@%Z1$i3O@6&A8HcOqPtEUO9<6|53*Ap$xOm!k-sS~X1FV8bqCHF+?=vrjWcd9he$X}$DXC*)#X({Q)zA! z>ChH;gtS-4hs+r2gitTH_PaU&!StiidhsKXKDtU~DyS?wghn0Kc|U=GWGC#LHiFAC z!!E$04y@fgH3@35bl*YGa6ek-!l12r7R&iD7SAhamZW!Yaqi|qs;iD zlV7}^S&~H+Z=2%__P6_ch8%)A4+0-b_OcJx!Xh7+y$&1GZtTpopihlyUg5*F+=eAh4c3d%{~}{|R5fn|s){Q!oU?mu4@caq$Q|2~qTY2| zXceK;`&GZB<5+1_B(SWK6-$Cq4jp(OX^1Q|GzFCD zfeGWoi^+s0%k6{CE(ymL{&?QgR0aa1?jG2kII&UCTceY&wnY*djGskx z)jD`{V^JGEbv7y`i(VXeYv4bPLSwDx&&FhDC+!Ygifg#V{`}8bJByovH<3T&W;%;2 z^y>!K4UFx}1`}E=giX+I;*ENFg*e^rFqpmZg@&7jgoU@cHRK5FvPqXz7#(@|#ix9c zS&)tXB4Q>mB+=n5C?LnJkh`ZKX2fym_l&qi#^nwXe0(;WwwkFURQZk!aMQGh1b<{# z0`#{F9%JJZ(`s)=VBLYD@u75Oj&Xw)kEs86yJ@Oi>Ft;xs$0!+y}q@rtR=yZo`d+#>@D;|)4ZE5R>Xb_fTdZnTmqggdDm5Kt9% z7nV2VUN+pMfh%6N4~zIXTkKKUmh=uO@YLE&9;F1?%aeootJXRcf{7(Rzh+RieV>`W zXGXD6Z(Fyr8Sfa}D3R1JYwn+E$<(D!?&Un;}0Or-z;e{yoc)YGC=9X@68 zv`HlHT{mpWK|*IycxY>YuE2rX(obVe;pR9^Zcm{`WP#Ih6kPV+l=d#bo@zIZI*Gpb zw+ALCGoUF)?6WH){Vk|kInUH*u$9WZdo84lqEFb3Oyil3meIc*=oc>Hx|IKzg7cvI z+Ri`u-AMxe{etFhIr3;LjXrsb&o?9D)7YwLrANd|al|)QXK~ZW-mwg>36^dMiG!~@ za%S?88#YQ~$o901!yMIv8=JsaS+vz%&szSxqi z@HT)atnjr7HUa|ORfsBgo{oh8#o|QN@C5*k)%D2FG%43+7@VvqT3pQHH&nI3N6`dV zl@KXAN|gvnm*M$?vgLgzA^x}G;Lmly8ty&AgZ@~o=H>1e0uYMWvz#q$z^hn;g<}4Kn6I3MrpF!_ zx{cJ&+z3zSzz@1AvV={{&7DoMc%ojn+nldCb2Pz(UsoB#E&{mCv)sH1j3?bqhBq80 zyH3$d5o($6I0%M8fXY9i5o5R&E6iwMurLwPXn%b2Lg=8lf!x|!(G;i|upLw)FUQ5N z@@e_{RD#XA!|!_en|82CP2JJ32<6>MK**%YVe8y`Tly`)X!&khTn(hi$Mhj~(Hg#m z!L&!4|8#wka$~h!Y(92z*6F8e-^>=z z5A^_2;wv06vqrZSKC+X;6TWq~p8xv=WtQNG0Hxy_hl+!<30K*^en_~Mig!q+!WC(& z6Wmj=^qSXEfp#vD9VQQATFtq&yMu_Rcplnq@j+cDQK`}a3=yX`aZBK)1shL=+kwvP zq8M%^ZFVmoHX)5j3sxMNtCRhHVP~!|{iH62ar57)@TFW7L0Q1$*#s-T!R)K}<&th2k%Rbs>OSuBRGNsit3nO) z$8=Kn|J}sa`hE~i_Dznxo@A-X-0fbOQec02eT3S6sAqwj8}Ehp|CQ2-B+Df?ch8o{ z38rWe0A#d76(S0L!lS%k57k|Mh9o4sSHTr%p zCta5?C>E8|7B{3qmU_IDn#22OYUZb@3OP0R@>O4A%4$d0~kn_dPQS|@t zAQB^V8=N`}Ngox!3B2u;vmnKk=`_+d4Yy^5*{aa3HWL#R5*iJC9pkWtF!+^qEHa9j7o5u3U$7tOmx${*S1U_K4l;_`K1+ALWtD*HeA!L+qrK3wYV|gVoKC93Tx{8*rDwVvDSyhktS~2CM&`PH zgP&eF>-Mn}|6M@ZLxE`Uk)}sd+GES~0?;Hn5wKlp4%Zn18s3pg)d+;aBp->v$<$?a zO)@0C!s&}B;VN~yqu@syX)2C@DHDFCgU7w`-39xV$)>r20)jZpDtuK0xJ!(P;o?O7}4KvF)-G}zRCt!VSMfxe1KQ6>?MmI6>O-sH}D` z+Fc`C^Uo~$WL#-S&=XmoN?>mkMe-8~$H5SKW-Y2zyiRl6BsBo=M-r9?AB?VxRTyN> z4ZtLrtYJXgU0P7Id+^x3Vx&-{$Gmj7wJKQDx4v@ptbAfg-Ql;`S$vCdxr5;vR{r}1 zvS`R6_fKy6=Grn3m%~FH?c$Z)NJ*+{yBQvY4(u3uInsQ%$?~<`r6T-sdx1y(Dz337 zQ9xEK)tiOSgJf#Yx2bS>_M`e?^5+2CJV}w_oneOxJJ8XQc647|e;Hd5QP^QWo-eWm zs$sjL3pU>JafqV>=0YzU4RDRL^rmEpUAQ3qoOsaZd&5cS(ooyl=LT}TCa?f+u#*O4 zj0GLcrtYT@gzPEy6-}3NJ5A(H(w#YU*fGw$inp*+M6>C-Oh@lnm@Kt`EVi-c-imOQW#;&hE=i%t zl8@~W>IA8iH#gJn7>C2y^U*5vD{fwxEGJrn_SA_Z|10C>qy4h+Z3X;}47YMedh*@8refDDgNxOxL)dfP7`kyBOY`-=v-0)oO#8Yh1_0+uL~U?LjI~(T_le9)CS0 zQ2cKhdQ4>RFXzYYzjPFLwzL^#b=U$BNe2QCe4D26hAsHY68X=r}qZRdxBH8 zSmAi>u=pCWT81AUk$rQ;la*AK=%=YUhL45yYDjpQt?B3x=jXrXkP+~wxY-^)^PK=J zQI;d`ud#^X%EH7-i|-fQ&@pI%Qg)~wwORew!L~@{Ia!)CT(FyDqG*^urAi$ulAj5&G0xcX~b*kGP^faFE_UaNgh#5!wJ`%BGkXodib!p}0&m5N7hx5+noFYC8WWduf{aZ>7v1a^vYo)Qp(%wAC@2aC_fUmN}t&@YEh^FD)kTv|&KGI$NJ zoSn_xlA9FdWeX<47Obhu@O7@-mujpGURKK)ZJwB`ER-y?&NwSI{@tfDa?o!C0*5Ce5^YZ=h&lNkXgz zSV>nf#MIdh`ub!+dBS&UEXC@wdwK6M{16y}*igS4)Xuh9on7x8-$wipGGcD;|K%jL zIrs|Q?0k%JW%6Jj4Z!g?O|?zGOAg%v#Y~h8XP1r0ojil^49oIJ`Wuals{}f8ap=ZwsXJNvDBoHklSw_SPsi{EbL1R zp;@PvJrW)Z8>K_pt|754+-FchpNF)FOMwQsBE^@9VrCz0uXm$J$yECS3@`9|pyG z8k&wCrQJGKKkOW!+QU$q!IqrP2r0(McGGM<+E$dFAYm zPI%+FJw;mTZi=A24^P)W*PZ{)!~b}pD^R{kYWx%$aF3(*2^sq(;(#$?m+JXUw$7SS3Sqz}ayp-3NGsr>m@aG2Y*<7R9h_K1Uv!oGvIOWZ-K?4rP%f@YyZP7T zVvV^pd#1Zi89E?M77dRV@0U&C%@1uxUauYYeP>v$Q1iLw4U&1NHc}N(HCiRZc!ju> zIbLn8sAT-@-nnqjZ*ONoSZ4pj?;{v7VU=JTyA;jPN9~L6*RsCO&*y^7q5)mWsHY$o zZLsP}XU^PIx_I_o9U8yhwD!FAiNU_TZ6}xUqKYU+*OjG(u7@&LUD4$CP4i-BX@k(p zH*zrtV7JYnx|8jiuh?M1xS&j|r;$kU=Z3c`6m+h(a=+^!=a{}3(%%*mjmL7WZ0WYv zMY(1Gnk3NB8AAm5`*)KB0L+&7L8IYx;+xva@onl`JZKqx9_AQcBXAkuUYvNF;Q^Kh#kWK3JL9NjFVg*e<}JD1K(=#2 zuEjYdQFi8L{W8PJo;ej)sZJEKKW+l$cI&+5zT?Wg#pZ9Zr9j(jJ{GL$<|j115KuOb z`#jQhn)ab}{+>-1t-)2?W?KP*FX5G>7A(ur)y-X=z6_RmF+1>&_5ofV17I3{Y->xf53y>A7M_T)m@j^N}pW?@}6DSQjvH;SebCY4r`auRq13` z)u4tc5}gTgQYoZ>lC)+%KK4Dg&e-MMoYzSg$9m+Cq*?8x| zYQFKid%bv4U8f@X#V8Y!VSK$dfGE0_qJ#??N3py#Ql!gq$Vf~n%(0x%z)ls#nYR+{ zlKj=W$DhjJZ-?bJX^4k@&P{DgdD|Nwm{FfSaSJG0(XuSA)A2ce6{j2@h6YMg5O&>A zqL&jt&S_Q9<&a6Ls6fcL*nHGXnC;gB_%m|RWmYRcqvSQa1Z0gT(N1DbTIBZ5Qp~bO zZO3sgZ4xeX_zh0?Q{9#anl-KN%+H=Yt;=d<1Qg)D%)`Q)1dxrWj7%cqfFit4PtQ9e zE#Wd9wVs}SZcX1GsS?S7=*S_38?Mr5`Y6@!7ff}`>LQ=#Qq3S&SLKp;oXULe=}(?jd(@K5mB>f*r{R#$D&$H{cX{e8WJou*@;u zYBCqCAWK7bdtpC1d(5s3Eh;|m3kL*ttGsCCoBeFH1&g=k%}{IW@1OMN;Us#FP?`z! z#}B2yUl8+s8LQeFRNP{p8=u?G*j$sAju*Hce*6-6-QT}*OB#SKB~mAz>c)117vIc^ zm2I?m_<%uE@m;HWqP(D#cG=Kj8M3&_mds?=pWunoRP)*!(uuRMyn|*x$b;S@EpTxw zCB4=&9jQoOb=fS~;?8V}%}%%EVJJNS*6R5c!L0tm>Tdhp1j9ulBpw}+zObrigq>~Z z*u^U{$>+Wfs9W^2xTRQ6%n2+-M^{>&tRTKRiu+! z8T)*Zp3L`Jdf$FJ|5#oO!~aV4_5A67>+a%v00jDXFqw(xg$WWl;;fDm6N}y51D=dd zdY@{qVed(DF>(`4%=AOWH0rIAC@z6fFC@%kz!fdnj(8^F=4HFoAg`CiZ9;%NK~+`f zNK~o1J@;bg#aUXoOs&!h_V~3JPjUWDRv_@6!|#Z9dH*~g7?>~I)meOR7@FGRp~Kl> z*ohFk>q$>wuOHi+E3{V2=5D^vb~^B65YCEQQ|p6#zu-bIYfI!vnvSUd=$0H2^ZkON ztO5h<;m2k}lDe(YX`5YR8P27O(C?dAl&Qw_w1VMqsl)5L;t&=&H2E8=io7eTfSBPs` zOui1q@C^MLuRE83oAy=!g+JTkxp`L(qgtN!+RzorS5vL!au&Rlx^MU!HC5PR($%pGldw(-U>;})$4$G$%aBbEUY45fW^R8mpAqW`?_B%U za|M(djQZmT#3y9nJ&9&{i;KFjJ6p@!UR%!#$~B?$>xJ~g+Kqn|$F`M@&y+w#GzH3> z;9AIN8{iw@-I^D#Cwaw2{VaNmG|a%Dxn1>Q`L{C`qdnpBDMhI1;QCpE!qP#g>CgBi zwx0_8gA?&F9)6P0XBGOx_4yE2C^6X0zAKc9**B>vQi9Wk`%-8~1i~k2jQvi7=sL0^y^(B?j&^lu z+45=G{y@Kxte|417eJ}8VBH$O{X-M0M25~sZL zNo!s+hzyU6+IEYlm*S5e9)7}%jrlVv?FMYW2 z{X#N}rbmo&j(c-FtE98d9pp&2emqh&K-}^9IOg&F0_T2Fy~l{zo4K*YtVO3On-T&3r!{rU zOlt|G^@88^WW!pC6$acNOj#Jik6ZjxxEvG{y6@WbpJeTiy)fD|>iB*E69gq#y$-|R znobQGAWe%m1TTkl30`Ss>VK#D`MSRDakFyZc?(wPRs{iqOO}zKNb+?S9isMohpuc?Esmt-hAFOK~iQ&wj@s^#Ja z+ryd>-Jr?Pupdff4alY@sD*)9w{XFdeiwFCmWZa1gz`5!Kkw|{Qih7t&PUr%kfYr? z`TZHcR7Yg)v(YD-bG;A$t%cp+CcGYlM(pao@M2jP_7}_8<4swaVHR~epVKl^hQxb) zqu*Ha)~>N`+8K1^Ep&eXy8UA{mq&*t2!*_gib zzR>6NxdHuAh@C7s-Dz`*zKR4rjKW!V+zA1z`Sa-l7pYNL0yIJ6*d8UM&)i(N zW9?D+4u#gz+sB3O--fTx-n+q_AW+ieuCUC6&MjopXpgOQ z%Y>|NSZ<7-=4^zIo2cZEPX2%u>pC)8*DFbCkFx&XFgks7B6(5dh)UBRD+7`!JJ$5>B@vCRwBo_*OYtoNz742%q zXtzwR#I5MSs%gViRj;yz@{+6+j~=}|b(2@|#MIQFRML$)l2D?O+J>$ZBx`gBwt7fB zE3iXKdv#FDNNOcOlIaSbP3Ldu*=V9+3{*Aa823bK?76pI5@DRs9f;Xl%)~u4e zqL?FQ29$NslB5JDB)=YoD5YyE084pGoRq)$JZ}VS%bOxVd2~T(?FR78GdDe+f~!AO zxMPNPCL6cDt?d!seBV?TV zwvg~}B8YV?B(Jc#sb;s>X?Yz*X^9jiaXNv(BgNU``l(_?CjGo^Zu`Yn_d219bbll7 zw4{@;NF_H29Yf5A$#zw7N}ZQEQiBf~cAq9#ktMFXYUsMG?8+)puS6<3B7U)Z5h&@U zeX8u2<%SM@IcK@F6k6A=K(qHHBo6Mg#x2(;%IO~GR!#1GiOQX#X<_P&X9UdH!{e^Z zI$z&=5<^@&=xW^e3nO-eG;7x#+~HS0jC2dzj*h)Mst)$os&AEqvgy;3OP4r*T4CuQ za9LWB6?4%(NVZXhkX1mSOneCA_k&(_l+;jVo z#21oLSrHfeSypeOmnpi-*DOvIq)vmFg4~DZe;T{_WNI(w#-kpjeQazAH9R7WG9~Q6 zNcn%;S0o=Fei$#%S7)V>J%zYVKSx;_3k(J>==SZ4YmtWB5yuaFUUy5>wxgT>Y?*T> zUWbRqvG_WN)F**GexQr0U}=W#Gg*0@cyOLi_2VVKc$4t&7lPwGB`y`Y3-7d^1tE<31;P`?&7SyOKRm7-nJVn8H-UW%Re(OJp4%Td5X+I`~2m3$!fAi ze4ni$EWu8}ir?v4K0D~ZFor@rZDf}o8q){5du(f=?;)Xcs2mg$$=ohCsMC9mwE{ZA zAdFqQ>$je?N@rPUd-dmcz4G|8vIx{Wg`k3bP+tb5sBiVT@!v0W4Uw0m>!Q@36cn%d z#&MuhYexCf}Ov|ZWz(Ai7JjR#~GJyGaKAW4lLisDW>6)s#|uMMp)jrZ`T&? z*h(q##0+v0eHx@vNCoi+$&T3;W&=fZJ3FtYz=edLA;BNl$Y&u)Wp=VUH)n%!Uj^5Z zA0quQSIt{|NUsi;=+rU{0=`pgkk^6Xq)U zpDtz+rL67@9!csf*IeF99F!W_@(SNO-jt?hV-AIfS_VqU$K^{aejN2;Y<@Ke%j}G| z>{MRUox4NL5 zTRNRwXrotrSyQ#$%*M{C+CORjk4uyv-q_&_qx(1Ov>)UNkEBI~$%c-^_;UQS!`}&V zQ+VdF)enU&j++%0*WuV-vpJB3&oG+(q}@!4QA?%XkH51L{uCW#n&mMxu3_A*9L|^I zvx~3&HfqER2yI1Wl5@0^ihHJLJTm39VRAWlHA@L<>6}Yeg^&jgH%v~#ZtZmK-U+_g z={WdgxVf@XJGU@CoT~-qsTJwz)6x?%JT}ODZy%B4XUhPbFpC=_SUIgA{awgJR&SD=!WOtXTP4_uT-Jz%F16YvrX;r$}6Hlz_Tr( zhX1M@N$CG9kDc>0Kn&{WJahoap7M(9uo(3v2}SxqT{OD##(i$?PgC)M;41sG$C0-vDx&gQC6`p$7&-H`K)<1DXmGJ zLUd)ax@19qLk}OM#izDSoJu1qf8~RUfdGH(Pa?U|+aZx6{G<7^3%EnJuUKwFm=Qin7&gxv-1GaEvQGWpd+)q>{b=GY{> zQnu7Tkn5|CD!@1wIA>8C{({&srkako41^fOm^Xjs($&4n?QOhLc@|;mbo{Kae0OBKY{z$HJ;yY=c46VUd6eG$`SIH#gCBSkVY)bRP?L!eJ zK!8zXV{L)#k*lQzA=Pvm3%#O+f}H-{jmv{BqN$wWaJ26rbX~ab4=HTY7)MG7ww=!V zdHjsKU@_5Lu*tr&GsOJ+h48qvOFWAvT#Fh$Z$M__?w5+5e<#ZS(vyE<@4$E&f3YBf z&sX|));xw6Cy4_kPehCP4H^dp8ANHR2S#<~F{XT*!V_uDU*~uFw0kO%j|KKr16^HO zF{08u77-1BF=f@Yo%P?QFZpq}Q;VDJ+G*d9L>a_vF>af0*0jC-UBN&gQ$JxWqGZhW4;Jp@)UEx)W+Vhn&oTteLsW($Ss9;nQZ9H$`jrCyQcIk_1!`apj zlxQpgex#os1RA5~oz1dV_5H%?X~np+i?^1C6N_C!6TC5|#hTq=2s*T`+RE=ZPbU1N zIrY!`c10+C=txmhxR)rCz!JK+K-b(zqig*ve|PUU!|uAb@t)lhlXLUvLaK4@{35KH zW!cNm5zF8FCIv05ex*!+Mdgy;FA%1l;FB`l;bW~Be%m>E-Ft%&OdzDAVY)bsZu8A? z;WrOoAN-?f!RpEO&7t9+>Let8S)`+>8CT(|d6w3E^~l!eO~pl0EOJv&eapx*DPz;C zTR~^0W4OB3D!fs7S0?k-)T-g=>j9rY-G^_Ve2ka!ik9(lSe*;bTQthxJ=S)usu

      X-$=Pz_#-i!krD94=6owN3Qm{GGjP7c!?I zOrHi&gKoyVO;A_%1N!SU0kW8^z_y->Knk{1Z5xK#V=|ws*BPYFS`A`3@}Dd~Mb7pu zZ#Rlor7k0m|8}LmufB(g4{}uKN1zCa!wjfXQ|-31WNlT)X0?9oS_vt|h~elI5Y>kx z+ly97pmDoXII?zDG*&%T!@1h_#F1?{wtv_Wf={ZMror5{UUTz4Y0Eb2cs-z9JekT+ z6;G88O0#uFgApDEI_7-|@f|gEK6((=jt$k4yubNF`Xwp=!boao3_(i&t?Y4jqsS|4 zp0j{9Ck#`ntfK_*Djz3ChRSp}jh9o4Q*u~)Iqcjb+D97SwoXZAEVYnAIrSw8-JTOQ zU(%#Jl1Mq#5v20jKJL!dfvlR~{KK-;#y(q1k5kSb42;`~wbr}?k_8nBh^!4= zq>Fqukp?yiNEC#!MBvG(mBz2QvS%FiK6;&cFqjvc-zuT zcqU56j5FCOsLU9J-lPb*Pn%%AIzkWi8dh@ZI^FBYEjKPv&6Zf(sI-Mne{CIFFMkCZ zRq@VsaA#+C^|WrdO_pxhSRc(0+blc}P_98Ur1s?(MqS;VLN*-}Sl9H4LFQ%-WZi^o z3GJ_Rh!GJr8f`m5qh(U^Gha<+XMQ>S`kzzozxBurk^N)#KZ9N7y)0u;dF^>~mn!C0 zQu`mv8;c`$H(gaOCU7EvDyi?^LhHrWz^8VxrB$ugD9gH!b)jG2COu7l`Yj+@V6Q4S zH{6r^z>+`$H-oApvO;{S{&Sm zay}z(a7AVec;7Cmd=oCSS~v@5jVDNhc+qQvv*BIgQW{6#_Y^*vDi~lyNNVPaUs0qQ z!kqIeqyeu&HqSqVNz^HeJAL~>xp6|(4eNxXwDotwBcBQ)mM3C#iibzS?10Z567v1R zI{n_VxY0L(0uR9sIJJ!k$~U+6+hRbPqAt~6McY8H3@Y3E(=c-m1mSXct%e?>T&}`hnDpBF7t4z)&eM!5wOf%E)05i+Ay5alUYlGS&@@&~< zU8pGC#fgBsx8JFbn-<3i;dYiR5J?MYr*c)D-CWDE8~-`*lt)&+&f9Az($qZ_)h{FP z^X|)*dl=ShAVOv1vCQ4N7@lOi806DRpZ+mYoSIz`C!(m~44^II{-`?t&!*wavKpt# zT`s&_K6LFvwKX7fVC2skve~N==hD^*Gw#dk@X$+$)Ndtv(2?ggd^03ljCmKm_Nv1T z6Z6IWc_m%a)z@@QV{Q4%aq)*s`S?m7LX9tVsEWY|mHDz`i)dp+L}StG0BojUuH zoiV%X8{Eof-Me+Tmjt(NDh^$hXe-r=Rrtwg>j=+ z9k9zy7Uih5krv+^DwW(K$ZG`8!Fsciq5)&xS=%zQ4-m-{0XdCh%clw@6^-3vS$%b4 zn4e8hyv1x9$6bMJ4f#Ie$%L+rxzxba*+c)!eZxm~imzUCWfVHB{a&=M*d|=;1vspp zV%jQ%D4m77{MEIUQ&eU2Lt=irr4L8a9!Rxx6}k+J&>wJ$#3XLW$`wb@t&)iE z(Hi=*Hjs$K6(i&H@0|=A{k+cSV-P_tPh24O+$03l7#-_Yxp_)#8!Y;on_J~O2)Hl^ zoMDD~S!zD2g+i4@S(osut2$HmhKBkMGwBi^%^#5MkiX}DTiKF?MJ|M?vdUa_=c}$U zsgdvx%i03zuf~#RM~*E;kSHgKv{^pSVvgmnIB3~)II)ng_SO5AVvPvk+>b4<>1N=n z#;ch)R|s>}gc92aS5>4L@GLOi+j8~!<89$P(Yk)QB-E1#AKq}~{mK668p-Eu@kyz_ zf3_SXFEW=Z9+>tM&$zAzDe9PjZf^yHp^h+q>W1I)Mst5X;$=eqR8M~&4+_OhM<$C? zLx*aJ!i(q0%T$;apl9+n%_&#L{Q~e@6%xEms7VcTl>8^d=N4|~O3wJn3#(naxZf%vS^@BDbs&Q9 zY)x5*3L_yC`Di!-SRK*f>Grqm!NL)`YBkeRYn~_O3Eg$yZF(0onO|dW!-t*O-w~>; zPe`ng%K#nwiv$@(*GL z!qh9bHtZm#zG=&es+2}vDm8pq+MZ@vaM_Gq4ez(#k8AE2PQr3P1^gZFtqGCX9N}Gv zZU)Z7kl0gIOj@lz$sxnjyy8;6+2?iXyonvG?>Eoo)r8jN?(tz864Ro&MedG~5kL7| zXJ=TQhF3Ua=GRKQuW58xF2p{sPaIXb=4xlc7lFKOo~+$W+(uRH$7hpz>{-sWTY-xe zU~YcNmp3CFcq#l?&>&)YZXf`Q7)L~W&1-shDt|MG7WkeJ6yKB3gM$C*y!|iy^Wux_ z3xEA@#?epxT!UZcB1IuxVX=2}Q>{F$yJGu&3%K63Urr~wEXPG4eMX1Jh6qgX`!A-T zX`P8p>RvZXzA!$$bHp0mGTPChzxt)zekrw%zt*X!Ok`~uooX=9Sjm}jPE`J1N4**> z2bbYt6Z81JT(vsS{7bm6PHa~-e z8HNAvR?e67Y0k~~I7J7^a>d||$2-DDf~A6_LCiogh|LY7C3{EKbjp>*y4BQLZ?GAp ze8HtlzCu|OKFdzml{twUC!}m*GN*Obzk$rMmK4c>*7tvk?Pc^Vn&Im_wQUN2PYf3~ zYV~$pOVDGO3NsR_+AHD~{+8=m+`MCIC->zmK55K;(rxF+3Q|iWi(JcgR5(4UZLK~| zWY~~@R?n9Z-D^BUFVPl!;X-TaScT@ISE|GZBK>WT47B^CPK&(3Rxvbhs_AB8MgLDk z1^coqqJ?rd(;gZ23}#x~2-I|3*U*&VsB7T?;?f9{Mj&9FGi_z<4%M=JdJ}AJ3a-@l|rSVqaS6jrd|O`e>1%OJCnUY-wrI9kpbqb|s8#)%AF|p|lPSC%nJy8BtW` zFd+LThfjssT_Y8mMv>O9<{2#uXHHTj5ovha1r<`ImMe*` zJSmaS-H$MU`oR_Z!cD)r3(raxwcPt$! zRcf4Aj}jus)7dEbi{Wr^5o!@e`Dg1#~rhGD=|1TkF*MR>b?M| z`Zd1q7edLvzO^0KdYv@qDq89fe;QxqZ!^a=q>rww%GiXp($r2P-}ab#vLiluTlIT9 zYZs@oxSPwZ!S`2?shtyi>c&#E!O%Rbo-b|i#fOXXB108F_TO0jdC{9F}|qSO76w+oxBPAo!N2}yzv$$()5zWyB<0Tylw2D1El_MLxibOV>xz$6zeXx1WaO%Pz8Dcv7`<6~vYV+m*F@nWkFF}o8?Pm8`a#qEp$c|c;?H}@?nCE53a|truC=uG?-eZ*jnkm zj8I1>;eG(3f3{XV$~-j<7k&Kb@>>2EqgV;km7rM0gz~o;o2W)eev_e&KBz_j;*f`b zk32Np>!7AQ{n?Ju|Fa`mcYG?(YG>`5_lR%mzHMhuKe~JK#GXL4t*&ms-EuBryEl65 z-0+{lJ6bn0k#!31)=k^HPTlP2xLsXlrlzE>U)s^(&$+8QI`@Tn3$RhJ-A@L*TnjiI zpXE09K$$W-Pti+fKffvLTH1n+r_cQe1n&3J&bihBK5aZwF9&!6FR=Ps+LaxC?A@}f z>wuF2pmSN??zCoKUfTVxXoqXRPgbU2+|NhpKee|5_pK>rRj-RbcFy(%WKJO2{Hp2e zqZ!{;T#D*;OPMab@?%hP-rUgb)q8*F0ncC&TE1JkHm3R_e;8=Bk{)oi(!Pgtpj+># zoDv8ahq}&$fMP7tj7Ot@_f(wuVf9n7_vy2kl%ksaMdhaUKW2Vf|E0{m>-e!1@0aED z`_J;P{#_ycS+d&n&)!wXw8iYE{m7aU@nWu4_gT#oS3X^pJ@V;wAzy4cbIPaq7qx{s z&wbU5*elG;SM7sm|MB=YSwpY-QKBd%BuF4)@+HpooLRa4Ll5Cy2lN}sBJe_y`HUcy;QzE}G4oT7~xFYbX( zJD-@&nF4IFfdFVTlU(_cuI>Xzi?;h`b)SURtiW>^bV|?Nym<8~L>;|Jjg@+{krK# zcvRlUm?N{?{>1yd6kN6XzVt-7xu@p%?0h)QOk^6=2Ud5E1WN<2v)yHB$?COhRs*FT zBTqlOsNV$(itT2R-yJQyWP6bOx|!n4tKUXlJ@#t1*`<_{`n%goT=ToGt=H3d_Gg{b zvK=`q;u-fuH*c!+wiVqUW}Ipe?6Kj&cBPB51^r0{YtAjwSusa6t5Z98cKn(9Gi%NJ zq9=BpPBz~0+Gn5CKb~cJ|4gQx`*-st=xUy+>++d|c7Q#t8(H&Cm@((|o@Y^)1#^zA zo|e6HCUBpaRjF3^4QbVV6T+&`T)Q9Pv(2hVr*HeoRf}A+yBkkRPrsXh^ z-{tZ9#N@x4&*UxHYr(7De|wJ46}Kmw`d;sHv$e34R?^;~{zu@R;r#Mx*Q6eh7tR#x zVmunW1$G7m`Gzs3oqzd8ZROF}2VeR0?i+UO%lAFod%9}IyQhBFfQN~6bI1XqNv3o5Ok+rrnjHUP zuflQrpsZ}3;Ms>?E}1H8wSJLUscqeXmEE;2iq+4OWhd{PEWKSy-*lakOvK5V+zYq6 zf67`b_t4mQ<$Z0a4KWydL5eOK?f^(N#>`Q_Vz-#a>QhW%LY8h<-~1#qzE zy#1$Lk8C!+_;y##J2I{4)_b*euO>zRyes3i`sm3^SHo9necw|M_xk5Us|O|PW?%aD zcI)LG+A=!2UO|`G+@AhjzNpmt*0PK z_ZEj=e6(S{J?21_v_wHZYtKx-?;hJoPJCF zqR&<##j8J7_`Xc~9q7(;y=+zC#^X00>)y-+O=w4LZq{A9I45waMM1Wpz;*4)su#dR z{20n84iK^pps)oGwU_b58%75(o9_TrXaJ~Z?5ti;XHdcRH&if#TqCH_G=SO7o&aMF z08MGjAKA&)$Q-(}HCC`w$B#G zC{-#&2G)!P;Y;`&=;mtd7BL7@l>9fKrFpn=Kg>OlHX0ORSU4r>Lt z8U{&(z@0%xu{;Q)1Qs)-byP)|r+bJlVx+MAg9jzG8N@e`8KX2rUoveO6ooLZP$07J zqU{=>eTg+=5S3k6Jw#MhvsTn$y?=%1A_eFf9av2o9D)R!{-TQ-^N00Z5a|t4B>vnB_aqhFpKMAb;EjK5mrt_8OE_W^~pU>v*&*G@7KAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ", - "thumb": "http://imgur.com/hegi9dZ.png", - "featured": true, - "i": 0 - }, - { - "name": "glsl.io", - "link": "http://glsl.io/", - "desc": "", - "thumb": "http://imgur.com/56SPiLL.png", - "featured": false, - "i": 1 - }, - { - "name": "kami", - "link": "https://github.com/mattdesl/kami", - "desc": "", - "thumb": "http://imgur.com/j5W3Tuw.png", - "featured": false, - "i": 2 - }, - { - "name": "run.south.im", - "link": "http://run.south.im/", - "desc": "", - "thumb": "http://imgur.com/kZjW5QD.png", - "featured": false, - "i": 3 - }, - { - "name": "nodesource.com", - "link": "http://nodesource.com/", - "desc": "", - "thumb": "http://imgur.com/tCKuJfx.png", - "featured": false, - "i": 4 - }, - { - "name": "voxel-mipmap-demo", - "link": "https://github.com/mikolalysenko/voxel-mipmap-demo/", - "desc": "", - "thumb": "http://imgur.com/9eUBmfB.png", - "featured": false, - "i": 5 - }, - { - "name": "raymarch", - "link": "https://github.com/mikolalysenko/raymarch/", - "desc": "", - "thumb": "http://imgur.com/NpvsXIH.png", - "featured": false, - "i": 6 - }, - { - "name": "moire #1", - "link": "http://hughsk.io/moire-1", - "desc": "", - "thumb": "http://imgur.com/9tbJfnF.png", - "featured": false, - "i": 7 - }, - { - "name": "campjs.com", - "link": "http://campjs.com/", - "desc": "", - "thumb": "http://imgur.com/d47Vesp.png", - "featured": false, - "i": 8 - }, - { - "name": "particle-excess-demo", - "link": "https://github.com/hughsk/particle-excess-demo/", - "desc": "", - "thumb": "http://imgur.com/YyrtLqM.png", - "featured": false, - "i": 9 - }, - { - "name": "web-audio-analyser", - "link": "https://github.com/hughsk/web-audio-analyser/", - "desc": "", - "thumb": "http://imgur.com/xhPfMFP.png", - "featured": false, - "i": 10 - } -] -},{}],2:[function(require,module,exports){ -module.exports={ - "WebGL Core": [ - { - "name": "gl-vao", - "desc": "\n", - "link": "http://ghub.io/gl-vao", - "thumb": "http://imgur.com/iv3pOSh.png", - "featured": false, - "i": 0 - }, - { - "name": "gl-fbo", - "desc": "\n", - "link": "http://ghub.io/gl-fbo", - "thumb": "http://imgur.com/xiXCQGN.png", - "featured": false, - "i": 1 - }, - { - "name": "gl-texture2d", - "desc": "\n", - "link": "http://ghub.io/gl-texture2d", - "thumb": "http://imgur.com/ZkcCvzx.jpg", - "featured": false, - "i": 2 - }, - { - "name": "gl-buffer", - "desc": "\n", - "link": "http://ghub.io/gl-buffer", - "thumb": "http://imgur.com/JFZGJBx.png", - "featured": false, - "i": 3 - } - ], - "Tools": [ - { - "name": "glslify", - "desc": "\n", - "link": "http://ghub.io/glslify", - "thumb": "http://imgur.com/ThMYeUx.png", - "featured": false, - "i": 0 - }, - { - "name": "glslify-live", - "desc": "\n", - "link": "http://ghub.io/glslify-live", - "thumb": "http://imgur.com/9mmysos.png", - "featured": false, - "i": 1 - }, - { - "name": "glslify-optimize", - "desc": "\n", - "link": "http://ghub.io/glslify-optimize", - "thumb": "http://imgur.com/pF9tmNg.png", - "featured": false, - "i": 2 - } - ], - "Math": [ - { - "name": "gl-mat2", - "desc": "", - "link": "http://ghub.io/gl-mat2", - "thumb": "default.jpg", - "featured": false, - "i": 0 - }, - { - "name": "gl-mat3", - "desc": "", - "link": "http://ghub.io/gl-mat3", - "thumb": "default.jpg", - "featured": false, - "i": 1 - }, - { - "name": "gl-mat4", - "desc": "", - "link": "http://ghub.io/gl-mat4", - "thumb": "default.jpg", - "featured": false, - "i": 2 - }, - { - "name": "gl-matrix", - "desc": "", - "link": "http://ghub.io/gl-matrix", - "thumb": "default.jpg", - "featured": false, - "i": 3 - } - ], - "Camera Controls": [ - { - "name": "turntable-camera", - "desc": "\n", - "link": "http://ghub.io/turntable-camera", - "thumb": "http://imgur.com/3wiGD3K.png", - "featured": false, - "i": 0 - }, - { - "name": "orbit-camera", - "desc": "\n", - "link": "http://ghub.io/orbit-camera", - "thumb": "http://imgur.com/BPkl0Yh.png", - "featured": false, - "i": 1 - }, - { - "name": "game-shell-orbit-camera", - "desc": "\n", - "link": "http://ghub.io/game-shell-orbit-camera", - "thumb": "http://imgur.com/BPkl0Yh.png", - "featured": false, - "i": 2 - }, - { - "name": "canvas-orbit-camera", - "desc": "\n", - "link": "http://ghub.io/canvas-orbit-camera", - "thumb": "http://imgur.com/BPkl0Yh.png", - "featured": false, - "i": 3 - } - ], - "Initialization": [ - { - "name": "gl-now", - "desc": "", - "link": "http://ghub.io/gl-now", - "thumb": "default.jpg", - "featured": false, - "i": 0 - }, - { - "name": "gl-context", - "desc": "", - "link": "http://ghub.io/gl-context", - "thumb": "default.jpg", - "featured": false, - "i": 1 - } - ], - "Input": [ - { - "name": "key-pressed", - "desc": "", - "link": "http://ghub.io/key-pressed", - "thumb": "default.jpg", - "featured": false, - "i": 0 - }, - { - "name": "mouse-pressed", - "desc": "", - "link": "http://ghub.io/mouse-pressed", - "thumb": "default.jpg", - "featured": false, - "i": 1 - }, - { - "name": "mouse-speed", - "desc": "", - "link": "http://ghub.io/mouse-speed", - "thumb": "default.jpg", - "featured": false, - "i": 2 - }, - { - "name": "scroll-speed", - "desc": "", - "link": "http://ghub.io/scroll-speed", - "thumb": "default.jpg", - "featured": false, - "i": 3 - }, - { - "name": "canvas-fit", - "desc": "", - "link": "http://ghub.io/canvas-fit", - "thumb": "default.jpg", - "featured": false, - "i": 4 - }, - { - "name": "vkey", - "desc": "", - "link": "http://ghub.io/vkey", - "thumb": "default.jpg", - "featured": false, - "i": 5 - } - ], - "Shader Components": [ - { - "name": "glsl-luma", - "desc": "\n", - "link": "http://ghub.io/glsl-luma", - "thumb": "http://imgur.com/SRxqxj2.png", - "featured": false, - "i": 0 - }, - { - "name": "glsl-dither", - "desc": "\n", - "link": "http://ghub.io/glsl-dither", - "thumb": "http://imgur.com/D4ccYiJ.png", - "featured": false, - "i": 1 - }, - { - "name": "glsl-noise", - "desc": "\n", - "link": "http://ghub.io/glsl-noise", - "thumb": "http://imgur.com/BFITCvl.jpg", - "featured": false, - "i": 2 - }, - { - "name": "glsl-curl-noise", - "desc": "\n", - "link": "http://ghub.io/glsl-curl-noise", - "thumb": "http://imgur.com/ABlBkoE.png", - "featured": false, - "i": 3 - }, - { - "name": "glsl-random", - "desc": "\n", - "link": "http://ghub.io/glsl-random", - "thumb": "http://imgur.com/9EOo2or.png", - "featured": false, - "i": 4 - }, - { - "name": "glsl-fog", - "desc": "\n", - "link": "http://ghub.io/glsl-fog", - "thumb": "http://imgur.com/8l0otem.png", - "featured": false, - "i": 5 - } - ], - "Shader Transforms": [ - { - "name": "glslify-hex", - "desc": "\n", - "link": "http://ghub.io/glslify-hex", - "thumb": "http://imgur.com/Dh8CPE9.png", - "featured": false, - "i": 0 - }, - { - "name": "glslify-import", - "desc": "\n", - "link": "http://ghub.io/glslify-import", - "thumb": "http://imgur.com/7trTmBF.png", - "featured": false, - "i": 1 - } - ], - "Visualisation": [ - { - "name": "gl-compare", - "desc": "\n", - "link": "http://ghub.io/gl-compare", - "thumb": "http://imgur.com/z8BkmZl.jpg", - "featured": false, - "i": 0 - } - ], - "Internals": [ - { - "name": "glsl-parser", - "desc": "", - "link": "http://ghub.io/glsl-parser", - "thumb": "default.jpg", - "featured": false, - "i": 0 - }, - { - "name": "glsl-tokenizer", - "desc": "", - "link": "http://ghub.io/glsl-tokenizer", - "thumb": "default.jpg", - "featured": false, - "i": 1 - }, - { - "name": "glsl-deparser", - "desc": "", - "link": "http://ghub.io/glsl-deparser", - "thumb": "default.jpg", - "featured": false, - "i": 2 - }, - { - "name": "glsl-extract", - "desc": "", - "link": "http://ghub.io/glsl-extract", - "thumb": "default.jpg", - "featured": false, - "i": 3 - }, - { - "name": "glslify-stream", - "desc": "", - "link": "http://ghub.io/glslify-stream", - "thumb": "default.jpg", - "featured": false, - "i": 4 - }, - { - "name": "gl-shader-core", - "desc": "", - "link": "http://ghub.io/gl-shader-core", - "thumb": "default.jpg", - "featured": false, - "i": 5 - } - ], - "Assets": [ - { - "name": "lena", - "desc": "\n", - "link": "http://ghub.io/lena", - "thumb": "http://imgur.com/eSx2pBu.png", - "featured": false, - "i": 0 - }, - { - "name": "baboon-image", - "desc": "\n", - "link": "http://ghub.io/baboon-image", - "thumb": "http://imgur.com/63yazJ1.png", - "featured": false, - "i": 1 - }, - { - "name": "bunny", - "desc": "\n", - "link": "http://ghub.io/bunny", - "thumb": "http://imgur.com/5VIykyD.png", - "featured": false, - "i": 2 - }, - { - "name": "teapot", - "desc": "", - "link": "http://ghub.io/teapot", - "thumb": "default.jpg", - "featured": false, - "i": 3 - }, - { - "name": "stanford-dragon", - "desc": "\n", - "link": "http://ghub.io/stanford-dragon", - "thumb": "http://imgur.com/XWYMq6J.png", - "featured": false, - "i": 4 - } - ] -} -},{}],3:[function(require,module,exports){ -var filter = require('./lib/filter') -var minstache = require('minstache') -var domify = require('domify') -var slice = require('sliced') -var grid = document.getElementById('grid').querySelector('canvas') -var flock = document.getElementById('community').querySelector('canvas') - -require('./lib/fill')(document.querySelectorAll('[data-fill]')) -require('@stackgl/splash-grid')(grid) -require('@stackgl/splash-flock')(flock) - -var thumb = minstache.compile("
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n") - -var examples = require('./build/examples.json').map(function(meta) { - return thumb(meta) -}).join('\n') - -var packages = require('./build/packages.json') - -packages = Object.keys(packages).reduce(function(pkgs, group) { - return pkgs.concat(packages[group].map(function(pkg) { - pkg.group = group - return pkg - })) -}, []).map(function(meta) { - return thumb(meta) -}).join('\n') - -document - .getElementById('examples') - .querySelector('ul.thumb-list') - .appendChild(domify(examples)) - -var pkgEl = document.getElementById('packages') - -pkgEl - .querySelector('ul.thumb-list') - .appendChild(domify(packages)) - -pkgEl - .querySelector('ul.thumb-filter') - .appendChild(filter(pkgEl)) - -},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,"domify":182,"minstache":186,"sliced":187}],4:[function(require,module,exports){ -var debounce = require('frame-debounce') - -module.exports = fill - -function fill(elements) { - refill() - window.addEventListener('resize' - , debounce(refill) - , false - ) - - function refill() { - var width = window.innerWidth + 'px' - var height = window.innerHeight + 'px' - - for (var i = 0; i < elements.length; i++) { - var s = elements[i].style - s.width = width - s.minHeight = height - } - } -} - -},{"frame-debounce":184}],5:[function(require,module,exports){ -var findup = require('findup-element') -var minstache = require('minstache') -var domify = require('domify') -var slice = require('sliced') -var all = 'All Packages' -var template = minstache.compile("{{#category}}\n
    • {{name}}
    • \n{{/category}}\n") - -module.exports = function(thumbs) { - var filtered = slice(thumbs.querySelectorAll('[data-filter]')) - - var categories = filtered.reduce(function(categories, el) { - var cat = el.getAttribute('data-filter') - if (categories.indexOf(cat) === -1) categories.push(cat) - return categories - }, []) - - categories.unshift(all) - categories = categories.map(function(name) { - return { name: name } - }) - - var list = domify(template({ category: categories })) - var prev = list.children[0] - - prev.setAttribute('class', 'selected') - slice(list.children).forEach(function(child) { - var name = child.getAttribute('data-name') - - child.addEventListener('click', function(e) { - e.preventDefault() - e.stopPropagation() - var target = findup(e.target, 'li') - if (target !== child) return false - - prev.setAttribute('class', '') - prev = target - prev.setAttribute('class', 'selected') - for (var i = 0; i < filtered.length; i++) { - filtered[i].style.display = ( - name === all || - name === filtered[i].getAttribute('data-filter') - ) ? 'block' - : 'none' - } - - return false - }, false) - }) - - return list -} - -},{"domify":182,"findup-element":183,"minstache":186,"sliced":187}],6:[function(require,module,exports){ -module.exports=require('ndpack-image')(16,16,4,"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAklEQVR4AewaftIAAAHfSURBVKXBcW+aQBjA4R94vsBR72Cl1Jr1+3+qJjYuuDo3hQnIiXYjoYlpmvSPPo/3+h9f4PNFig8452ialq7ruFx6fH9CEIRoHSEiXFO887eq+LPbsS/3NHXNqT+jlCKONYlN+JamzIzhjeJKVVW8bF5YFz/ZbF4oyz3OnRARrLXk+T3OOV7xMGbGQDFyzrHb7VkXa5bLJavVit/bLceuIwgDsts7mqbB4xURIQwDRATFqGlbynLPZrNh9WPF09MTRVHQNi2RjlgsSgZaa4y1WGsRERSj7njkcDhQliXbX1uKomD5/ExVlhhjwANrLfP5PXVd4zrHQDG6XC705x7nHF3X0bYtVVmyXq8Bj7Zp6I4dzp3o+zPny5mBYjTxfdREMZUpQRAQRRHWGPDAmhlaxwRRgMgUpSZMfJ+BYiRhyM1NTGITsixjsViAB23donXEw8MDd7cZ1lriOEbCgIFipKMIaxPyPKdpGjw8rLV03ZEgCMmyjO+Pj+T5PWmSoiPNQDESEdI0xbkT4KG1Jp/nnNyJqUxJbEKe5ywWc5I0RUQYKK4YYxiITEms4VDX9H2PUlPiWJMkCWmaYsyMN4p3jDGEYUhiLUfnuJzP+L5PGIZEUYSIcE3xARFBRLB87h/fHcFMratoHAAAAABJRU5ErkJggg==") - -},{"ndpack-image":88}],7:[function(require,module,exports){ -var clear = require("gl-clear")({ - color: [1, 1, 1, 1] -}); - -var triangle = require("a-big-triangle"); -var debounce = require("frame-debounce"); -var fit = require("canvas-fit"); -var createBuffer = require("gl-buffer"); -var ndarray = require("ndarray"); -var Shader = require("glslify"); -var FBO = require("gl-fbo"); -var VAO = require("gl-vao"); -var SIZE = 32; -var STEPS = 2; -module.exports = init; - -function init(canvas) { - var gl = require("gl-context")(canvas, render); - var boid = require("gl-texture2d")(gl, require("./boid")); - var vao = createParticleVAO(gl, SIZE); - var shaders = {}; - var pdata = []; - var starter = createStartPositions(SIZE); - - for (var i = 0; i < STEPS; i++) { - pdata[i] = FBO(gl, [SIZE, SIZE], { - float: true - }); - - pdata[i].color[0].setPixels(starter); - } - - window.addEventListener("resize", debounce(fit(canvas, window))); - shaders.logic = require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}", "\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}", [{"name":"positions","type":"sampler2D"}], [{"name":"position","type":"vec2"}])(gl); - shaders.render = require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}", "\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}", [{"name":"positions","type":"sampler2D"},{"name":"screenSize","type":"vec2"},{"name":"tex","type":"sampler2D"}], [{"name":"uv","type":"vec2"}])(gl); - - function render() { - var width = canvas.width; - var height = canvas.height; - gl.disable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - gl.disable(gl.BLEND); - pdata[0].bind(); - gl.viewport(0, 0, width, height); - shaders.logic.bind(); - shaders.logic.uniforms.positions = pdata[1].color[0].bind(0); - triangle(gl); - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - gl.viewport(0, 0, width, height); - clear(gl); - gl.enable(gl.BLEND); - gl.blendFunc(gl.DST_COLOR, gl.ZERO); - shaders.render.bind(); - shaders.render.uniforms.positions = pdata[0].color[0].bind(0); - shaders.render.uniforms.tex = boid.bind(1); - shaders.render.uniforms.screenSize = [width, height]; - vao.bind(); - vao.draw(gl.POINTS, vao.length); - switchFrames(pdata); - } -} - -function switchFrames(data) { - data.push(data.shift()); - return data; -} - -function createParticleVAO(gl, size) { - var data = new Float32Array(size * size); - var n = 0; - - for (var x = 0; x < size; x++) for (var y = 0; y < size; y++) { - data[n++] = x / size; - data[n++] = y / size; - } - - var buffer = createBuffer(gl, data); - - var vao = VAO(gl, [{ - buffer: buffer, - type: gl.FLOAT, - size: 2 - }]); - - vao.length = data.length / 2; - return vao; -} - -function createStartPositions(size) { - var data = new Float32Array(size * size * 4); - - for (var i = 0; i < data.length; ) { - data[i++] = Math.random() - 0.5; - data[i++] = Math.random() - 0.5; - data[i++] = Math.random() * 0.1 - 0.05; - data[i++] = Math.random() * 0.1 - 0.05; - } - - return ndarray(data, [size, size, 4]); -} -},{"./boid":6,"a-big-triangle":24,"canvas-fit":25,"frame-debounce":27,"gl-buffer":31,"gl-clear":45,"gl-context":46,"gl-fbo":48,"gl-texture2d":72,"gl-vao":78,"glslify":80,"glslify/adapter.js":79,"ndarray":86}],8:[function(require,module,exports){ -"use strict" - -var pool = require("typedarray-pool") -var ops = require("ndarray-ops") -var ndarray = require("ndarray") - -function GLBuffer(gl, type, handle, length, usage) { - this.gl = gl - this.type = type - this.handle = handle - this.length = length - this.usage = usage -} - -GLBuffer.prototype.bind = function() { - this.gl.bindBuffer(this.type, this.handle) -} - -GLBuffer.prototype.dispose = function() { - this.gl.deleteBuffer(this.handle) -} - -function updateTypeArray(gl, type, len, usage, data, offset) { - if(offset <= 0 && data.length > len) { - gl.bufferData(type, data, usage) - return data.length - } - if(data.length + offset > len) { - throw new Error("gl-buffer: If resizing buffer, offset must be 0") - } - gl.bufferSubData(type, offset, data) - return len -} - -function makeScratchTypeArray(array, dtype) { - var res = pool.malloc(array.length, dtype) - var n = array.length - for(var i=0; i 0) { - throw new Error("gl-buffer: Cannot specify offset when resizing buffer") - } - this.gl.bufferData(this.type, array, this.usage) - this.length = array - } else if(array.shape) { - var dtype = array.dtype - if(dtype === "float64" || dtype === "array" || dtype === "generic") { - dtype = "float32" - } - if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) { - dtype = "uint16" - } - if(array.shape.length !== 1) { - throw new Error("gl-buffer: Array length must be 1") - } - if(dtype === array.dtype && array.stride[0] === 1) { - if(array.offset === 0 && array.data.length === array.shape[0]) { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data, offset) - } else { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data.subarray(array.offset, array.shape[0]), offset) - } - } else { - var tmp = pool.malloc(array.shape[0], dtype) - var ndt = ndarray(tmp) - ops.assign(ndt, array) - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, tmp, offset) - pool.free(tmp) - } - } else if(Array.isArray(array)) { - if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) { - var t = makeScratchTypeArray(array, "uint16") - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t.subarray(0, array.length), offset) - pool.freeUint16(t) - } else { - var t = makeScratchTypeArray(array, "float32") - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t.subarray(0, array.length), offset) - pool.freeFloat32(t) - } - } else { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array, offset) - } -} - -GLBuffer.prototype.draw = function(mode, count, offset) { - offset = offset || 0 - var gl = this.gl - if(this.type === gl.ARRAY_BUFFER) { - gl.drawArrays(mode, offset, count) - } else if(this.type === gl.ELEMENT_ARRAY_BUFFER) { - this.bind() - gl.drawElements(mode, count, gl.UNSIGNED_SHORT, offset) - } else { - throw new Error("Invalid type for WebGL buffer") - } -} - -function createBuffer(gl, type, data, usage) { - if(data === undefined) { - data = type - type = gl.ARRAY_BUFFER - } - if(!usage) { - usage = gl.DYNAMIC_DRAW - } - var len = 0 - var handle = gl.createBuffer() - gl.bindBuffer(type, handle) - if(typeof data === "number") { - gl.bufferData(type, data, usage) - len = data - } else if(data instanceof Array) { - if(type === gl.ELEMENT_ARRAY_BUFFER) { - gl.bufferData(type, new Uint16Array(data), usage) - } else { - gl.bufferData(type, new Float32Array(data), usage) - } - len = data.length - } else if(data.length) { - gl.bufferData(type, data, usage) - len = data.length - } else if(data.shape) { - var dtype = data.dtype - if(dtype === "float64" || dtype === "array" || dtype === "generic") { - dtype = "float32" - } - if(type === gl.ELEMENT_ARRAY_BUFFER) { - dtype = "uint16" - } - if(data.shape.length !== 1) { - throw new Error("gl-buffer: Array shape must be 1D") - } - var len = data.shape[0] - if(dtype === data.type && data.stride[0] === 1) { - gl.bufferData(type, data.data.subarray(data.offset, data.offset+len), usage) - } else { - var tmp = pool.malloc(data.shape[0], dtype) - var ndt = ndarray(tmp) - ops.assign(ndt, data) - gl.bufferData(type, tmp, usage) - pool.free(tmp) - } - } else { - throw new Error("gl-buffer: Invalid format for buffer data") - } - if(type !== gl.ARRAY_BUFFER && type !== gl.ELEMENT_ARRAY_BUFFER) { - throw new Error("gl-buffer: Invalid type for webgl buffer") - } - if(usage !== gl.DYNAMIC_DRAW && usage !== gl.STATIC_DRAW && usage !== gl.STREAM_DRAW) { - throw new Error("gl-buffer: Invalid usage for buffer") - } - return new GLBuffer(gl, type, handle, len, usage) -} - -module.exports = createBuffer -},{"ndarray":14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){ -"use strict" - -var compile = require("cwise-compiler") - -var EmptyProc = { - body: "", - args: [], - thisVars: [], - localVars: [] -} - -function fixup(x) { - if(!x) { - return EmptyProc - } - for(var i=0; i>", - rrshift: ">>>" -} -;(function(){ - for(var id in assign_ops) { - var op = assign_ops[id] - exports[id] = makeOp({ - args: ["array","array","array"], - body: {args:["a","b","c"], - body: "a=b"+op+"c"}, - funcName: id - }) - exports[id+"eq"] = makeOp({ - args: ["array","array"], - body: {args:["a","b"], - body:"a"+op+"=b"}, - rvalue: true, - funcName: id+"eq" - }) - exports[id+"s"] = makeOp({ - args: ["array", "array", "scalar"], - body: {args:["a","b","s"], - body:"a=b"+op+"s"}, - funcName: id+"s" - }) - exports[id+"seq"] = makeOp({ - args: ["array","scalar"], - body: {args:["a","s"], - body:"a"+op+"=s"}, - rvalue: true, - funcName: id+"seq" - }) - } -})(); - -var unary_ops = { - not: "!", - bnot: "~", - neg: "-", - recip: "1.0/" -} -;(function(){ - for(var id in unary_ops) { - var op = unary_ops[id] - exports[id] = makeOp({ - args: ["array", "array"], - body: {args:["a","b"], - body:"a="+op+"b"}, - funcName: id - }) - exports[id+"eq"] = makeOp({ - args: ["array"], - body: {args:["a"], - body:"a="+op+"a"}, - rvalue: true, - count: 2, - funcName: id+"eq" - }) - } -})(); - -var binary_ops = { - and: "&&", - or: "||", - eq: "===", - neq: "!==", - lt: "<", - gt: ">", - leq: "<=", - geq: ">=" -} -;(function() { - for(var id in binary_ops) { - var op = binary_ops[id] - exports[id] = makeOp({ - args: ["array","array","array"], - body: {args:["a", "b", "c"], - body:"a=b"+op+"c"}, - funcName: id - }) - exports[id+"s"] = makeOp({ - args: ["array","array","scalar"], - body: {args:["a", "b", "s"], - body:"a=b"+op+"s"}, - funcName: id+"s" - }) - exports[id+"eq"] = makeOp({ - args: ["array", "array"], - body: {args:["a", "b"], - body:"a=a"+op+"b"}, - rvalue:true, - count:2, - funcName: id+"eq" - }) - exports[id+"seq"] = makeOp({ - args: ["array", "scalar"], - body: {args:["a","s"], - body:"a=a"+op+"s"}, - rvalue:true, - count:2, - funcName: id+"seq" - }) - } -})(); - -var math_unary = [ - "abs", - "acos", - "asin", - "atan", - "ceil", - "cos", - "exp", - "floor", - "log", - "round", - "sin", - "sqrt", - "tan" -] -;(function() { - for(var i=0; ithis_s){this_s=-a}else if(a>this_s){this_s=a}", localVars: [], thisVars: ["this_s"]}, - post: {args:[], localVars:[], thisVars:["this_s"], body:"return this_s"}, - funcName: "norminf" -}) - -exports.norm1 = compile({ - args:["array"], - pre: {args:[], localVars:[], thisVars:["this_s"], body:"this_s=0"}, - body: {args:[{name:"a", lvalue:false, rvalue:true, count:3}], body: "this_s+=a<0?-a:a", localVars: [], thisVars: ["this_s"]}, - post: {args:[], localVars:[], thisVars:["this_s"], body:"return this_s"}, - funcName: "norm1" -}) - -exports.sup = compile({ - args: [ "array" ], - pre: - { body: "this_h=-Infinity", - args: [], - thisVars: [ "this_h" ], - localVars: [] }, - body: - { body: "if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_", - args: [{"name":"_inline_1_arg0_","lvalue":false,"rvalue":true,"count":2} ], - thisVars: [ "this_h" ], - localVars: [] }, - post: - { body: "return this_h", - args: [], - thisVars: [ "this_h" ], - localVars: [] } - }) - -exports.inf = compile({ - args: [ "array" ], - pre: - { body: "this_h=Infinity", - args: [], - thisVars: [ "this_h" ], - localVars: [] }, - body: - { body: "if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}", - args:[ - {name:"_inline_1_arg0_",lvalue:false,rvalue:true,count:2}, - {name:"_inline_1_arg1_",lvalue:false,rvalue:true,count:2}], - thisVars:["this_i","this_v"], - localVars:["_inline_1_k"]}, - post:{ - body:"{return this_i}", - args:[], - thisVars:["this_i"], - localVars:[]} -}) - -exports.random = makeOp({ - args: ["array"], - pre: {args:[], body:"this_f=Math.random", thisVars:["this_f"]}, - body: {args: ["a"], body:"a=this_f()", thisVars:["this_f"]}, - funcName: "random" -}) - -exports.assign = makeOp({ - args:["array", "array"], - body: {args:["a", "b"], body:"a=b"}, - funcName: "assign" }) - -exports.assigns = makeOp({ - args:["array", "scalar"], - body: {args:["a", "b"], body:"a=b"}, - funcName: "assigns" }) - - -exports.equals = compile({ - args:["array", "array"], - pre: EmptyProc, - body: {args:[{name:"x", lvalue:false, rvalue:true, count:1}, - {name:"y", lvalue:false, rvalue:true, count:1}], - body: "if(x!==y){return false}", - localVars: [], - thisVars: []}, - post: {args:[], localVars:[], thisVars:[], body:"return true"}, - funcName: "equals" -}) - - - -},{"cwise-compiler":10}],10:[function(require,module,exports){ -"use strict" - -var createThunk = require("./lib/thunk.js") - -function Procedure() { - this.argTypes = [] - this.shimArgs = [] - this.arrayArgs = [] - this.scalarArgs = [] - this.offsetArgs = [] - this.offsetArgIndex = [] - this.indexArgs = [] - this.shapeArgs = [] - this.funcName = "" - this.pre = null - this.body = null - this.post = null - this.debug = false -} - -function compileCwise(user_args) { - //Create procedure - var proc = new Procedure() - - //Parse blocks - proc.pre = user_args.pre - proc.body = user_args.body - proc.post = user_args.post - - //Parse arguments - var proc_args = user_args.args.slice(0) - proc.argTypes = proc_args - for(var i=0; i0) { - throw new Error("cwise: pre() block may not reference array args") - } - if(i < proc.post.args.length && proc.post.args[i].count>0) { - throw new Error("cwise: post() block may not reference array args") - } - } else if(arg_type === "scalar") { - proc.scalarArgs.push(i) - proc.shimArgs.push("scalar" + i) - } else if(arg_type === "index") { - proc.indexArgs.push(i) - if(i < proc.pre.args.length && proc.pre.args[i].count > 0) { - throw new Error("cwise: pre() block may not reference array index") - } - if(i < proc.body.args.length && proc.body.args[i].lvalue) { - throw new Error("cwise: body() block may not write to array index") - } - if(i < proc.post.args.length && proc.post.args[i].count > 0) { - throw new Error("cwise: post() block may not reference array index") - } - } else if(arg_type === "shape") { - proc.shapeArgs.push(i) - if(i < proc.pre.args.length && proc.pre.args[i].lvalue) { - throw new Error("cwise: pre() block may not write to array shape") - } - if(i < proc.body.args.length && proc.body.args[i].lvalue) { - throw new Error("cwise: body() block may not write to array shape") - } - if(i < proc.post.args.length && proc.post.args[i].lvalue) { - throw new Error("cwise: post() block may not write to array shape") - } - } else if(typeof arg_type === "object" && arg_type.offset) { - proc.argTypes[i] = "offset" - proc.offsetArgs.push({ array: arg_type.array, offset:arg_type.offset }) - proc.offsetArgIndex.push(i) - } else { - throw new Error("cwise: Unknown argument type " + proc_args[i]) - } - } - - //Make sure at least one array argument was specified - if(proc.arrayArgs.length <= 0) { - throw new Error("cwise: No array arguments specified") - } - - //Make sure arguments are correct - if(proc.pre.args.length > proc_args.length) { - throw new Error("cwise: Too many arguments in pre() block") - } - if(proc.body.args.length > proc_args.length) { - throw new Error("cwise: Too many arguments in body() block") - } - if(proc.post.args.length > proc_args.length) { - throw new Error("cwise: Too many arguments in post() block") - } - - //Check debug flag - proc.debug = !!user_args.printCode || !!user_args.debug - - //Retrieve name - proc.funcName = user_args.funcName || "cwise" - - //Read in block size - proc.blockSize = user_args.blockSize || 64 - - return createThunk(proc) -} - -module.exports = compileCwise - -},{"./lib/thunk.js":12}],11:[function(require,module,exports){ -"use strict" - -var uniq = require("uniq") - -function innerFill(order, proc, body) { - var dimension = order.length - , nargs = proc.arrayArgs.length - , has_index = proc.indexArgs.length>0 - , code = [] - , vars = [] - , idx=0, pidx=0, i, j - for(i=0; i=0; --i) { - idx = order[i] - code.push(["for(i",i,"=0;i",i," 0) { - code.push(["index[",pidx,"]-=s",pidx].join("")) - } - code.push(["++index[",idx,"]"].join("")) - } - code.push("}") - } - return code.join("\n") -} - -function outerFill(matched, order, proc, body) { - var dimension = order.length - , nargs = proc.arrayArgs.length - , blockSize = proc.blockSize - , has_index = proc.indexArgs.length > 0 - , code = [] - for(var i=0; i0;){"].join("")) - code.push(["if(j",i,"<",blockSize,"){"].join("")) - code.push(["s",order[i],"=j",i].join("")) - code.push(["j",i,"=0"].join("")) - code.push(["}else{s",order[i],"=",blockSize].join("")) - code.push(["j",i,"-=",blockSize,"}"].join("")) - if(has_index) { - code.push(["index[",order[i],"]=j",i].join("")) - } - } - for(var i=0; i 0) { - allEqual = allEqual && summary[i] === summary[i-1] - } - } - if(allEqual) { - return summary[0] - } - return summary.join("") -} - -//Generates a cwise operator -function generateCWiseOp(proc, typesig) { - - //Compute dimension - var dimension = typesig[1].length|0 - var orders = new Array(proc.arrayArgs.length) - var dtypes = new Array(proc.arrayArgs.length) - - //First create arguments for procedure - var arglist = ["SS"] - var code = ["'use strict'"] - var vars = [] - - for(var j=0; j 0) { - vars.push("shape=SS.slice(0)") - } - if(proc.indexArgs.length > 0) { - var zeros = new Array(dimension) - for(var i=0; i 3) { - code.push(processBlock(proc.pre, proc, dtypes)) - } - - //Process body - var body = processBlock(proc.body, proc, dtypes) - var matched = countMatches(orders) - if(matched < dimension) { - code.push(outerFill(matched, orders[0], proc, body)) - } else { - code.push(innerFill(orders[0], proc, body)) - } - - //Inline epilog - if(proc.post.body.length > 3) { - code.push(processBlock(proc.post, proc, dtypes)) - } - - if(proc.debug) { - console.log("Generated cwise routine for ", typesig, ":\n\n", code.join("\n")) - } - - var loopName = [(proc.funcName||"unnamed"), "_cwise_loop_", orders[0].join("s"),"m",matched,typeSummary(dtypes)].join("") - var f = new Function(["function ",loopName,"(", arglist.join(","),"){", code.join("\n"),"} return ", loopName].join("")) - return f() -} -module.exports = generateCWiseOp -},{"uniq":13}],12:[function(require,module,exports){ -"use strict" - -var compile = require("./compile.js") - -function createThunk(proc) { - var code = ["'use strict'", "var CACHED={}"] - var vars = [] - var thunkName = proc.funcName + "_cwise_thunk" - - //Build thunk - code.push(["return function ", thunkName, "(", proc.shimArgs.join(","), "){"].join("")) - var typesig = [] - var string_typesig = [] - var proc_args = [["array",proc.arrayArgs[0],".shape"].join("")] - for(var i=0; iMath.abs(this._stride1))?[1,0]:[0,1]}})") - } else if(dimension === 3) { - code.push( -"var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);\ -if(s0>s1){\ -if(s1>s2){\ -return [2,1,0];\ -}else if(s0>s2){\ -return [1,2,0];\ -}else{\ -return [1,0,2];\ -}\ -}else if(s0>s2){\ -return [2,0,1];\ -}else if(s2>s1){\ -return [0,1,2];\ -}else{\ -return [0,2,1];\ -}}})") - } - } else { - code.push("ORDER})") - } - } - - //view.set(i0, ..., v): - code.push( -"proto.set=function "+className+"_set("+args.join(",")+",v){") - if(useGetters) { - code.push("return this.data.set("+index_str+",v)}") - } else { - code.push("return this.data["+index_str+"]=v}") - } - - //view.get(i0, ...): - code.push("proto.get=function "+className+"_get("+args.join(",")+"){") - if(useGetters) { - code.push("return this.data.get("+index_str+")}") - } else { - code.push("return this.data["+index_str+"]}") - } - - //view.index: - code.push( - "proto.index=function "+className+"_index(", args.join(), "){return "+index_str+"}") - - //view.hi(): - code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+ - indices.map(function(i) { - return ["(typeof i",i,"!=='number'||i",i,"<0)?this._shape", i, ":i", i,"|0"].join("") - }).join(",")+","+ - indices.map(function(i) { - return "this._stride"+i - }).join(",")+",this.offset)}") - - //view.lo(): - var a_vars = indices.map(function(i) { return "a"+i+"=this._shape"+i }) - var c_vars = indices.map(function(i) { return "c"+i+"=this._stride"+i }) - code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(",")) - for(var i=0; i=0){\ -d=i"+i+"|0;\ -b+=c"+i+"*d;\ -a"+i+"-=d}") - } - code.push("return new "+className+"(this.data,"+ - indices.map(function(i) { - return "a"+i - }).join(",")+","+ - indices.map(function(i) { - return "c"+i - }).join(",")+",b)}") - - //view.step(): - code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+ - indices.map(function(i) { - return "a"+i+"=this._shape"+i - }).join(",")+","+ - indices.map(function(i) { - return "b"+i+"=this._stride"+i - }).join(",")+",c=this.offset,d=0,ceil=Math.ceil") - for(var i=0; i=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}") - } - code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}") - - //Add return statement - code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+ - indices.map(function(i) { - return "shape["+i+"]" - }).join(",")+","+ - indices.map(function(i) { - return "stride["+i+"]" - }).join(",")+",offset)}") - - //Compile procedure - var procedure = new Function("CTOR_LIST", "ORDER", code.join("\n")) - return procedure(CACHED_CONSTRUCTORS[dtype], order) -} - -function arrayDType(data) { - if(hasBuffer) { - if(Buffer.isBuffer(data)) { - return "buffer" - } - } - if(hasTypedArrays) { - switch(Object.prototype.toString.call(data)) { - case "[object Float64Array]": - return "float64" - case "[object Float32Array]": - return "float32" - case "[object Int8Array]": - return "int8" - case "[object Int16Array]": - return "int16" - case "[object Int32Array]": - return "int32" - case "[object Uint8Array]": - return "uint8" - case "[object Uint16Array]": - return "uint16" - case "[object Uint32Array]": - return "uint32" - case "[object Uint8ClampedArray]": - return "uint8_clamped" - } - } - if(Array.isArray(data)) { - return "array" - } - return "generic" -} - -var CACHED_CONSTRUCTORS = { - "float32":[], - "float64":[], - "int8":[], - "int16":[], - "int32":[], - "uint8":[], - "uint16":[], - "uint32":[], - "array":[], - "uint8_clamped":[], - "buffer":[], - "generic":[] -} - -;(function() { - for(var id in CACHED_CONSTRUCTORS) { - CACHED_CONSTRUCTORS[id].push(compileConstructor(id, -1)) - } -}); - -function wrappedNDArrayCtor(data, shape, stride, offset) { - if(data === undefined) { - var ctor = CACHED_CONSTRUCTORS.array[0] - return ctor([]) - } else if(typeof data === "number") { - data = [data] - } - if(shape === undefined) { - shape = [ data.length ] - } - var d = shape.length - if(stride === undefined) { - stride = new Array(d) - for(var i=d-1, sz=1; i>=0; --i) { - stride[i] = sz - sz *= shape[i] - } - } - if(offset === undefined) { - offset = 0 - for(var i=0; i 0) - (v < 0); -} - -//Computes absolute value of integer -exports.abs = function(v) { - var mask = v >> (INT_BITS-1); - return (v ^ mask) - mask; -} - -//Computes minimum of integers x and y -exports.min = function(x, y) { - return y ^ ((x ^ y) & -(x < y)); -} - -//Computes maximum of integers x and y -exports.max = function(x, y) { - return x ^ ((x ^ y) & -(x < y)); -} - -//Checks if a number is a power of two -exports.isPow2 = function(v) { - return !(v & (v-1)) && (!!v); -} - -//Computes log base 2 of v -exports.log2 = function(v) { - var r, shift; - r = (v > 0xFFFF) << 4; v >>>= r; - shift = (v > 0xFF ) << 3; v >>>= shift; r |= shift; - shift = (v > 0xF ) << 2; v >>>= shift; r |= shift; - shift = (v > 0x3 ) << 1; v >>>= shift; r |= shift; - return r | (v >> 1); -} - -//Computes log base 10 of v -exports.log10 = function(v) { - return (v >= 1000000000) ? 9 : (v >= 100000000) ? 8 : (v >= 10000000) ? 7 : - (v >= 1000000) ? 6 : (v >= 100000) ? 5 : (v >= 10000) ? 4 : - (v >= 1000) ? 3 : (v >= 100) ? 2 : (v >= 10) ? 1 : 0; -} - -//Counts number of bits -exports.popCount = function(v) { - v = v - ((v >>> 1) & 0x55555555); - v = (v & 0x33333333) + ((v >>> 2) & 0x33333333); - return ((v + (v >>> 4) & 0xF0F0F0F) * 0x1010101) >>> 24; -} - -//Counts number of trailing zeros -function countTrailingZeros(v) { - var c = 32; - v &= -v; - if (v) c--; - if (v & 0x0000FFFF) c -= 16; - if (v & 0x00FF00FF) c -= 8; - if (v & 0x0F0F0F0F) c -= 4; - if (v & 0x33333333) c -= 2; - if (v & 0x55555555) c -= 1; - return c; -} -exports.countTrailingZeros = countTrailingZeros; - -//Rounds to next power of 2 -exports.nextPow2 = function(v) { - v += v === 0; - --v; - v |= v >>> 1; - v |= v >>> 2; - v |= v >>> 4; - v |= v >>> 8; - v |= v >>> 16; - return v + 1; -} - -//Rounds down to previous power of 2 -exports.prevPow2 = function(v) { - v |= v >>> 1; - v |= v >>> 2; - v |= v >>> 4; - v |= v >>> 8; - v |= v >>> 16; - return v - (v>>>1); -} - -//Computes parity of word -exports.parity = function(v) { - v ^= v >>> 16; - v ^= v >>> 8; - v ^= v >>> 4; - v &= 0xf; - return (0x6996 >>> v) & 1; -} - -var REVERSE_TABLE = new Array(256); - -(function(tab) { - for(var i=0; i<256; ++i) { - var v = i, r = i, s = 7; - for (v >>>= 1; v; v >>>= 1) { - r <<= 1; - r |= v & 1; - --s; - } - tab[i] = (r << s) & 0xff; - } -})(REVERSE_TABLE); - -//Reverse bits in a 32 bit word -exports.reverse = function(v) { - return (REVERSE_TABLE[ v & 0xff] << 24) | - (REVERSE_TABLE[(v >>> 8) & 0xff] << 16) | - (REVERSE_TABLE[(v >>> 16) & 0xff] << 8) | - REVERSE_TABLE[(v >>> 24) & 0xff]; -} - -//Interleave bits of 2 coordinates with 16 bits. Useful for fast quadtree codes -exports.interleave2 = function(x, y) { - x &= 0xFFFF; - x = (x | (x << 8)) & 0x00FF00FF; - x = (x | (x << 4)) & 0x0F0F0F0F; - x = (x | (x << 2)) & 0x33333333; - x = (x | (x << 1)) & 0x55555555; - - y &= 0xFFFF; - y = (y | (y << 8)) & 0x00FF00FF; - y = (y | (y << 4)) & 0x0F0F0F0F; - y = (y | (y << 2)) & 0x33333333; - y = (y | (y << 1)) & 0x55555555; - - return x | (y << 1); -} - -//Extracts the nth interleaved component -exports.deinterleave2 = function(v, n) { - v = (v >>> n) & 0x55555555; - v = (v | (v >>> 1)) & 0x33333333; - v = (v | (v >>> 2)) & 0x0F0F0F0F; - v = (v | (v >>> 4)) & 0x00FF00FF; - v = (v | (v >>> 16)) & 0x000FFFF; - return (v << 16) >> 16; -} - - -//Interleave bits of 3 coordinates, each with 10 bits. Useful for fast octree codes -exports.interleave3 = function(x, y, z) { - x &= 0x3FF; - x = (x | (x<<16)) & 4278190335; - x = (x | (x<<8)) & 251719695; - x = (x | (x<<4)) & 3272356035; - x = (x | (x<<2)) & 1227133513; - - y &= 0x3FF; - y = (y | (y<<16)) & 4278190335; - y = (y | (y<<8)) & 251719695; - y = (y | (y<<4)) & 3272356035; - y = (y | (y<<2)) & 1227133513; - x |= (y << 1); - - z &= 0x3FF; - z = (z | (z<<16)) & 4278190335; - z = (z | (z<<8)) & 251719695; - z = (z | (z<<4)) & 3272356035; - z = (z | (z<<2)) & 1227133513; - - return x | (z << 2); -} - -//Extracts nth interleaved component of a 3-tuple -exports.deinterleave3 = function(v, n) { - v = (v >>> n) & 1227133513; - v = (v | (v>>>2)) & 3272356035; - v = (v | (v>>>4)) & 251719695; - v = (v | (v>>>8)) & 4278190335; - v = (v | (v>>>16)) & 0x3FF; - return (v<<22)>>22; -} - -//Computes next combination in colexicographic order (this is mistakenly called nextPermutation on the bit twiddling hacks page) -exports.nextCombination = function(v) { - var t = v | (v - 1); - return (t + 1) | (((~t & -~t) - 1) >>> (countTrailingZeros(v) + 1)); -} - - -},{}],17:[function(require,module,exports){ -"use strict" - -function dupe_array(count, value, i) { - var c = count[i]|0 - if(c <= 0) { - return [] - } - var result = new Array(c), j - if(i === count.length-1) { - for(j=0; j 0) { - return dupe_number(count|0, value) - } - break - case "object": - if(typeof (count.length) === "number") { - return dupe_array(count, value, 0) - } - break - } - return [] -} - -module.exports = dupe -},{}],18:[function(require,module,exports){ -(function (global){ -"use strict" - -var bits = require("bit-twiddle") -var dup = require("dup") -if(!global.__TYPEDARRAY_POOL) { - global.__TYPEDARRAY_POOL = { - UINT8 : dup([32, 0]) - , UINT16 : dup([32, 0]) - , UINT32 : dup([32, 0]) - , INT8 : dup([32, 0]) - , INT16 : dup([32, 0]) - , INT32 : dup([32, 0]) - , FLOAT : dup([32, 0]) - , DOUBLE : dup([32, 0]) - , DATA : dup([32, 0]) - } -} -var POOL = global.__TYPEDARRAY_POOL -var UINT8 = POOL.UINT8 - , UINT16 = POOL.UINT16 - , UINT32 = POOL.UINT32 - , INT8 = POOL.INT8 - , INT16 = POOL.INT16 - , INT32 = POOL.INT32 - , FLOAT = POOL.FLOAT - , DOUBLE = POOL.DOUBLE - , DATA = POOL.DATA - -exports.free = function free(array) { - if(array instanceof ArrayBuffer) { - var n = array.byteLength|0 - , log_n = bits.log2(n) - DATA[log_n].push(array) - } else { - var n = array.length|0 - , log_n = bits.log2(n) - if(array instanceof Uint8Array) { - UINT8[log_n].push(array) - } else if(array instanceof Uint16Array) { - UINT16[log_n].push(array) - } else if(array instanceof Uint32Array) { - UINT32[log_n].push(array) - } else if(array instanceof Int8Array) { - INT8[log_n].push(array) - } else if(array instanceof Int16Array) { - INT16[log_n].push(array) - } else if(array instanceof Int32Array) { - INT32[log_n].push(array) - } else if(array instanceof Float32Array) { - FLOAT[log_n].push(array) - } else if(array instanceof Float64Array) { - DOUBLE[log_n].push(array) - } - } -} - -exports.freeUint8 = function freeUint8(array) { - UINT8[bits.log2(array.length)].push(array) -} - -exports.freeUint16 = function freeUint16(array) { - UINT16[bits.log2(array.length)].push(array) -} - -exports.freeUint32 = function freeUint32(array) { - UINT32[bits.log2(array.length)].push(array) -} - -exports.freeInt8 = function freeInt8(array) { - INT8[bits.log2(array.length)].push(array) -} - -exports.freeInt16 = function freeInt16(array) { - INT16[bits.log2(array.length)].push(array) -} - -exports.freeInt32 = function freeInt32(array) { - INT32[bits.log2(array.length)].push(array) -} - -exports.freeFloat32 = exports.freeFloat = function freeFloat(array) { - FLOAT[bits.log2(array.length)].push(array) -} - -exports.freeFloat64 = exports.freeDouble = function freeDouble(array) { - DOUBLE[bits.log2(array.length)].push(array) -} - -exports.freeArrayBuffer = function freeArrayBuffer(array) { - DATA[bits.log2(array.length)].push(array) -} - -exports.malloc = function malloc(n, dtype) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - if(dtype === undefined) { - var d = DATA[log_n] - if(d.length > 0) { - var r = d[d.length-1] - d.pop() - return r - } - return new ArrayBuffer(n) - } else { - switch(dtype) { - case "uint8": - var u8 = UINT8[log_n] - if(u8.length > 0) { - return u8.pop() - } - return new Uint8Array(n) - break - - case "uint16": - var u16 = UINT16[log_n] - if(u16.length > 0) { - return u16.pop() - } - return new Uint16Array(n) - break - - case "uint32": - var u32 = UINT32[log_n] - if(u32.length > 0) { - return u32.pop() - } - return new Uint32Array(n) - break - - case "int8": - var i8 = INT8[log_n] - if(i8.length > 0) { - return i8.pop() - } - return new Int8Array(n) - break - - case "int16": - var i16 = INT16[log_n] - if(i16.length > 0) { - return i16.pop() - } - return new Int16Array(n) - break - - case "int32": - var i32 = INT32[log_n] - if(i32.length > 0) { - return i32.pop() - } - return new Int32Array(n) - break - - case "float": - case "float32": - var f = FLOAT[log_n] - if(f.length > 0) { - return f.pop() - } - return new Float32Array(n) - break - - case "double": - case "float64": - var dd = DOUBLE[log_n] - if(dd.length > 0) { - return dd.pop() - } - return new Float64Array(n) - break - - default: - return null - } - } - return null -} - -exports.mallocUint8 = function mallocUint8(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = UINT8[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Uint8Array(n) -} - -exports.mallocUint16 = function mallocUint16(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = UINT16[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Uint16Array(n) -} - -exports.mallocUint32 = function mallocUint32(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = UINT32[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Uint32Array(n) -} - -exports.mallocInt8 = function mallocInt8(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = INT8[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Int8Array(n) -} - -exports.mallocInt16 = function mallocInt16(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = INT16[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Int16Array(n) -} - -exports.mallocInt32 = function mallocInt32(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = INT32[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Int32Array(n) -} - -exports.mallocFloat32 = exports.mallocFloat = function mallocFloat(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = FLOAT[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Float32Array(n) -} - -exports.mallocFloat64 = exports.mallocDouble = function mallocDouble(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = DOUBLE[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Float64Array(n) -} - -exports.mallocArrayBuffer = function mallocArrayBuffer(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = DATA[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new ArrayBuffer(n) -} - -exports.clearCache = function clearCache() { - for(var i=0; i<32; ++i) { - UINT8[i].length = 0 - UINT16[i].length = 0 - UINT32[i].length = 0 - INT8[i].length = 0 - INT16[i].length = 0 - INT32[i].length = 0 - FLOAT[i].length = 0 - DOUBLE[i].length = 0 - DATA[i].length = 0 - } -} - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"bit-twiddle":16,"dup":17}],19:[function(require,module,exports){ -"use strict" - -function doBind(gl, elements, attributes) { - if(elements) { - elements.bind() - } else { - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null) - } - var nattribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS)|0 - if(attributes) { - if(attributes.length > nattribs) { - throw new Error("Too many vertex attributes") - } - for(var i=0; i start) { - ret[len - start] = args[len]; - } - - return ret; -} - - -},{}],31:[function(require,module,exports){ -"use strict" - -var pool = require("typedarray-pool") -var ops = require("ndarray-ops") -var ndarray = require("ndarray") -var webglew = require("webglew") - -var SUPPORTED_TYPES = [ - "uint8", - "uint8_clamped", - "uint16", - "uint32", - "int8", - "int16", - "int32", - "float32" ] - -function GLBuffer(gl, type, handle, length, usage) { - this.gl = gl - this.type = type - this.handle = handle - this.length = length - this.usage = usage -} - -var proto = GLBuffer.prototype - -proto.bind = function() { - this.gl.bindBuffer(this.type, this.handle) -} - -proto.dispose = function() { - this.gl.deleteBuffer(this.handle) -} - -function updateTypeArray(gl, type, len, usage, data, offset) { - var dataLen = data.length * data.BYTES_PER_ELEMENT - if(offset < 0) { - gl.bufferData(type, data, usage) - return dataLen - } - if(dataLen + offset > len) { - throw new Error("gl-buffer: If resizing buffer, must not specify offset") - } - gl.bufferSubData(type, offset, data) - return len -} - -function makeScratchTypeArray(array, dtype) { - var res = pool.malloc(array.length, dtype) - var n = array.length - for(var i=0; i=0; --i) { - if(stride[i] !== n) { - return false - } - n *= shape[i] - } - return true -} - -proto.update = function(array, offset) { - if(typeof offset !== "number") { - offset = -1 - } - this.bind() - if(typeof array === "object" && typeof array.shape !== "undefined") { //ndarray - var dtype = array.dtype - if(SUPPORTED_TYPES.indexOf(dtype) < 0) { - dtype = "float32" - } - if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) { - var wgl = webglew(this.gl) - var ext = wgl.OES_element_index_uint - if(ext && dtype !== "uint16") { - dtype = "uint32" - } else { - dtype = "uint16" - } - } - if(dtype === array.dtype && isPacked(array.shape, array.stride)) { - if(array.offset === 0 && array.data.length === array.shape[0]) { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data, offset) - } else { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data.subarray(array.offset, array.shape[0]), offset) - } - } else { - var tmp = pool.malloc(array.size, dtype) - var ndt = ndarray(tmp, array.shape) - ops.assign(ndt, array) - if(offset < 0) { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, tmp, offset) - } else { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, tmp.subarray(0, array.size), offset) - } - pool.free(tmp) - } - } else if(Array.isArray(array)) { //Vanilla array - var t - if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) { - t = makeScratchTypeArray(array, "uint16") - } else { - t = makeScratchTypeArray(array, "float32") - } - if(offset < 0) { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t, offset) - } else { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t.subarray(0, array.length), offset) - } - pool.free(t) - } else if(typeof array === "object" && typeof array.length === "number") { //Typed array - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array, offset) - } else if(typeof array === "number" || array === undefined) { //Number/default - if(offset >= 0) { - throw new Error("gl-buffer: Cannot specify offset when resizing buffer") - } - array = array | 0 - if(array <= 0) { - array = 1 - } - this.gl.bufferData(this.type, array|0, this.usage) - this.length = array - } else { //Error, case should not happen - throw new Error("gl-buffer: Invalid data type") - } -} - -function createBuffer(gl, data, type, usage) { - webglew(gl) - type = type || gl.ARRAY_BUFFER - usage = usage || gl.DYNAMIC_DRAW - if(type !== gl.ARRAY_BUFFER && type !== gl.ELEMENT_ARRAY_BUFFER) { - throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER") - } - if(usage !== gl.DYNAMIC_DRAW && usage !== gl.STATIC_DRAW && usage !== gl.STREAM_DRAW) { - throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW") - } - var handle = gl.createBuffer() - var result = new GLBuffer(gl, type, handle, 0, usage) - result.update(data) - return result -} - -module.exports = createBuffer -},{"ndarray":37,"ndarray-ops":32,"typedarray-pool":41,"webglew":43}],32:[function(require,module,exports){ -arguments[4][9][0].apply(exports,arguments) -},{"cwise-compiler":33}],33:[function(require,module,exports){ -arguments[4][10][0].apply(exports,arguments) -},{"./lib/thunk.js":35}],34:[function(require,module,exports){ -arguments[4][11][0].apply(exports,arguments) -},{"uniq":36}],35:[function(require,module,exports){ -arguments[4][12][0].apply(exports,arguments) -},{"./compile.js":34}],36:[function(require,module,exports){ -module.exports=require(13) -},{}],37:[function(require,module,exports){ -arguments[4][14][0].apply(exports,arguments) -},{"buffer":189,"iota-array":38}],38:[function(require,module,exports){ -module.exports=require(15) -},{}],39:[function(require,module,exports){ -module.exports=require(16) -},{}],40:[function(require,module,exports){ -module.exports=require(17) -},{}],41:[function(require,module,exports){ -(function (global,Buffer){ -var bits = require("bit-twiddle") -var dup = require("dup") -if(!global.__TYPEDARRAY_POOL) { - global.__TYPEDARRAY_POOL = { - UINT8 : dup([32, 0]) - , UINT16 : dup([32, 0]) - , UINT32 : dup([32, 0]) - , INT8 : dup([32, 0]) - , INT16 : dup([32, 0]) - , INT32 : dup([32, 0]) - , FLOAT : dup([32, 0]) - , DOUBLE : dup([32, 0]) - , DATA : dup([32, 0]) - , UINT8C : dup([32, 0]) - , BUFFER : dup([32, 0]) - } -} -var hasUint8C = (typeof Uint8ClampedArray) !== "undefined" -var POOL = global.__TYPEDARRAY_POOL -if(!POOL.UINT8C) { - POOL.UINT8C = dup([32, 0]) -} -if(!POOL.BUFFER) { - POOL.BUFFER = dup([32, 0]) -} -var UINT8 = POOL.UINT8 - , UINT16 = POOL.UINT16 - , UINT32 = POOL.UINT32 - , INT8 = POOL.INT8 - , INT16 = POOL.INT16 - , INT32 = POOL.INT32 - , FLOAT = POOL.FLOAT - , DOUBLE = POOL.DOUBLE - , DATA = POOL.DATA - , UINT8C = POOL.UINT8C - , BUFFER = POOL.BUFFER - -exports.free = function free(array) { - var n = array.length|0 - , log_n = bits.log2(n) - if(Buffer.isBuffer(array)) { - BUFFER[log_n].push(array) - } else { - switch(Object.prototype.toString.call(array)) { - case "[object Uint8Array]": - UINT8[log_n].push(array) - break - case "[object Uint16Array]": - UINT16[log_n].push(array) - break - case "[object Uint32Array]": - UINT32[log_n].push(array) - break - case "[object Int8Array]": - INT8[log_n].push(array) - break - case "[object Int16Array]": - INT16[log_n].push(array) - break - case "[object Int32Array]": - INT32[log_n].push(array) - break - case "[object Uint8ClampedArray]": - UINT8C[log_n].push(array) - break - case "[object Float32Array]": - FLOAT[log_n].push(array) - break - case "[object Float64Array]": - DOUBLE[log_n].push(array) - break - case "[object ArrayBuffer]": - DATA[log_n].push(array) - break - default: - throw new Error("typedarray-pool: Unspecified array type") - } - } -} - -exports.freeUint8 = function freeUint8(array) { - UINT8[bits.log2(array.length)].push(array) -} - -exports.freeUint16 = function freeUint16(array) { - UINT16[bits.log2(array.length)].push(array) -} - -exports.freeUint32 = function freeUint32(array) { - UINT32[bits.log2(array.length)].push(array) -} - -exports.freeInt8 = function freeInt8(array) { - INT8[bits.log2(array.length)].push(array) -} - -exports.freeInt16 = function freeInt16(array) { - INT16[bits.log2(array.length)].push(array) -} - -exports.freeInt32 = function freeInt32(array) { - INT32[bits.log2(array.length)].push(array) -} - -exports.freeFloat32 = exports.freeFloat = function freeFloat(array) { - FLOAT[bits.log2(array.length)].push(array) -} - -exports.freeFloat64 = exports.freeDouble = function freeDouble(array) { - DOUBLE[bits.log2(array.length)].push(array) -} - -exports.freeArrayBuffer = function freeArrayBuffer(array) { - DATA[bits.log2(array.length)].push(array) -} - -if(hasUint8C) { - exports.freeUint8Clamped = function freeUint8Clamped(array) { - UINT8C[bits.log2(array.length)].push(array) - } -} else { - exports.freeUint8Clamped = exports.freeUint8 -} - -exports.freeBuffer = function freeBuffer(array) { - BUFFER[bits.log2(array.length)].push(array) -} - -exports.malloc = function malloc(n, dtype) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - if(dtype === undefined || dtype === "arraybuffer") { - var d = DATA[log_n] - if(d.length > 0) { - var r = d[d.length-1] - d.pop() - return r - } - return new ArrayBuffer(n) - } else { - switch(dtype) { - case "uint8": - var u8 = UINT8[log_n] - if(u8.length > 0) { - return u8.pop() - } - return new Uint8Array(n) - break - - case "uint16": - var u16 = UINT16[log_n] - if(u16.length > 0) { - return u16.pop() - } - return new Uint16Array(n) - break - - case "uint32": - var u32 = UINT32[log_n] - if(u32.length > 0) { - return u32.pop() - } - return new Uint32Array(n) - break - - case "int8": - var i8 = INT8[log_n] - if(i8.length > 0) { - return i8.pop() - } - return new Int8Array(n) - break - - case "int16": - var i16 = INT16[log_n] - if(i16.length > 0) { - return i16.pop() - } - return new Int16Array(n) - break - - case "int32": - var i32 = INT32[log_n] - if(i32.length > 0) { - return i32.pop() - } - return new Int32Array(n) - break - - case "float": - case "float32": - var f = FLOAT[log_n] - if(f.length > 0) { - return f.pop() - } - return new Float32Array(n) - break - - case "double": - case "float64": - var dd = DOUBLE[log_n] - if(dd.length > 0) { - return dd.pop() - } - return new Float64Array(n) - break - - case "uint8_clamped": - if(hasUint8C) { - var u8c = UINT8C[log_n] - if(u8c.length > 0) { - return u8c.pop() - } - return new Uint8ClampedArray(n) - } else { - var u8 = UINT8[log_n] - if(u8.length > 0) { - return u8.pop() - } - return new Uint8Array(n) - } - break - - case "buffer": - var buf = BUFFER[log_n] - if(buf.length > 0) { - return buf.pop() - } - return new Buffer(n) - break - - default: - return null - } - } - return null -} - -exports.mallocUint8 = function mallocUint8(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = UINT8[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Uint8Array(n) -} - -exports.mallocUint16 = function mallocUint16(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = UINT16[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Uint16Array(n) -} - -exports.mallocUint32 = function mallocUint32(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = UINT32[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Uint32Array(n) -} - -exports.mallocInt8 = function mallocInt8(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = INT8[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Int8Array(n) -} - -exports.mallocInt16 = function mallocInt16(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = INT16[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Int16Array(n) -} - -exports.mallocInt32 = function mallocInt32(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = INT32[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Int32Array(n) -} - -exports.mallocFloat32 = exports.mallocFloat = function mallocFloat(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = FLOAT[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Float32Array(n) -} - -exports.mallocFloat64 = exports.mallocDouble = function mallocDouble(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = DOUBLE[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Float64Array(n) -} - -exports.mallocArrayBuffer = function mallocArrayBuffer(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = DATA[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new ArrayBuffer(n) -} - -if(hasUint8C) { - exports.mallocUint8Clamped = function mallocUint8Clamped(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = UINT8C[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Uint8ClampedArray(n) - } -} else { - exports.mallocUint8Clamped = exports.mallocUint8 -} - -exports.mallocBuffer = function mallocBuffer(n) { - n = bits.nextPow2(n) - var log_n = bits.log2(n) - var cache = BUFFER[log_n] - if(cache.length > 0) { - return cache.pop() - } - return new Buffer(n) -} - -exports.clearCache = function clearCache() { - for(var i=0; i<32; ++i) { - UINT8[i].length = 0 - UINT16[i].length = 0 - UINT32[i].length = 0 - INT8[i].length = 0 - INT16[i].length = 0 - INT32[i].length = 0 - FLOAT[i].length = 0 - DOUBLE[i].length = 0 - DATA[i].length = 0 - UINT8C[i].length = 0 - BUFFER[i].length = 0 - } -} -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) -},{"bit-twiddle":39,"buffer":189,"dup":40}],42:[function(require,module,exports){ -/* (The MIT License) - * - * Copyright (c) 2012 Brandon Benvie - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the 'Software'), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included with all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -// Original WeakMap implementation by Gozala @ https://gist.github.com/1269991 -// Updated and bugfixed by Raynos @ https://gist.github.com/1638059 -// Expanded by Benvie @ https://github.com/Benvie/harmony-collections - -void function(global, undefined_, undefined){ - var getProps = Object.getOwnPropertyNames, - defProp = Object.defineProperty, - toSource = Function.prototype.toString, - create = Object.create, - hasOwn = Object.prototype.hasOwnProperty, - funcName = /^\n?function\s?(\w*)?_?\(/; - - - function define(object, key, value){ - if (typeof key === 'function') { - value = key; - key = nameOf(value).replace(/_$/, ''); - } - return defProp(object, key, { configurable: true, writable: true, value: value }); - } - - function nameOf(func){ - return typeof func !== 'function' - ? '' : 'name' in func - ? func.name : toSource.call(func).match(funcName)[1]; - } - - // ############ - // ### Data ### - // ############ - - var Data = (function(){ - var dataDesc = { value: { writable: true, value: undefined } }, - datalock = 'return function(k){if(k===s)return l}', - uids = create(null), - - createUID = function(){ - var key = Math.random().toString(36).slice(2); - return key in uids ? createUID() : uids[key] = key; - }, - - globalID = createUID(), - - storage = function(obj){ - if (hasOwn.call(obj, globalID)) - return obj[globalID]; - - if (!Object.isExtensible(obj)) - throw new TypeError("Object must be extensible"); - - var store = create(null); - defProp(obj, globalID, { value: store }); - return store; - }; - - // common per-object storage area made visible by patching getOwnPropertyNames' - define(Object, function getOwnPropertyNames(obj){ - var props = getProps(obj); - if (hasOwn.call(obj, globalID)) - props.splice(props.indexOf(globalID), 1); - return props; - }); - - function Data(){ - var puid = createUID(), - secret = {}; - - this.unlock = function(obj){ - var store = storage(obj); - if (hasOwn.call(store, puid)) - return store[puid](secret); - - var data = create(null, dataDesc); - defProp(store, puid, { - value: new Function('s', 'l', datalock)(secret, data) - }); - return data; - } - } - - define(Data.prototype, function get(o){ return this.unlock(o).value }); - define(Data.prototype, function set(o, v){ this.unlock(o).value = v }); - - return Data; - }()); - - - var WM = (function(data){ - var validate = function(key){ - if (key == null || typeof key !== 'object' && typeof key !== 'function') - throw new TypeError("Invalid WeakMap key"); - } - - var wrap = function(collection, value){ - var store = data.unlock(collection); - if (store.value) - throw new TypeError("Object is already a WeakMap"); - store.value = value; - } - - var unwrap = function(collection){ - var storage = data.unlock(collection).value; - if (!storage) - throw new TypeError("WeakMap is not generic"); - return storage; - } - - var initialize = function(weakmap, iterable){ - if (iterable !== null && typeof iterable === 'object' && typeof iterable.forEach === 'function') { - iterable.forEach(function(item, i){ - if (item instanceof Array && item.length === 2) - set.call(weakmap, iterable[i][0], iterable[i][1]); - }); - } - } - - - function WeakMap(iterable){ - if (this === global || this == null || this === WeakMap.prototype) - return new WeakMap(iterable); - - wrap(this, new Data); - initialize(this, iterable); - } - - function get(key){ - validate(key); - var value = unwrap(this).get(key); - return value === undefined_ ? undefined : value; - } - - function set(key, value){ - validate(key); - // store a token for explicit undefined so that "has" works correctly - unwrap(this).set(key, value === undefined ? undefined_ : value); - } - - function has(key){ - validate(key); - return unwrap(this).get(key) !== undefined; - } - - function delete_(key){ - validate(key); - var data = unwrap(this), - had = data.get(key) !== undefined; - data.set(key, undefined); - return had; - } - - function toString(){ - unwrap(this); - return '[object WeakMap]'; - } - - try { - var src = ('return '+delete_).replace('e_', '\\u0065'), - del = new Function('unwrap', 'validate', src)(unwrap, validate); - } catch (e) { - var del = delete_; - } - - var src = (''+Object).split('Object'); - var stringifier = function toString(){ - return src[0] + nameOf(this) + src[1]; - }; - - define(stringifier, stringifier); - - var prep = { __proto__: [] } instanceof Array - ? function(f){ f.__proto__ = stringifier } - : function(f){ define(f, stringifier) }; - - prep(WeakMap); - - [toString, get, set, has, del].forEach(function(method){ - define(WeakMap.prototype, method); - prep(method); - }); - - return WeakMap; - }(new Data)); - - var defaultCreator = Object.create - ? function(){ return Object.create(null) } - : function(){ return {} }; - - function createStorage(creator){ - var weakmap = new WM; - creator || (creator = defaultCreator); - - function storage(object, value){ - if (value || arguments.length === 2) { - weakmap.set(object, value); - } else { - value = weakmap.get(object); - if (value === undefined) { - value = creator(object); - weakmap.set(object, value); - } - } - return value; - } - - return storage; - } - - - if (typeof module !== 'undefined') { - module.exports = WM; - } else if (typeof exports !== 'undefined') { - exports.WeakMap = WM; - } else if (!('WeakMap' in global)) { - global.WeakMap = WM; - } - - WM.createStorage = createStorage; - if (global.WeakMap) - global.WeakMap.createStorage = createStorage; -}((0, eval)('this')); - -},{}],43:[function(require,module,exports){ -"use strict"; - -var weakMap = typeof WeakMap === "undefined" ? require("weakmap") : WeakMap - -var WebGLEWStruct = new weakMap() - -function baseName(ext_name) { - return ext_name.replace(/^[A-Z]+_/, "") -} - -function initWebGLEW(gl) { - var struct = WebGLEWStruct.get(gl) - if(struct) { - return struct - } - var extensions = {} - var supported = gl.getSupportedExtensions() - for(var i=0; i 1) { - ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]) - } - - //Allocate depth/stencil buffers - if(extensions.WEBGL_depth_texture) { - if(useStencil) { - fbo.depth = initTexture(gl, width, height, - extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL, - gl.DEPTH_STENCIL, - gl.DEPTH_STENCIL_ATTACHMENT) - } else if(useDepth) { - fbo.depth = initTexture(gl, width, height, - gl.UNSIGNED_SHORT, - gl.DEPTH_COMPONENT, - gl.DEPTH_ATTACHMENT) - } - } else { - if(useDepth && useStencil) { - fbo._depth_rb = initRenderBuffer(gl, width, height, gl.DEPTH_STENCIL, gl.DEPTH_STENCIL_ATTACHMENT) - } else if(useDepth) { - fbo._depth_rb = initRenderBuffer(gl, width, height, gl.DEPTH_COMPONENT16, gl.DEPTH_ATTACHMENT) - } else if(useStencil) { - fbo._depth_rb = initRenderBuffer(gl, width, height, gl.STENCIL_INDEX, gl.STENCIL_ATTACHMENT) - } - } - - //Check frame buffer state - var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER) - if(status !== gl.FRAMEBUFFER_COMPLETE) { - - //Release all partially allocated resources - fbo._destroyed = true - - //Release all resources - gl.bindFramebuffer(gl.FRAMEBUFFER, null) - gl.deleteFramebuffer(fbo.handle) - fbo.handle = null - if(fbo.depth) { - fbo.depth.dispose() - fbo.depth = null - } - if(fbo._depth_rb) { - gl.deleteRenderbuffer(fbo._depth_rb) - fbo._depth_rb = null - } - for(var i=0; i maxFBOSize || - h < 0 || h > maxFBOSize) { - throw new Error('gl-fbo: Can\'t resize FBO, invalid dimensions') - } - - //Update shape - fbo._shape[0] = w - fbo._shape[1] = h - - //Save framebuffer state - var state = saveFBOState(gl) - - //Resize framebuffer attachments - for(var i=0; i maxFBOSize || height < 0 || height > maxFBOSize) { - throw new Error('gl-fbo: Parameters are too large for FBO') - } - - //Handle each option type - options = options || {} - - //Figure out number of color buffers to use - var numColors = 1 - if('color' in options) { - numColors = Math.max(options.color|0, 0) - if(numColors < 0) { - throw new Error('gl-fbo: Must specify a nonnegative number of colors') - } - if(numColors > 1) { - //Check if multiple render targets supported - var mrtext = extensions.WEBGL_draw_buffers - if(!mrtext) { - throw new Error('gl-fbo: Multiple draw buffer extension not supported') - } else if(numColors > gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL)) { - throw new Error('gl-fbo: Context does not support ' + numColors + ' draw buffers') - } - } - } - - //Determine whether to use floating point textures - var colorType = gl.UNSIGNED_BYTE - if(options.float && numColors > 0) { - if(!extensions.OES_texture_float) { - throw new Error('gl-fbo: Context does not support floating point textures') - } - colorType = gl.FLOAT - } else if(options.preferFloat && numColors > 0) { - if(extensions.OES_texture_float) { - colorType = gl.FLOAT - } - } - - //Check if we should use depth buffer - var useDepth = true - if('depth' in options) { - useDepth = !!options.depth - } - - //Check if we should use a stencil buffer - var useStencil = false - if('stencil' in options) { - useStencil = !!options.stencil - } - - return new Framebuffer( - gl, - width, - height, - colorType, - numColors, - useDepth, - useStencil, - extensions.WEBGL_draw_buffers) -} -},{"gl-texture2d":59,"webglew":61}],49:[function(require,module,exports){ -arguments[4][9][0].apply(exports,arguments) -},{"cwise-compiler":50}],50:[function(require,module,exports){ -arguments[4][10][0].apply(exports,arguments) -},{"./lib/thunk.js":52}],51:[function(require,module,exports){ -arguments[4][11][0].apply(exports,arguments) -},{"uniq":53}],52:[function(require,module,exports){ -arguments[4][12][0].apply(exports,arguments) -},{"./compile.js":51}],53:[function(require,module,exports){ -module.exports=require(13) -},{}],54:[function(require,module,exports){ -arguments[4][14][0].apply(exports,arguments) -},{"buffer":189,"iota-array":55}],55:[function(require,module,exports){ -module.exports=require(15) -},{}],56:[function(require,module,exports){ -module.exports=require(16) -},{}],57:[function(require,module,exports){ -module.exports=require(17) -},{}],58:[function(require,module,exports){ -module.exports=require(41) -},{"bit-twiddle":56,"buffer":189,"dup":57}],59:[function(require,module,exports){ -'use strict' - -var ndarray = require('ndarray') -var ops = require('ndarray-ops') -var pool = require('typedarray-pool') -var webglew = require('webglew') - -module.exports = createTexture2D - -var linearTypes = null -var filterTypes = null -var wrapTypes = null - -function lazyInitLinearTypes(gl) { - linearTypes = [ - gl.LINEAR, - gl.NEAREST_MIPMAP_LINEAR, - gl.LINEAR_MIPMAP_NEAREST, - gl.LINEAR_MIPMAP_NEAREST - ] - filterTypes = [ - gl.NEAREST, - gl.LINEAR, - gl.NEAREST_MIPMAP_NEAREST, - gl.NEAREST_MIPMAP_LINEAR, - gl.LINEAR_MIPMAP_NEAREST, - gl.LINEAR_MIPMAP_LINEAR - ] - wrapTypes = [ - gl.REPEAT, - gl.CLAMP_TO_EDGE, - gl.MIRRORED_REPEAT - ] -} - -var convertFloatToUint8 = function(out, inp) { - ops.muls(out, inp, 255.0) -} - -function reshapeTexture(tex, w, h) { - var gl = tex.gl - var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) - if(w < 0 || w > maxSize || h < 0 || h > maxSize) { - throw new Error("gl-texture2d: Invalid texture size") - } - tex._shape = [w, h] - tex.bind() - gl.texImage2D(gl.TEXTURE_2D, 0, tex.format, w, h, 0, tex.format, tex.type, null) - tex._mipLevels = [0] - return tex -} - -function Texture2D(gl, handle, width, height, format, type) { - this.gl = gl - this.handle = handle - this.format = format - this.type = type - this._shape = [width, height] - this._mipLevels = [0] - this._magFilter = gl.NEAREST - this._minFilter = gl.NEAREST - this._wrapS = gl.CLAMP_TO_EDGE - this._wrapT = gl.CLAMP_TO_EDGE - this._anisoSamples = 1 - - var parent = this - var wrapVector = [this._wrapS, this._wrapT] - Object.defineProperties(wrapVector, { - "0": { - get: function() { - return parent._wrapS - }, - set: function(v) { - return parent.wrapS = v - } - }, - "1": { - get: function() { - return parent._wrapT - }, - set: function(v) { - return parent.wrapT = v - } - } - }) - this._wrapVector = wrapVector - - var shapeVector = [this._shape[0], this._shape[1]] - Object.defineProperties(shapeVector, { - "0": { - get: function() { - return parent._shape[0] - }, - set: function(v) { - return parent.width = v - } - }, - "1" : { - get: function() { - return parent._shape[1] - }, - set: function(v) { - return parent.height = v - } - } - }) - this._shapeVector = shapeVector -} - -var proto = Texture2D.prototype - -Object.defineProperties(proto, { - "minFilter": { - get: function() { - return this._minFilter - }, - set: function(v) { - this.bind() - var gl = this.gl - if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) { - if(!webglew(gl).OES_texture_float_linear) { - v = gl.NEAREST - } - } - if(filterTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown filter mode " + v) - } - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, v) - return this._minFilter = v - } - }, - "magFilter": { - get: function() { - return this._magFilter - }, - set: function(v) { - this.bind() - var gl = this.gl - if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) { - if(!webglew(gl).OES_texture_float_linear) { - v = gl.NEAREST - } - } - if(filterTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown filter mode " + v) - } - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, v) - return this._magFilter = v - } - }, - "mipSamples": { - get: function() { - return this._anisoSamples - }, - set: function(i) { - var psamples = this._anisoSamples - this._anisoSamples = Math.max(i, 1)|0 - if(psamples !== this._anisoSamples) { - var ext = webglew(this.gl).EXT_texture_filter_anisotropic - if(ext) { - this.gl.texParameterf(this.gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, this._anisoSamples) - } - } - return this._anisoSamples - } - }, - "wrapS": { - get: function() { - return this._wrapS - }, - set: function(v) { - this.bind() - if(wrapTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown wrap mode " + v) - } - this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, v) - return this._wrapS = v - } - }, - "wrapT": { - get: function() { - return this._wrapT - }, - set: function(v) { - this.bind() - if(wrapTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown wrap mode " + v) - } - this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, v) - return this._wrapT = v - } - }, - "wrap": { - get: function() { - return this._wrapVector - }, - set: function(v) { - if(!Array.isArray(v)) { - v = [v,v] - } - if(v.length !== 2) { - throw new Error("gl-texture2d: Must specify wrap mode for rows and columns") - } - for(var i=0; i<2; ++i) { - if(wrapTypes.indexOf(v[i]) < 0) { - throw new Error("gl-texture2d: Unknown wrap mode " + v) - } - } - this._wrapS = v[0] - this._wrapT = v[1] - - var gl = this.gl - this.bind() - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this._wrapS) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this._wrapT) - - return v - } - }, - "shape": { - get: function() { - return this._shapeVector - }, - set: function(x) { - if(!Array.isArray(x)) { - x = [x|0,x|0] - } else { - if(x.length !== 2) { - throw new Error("gl-texture2d: Invalid texture shape") - } - } - reshapeTexture(this, x[0]|0, x[1]|0) - return [x[0]|0, x[1]|0] - } - }, - "width": { - get: function() { - return this._shape[0] - }, - set: function(w) { - w = w|0 - reshapeTexture(this, w, this._shape[1]) - return w - } - }, - "height": { - get: function() { - return this._shape[1] - }, - set: function(h) { - h = h|0 - reshapeTexture(this, this._shape[0], h) - return h - } - } -}) - -proto.bind = function(unit) { - var gl = this.gl - if(unit !== undefined) { - gl.activeTexture(gl.TEXTURE0 + (unit|0)) - } - gl.bindTexture(gl.TEXTURE_2D, this.handle) - if(unit !== undefined) { - return unit - } - return gl.getParameter(gl.ACTIVE_TEXTURE) - gl.TEXTURE0 -} - -proto.dispose = function() { - this.gl.deleteTexture(this.handle) -} - -proto.generateMipmap = function() { - this.bind() - this.gl.generateMipmap(this.gl.TEXTURE_2D) - - //Update mip levels - var l = Math.min(this._shape[0], this._shape[1]) - for(var i=0; l>0; ++i, l>>>=1) { - if(this._mipLevels.indexOf(i) < 0) { - this._mipLevels.push(i) - } - } -} - -proto.setPixels = function(data, x_off, y_off, mip_level) { - var gl = this.gl - this.bind() - if(Array.isArray(x_off)) { - mip_level = y_off - y_off = x_off[1]|0 - x_off = x_off[0]|0 - } else { - x_off = x_off || 0 - y_off = y_off || 0 - } - mip_level = mip_level || 0 - if(data instanceof HTMLCanvasElement || - data instanceof ImageData || - data instanceof HTMLImageElement || - data instanceof HTMLVideoElement) { - var needsMip = this._mipLevels.indexOf(mip_level) < 0 - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, data) - this._mipLevels.push(mip_level) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, this.format, this.type, data) - } - } else if(data.shape && data.stride && data.data) { - if(data.shape.length < 2 || - x_off + data.shape[1] > this._shape[1]>>>mip_level || - y_off + data.shape[0] > this._shape[0]>>>mip_level || - x_off < 0 || - y_off < 0) { - throw new Error("gl-texture2d: Texture dimensions are out of bounds") - } - texSubImageArray(gl, x_off, y_off, mip_level, this.format, this.type, this._mipLevels, data) - } else { - throw new Error("gl-texture2d: Unsupported data type") - } -} - - -function isPacked(shape, stride) { - if(shape.length === 3) { - return (stride[2] === 1) && - (stride[1] === shape[0]*shape[2]) && - (stride[0] === shape[2]) - } - return (stride[0] === 1) && - (stride[1] === shape[0]) -} - -function texSubImageArray(gl, x_off, y_off, mip_level, cformat, ctype, mipLevels, array) { - var dtype = array.dtype - var shape = array.shape.slice() - if(shape.length < 2 || shape.length > 3) { - throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d") - } - var type = 0, format = 0 - var packed = isPacked(shape, array.stride.slice()) - if(dtype === "float32") { - type = gl.FLOAT - } else if(dtype === "float64") { - type = gl.FLOAT - packed = false - dtype = "float32" - } else if(dtype === "uint8") { - type = gl.UNSIGNED_BYTE - } else { - type = gl.UNSIGNED_BYTE - packed = false - dtype = "uint8" - } - var channels = 1 - if(shape.length === 2) { - format = gl.LUMINANCE - shape = [shape[0], shape[1], 1] - array = ndarray(array.data, shape, [array.stride[0], array.stride[1], 1], array.offset) - } else if(shape.length === 3) { - if(shape[2] === 1) { - format = gl.ALPHA - } else if(shape[2] === 2) { - format = gl.LUMINANCE_ALPHA - } else if(shape[2] === 3) { - format = gl.RGB - } else if(shape[2] === 4) { - format = gl.RGBA - } else { - throw new Error("gl-texture2d: Invalid shape for pixel coords") - } - channels = shape[2] - } else { - throw new Error("gl-texture2d: Invalid shape for texture") - } - //For 1-channel textures allow conversion between formats - if((format === gl.LUMINANCE || format === gl.ALPHA) && - (cformat === gl.LUMINANCE || cformat === gl.ALPHA)) { - format = cformat - } - if(format !== cformat) { - throw new Error("gl-texture2d: Incompatible texture format for setPixels") - } - var size = array.size - var needsMip = mipLevels.indexOf(mip_level) < 0 - if(needsMip) { - mipLevels.push(mip_level) - } - if(type === ctype && packed) { - //Array data types are compatible, can directly copy into texture - if(array.offset === 0 && array.data.length === size) { - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[0], shape[1], 0, cformat, ctype, array.data) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[0], shape[1], cformat, ctype, array.data) - } - } else { - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[0], shape[1], 0, cformat, ctype, array.data.subarray(array.offset, array.offset+size)) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[0], shape[1], cformat, ctype, array.data.subarray(array.offset, array.offset+size)) - } - } - } else { - //Need to do type conversion to pack data into buffer - var pack_buffer - if(ctype === gl.FLOAT) { - pack_buffer = pool.mallocFloat32(size) - } else { - pack_buffer = pool.mallocUint8(size) - } - var pack_view = ndarray(pack_buffer, shape, [shape[2], shape[2]*shape[0], 1]) - if(type === gl.FLOAT && ctype === gl.UNSIGNED_BYTE) { - convertFloatToUint8(pack_view, array) - } else { - ops.assign(pack_view, array) - } - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[0], shape[1], 0, cformat, ctype, pack_buffer.subarray(0, size)) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[0], shape[1], cformat, ctype, pack_buffer.subarray(0, size)) - } - if(ctype === gl.FLOAT) { - pool.freeFloat32(pack_buffer) - } else { - pool.freeUint8(pack_buffer) - } - } -} - -function initTexture(gl) { - var tex = gl.createTexture() - gl.bindTexture(gl.TEXTURE_2D, tex) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) - return tex -} - -function createTextureShape(gl, width, height, format, type) { - var maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) - if(width < 0 || width > maxTextureSize || height < 0 || height > maxTextureSize) { - throw new Error("gl-texture2d: Invalid texture shape") - } - var tex = initTexture(gl) - gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, type, null) - return new Texture2D(gl, tex, width, height, format, type) -} - -function createTextureDOM(gl, element, format, type) { - var tex = initTexture(gl) - gl.texImage2D(gl.TEXTURE_2D, 0, format, format, type, element) - return new Texture2D(gl, tex, element.width|0, element.height|0, format, type) -} - -//Creates a texture from an ndarray -function createTextureArray(gl, array) { - var dtype = array.dtype - var shape = array.shape.slice() - var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) - if(shape[0] < 0 || shape[0] > maxSize || shape[1] < 0 || shape[1] > maxSize) { - throw new Error("gl-texture2d: Invalid texture size") - } - var packed = isPacked(shape, array.stride.slice()) - var type = 0 - if(dtype === "float32") { - type = gl.FLOAT - } else if(dtype === "float64") { - type = gl.FLOAT - packed = false - dtype = "float32" - } else if(dtype === "uint8") { - type = gl.UNSIGNED_BYTE - } else { - type = gl.UNSIGNED_BYTE - packed = false - dtype = "uint8" - } - var format = 0 - if(shape.length === 2) { - format = gl.LUMINANCE - shape = [shape[0], shape[1], 1] - array = ndarray(array.data, shape, [array.stride[0], array.stride[1], 1], array.offset) - } else if(shape.length === 3) { - if(shape[2] === 1) { - format = gl.ALPHA - } else if(shape[2] === 2) { - format = gl.LUMINANCE_ALPHA - } else if(shape[2] === 3) { - format = gl.RGB - } else if(shape[2] === 4) { - format = gl.RGBA - } else { - throw new Error("Invalid shape for pixel coords") - } - } else { - throw new Error("Invalid shape for texture") - } - if(type === gl.FLOAT && !webglew(gl).texture_float) { - type = gl.UNSIGNED_BYTE - packed = false - } - var buffer, buf_store - var size = array.size - if(!packed) { - var stride = [shape[2], shape[2]*shape[0], 1] - buf_store = pool.malloc(size, dtype) - var buf_array = ndarray(buf_store, shape, stride, 0) - if((dtype === "float32" || dtype === "float64") && type === gl.UNSIGNED_BYTE) { - convertFloatToUint8(buf_array, array) - } else { - ops.assign(buf_array, array) - } - buffer = buf_store.subarray(0, size) - } else if (array.offset === 0 && array.data.length === size) { - buffer = array.data - } else { - buffer = array.data.subarray(array.offset, array.offset + size) - } - var tex = initTexture(gl) - gl.texImage2D(gl.TEXTURE_2D, 0, format, shape[0], shape[1], 0, format, type, buffer) - if(!packed) { - pool.free(buf_store) - } - return new Texture2D(gl, tex, shape[1], shape[0], format, type) -} - -function createTexture2D(gl) { - if(arguments.length <= 1) { - throw new Error("Missing arguments for texture2d constructor") - } - if(!linearTypes) { - lazyInitLinearTypes(gl) - } - if(typeof arguments[1] === "number") { - return createTextureShape(gl, arguments[1], arguments[2], arguments[3]||gl.RGBA, arguments[4]||gl.UNSIGNED_BYTE) - } - if(Array.isArray(arguments[1])) { - return createTextureShape(gl, arguments[1][0]|0, arguments[1][1]|0, arguments[2]||gl.RGBA, arguments[4]||gl.UNSIGNED_BYTE) - } - if(typeof arguments[1] === "object") { - var obj = arguments[1] - if(obj instanceof HTMLCanvasElement || - obj instanceof HTMLImageElement || - obj instanceof HTMLVideoElement || - obj instanceof ImageData) { - return createTextureDOM(gl, obj, arguments[2]||gl.RGBA, arguments[3]||gl.UNSIGNED_BYTE) - } else if(obj.shape && obj.data && obj.stride) { - return createTextureArray(gl, obj) - } - } - throw new Error("Invalid arguments for texture2d constructor") -} -},{"ndarray":54,"ndarray-ops":49,"typedarray-pool":58,"webglew":61}],60:[function(require,module,exports){ -module.exports=require(42) -},{}],61:[function(require,module,exports){ -module.exports=require(43) -},{"weakmap":60}],62:[function(require,module,exports){ -arguments[4][9][0].apply(exports,arguments) -},{"cwise-compiler":63}],63:[function(require,module,exports){ -arguments[4][10][0].apply(exports,arguments) -},{"./lib/thunk.js":65}],64:[function(require,module,exports){ -arguments[4][11][0].apply(exports,arguments) -},{"uniq":66}],65:[function(require,module,exports){ -arguments[4][12][0].apply(exports,arguments) -},{"./compile.js":64}],66:[function(require,module,exports){ -module.exports=require(13) -},{}],67:[function(require,module,exports){ -module.exports=require(16) -},{}],68:[function(require,module,exports){ -module.exports=require(17) -},{}],69:[function(require,module,exports){ -module.exports=require(41) -},{"bit-twiddle":67,"buffer":189,"dup":68}],70:[function(require,module,exports){ -module.exports=require(42) -},{}],71:[function(require,module,exports){ -module.exports=require(43) -},{"weakmap":70}],72:[function(require,module,exports){ -arguments[4][59][0].apply(exports,arguments) -},{"ndarray":86,"ndarray-ops":62,"typedarray-pool":69,"webglew":71}],73:[function(require,module,exports){ -"use strict" - -function doBind(gl, elements, attributes) { - if(elements) { - elements.bind() - } else { - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null) - } - var nattribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS)|0 - if(attributes) { - if(attributes.length > nattribs) { - throw new Error("gl-vao: Too many vertex attributes") - } - for(var i=0; i= 0) { - var d = type.charCodeAt(type.length-1) - 48 - if(d < 2 || d > 4) { - throw new Error("Invalid data type for attribute " + name + ": " + type) - } - addVectorAttribute(gl, program, location, d, obj, name, doLink) - } else { - throw new Error("Unknown data type for attribute " + name + ": " + type) - } - break - } - } - return obj -} - -},{}],82:[function(require,module,exports){ -"use strict" - -var dup = require("dup") -var coallesceUniforms = require("./reflect.js") - -module.exports = createUniformWrapper - -//Binds a function and returns a value -function identity(x) { - var c = new Function("y", "return function(){return y}") - return c(x) -} - -//Create shims for uniforms -function createUniformWrapper(gl, program, uniforms, locations) { - - function makeGetter(index) { - var proc = new Function("gl", "prog", "locations", - "return function(){return gl.getUniform(prog,locations[" + index + "])}") - return proc(gl, program, locations) - } - - function makePropSetter(path, index, type) { - switch(type) { - case "bool": - case "int": - case "sampler2D": - case "samplerCube": - return "gl.uniform1i(locations[" + index + "],obj" + path + ")" - case "float": - return "gl.uniform1f(locations[" + index + "],obj" + path + ")" - default: - var vidx = type.indexOf("vec") - if(0 <= vidx && vidx <= 1 && type.length === 4 + vidx) { - var d = type.charCodeAt(type.length-1) - 48 - if(d < 2 || d > 4) { - throw new Error("Invalid data type") - } - switch(type.charAt(0)) { - case "b": - case "i": - return "gl.uniform" + d + "iv(locations[" + index + "],obj" + path + ")" - case "v": - return "gl.uniform" + d + "fv(locations[" + index + "],obj" + path + ")" - default: - throw new Error("Unrecognized data type for vector " + name + ": " + type) - } - } else if(type.indexOf("mat") === 0 && type.length === 4) { - var d = type.charCodeAt(type.length-1) - 48 - if(d < 2 || d > 4) { - throw new Error("Invalid uniform dimension type for matrix " + name + ": " + type) - } - return "gl.uniformMatrix" + d + "fv(locations[" + index + "],false,obj" + path + ")" - } else { - throw new Error("Unknown uniform data type for " + name + ": " + type) - } - break - } - } - - function enumerateIndices(prefix, type) { - if(typeof type !== "object") { - return [ [prefix, type] ] - } - var indices = [] - for(var id in type) { - var prop = type[id] - var tprefix = prefix - if(parseInt(id) + "" === id) { - tprefix += "[" + id + "]" - } else { - tprefix += "." + id - } - if(typeof prop === "object") { - indices.push.apply(indices, enumerateIndices(tprefix, prop)) - } else { - indices.push([tprefix, prop]) - } - } - return indices - } - - function makeSetter(type) { - var code = [ "return function updateProperty(obj){" ] - var indices = enumerateIndices("", type) - for(var i=0; i 4) { - throw new Error("Invalid data type") - } - if(type.charAt(0) === "b") { - return dup(d, false) - } - return dup(d) - } else if(type.indexOf("mat") === 0 && type.length === 4) { - var d = type.charCodeAt(type.length-1) - 48 - if(d < 2 || d > 4) { - throw new Error("Invalid uniform dimension type for matrix " + name + ": " + type) - } - return dup([d,d]) - } else { - throw new Error("Unknown uniform data type for " + name + ": " + type) - } - break - } - } - - function storeProperty(obj, prop, type) { - if(typeof type === "object") { - var child = processObject(type) - Object.defineProperty(obj, prop, { - get: identity(child), - set: makeSetter(type), - enumerable: true, - configurable: false - }) - } else { - if(locations[type]) { - Object.defineProperty(obj, prop, { - get: makeGetter(type), - set: makeSetter(type), - enumerable: true, - configurable: false - }) - } else { - obj[prop] = defaultValue(uniforms[type].type) - } - } - } - - function processObject(obj) { - var result - if(Array.isArray(obj)) { - result = new Array(obj.length) - for(var i=0; i 1) { - if(!(x[0] in o)) { - o[x[0]] = [] - } - o = o[x[0]] - for(var k=1; k height) - return; - - var now = getTime() * TIMESCALE; - heightmap.bind(); - gl.viewport(0, 0, SIZE, SIZE); - gl.disable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - heightShader.bind(); - heightShader.uniforms.uTime = now; - heightShader.uniforms.uResolution = RES; - triangle(gl); - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - gl.viewport(0, 0, width, height); - gl.enable(gl.DEPTH_TEST); - gl.enable(gl.CULL_FACE); - clear(gl); - mat4.perspective(projection, Math.PI / 4, width / height, 0.001, 100); - quat.identity(camera.rotation); - quat.rotateY(camera.rotation, camera.rotation, now * 0.0002); - quat.rotateX(camera.rotation, camera.rotation, -0.5); - camera.view(view); - quat.identity(camera.rotation); - quat.rotateY(camera.rotation, camera.rotation, now * 0.0002); - geom.bind(shader); - shader.uniforms.uResolution = RES; - shader.uniforms.uViewRotation = mat4.fromQuat(viewrot, camera.rotation); - shader.uniforms.uProjection = projection; - shader.uniforms.uModel = model; - shader.uniforms.uView = view; - shader.uniforms.tHeightmap = heightmap.color[0].bind(0); - shader.uniforms.tGradient = gradient.bind(1); - geom.draw(); - geom.unbind(); - } -}; - -function createMesh() { - var voxels = qbqb(SIZE, 1, SIZE); - var positions = unindex(combine(voxels)); - var edges = unindex(combine(getEdges(voxels))); - var centroids = unindex(combine(getCentroids(voxels))); - - return { - positions: positions, - centroids: centroids, - normals: normals(positions), - edges: edges - }; -} - -function getCentroids(meshes) { - return meshes.map(function(mesh) { - mesh = clone(mesh); - - for (var i = 0; i < mesh.positions.length; i++) { - mesh.positions[i] = mesh.centroid; - } - - return mesh; - }); -} - -function getEdges(meshes) { - return meshes.map(function(mesh) { - mesh = clone(mesh); - var idx = mesh.index; - - for (var i = 0; i < mesh.positions.length; i++) { - var pos = mesh.positions[i]; - mesh.positions[i] = mesh.positions[i].slice(); - mesh.positions[i][0] = (pos[0] * SIZE - idx[0] - 0.5) * 2; - mesh.positions[i][2] = (pos[2] * SIZE - idx[2] - 0.5) * 2; - mesh.positions[i][1] = (pos[1] - idx[1] - 0.5) * 2; - } - - return mesh; - }); -} -},{"./gradient-map":89,"a-big-triangle":107,"canvas-fit":108,"clone":110,"cube-cube":111,"face-normals":114,"frame-debounce":115,"gl-clear":120,"gl-context":121,"gl-fbo":123,"gl-geometry":126,"gl-matrix":151,"gl-texture2d":164,"glslify":166,"glslify/adapter.js":165,"mesh-combine":172,"orbit-camera":179,"right-now":180,"unindex-mesh":181}],91:[function(require,module,exports){ -arguments[4][8][0].apply(exports,arguments) -},{"ndarray":97,"ndarray-ops":92,"typedarray-pool":101}],92:[function(require,module,exports){ -arguments[4][9][0].apply(exports,arguments) -},{"cwise-compiler":93}],93:[function(require,module,exports){ -arguments[4][10][0].apply(exports,arguments) -},{"./lib/thunk.js":95}],94:[function(require,module,exports){ -arguments[4][11][0].apply(exports,arguments) -},{"uniq":96}],95:[function(require,module,exports){ -arguments[4][12][0].apply(exports,arguments) -},{"./compile.js":94}],96:[function(require,module,exports){ -module.exports=require(13) -},{}],97:[function(require,module,exports){ -arguments[4][14][0].apply(exports,arguments) -},{"buffer":189,"iota-array":98}],98:[function(require,module,exports){ -module.exports=require(15) -},{}],99:[function(require,module,exports){ -module.exports=require(16) -},{}],100:[function(require,module,exports){ -module.exports=require(17) -},{}],101:[function(require,module,exports){ -module.exports=require(18) -},{"bit-twiddle":99,"dup":100}],102:[function(require,module,exports){ -module.exports=require(19) -},{}],103:[function(require,module,exports){ -module.exports=require(20) -},{"./do-bind.js":102}],104:[function(require,module,exports){ -module.exports=require(21) -},{"./do-bind.js":102}],105:[function(require,module,exports){ -module.exports=require(22) -},{}],106:[function(require,module,exports){ -module.exports=require(23) -},{"./lib/vao-emulated.js":103,"./lib/vao-native.js":104,"webglew":105}],107:[function(require,module,exports){ -module.exports=require(24) -},{"gl-buffer":91,"gl-vao":106}],108:[function(require,module,exports){ -var size = require('element-size') - -module.exports = fit - -function fit(canvas) { - canvas.style.position = canvas.style.position || 'absolute' - canvas.style.top = 0 - canvas.style.left = 0 - - return resize() - - function resize() { - if (canvas.parentNode && canvas.parentNode !== document.body) { - var psize = size(canvas.parentNode) - var width = psize[0]|0 - var height = psize[1]|0 - } else { - var width = window.innerWidth - var height = window.innerHeight - } - - canvas.width = width - canvas.height = height - canvas.style.width = width + 'px' - canvas.style.height = height + 'px' - - return resize - } -} - -},{"element-size":109}],109:[function(require,module,exports){ -module.exports = getSize - -function getSize(element) { - // Handle cases where the element is not already - // attached to the DOM by briefly appending it - // to document.body, and removing it again later. - if (!element.parentNode) { - var temporary = true - document.body.appendChild(element) - } - - var bounds = element.getBoundingClientRect() - var styles = getComputedStyle(element) - var height = (bounds.height|0) - + parse(styles.getPropertyValue('margin-top')) - + parse(styles.getPropertyValue('margin-bottom')) - var width = (bounds.width|0) - + parse(styles.getPropertyValue('margin-left')) - + parse(styles.getPropertyValue('margin-right')) - - if (temporary) { - document.body.removeChild(element) - } - - return [width, height] -} - -function parse(prop) { - return parseFloat(prop) || 0 -} - -},{}],110:[function(require,module,exports){ -(function (Buffer){ -'use strict'; - -function objectToString(o) { - return Object.prototype.toString.call(o); -} - -// shim for Node's 'util' package -// DO NOT REMOVE THIS! It is required for compatibility with EnderJS (http://enderjs.com/). -var util = { - isArray: function (ar) { - return Array.isArray(ar) || (typeof ar === 'object' && objectToString(ar) === '[object Array]'); - }, - isDate: function (d) { - return typeof d === 'object' && objectToString(d) === '[object Date]'; - }, - isRegExp: function (re) { - return typeof re === 'object' && objectToString(re) === '[object RegExp]'; - }, - getRegExpFlags: function (re) { - var flags = ''; - re.global && (flags += 'g'); - re.ignoreCase && (flags += 'i'); - re.multiline && (flags += 'm'); - return flags; - } -}; - - -if (typeof module === 'object') - module.exports = clone; - -/** - * Clones (copies) an Object using deep copying. - * - * This function supports circular references by default, but if you are certain - * there are no circular references in your object, you can save some CPU time - * by calling clone(obj, false). - * - * Caution: if `circular` is false and `parent` contains circular references, - * your program may enter an infinite loop and crash. - * - * @param `parent` - the object to be cloned - * @param `circular` - set to true if the object to be cloned may contain - * circular references. (optional - true by default) - * @param `depth` - set to a number if the object is only to be cloned to - * a particular depth. (optional - defaults to Infinity) - * @param `prototype` - sets the prototype to be used when cloning an object. - * (optional - defaults to parent prototype). -*/ - -function clone(parent, circular, depth, prototype) { - // maintain two arrays for circular references, where corresponding parents - // and children have the same index - var allParents = []; - var allChildren = []; - - var useBuffer = typeof Buffer != 'undefined'; - - if (typeof circular == 'undefined') - circular = true; - - if (typeof depth == 'undefined') - depth = Infinity; - - // recurse this function so we don't reset allParents and allChildren - function _clone(parent, depth) { - // cloning null always returns null - if (parent === null) - return null; - - if (depth == 0) - return parent; - - var child; - if (typeof parent != 'object') { - return parent; - } - - if (util.isArray(parent)) { - child = []; - } else if (util.isRegExp(parent)) { - child = new RegExp(parent.source, util.getRegExpFlags(parent)); - if (parent.lastIndex) child.lastIndex = parent.lastIndex; - } else if (util.isDate(parent)) { - child = new Date(parent.getTime()); - } else if (useBuffer && Buffer.isBuffer(parent)) { - child = new Buffer(parent.length); - parent.copy(child); - return child; - } else { - if (typeof prototype == 'undefined') child = Object.create(Object.getPrototypeOf(parent)); - else child = Object.create(prototype); - } - - if (circular) { - var index = allParents.indexOf(parent); - - if (index != -1) { - return allChildren[index]; - } - allParents.push(parent); - allChildren.push(child); - } - - for (var i in parent) { - child[i] = _clone(parent[i], depth - 1); - } - - return child; - } - - return _clone(parent, depth); -} - -/** - * Simple flat clone using prototype, accepts only objects, usefull for property - * override on FLAT configuration object (no nested props). - * - * USE WITH CAUTION! This may not behave as you wish if you do not know how this - * works. - */ -clone.clonePrototype = function(parent) { - if (parent === null) - return null; - - var c = function () {}; - c.prototype = parent; - return new c(); -}; - -}).call(this,require("buffer").Buffer) -},{"buffer":189}],111:[function(require,module,exports){ -var prism = require('rectangular-prism') -var truthy = function() { return true } - -module.exports = cubecube - -function cubecube(w, h, d, filter) { - filter = filter || truthy - - var size = [1/w, 1/h, 1/d] - var cubes = [] - - for (var x = 0; x < w; x++) - for (var y = 0; y < h; y++) - for (var z = 0; z < d; z++) { - if (filter(x, y, z)) { - var cube = prism(size, [x/w, y/h, z/d]) - - cubes.push(cube) - cube.centroid = [(x+0.5)/w, (y+0.5)/h, (z+0.5)/d] - cube.index = [x, y, z] - } - } - - return cubes -} - -},{"rectangular-prism":113}],112:[function(require,module,exports){ -module.exports = { - cells: [ - [1, 0, 2], - [3, 1, 2], - [4, 5, 6], - [5, 7, 6], - [0, 1, 5], - [4, 0, 5], - [1, 3, 5], - [3, 7, 5], - [2, 0, 4], - [2, 4, 6], - [2, 6, 3], - [6, 7, 3] - ], - positions: [ - [0, 0, 0], - [0, 0, 1], - [1, 0, 0], - [1, 0, 1], - [0, 1, 0], - [0, 1, 1], - [1, 1, 0], - [1, 1, 1] - ] -} - -},{}],113:[function(require,module,exports){ -var prism = require('./cube') - -module.exports = createPrism - -function createPrism(size, pos) { - pos = pos || [0,0,0] - size = size || [1,1,1] - - if (!Array.isArray(size)) { - size = [size, size, size] - } - - var prism = clonePrism() - - for (var i = 0; i < prism.positions.length; i++) { - prism.positions[i][0] *= size[0] - prism.positions[i][1] *= size[1] - prism.positions[i][2] *= size[2] - prism.positions[i][0] += pos[0] - prism.positions[i][1] += pos[1] - prism.positions[i][2] += pos[2] - } - - return prism -} - -function clonePrism() { - return { - cells: prism.cells.map(function(d) { - return d.slice() - }), - positions: prism.positions.map(function(d) { - return d.slice() - }) - } -} - -},{"./cube":112}],114:[function(require,module,exports){ -module.exports = faceNormals - -function faceNormals(verts, output) { - var l = verts.length - if (!output) output = new Float32Array(l) - - for (var i = 0; i < l; i += 9) { - var p1x = verts[i+3] - verts[i] - var p1y = verts[i+4] - verts[i+1] - var p1z = verts[i+5] - verts[i+2] - - var p2x = verts[i+6] - verts[i] - var p2y = verts[i+7] - verts[i+1] - var p2z = verts[i+8] - verts[i+2] - - var p3x = p1y * p2z - p1z * p2y - var p3y = p1z * p2x - p1x * p2z - var p3z = p1x * p2y - p1y * p2x - - var mag = Math.sqrt(p3x * p3x + p3y * p3y + p3z * p3z) - if (mag === 0) { - output[i ] = 0 - output[i+1] = 0 - output[i+2] = 0 - - output[i+3] = 0 - output[i+4] = 0 - output[i+5] = 0 - - output[i+6] = 0 - output[i+7] = 0 - output[i+8] = 0 - } else { - p3x = p3x / mag - p3y = p3y / mag - p3z = p3z / mag - - output[i ] = p3x - output[i+1] = p3y - output[i+2] = p3z - - output[i+3] = p3x - output[i+4] = p3y - output[i+5] = p3z - - output[i+6] = p3x - output[i+7] = p3y - output[i+8] = p3z - } - } - - return output -} - -},{}],115:[function(require,module,exports){ -arguments[4][27][0].apply(exports,arguments) -},{"_process":192,"raf-component":116,"sliced":117}],116:[function(require,module,exports){ -module.exports=require(28) -},{}],117:[function(require,module,exports){ -arguments[4][29][0].apply(exports,arguments) -},{"./lib/sliced":118}],118:[function(require,module,exports){ -module.exports=require(30) -},{}],119:[function(require,module,exports){ -module.exports=require(44) -},{}],120:[function(require,module,exports){ -module.exports=require(45) -},{"./defaults":119}],121:[function(require,module,exports){ -var raf = require('raf-component') - -module.exports = createContext - -function createContext(canvas, opts, render) { - if (typeof opts === 'function') { - render = opts - opts = {} - } else { - opts = opts || {} - } - - var gl = ( - canvas.getContext('webgl', opts) || - canvas.getContext('webgl-experimental', opts) || - canvas.getContext('experimental-webgl', opts) - ) - - if (!gl) { - throw new Error('Unable to initialize WebGL') - } - - if (render) raf(tick) - - return gl - - function tick() { - render(gl) - raf(tick) - } -} - -},{"raf-component":122}],122:[function(require,module,exports){ -module.exports=require(28) -},{}],123:[function(require,module,exports){ -"use strict"; - -var webglew = require("webglew") -var createTexture = require("gl-texture2d") - -module.exports = createFBO - -var colorAttachmentArrays = null -var FRAMEBUFFER_UNSUPPORTED -var FRAMEBUFFER_INCOMPLETE_ATTACHMENT -var FRAMEBUFFER_INCOMPLETE_DIMENSIONS -var FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT - -function lazyInitColorAttachments(gl, ext) { - var maxColorAttachments = gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL); - colorAttachmentArrays = new Array(maxColorAttachments + 1) - for(var i=0; i<=maxColorAttachments; ++i) { - var x = new Array(maxColorAttachments) - for(var j=0; j 1) { - ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]) - } - - //Allocate depth/stencil buffers - if(extensions.WEBGL_depth_texture) { - if(useStencil) { - fbo.depth = initTexture(gl, width, height, - extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL, - gl.DEPTH_STENCIL, - gl.DEPTH_STENCIL_ATTACHMENT) - } else if(useDepth) { - fbo.depth = initTexture(gl, width, height, - gl.UNSIGNED_SHORT, - gl.DEPTH_COMPONENT, - gl.DEPTH_ATTACHMENT) - } - } else { - if(useDepth && useStencil) { - fbo._depth_rb = initRenderBuffer(gl, width, height, gl.DEPTH_STENCIL, gl.DEPTH_STENCIL_ATTACHMENT) - } else if(useDepth) { - fbo._depth_rb = initRenderBuffer(gl, width, height, gl.DEPTH_COMPONENT16, gl.DEPTH_ATTACHMENT) - } else if(useStencil) { - fbo._depth_rb = initRenderBuffer(gl, width, height, gl.STENCIL_INDEX, gl.STENCIL_ATTACHMENT) - } - } - - //Check frame buffer state - var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER) - if(status !== gl.FRAMEBUFFER_COMPLETE) { - - //Release all partially allocated resources - fbo._destroyed = true - - //Release all resources - gl.bindFramebuffer(gl.FRAMEBUFFER, null) - gl.deleteFramebuffer(fbo.handle) - fbo.handle = null - if(fbo.depth) { - fbo.depth.dispose() - fbo.depth = null - } - if(fbo._depth_rb) { - gl.deleteRenderbuffer(fbo._depth_rb) - fbo._depth_rb = null - } - for(var i=0; i maxFBOSize || - x[1] < 0 || x[1] > maxFBOSize) { - throw new Error("gl-fbo: Can't resize FBO, invalid dimensions") - } - - //Update shape - this._shape[0] = x[0]|0 - this._shape[1] = x[1]|0 - - //Resize framebuffer attachments - for(var i=0; i maxFBOSize || height < 0 || height > maxFBOSize) { - throw new Error("gl-fbo: Parameters are too large for FBO") - } - - //Handle each option type - options = options || {} - - //Figure out number of color buffers to use - var numColors = 1 - if("color" in options) { - numColors = Math.max(options.color|0, 0) - if(numColors < 0) { - throw new Error("gl-fbo: Must specify a nonnegative number of colors") - } - if(numColors > 1) { - //Check if multiple render targets supported - var mrtext = extensions.WEBGL_draw_buffers - if(!mrtext) { - throw new Error("gl-fbo: Multiple draw buffer extension not supported") - } else if(numColors > gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL)) { - throw new Error("gl-fbo: Context does not support " + numColors + " draw buffers") - } - } - } - - //Determine whether to use floating point textures - var colorType = gl.UNSIGNED_BYTE - if(options.float && numColors > 0) { - if(!extensions.OES_texture_float) { - throw new Error("gl-fbo: Context does not support floating point textures") - } - colorType = gl.FLOAT - } else if(options.preferFloat && numColors > 0) { - if(extensions.OES_texture_float) { - colorType = gl.FLOAT - } - } - - //Check if we should use depth buffer - var useDepth = true - if("depth" in options) { - useDepth = !!options.depth - } - - //Check if we should use a stencil buffer - var useStencil = false - if("stencil" in options) { - useStencil = !!options.stencil - } - - return new Framebuffer( - gl, - width, - height, - colorType, - numColors, - useDepth, - useStencil, - extensions.WEBGL_draw_buffers) -} -},{"gl-texture2d":164,"webglew":125}],124:[function(require,module,exports){ -module.exports=require(42) -},{}],125:[function(require,module,exports){ -module.exports=require(43) -},{"weakmap":124}],126:[function(require,module,exports){ -var normalize = require('./normalize') -var createVAO = require('gl-vao') - -module.exports = GLGeometry - -function GLGeometry(gl) { - if (!(this instanceof GLGeometry)) - return new GLGeometry(gl) - - this._attributes = [] - this._dirty = true - this._length = 0 - this._index = null - this._vao = null - this._keys = [] - this.gl = gl -} - -GLGeometry.prototype.faces = function faces(attr, opts) { - var size = opts && opts.size || 3 - attr = attr.cells ? attr.cells : attr - - this._dirty = true - this._index = normalize(this.gl - , attr - , size - , this.gl.ELEMENT_ARRAY_BUFFER - , 'uint16' - ) - - this._length = this._index.length * size - this._index = this._index.buffer - - return this -} - -GLGeometry.prototype.attr = function attr(name, attr, opts) { - opts = opts || {} - this._dirty = true - - var gl = this.gl - var first = !this._attributes.length - var size = opts.size || 3 - - var attribute = normalize(gl, attr, size) - if (!attribute) { - throw new Error( - 'Unexpected attribute format: needs an ndarray, array, typed array, ' - + 'gl-buffer or simplicial complex' - ) - } - - var buffer = attribute.buffer - var length = attribute.length - var index = attribute.index - - this._keys.push(name) - this._attributes.push({ - size: size - , buffer: buffer - }) - - if (first) { - this._length = length - } - - if (first && index) { - this._index = index - } - - return this -} - -GLGeometry.prototype.bind = function bind(shader) { - this.update() - this._vao.bind() - - if (!shader) return - shader.bind() - - if (!this._keys) return - for (var i = 0; i < this._keys.length; i++) { - var attr = shader.attributes[this._keys[i]] - if (attr) attr.location = i - } -} - -GLGeometry.prototype.draw = function draw(mode) { - this.update() - this._vao.draw(mode || this.gl.TRIANGLES, this._length) -} - -GLGeometry.prototype.unbind = function unbind() { - this.update() - this._vao.unbind() -} - -GLGeometry.prototype.update = function update() { - if (!this._dirty) return - this._dirty = false - if (this._vao) this._vao.dispose() - - this._vao = createVAO( - this.gl - , this._attributes - , this._index - ) -} - -},{"./normalize":150,"gl-vao":147}],127:[function(require,module,exports){ -var dtype = require('dtype') - -module.exports = pack - -function pack(arr, type) { - type = type || 'float32' - - if (!arr[0] || !arr[0].length) { - return arr - } - - var Arr = typeof type === 'string' - ? dtype(type) - : type - - var dim = arr[0].length - var out = new Arr(arr.length * dim) - var k = 0 - - for (var i = 0; i < arr.length; i++) - for (var j = 0; j < dim; j++) { - out[k++] = arr[i][j] - } - - return out -} - -},{"dtype":128}],128:[function(require,module,exports){ -module.exports = function(dtype) { - switch (dtype) { - case 'int8': - return Int8Array - case 'int16': - return Int16Array - case 'int32': - return Int32Array - case 'uint8': - return Uint8Array - case 'uint16': - return Uint16Array - case 'uint32': - return Uint32Array - case 'float32': - return Float32Array - case 'float64': - return Float64Array - case 'array': - return Array - } -} -},{}],129:[function(require,module,exports){ -"use strict" - -var pool = require("typedarray-pool") -var ops = require("ndarray-ops") -var ndarray = require("ndarray") -var webglew = require("webglew") - -var SUPPORTED_TYPES = [ - "uint8", - "uint8_clamped", - "uint16", - "uint32", - "int8", - "int16", - "int32", - "float32" ] - -function GLBuffer(gl, type, handle, length, usage) { - this.gl = gl - this.type = type - this.handle = handle - this.length = length - this.usage = usage -} - -var proto = GLBuffer.prototype - -proto.bind = function() { - this.gl.bindBuffer(this.type, this.handle) -} - -proto.dispose = function() { - this.gl.deleteBuffer(this.handle) -} - -function updateTypeArray(gl, type, len, usage, data, offset) { - var dataLen = data.length * data.BYTES_PER_ELEMENT - if(offset < 0) { - gl.bufferData(type, data, usage) - return dataLen - } - if(dataLen + offset > len) { - throw new Error("gl-buffer: If resizing buffer, must not specify offset") - } - gl.bufferSubData(type, offset, data) - return len -} - -function makeScratchTypeArray(array, dtype) { - var res = pool.malloc(array.length, dtype) - var n = array.length - for(var i=0; i=0; --i) { - if(stride[i] !== n) { - return false - } - n *= shape[i] - } - return true -} - -proto.update = function(array, offset) { - if(typeof offset !== "number") { - offset = -1 - } - this.bind() - if(typeof array === "object" && typeof array.shape !== "undefined") { //ndarray - var dtype = array.dtype - if(SUPPORTED_TYPES.indexOf(dtype) < 0) { - dtype = "float32" - } - if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) { - var wgl = webglew(gl) - var ext = wgl.OES_element_index_uint - if(ext && dtype !== "uint16") { - dtype = "uint32" - } else { - dtype = "uint16" - } - } - if(dtype === array.dtype && isPacked(array.shape, array.stride)) { - if(array.offset === 0 && array.data.length === array.shape[0]) { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data, offset) - } else { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data.subarray(array.offset, array.shape[0]), offset) - } - } else { - var tmp = pool.malloc(array.size, dtype) - var ndt = ndarray(tmp, array.shape) - ops.assign(ndt, array) - if(offset < 0) { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, tmp, offset) - } else { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, tmp.subarray(0, array.size), offset) - } - pool.free(tmp) - } - } else if(Array.isArray(array)) { //Vanilla array - var t - if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) { - t = makeScratchTypeArray(array, "uint16") - } else { - t = makeScratchTypeArray(array, "float32") - } - if(offset < 0) { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t, offset) - } else { - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t.subarray(0, array.length), offset) - } - pool.free(t) - } else if(typeof array === "object" && typeof array.length === "number") { //Typed array - this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array, offset) - } else if(typeof array === "number" || array === undefined) { //Number/default - if(offset >= 0) { - throw new Error("gl-buffer: Cannot specify offset when resizing buffer") - } - array = array | 0 - if(array <= 0) { - array = 1 - } - this.gl.bufferData(this.type, array|0, this.usage) - this.length = array - } else { //Error, case should not happen - throw new Error("gl-buffer: Invalid data type") - } -} - -function createBuffer(gl, data, type, usage) { - webglew(gl) - type = type || gl.ARRAY_BUFFER - usage = usage || gl.DYNAMIC_DRAW - if(type !== gl.ARRAY_BUFFER && type !== gl.ELEMENT_ARRAY_BUFFER) { - throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER") - } - if(usage !== gl.DYNAMIC_DRAW && usage !== gl.STATIC_DRAW && usage !== gl.STREAM_DRAW) { - throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW") - } - var handle = gl.createBuffer() - var result = new GLBuffer(gl, type, handle, 0, usage) - result.update(data) - return result -} - -module.exports = createBuffer -},{"ndarray":135,"ndarray-ops":130,"typedarray-pool":139,"webglew":141}],130:[function(require,module,exports){ -arguments[4][9][0].apply(exports,arguments) -},{"cwise-compiler":131}],131:[function(require,module,exports){ -arguments[4][10][0].apply(exports,arguments) -},{"./lib/thunk.js":133}],132:[function(require,module,exports){ -arguments[4][11][0].apply(exports,arguments) -},{"uniq":134}],133:[function(require,module,exports){ -arguments[4][12][0].apply(exports,arguments) -},{"./compile.js":132}],134:[function(require,module,exports){ -module.exports=require(13) -},{}],135:[function(require,module,exports){ -arguments[4][14][0].apply(exports,arguments) -},{"buffer":189,"iota-array":136}],136:[function(require,module,exports){ -module.exports=require(15) -},{}],137:[function(require,module,exports){ -module.exports=require(16) -},{}],138:[function(require,module,exports){ -module.exports=require(17) -},{}],139:[function(require,module,exports){ -module.exports=require(41) -},{"bit-twiddle":137,"buffer":189,"dup":138}],140:[function(require,module,exports){ -module.exports=require(42) -},{}],141:[function(require,module,exports){ -module.exports=require(43) -},{"weakmap":140}],142:[function(require,module,exports){ -module.exports=require(73) -},{}],143:[function(require,module,exports){ -"use strict" - -var bindAttribs = require("./do-bind.js") - -function VAOEmulated(gl) { - this.gl = gl - this._elements = null - this._attributes = null -} - -VAOEmulated.prototype.bind = function() { - bindAttribs(this.gl, this._elements, this._attributes) -} - -VAOEmulated.prototype.update = function(attributes, elements) { - this._elements = elements - this._attributes = attributes -} - -VAOEmulated.prototype.dispose = function() { } -VAOEmulated.prototype.unbind = function() { } - -VAOEmulated.prototype.draw = function(mode, count, offset) { - offset = offset || 0 - var gl = this.gl - if(this._elements) { - gl.drawElements(mode, count, gl.UNSIGNED_SHORT, offset) - } else { - gl.drawArrays(mode, offset, count) - } -} - -function createVAOEmulated(gl) { - return new VAOEmulated(gl) -} - -module.exports = createVAOEmulated -},{"./do-bind.js":142}],144:[function(require,module,exports){ -"use strict" - -var bindAttribs = require("./do-bind.js") - -function VertexAttribute(location, dimension, a, b, c, d) { - this.location = location - this.dimension = dimension - this.a = a - this.b = b - this.c = c - this.d = d -} - -VertexAttribute.prototype.bind = function(gl) { - switch(this.dimension) { - case 1: - gl.vertexAttrib1f(this.location, this.a) - break - case 2: - gl.vertexAttrib2f(this.location, this.a, this.b) - break - case 3: - gl.vertexAttrib3f(this.location, this.a, this.b, this.c) - break - case 4: - gl.vertexAttrib4f(this.location, this.a, this.b, this.c, this.d) - break - } -} - -function VAONative(gl, ext, handle) { - this.gl = gl - this._ext = ext - this.handle = handle - this._attribs = [] - this._useElements = false -} - -VAONative.prototype.bind = function() { - this._ext.bindVertexArrayOES(this.handle) - for(var i=0; i 0) { - //TODO: evaluate use of glm_invsqrt here? - len = 1 / Math.sqrt(len); - out[0] = a[0] * len; - out[1] = a[1] * len; - } - return out; -}; - -/** - * Calculates the dot product of two vec2's - * - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {Number} dot product of a and b - */ -vec2.dot = function (a, b) { - return a[0] * b[0] + a[1] * b[1]; -}; - -/** - * Computes the cross product of two vec2's - * Note that the cross product must by definition produce a 3D vector - * - * @param {vec3} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {vec3} out - */ -vec2.cross = function(out, a, b) { - var z = a[0] * b[1] - a[1] * b[0]; - out[0] = out[1] = 0; - out[2] = z; - return out; -}; - -/** - * Performs a linear interpolation between two vec2's - * - * @param {vec2} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {vec2} out - */ -vec2.lerp = function (out, a, b, t) { - var ax = a[0], - ay = a[1]; - out[0] = ax + t * (b[0] - ax); - out[1] = ay + t * (b[1] - ay); - return out; -}; - -/** - * Transforms the vec2 with a mat2 - * - * @param {vec2} out the receiving vector - * @param {vec2} a the vector to transform - * @param {mat2} m matrix to transform with - * @returns {vec2} out - */ -vec2.transformMat2 = function(out, a, m) { - var x = a[0], - y = a[1]; - out[0] = m[0] * x + m[2] * y; - out[1] = m[1] * x + m[3] * y; - return out; -}; - -/** - * Transforms the vec2 with a mat2d - * - * @param {vec2} out the receiving vector - * @param {vec2} a the vector to transform - * @param {mat2d} m matrix to transform with - * @returns {vec2} out - */ -vec2.transformMat2d = function(out, a, m) { - var x = a[0], - y = a[1]; - out[0] = m[0] * x + m[2] * y + m[4]; - out[1] = m[1] * x + m[3] * y + m[5]; - return out; -}; - -/** - * Transforms the vec2 with a mat3 - * 3rd vector component is implicitly '1' - * - * @param {vec2} out the receiving vector - * @param {vec2} a the vector to transform - * @param {mat3} m matrix to transform with - * @returns {vec2} out - */ -vec2.transformMat3 = function(out, a, m) { - var x = a[0], - y = a[1]; - out[0] = m[0] * x + m[3] * y + m[6]; - out[1] = m[1] * x + m[4] * y + m[7]; - return out; -}; - -/** - * Transforms the vec2 with a mat4 - * 3rd vector component is implicitly '0' - * 4th vector component is implicitly '1' - * - * @param {vec2} out the receiving vector - * @param {vec2} a the vector to transform - * @param {mat4} m matrix to transform with - * @returns {vec2} out - */ -vec2.transformMat4 = function(out, a, m) { - var x = a[0], - y = a[1]; - out[0] = m[0] * x + m[4] * y + m[12]; - out[1] = m[1] * x + m[5] * y + m[13]; - return out; -}; - -/** - * Perform some operation over an array of vec2s. - * - * @param {Array} a the array of vectors to iterate over - * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed - * @param {Number} offset Number of elements to skip at the beginning of the array - * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array - * @param {Function} fn Function to call for each vector in the array - * @param {Object} [arg] additional argument to pass to fn - * @returns {Array} a - * @function - */ -vec2.forEach = (function() { - var vec = vec2.create(); - - return function(a, stride, offset, count, fn, arg) { - var i, l; - if(!stride) { - stride = 2; - } - - if(!offset) { - offset = 0; - } - - if(count) { - l = Math.min((count * stride) + offset, a.length); - } else { - l = a.length; - } - - for(i = offset; i < l; i += stride) { - vec[0] = a[i]; vec[1] = a[i+1]; - fn(vec, vec, arg); - a[i] = vec[0]; a[i+1] = vec[1]; - } - - return a; - }; -})(); - -/** - * Returns a string representation of a vector - * - * @param {vec2} vec vector to represent as a string - * @returns {String} string representation of the vector - */ -vec2.str = function (a) { - return 'vec2(' + a[0] + ', ' + a[1] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.vec2 = vec2; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 3 Dimensional Vector - * @name vec3 - */ - -var vec3 = {}; - -/** - * Creates a new, empty vec3 - * - * @returns {vec3} a new 3D vector - */ -vec3.create = function() { - var out = new GLMAT_ARRAY_TYPE(3); - out[0] = 0; - out[1] = 0; - out[2] = 0; - return out; -}; - -/** - * Creates a new vec3 initialized with values from an existing vector - * - * @param {vec3} a vector to clone - * @returns {vec3} a new 3D vector - */ -vec3.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(3); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - return out; -}; - -/** - * Creates a new vec3 initialized with the given values - * - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @returns {vec3} a new 3D vector - */ -vec3.fromValues = function(x, y, z) { - var out = new GLMAT_ARRAY_TYPE(3); - out[0] = x; - out[1] = y; - out[2] = z; - return out; -}; - -/** - * Copy the values from one vec3 to another - * - * @param {vec3} out the receiving vector - * @param {vec3} a the source vector - * @returns {vec3} out - */ -vec3.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - return out; -}; - -/** - * Set the components of a vec3 to the given values - * - * @param {vec3} out the receiving vector - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @returns {vec3} out - */ -vec3.set = function(out, x, y, z) { - out[0] = x; - out[1] = y; - out[2] = z; - return out; -}; - -/** - * Adds two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.add = function(out, a, b) { - out[0] = a[0] + b[0]; - out[1] = a[1] + b[1]; - out[2] = a[2] + b[2]; - return out; -}; - -/** - * Subtracts two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.subtract = function(out, a, b) { - out[0] = a[0] - b[0]; - out[1] = a[1] - b[1]; - out[2] = a[2] - b[2]; - return out; -}; - -/** - * Alias for {@link vec3.subtract} - * @function - */ -vec3.sub = vec3.subtract; - -/** - * Multiplies two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.multiply = function(out, a, b) { - out[0] = a[0] * b[0]; - out[1] = a[1] * b[1]; - out[2] = a[2] * b[2]; - return out; -}; - -/** - * Alias for {@link vec3.multiply} - * @function - */ -vec3.mul = vec3.multiply; - -/** - * Divides two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.divide = function(out, a, b) { - out[0] = a[0] / b[0]; - out[1] = a[1] / b[1]; - out[2] = a[2] / b[2]; - return out; -}; - -/** - * Alias for {@link vec3.divide} - * @function - */ -vec3.div = vec3.divide; - -/** - * Returns the minimum of two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.min = function(out, a, b) { - out[0] = Math.min(a[0], b[0]); - out[1] = Math.min(a[1], b[1]); - out[2] = Math.min(a[2], b[2]); - return out; -}; - -/** - * Returns the maximum of two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.max = function(out, a, b) { - out[0] = Math.max(a[0], b[0]); - out[1] = Math.max(a[1], b[1]); - out[2] = Math.max(a[2], b[2]); - return out; -}; - -/** - * Scales a vec3 by a scalar number - * - * @param {vec3} out the receiving vector - * @param {vec3} a the vector to scale - * @param {Number} b amount to scale the vector by - * @returns {vec3} out - */ -vec3.scale = function(out, a, b) { - out[0] = a[0] * b; - out[1] = a[1] * b; - out[2] = a[2] * b; - return out; -}; - -/** - * Calculates the euclidian distance between two vec3's - * - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {Number} distance between a and b - */ -vec3.distance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2]; - return Math.sqrt(x*x + y*y + z*z); -}; - -/** - * Alias for {@link vec3.distance} - * @function - */ -vec3.dist = vec3.distance; - -/** - * Calculates the squared euclidian distance between two vec3's - * - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {Number} squared distance between a and b - */ -vec3.squaredDistance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2]; - return x*x + y*y + z*z; -}; - -/** - * Alias for {@link vec3.squaredDistance} - * @function - */ -vec3.sqrDist = vec3.squaredDistance; - -/** - * Calculates the length of a vec3 - * - * @param {vec3} a vector to calculate length of - * @returns {Number} length of a - */ -vec3.length = function (a) { - var x = a[0], - y = a[1], - z = a[2]; - return Math.sqrt(x*x + y*y + z*z); -}; - -/** - * Alias for {@link vec3.length} - * @function - */ -vec3.len = vec3.length; - -/** - * Calculates the squared length of a vec3 - * - * @param {vec3} a vector to calculate squared length of - * @returns {Number} squared length of a - */ -vec3.squaredLength = function (a) { - var x = a[0], - y = a[1], - z = a[2]; - return x*x + y*y + z*z; -}; - -/** - * Alias for {@link vec3.squaredLength} - * @function - */ -vec3.sqrLen = vec3.squaredLength; - -/** - * Negates the components of a vec3 - * - * @param {vec3} out the receiving vector - * @param {vec3} a vector to negate - * @returns {vec3} out - */ -vec3.negate = function(out, a) { - out[0] = -a[0]; - out[1] = -a[1]; - out[2] = -a[2]; - return out; -}; - -/** - * Normalize a vec3 - * - * @param {vec3} out the receiving vector - * @param {vec3} a vector to normalize - * @returns {vec3} out - */ -vec3.normalize = function(out, a) { - var x = a[0], - y = a[1], - z = a[2]; - var len = x*x + y*y + z*z; - if (len > 0) { - //TODO: evaluate use of glm_invsqrt here? - len = 1 / Math.sqrt(len); - out[0] = a[0] * len; - out[1] = a[1] * len; - out[2] = a[2] * len; - } - return out; -}; - -/** - * Calculates the dot product of two vec3's - * - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {Number} dot product of a and b - */ -vec3.dot = function (a, b) { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; -}; - -/** - * Computes the cross product of two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.cross = function(out, a, b) { - var ax = a[0], ay = a[1], az = a[2], - bx = b[0], by = b[1], bz = b[2]; - - out[0] = ay * bz - az * by; - out[1] = az * bx - ax * bz; - out[2] = ax * by - ay * bx; - return out; -}; - -/** - * Performs a linear interpolation between two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {vec3} out - */ -vec3.lerp = function (out, a, b, t) { - var ax = a[0], - ay = a[1], - az = a[2]; - out[0] = ax + t * (b[0] - ax); - out[1] = ay + t * (b[1] - ay); - out[2] = az + t * (b[2] - az); - return out; -}; - -/** - * Transforms the vec3 with a mat4. - * 4th vector component is implicitly '1' - * - * @param {vec3} out the receiving vector - * @param {vec3} a the vector to transform - * @param {mat4} m matrix to transform with - * @returns {vec3} out - */ -vec3.transformMat4 = function(out, a, m) { - var x = a[0], y = a[1], z = a[2]; - out[0] = m[0] * x + m[4] * y + m[8] * z + m[12]; - out[1] = m[1] * x + m[5] * y + m[9] * z + m[13]; - out[2] = m[2] * x + m[6] * y + m[10] * z + m[14]; - return out; -}; - -/** - * Transforms the vec3 with a quat - * - * @param {vec3} out the receiving vector - * @param {vec3} a the vector to transform - * @param {quat} q quaternion to transform with - * @returns {vec3} out - */ -vec3.transformQuat = function(out, a, q) { - var x = a[0], y = a[1], z = a[2], - qx = q[0], qy = q[1], qz = q[2], qw = q[3], - - // calculate quat * vec - ix = qw * x + qy * z - qz * y, - iy = qw * y + qz * x - qx * z, - iz = qw * z + qx * y - qy * x, - iw = -qx * x - qy * y - qz * z; - - // calculate result * inverse quat - out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; - out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; - out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; - return out; -}; - -/** - * Perform some operation over an array of vec3s. - * - * @param {Array} a the array of vectors to iterate over - * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed - * @param {Number} offset Number of elements to skip at the beginning of the array - * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array - * @param {Function} fn Function to call for each vector in the array - * @param {Object} [arg] additional argument to pass to fn - * @returns {Array} a - * @function - */ -vec3.forEach = (function() { - var vec = vec3.create(); - - return function(a, stride, offset, count, fn, arg) { - var i, l; - if(!stride) { - stride = 3; - } - - if(!offset) { - offset = 0; - } - - if(count) { - l = Math.min((count * stride) + offset, a.length); - } else { - l = a.length; - } - - for(i = offset; i < l; i += stride) { - vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; - fn(vec, vec, arg); - a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; - } - - return a; - }; -})(); - -/** - * Returns a string representation of a vector - * - * @param {vec3} vec vector to represent as a string - * @returns {String} string representation of the vector - */ -vec3.str = function (a) { - return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.vec3 = vec3; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 4 Dimensional Vector - * @name vec4 - */ - -var vec4 = {}; - -/** - * Creates a new, empty vec4 - * - * @returns {vec4} a new 4D vector - */ -vec4.create = function() { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = 0; - out[1] = 0; - out[2] = 0; - out[3] = 0; - return out; -}; - -/** - * Creates a new vec4 initialized with values from an existing vector - * - * @param {vec4} a vector to clone - * @returns {vec4} a new 4D vector - */ -vec4.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - return out; -}; - -/** - * Creates a new vec4 initialized with the given values - * - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @param {Number} w W component - * @returns {vec4} a new 4D vector - */ -vec4.fromValues = function(x, y, z, w) { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = x; - out[1] = y; - out[2] = z; - out[3] = w; - return out; -}; - -/** - * Copy the values from one vec4 to another - * - * @param {vec4} out the receiving vector - * @param {vec4} a the source vector - * @returns {vec4} out - */ -vec4.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - return out; -}; - -/** - * Set the components of a vec4 to the given values - * - * @param {vec4} out the receiving vector - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @param {Number} w W component - * @returns {vec4} out - */ -vec4.set = function(out, x, y, z, w) { - out[0] = x; - out[1] = y; - out[2] = z; - out[3] = w; - return out; -}; - -/** - * Adds two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.add = function(out, a, b) { - out[0] = a[0] + b[0]; - out[1] = a[1] + b[1]; - out[2] = a[2] + b[2]; - out[3] = a[3] + b[3]; - return out; -}; - -/** - * Subtracts two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.subtract = function(out, a, b) { - out[0] = a[0] - b[0]; - out[1] = a[1] - b[1]; - out[2] = a[2] - b[2]; - out[3] = a[3] - b[3]; - return out; -}; - -/** - * Alias for {@link vec4.subtract} - * @function - */ -vec4.sub = vec4.subtract; - -/** - * Multiplies two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.multiply = function(out, a, b) { - out[0] = a[0] * b[0]; - out[1] = a[1] * b[1]; - out[2] = a[2] * b[2]; - out[3] = a[3] * b[3]; - return out; -}; - -/** - * Alias for {@link vec4.multiply} - * @function - */ -vec4.mul = vec4.multiply; - -/** - * Divides two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.divide = function(out, a, b) { - out[0] = a[0] / b[0]; - out[1] = a[1] / b[1]; - out[2] = a[2] / b[2]; - out[3] = a[3] / b[3]; - return out; -}; - -/** - * Alias for {@link vec4.divide} - * @function - */ -vec4.div = vec4.divide; - -/** - * Returns the minimum of two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.min = function(out, a, b) { - out[0] = Math.min(a[0], b[0]); - out[1] = Math.min(a[1], b[1]); - out[2] = Math.min(a[2], b[2]); - out[3] = Math.min(a[3], b[3]); - return out; -}; - -/** - * Returns the maximum of two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.max = function(out, a, b) { - out[0] = Math.max(a[0], b[0]); - out[1] = Math.max(a[1], b[1]); - out[2] = Math.max(a[2], b[2]); - out[3] = Math.max(a[3], b[3]); - return out; -}; - -/** - * Scales a vec4 by a scalar number - * - * @param {vec4} out the receiving vector - * @param {vec4} a the vector to scale - * @param {Number} b amount to scale the vector by - * @returns {vec4} out - */ -vec4.scale = function(out, a, b) { - out[0] = a[0] * b; - out[1] = a[1] * b; - out[2] = a[2] * b; - out[3] = a[3] * b; - return out; -}; - -/** - * Calculates the euclidian distance between two vec4's - * - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {Number} distance between a and b - */ -vec4.distance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2], - w = b[3] - a[3]; - return Math.sqrt(x*x + y*y + z*z + w*w); -}; - -/** - * Alias for {@link vec4.distance} - * @function - */ -vec4.dist = vec4.distance; - -/** - * Calculates the squared euclidian distance between two vec4's - * - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {Number} squared distance between a and b - */ -vec4.squaredDistance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2], - w = b[3] - a[3]; - return x*x + y*y + z*z + w*w; -}; - -/** - * Alias for {@link vec4.squaredDistance} - * @function - */ -vec4.sqrDist = vec4.squaredDistance; - -/** - * Calculates the length of a vec4 - * - * @param {vec4} a vector to calculate length of - * @returns {Number} length of a - */ -vec4.length = function (a) { - var x = a[0], - y = a[1], - z = a[2], - w = a[3]; - return Math.sqrt(x*x + y*y + z*z + w*w); -}; - -/** - * Alias for {@link vec4.length} - * @function - */ -vec4.len = vec4.length; - -/** - * Calculates the squared length of a vec4 - * - * @param {vec4} a vector to calculate squared length of - * @returns {Number} squared length of a - */ -vec4.squaredLength = function (a) { - var x = a[0], - y = a[1], - z = a[2], - w = a[3]; - return x*x + y*y + z*z + w*w; -}; - -/** - * Alias for {@link vec4.squaredLength} - * @function - */ -vec4.sqrLen = vec4.squaredLength; - -/** - * Negates the components of a vec4 - * - * @param {vec4} out the receiving vector - * @param {vec4} a vector to negate - * @returns {vec4} out - */ -vec4.negate = function(out, a) { - out[0] = -a[0]; - out[1] = -a[1]; - out[2] = -a[2]; - out[3] = -a[3]; - return out; -}; - -/** - * Normalize a vec4 - * - * @param {vec4} out the receiving vector - * @param {vec4} a vector to normalize - * @returns {vec4} out - */ -vec4.normalize = function(out, a) { - var x = a[0], - y = a[1], - z = a[2], - w = a[3]; - var len = x*x + y*y + z*z + w*w; - if (len > 0) { - len = 1 / Math.sqrt(len); - out[0] = a[0] * len; - out[1] = a[1] * len; - out[2] = a[2] * len; - out[3] = a[3] * len; - } - return out; -}; - -/** - * Calculates the dot product of two vec4's - * - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {Number} dot product of a and b - */ -vec4.dot = function (a, b) { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; -}; - -/** - * Performs a linear interpolation between two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {vec4} out - */ -vec4.lerp = function (out, a, b, t) { - var ax = a[0], - ay = a[1], - az = a[2], - aw = a[3]; - out[0] = ax + t * (b[0] - ax); - out[1] = ay + t * (b[1] - ay); - out[2] = az + t * (b[2] - az); - out[3] = aw + t * (b[3] - aw); - return out; -}; - -/** - * Transforms the vec4 with a mat4. - * - * @param {vec4} out the receiving vector - * @param {vec4} a the vector to transform - * @param {mat4} m matrix to transform with - * @returns {vec4} out - */ -vec4.transformMat4 = function(out, a, m) { - var x = a[0], y = a[1], z = a[2], w = a[3]; - out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w; - out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w; - out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w; - out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w; - return out; -}; - -/** - * Transforms the vec4 with a quat - * - * @param {vec4} out the receiving vector - * @param {vec4} a the vector to transform - * @param {quat} q quaternion to transform with - * @returns {vec4} out - */ -vec4.transformQuat = function(out, a, q) { - var x = a[0], y = a[1], z = a[2], - qx = q[0], qy = q[1], qz = q[2], qw = q[3], - - // calculate quat * vec - ix = qw * x + qy * z - qz * y, - iy = qw * y + qz * x - qx * z, - iz = qw * z + qx * y - qy * x, - iw = -qx * x - qy * y - qz * z; - - // calculate result * inverse quat - out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; - out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; - out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; - return out; -}; - -/** - * Perform some operation over an array of vec4s. - * - * @param {Array} a the array of vectors to iterate over - * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed - * @param {Number} offset Number of elements to skip at the beginning of the array - * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array - * @param {Function} fn Function to call for each vector in the array - * @param {Object} [arg] additional argument to pass to fn - * @returns {Array} a - * @function - */ -vec4.forEach = (function() { - var vec = vec4.create(); - - return function(a, stride, offset, count, fn, arg) { - var i, l; - if(!stride) { - stride = 4; - } - - if(!offset) { - offset = 0; - } - - if(count) { - l = Math.min((count * stride) + offset, a.length); - } else { - l = a.length; - } - - for(i = offset; i < l; i += stride) { - vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3]; - fn(vec, vec, arg); - a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3]; - } - - return a; - }; -})(); - -/** - * Returns a string representation of a vector - * - * @param {vec4} vec vector to represent as a string - * @returns {String} string representation of the vector - */ -vec4.str = function (a) { - return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.vec4 = vec4; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 2x2 Matrix - * @name mat2 - */ - -var mat2 = {}; - -var mat2Identity = new Float32Array([ - 1, 0, - 0, 1 -]); - -/** - * Creates a new identity mat2 - * - * @returns {mat2} a new 2x2 matrix - */ -mat2.create = function() { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 1; - return out; -}; - -/** - * Creates a new mat2 initialized with values from an existing matrix - * - * @param {mat2} a matrix to clone - * @returns {mat2} a new 2x2 matrix - */ -mat2.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - return out; -}; - -/** - * Copy the values from one mat2 to another - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the source matrix - * @returns {mat2} out - */ -mat2.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - return out; -}; - -/** - * Set a mat2 to the identity matrix - * - * @param {mat2} out the receiving matrix - * @returns {mat2} out - */ -mat2.identity = function(out) { - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 1; - return out; -}; - -/** - * Transpose the values of a mat2 - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the source matrix - * @returns {mat2} out - */ -mat2.transpose = function(out, a) { - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (out === a) { - var a1 = a[1]; - out[1] = a[2]; - out[2] = a1; - } else { - out[0] = a[0]; - out[1] = a[2]; - out[2] = a[1]; - out[3] = a[3]; - } - - return out; -}; - -/** - * Inverts a mat2 - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the source matrix - * @returns {mat2} out - */ -mat2.invert = function(out, a) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], - - // Calculate the determinant - det = a0 * a3 - a2 * a1; - - if (!det) { - return null; - } - det = 1.0 / det; - - out[0] = a3 * det; - out[1] = -a1 * det; - out[2] = -a2 * det; - out[3] = a0 * det; - - return out; -}; - -/** - * Calculates the adjugate of a mat2 - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the source matrix - * @returns {mat2} out - */ -mat2.adjoint = function(out, a) { - // Caching this value is nessecary if out == a - var a0 = a[0]; - out[0] = a[3]; - out[1] = -a[1]; - out[2] = -a[2]; - out[3] = a0; - - return out; -}; - -/** - * Calculates the determinant of a mat2 - * - * @param {mat2} a the source matrix - * @returns {Number} determinant of a - */ -mat2.determinant = function (a) { - return a[0] * a[3] - a[2] * a[1]; -}; - -/** - * Multiplies two mat2's - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the first operand - * @param {mat2} b the second operand - * @returns {mat2} out - */ -mat2.multiply = function (out, a, b) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3]; - var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; - out[0] = a0 * b0 + a1 * b2; - out[1] = a0 * b1 + a1 * b3; - out[2] = a2 * b0 + a3 * b2; - out[3] = a2 * b1 + a3 * b3; - return out; -}; - -/** - * Alias for {@link mat2.multiply} - * @function - */ -mat2.mul = mat2.multiply; - -/** - * Rotates a mat2 by the given angle - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat2} out - */ -mat2.rotate = function (out, a, rad) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], - s = Math.sin(rad), - c = Math.cos(rad); - out[0] = a0 * c + a1 * s; - out[1] = a0 * -s + a1 * c; - out[2] = a2 * c + a3 * s; - out[3] = a2 * -s + a3 * c; - return out; -}; - -/** - * Scales the mat2 by the dimensions in the given vec2 - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the matrix to rotate - * @param {vec2} v the vec2 to scale the matrix by - * @returns {mat2} out - **/ -mat2.scale = function(out, a, v) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], - v0 = v[0], v1 = v[1]; - out[0] = a0 * v0; - out[1] = a1 * v1; - out[2] = a2 * v0; - out[3] = a3 * v1; - return out; -}; - -/** - * Returns a string representation of a mat2 - * - * @param {mat2} mat matrix to represent as a string - * @returns {String} string representation of the matrix - */ -mat2.str = function (a) { - return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.mat2 = mat2; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 2x3 Matrix - * @name mat2d - * - * @description - * A mat2d contains six elements defined as: - *
      - * [a, b,
      - *  c, d,
      - *  tx,ty]
      - * 
      - * This is a short form for the 3x3 matrix: - *
      - * [a, b, 0
      - *  c, d, 0
      - *  tx,ty,1]
      - * 
      - * The last column is ignored so the array is shorter and operations are faster. - */ - -var mat2d = {}; - -var mat2dIdentity = new Float32Array([ - 1, 0, - 0, 1, - 0, 0 -]); - -/** - * Creates a new identity mat2d - * - * @returns {mat2d} a new 2x3 matrix - */ -mat2d.create = function() { - var out = new GLMAT_ARRAY_TYPE(6); - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 1; - out[4] = 0; - out[5] = 0; - return out; -}; - -/** - * Creates a new mat2d initialized with values from an existing matrix - * - * @param {mat2d} a matrix to clone - * @returns {mat2d} a new 2x3 matrix - */ -mat2d.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(6); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - return out; -}; - -/** - * Copy the values from one mat2d to another - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the source matrix - * @returns {mat2d} out - */ -mat2d.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - return out; -}; - -/** - * Set a mat2d to the identity matrix - * - * @param {mat2d} out the receiving matrix - * @returns {mat2d} out - */ -mat2d.identity = function(out) { - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 1; - out[4] = 0; - out[5] = 0; - return out; -}; - -/** - * Inverts a mat2d - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the source matrix - * @returns {mat2d} out - */ -mat2d.invert = function(out, a) { - var aa = a[0], ab = a[1], ac = a[2], ad = a[3], - atx = a[4], aty = a[5]; - - var det = aa * ad - ab * ac; - if(!det){ - return null; - } - det = 1.0 / det; - - out[0] = ad * det; - out[1] = -ab * det; - out[2] = -ac * det; - out[3] = aa * det; - out[4] = (ac * aty - ad * atx) * det; - out[5] = (ab * atx - aa * aty) * det; - return out; -}; - -/** - * Calculates the determinant of a mat2d - * - * @param {mat2d} a the source matrix - * @returns {Number} determinant of a - */ -mat2d.determinant = function (a) { - return a[0] * a[3] - a[1] * a[2]; -}; - -/** - * Multiplies two mat2d's - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the first operand - * @param {mat2d} b the second operand - * @returns {mat2d} out - */ -mat2d.multiply = function (out, a, b) { - var aa = a[0], ab = a[1], ac = a[2], ad = a[3], - atx = a[4], aty = a[5], - ba = b[0], bb = b[1], bc = b[2], bd = b[3], - btx = b[4], bty = b[5]; - - out[0] = aa*ba + ab*bc; - out[1] = aa*bb + ab*bd; - out[2] = ac*ba + ad*bc; - out[3] = ac*bb + ad*bd; - out[4] = ba*atx + bc*aty + btx; - out[5] = bb*atx + bd*aty + bty; - return out; -}; - -/** - * Alias for {@link mat2d.multiply} - * @function - */ -mat2d.mul = mat2d.multiply; - - -/** - * Rotates a mat2d by the given angle - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat2d} out - */ -mat2d.rotate = function (out, a, rad) { - var aa = a[0], - ab = a[1], - ac = a[2], - ad = a[3], - atx = a[4], - aty = a[5], - st = Math.sin(rad), - ct = Math.cos(rad); - - out[0] = aa*ct + ab*st; - out[1] = -aa*st + ab*ct; - out[2] = ac*ct + ad*st; - out[3] = -ac*st + ct*ad; - out[4] = ct*atx + st*aty; - out[5] = ct*aty - st*atx; - return out; -}; - -/** - * Scales the mat2d by the dimensions in the given vec2 - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the matrix to translate - * @param {mat2d} v the vec2 to scale the matrix by - * @returns {mat2d} out - **/ -mat2d.scale = function(out, a, v) { - var vx = v[0], vy = v[1]; - out[0] = a[0] * vx; - out[1] = a[1] * vy; - out[2] = a[2] * vx; - out[3] = a[3] * vy; - out[4] = a[4] * vx; - out[5] = a[5] * vy; - return out; -}; - -/** - * Translates the mat2d by the dimensions in the given vec2 - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the matrix to translate - * @param {mat2d} v the vec2 to translate the matrix by - * @returns {mat2d} out - **/ -mat2d.translate = function(out, a, v) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4] + v[0]; - out[5] = a[5] + v[1]; - return out; -}; - -/** - * Returns a string representation of a mat2d - * - * @param {mat2d} a matrix to represent as a string - * @returns {String} string representation of the matrix - */ -mat2d.str = function (a) { - return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + - a[3] + ', ' + a[4] + ', ' + a[5] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.mat2d = mat2d; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 3x3 Matrix - * @name mat3 - */ - -var mat3 = {}; - -var mat3Identity = new Float32Array([ - 1, 0, 0, - 0, 1, 0, - 0, 0, 1 -]); - -/** - * Creates a new identity mat3 - * - * @returns {mat3} a new 3x3 matrix - */ -mat3.create = function() { - var out = new GLMAT_ARRAY_TYPE(9); - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 1; - out[5] = 0; - out[6] = 0; - out[7] = 0; - out[8] = 1; - return out; -}; - -/** - * Creates a new mat3 initialized with values from an existing matrix - * - * @param {mat3} a matrix to clone - * @returns {mat3} a new 3x3 matrix - */ -mat3.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(9); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - return out; -}; - -/** - * Copy the values from one mat3 to another - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - return out; -}; - -/** - * Set a mat3 to the identity matrix - * - * @param {mat3} out the receiving matrix - * @returns {mat3} out - */ -mat3.identity = function(out) { - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 1; - out[5] = 0; - out[6] = 0; - out[7] = 0; - out[8] = 1; - return out; -}; - -/** - * Transpose the values of a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.transpose = function(out, a) { - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (out === a) { - var a01 = a[1], a02 = a[2], a12 = a[5]; - out[1] = a[3]; - out[2] = a[6]; - out[3] = a01; - out[5] = a[7]; - out[6] = a02; - out[7] = a12; - } else { - out[0] = a[0]; - out[1] = a[3]; - out[2] = a[6]; - out[3] = a[1]; - out[4] = a[4]; - out[5] = a[7]; - out[6] = a[2]; - out[7] = a[5]; - out[8] = a[8]; - } - - return out; -}; - -/** - * Inverts a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.invert = function(out, a) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], - - b01 = a22 * a11 - a12 * a21, - b11 = -a22 * a10 + a12 * a20, - b21 = a21 * a10 - a11 * a20, - - // Calculate the determinant - det = a00 * b01 + a01 * b11 + a02 * b21; - - if (!det) { - return null; - } - det = 1.0 / det; - - out[0] = b01 * det; - out[1] = (-a22 * a01 + a02 * a21) * det; - out[2] = (a12 * a01 - a02 * a11) * det; - out[3] = b11 * det; - out[4] = (a22 * a00 - a02 * a20) * det; - out[5] = (-a12 * a00 + a02 * a10) * det; - out[6] = b21 * det; - out[7] = (-a21 * a00 + a01 * a20) * det; - out[8] = (a11 * a00 - a01 * a10) * det; - return out; -}; - -/** - * Calculates the adjugate of a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.adjoint = function(out, a) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8]; - - out[0] = (a11 * a22 - a12 * a21); - out[1] = (a02 * a21 - a01 * a22); - out[2] = (a01 * a12 - a02 * a11); - out[3] = (a12 * a20 - a10 * a22); - out[4] = (a00 * a22 - a02 * a20); - out[5] = (a02 * a10 - a00 * a12); - out[6] = (a10 * a21 - a11 * a20); - out[7] = (a01 * a20 - a00 * a21); - out[8] = (a00 * a11 - a01 * a10); - return out; -}; - -/** - * Calculates the determinant of a mat3 - * - * @param {mat3} a the source matrix - * @returns {Number} determinant of a - */ -mat3.determinant = function (a) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8]; - - return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); -}; - -/** - * Multiplies two mat3's - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the first operand - * @param {mat3} b the second operand - * @returns {mat3} out - */ -mat3.multiply = function (out, a, b) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], - - b00 = b[0], b01 = b[1], b02 = b[2], - b10 = b[3], b11 = b[4], b12 = b[5], - b20 = b[6], b21 = b[7], b22 = b[8]; - - out[0] = b00 * a00 + b01 * a10 + b02 * a20; - out[1] = b00 * a01 + b01 * a11 + b02 * a21; - out[2] = b00 * a02 + b01 * a12 + b02 * a22; - - out[3] = b10 * a00 + b11 * a10 + b12 * a20; - out[4] = b10 * a01 + b11 * a11 + b12 * a21; - out[5] = b10 * a02 + b11 * a12 + b12 * a22; - - out[6] = b20 * a00 + b21 * a10 + b22 * a20; - out[7] = b20 * a01 + b21 * a11 + b22 * a21; - out[8] = b20 * a02 + b21 * a12 + b22 * a22; - return out; -}; - -/** - * Alias for {@link mat3.multiply} - * @function - */ -mat3.mul = mat3.multiply; - -/** - * Translate a mat3 by the given vector - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the matrix to translate - * @param {vec2} v vector to translate by - * @returns {mat3} out - */ -mat3.translate = function(out, a, v) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], - x = v[0], y = v[1]; - - out[0] = a00; - out[1] = a01; - out[2] = a02; - - out[3] = a10; - out[4] = a11; - out[5] = a12; - - out[6] = x * a00 + y * a10 + a20; - out[7] = x * a01 + y * a11 + a21; - out[8] = x * a02 + y * a12 + a22; - return out; -}; - -/** - * Rotates a mat3 by the given angle - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat3} out - */ -mat3.rotate = function (out, a, rad) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], - - s = Math.sin(rad), - c = Math.cos(rad); - - out[0] = c * a00 + s * a10; - out[1] = c * a01 + s * a11; - out[2] = c * a02 + s * a12; - - out[3] = c * a10 - s * a00; - out[4] = c * a11 - s * a01; - out[5] = c * a12 - s * a02; - - out[6] = a20; - out[7] = a21; - out[8] = a22; - return out; -}; - -/** - * Scales the mat3 by the dimensions in the given vec2 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the matrix to rotate - * @param {vec2} v the vec2 to scale the matrix by - * @returns {mat3} out - **/ -mat3.scale = function(out, a, v) { - var x = v[0], y = v[2]; - - out[0] = x * a[0]; - out[1] = x * a[1]; - out[2] = x * a[2]; - - out[3] = y * a[3]; - out[4] = y * a[4]; - out[5] = y * a[5]; - - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - return out; -}; - -/** - * Copies the values from a mat2d into a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the matrix to rotate - * @param {vec2} v the vec2 to scale the matrix by - * @returns {mat3} out - **/ -mat3.fromMat2d = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = 0; - - out[3] = a[2]; - out[4] = a[3]; - out[5] = 0; - - out[6] = a[4]; - out[7] = a[5]; - out[8] = 1; - return out; -}; - -/** -* Calculates a 3x3 matrix from the given quaternion -* -* @param {mat3} out mat3 receiving operation result -* @param {quat} q Quaternion to create matrix from -* -* @returns {mat3} out -*/ -mat3.fromQuat = function (out, q) { - var x = q[0], y = q[1], z = q[2], w = q[3], - x2 = x + x, - y2 = y + y, - z2 = z + z, - - xx = x * x2, - xy = x * y2, - xz = x * z2, - yy = y * y2, - yz = y * z2, - zz = z * z2, - wx = w * x2, - wy = w * y2, - wz = w * z2; - - out[0] = 1 - (yy + zz); - out[1] = xy + wz; - out[2] = xz - wy; - - out[3] = xy - wz; - out[4] = 1 - (xx + zz); - out[5] = yz + wx; - - out[6] = xz + wy; - out[7] = yz - wx; - out[8] = 1 - (xx + yy); - - return out; -}; - -/** - * Returns a string representation of a mat3 - * - * @param {mat3} mat matrix to represent as a string - * @returns {String} string representation of the matrix - */ -mat3.str = function (a) { - return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + - a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + - a[6] + ', ' + a[7] + ', ' + a[8] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.mat3 = mat3; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 4x4 Matrix - * @name mat4 - */ - -var mat4 = {}; - -var mat4Identity = new Float32Array([ - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 -]); - -/** - * Creates a new identity mat4 - * - * @returns {mat4} a new 4x4 matrix - */ -mat4.create = function() { - var out = new GLMAT_ARRAY_TYPE(16); - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = 1; - out[6] = 0; - out[7] = 0; - out[8] = 0; - out[9] = 0; - out[10] = 1; - out[11] = 0; - out[12] = 0; - out[13] = 0; - out[14] = 0; - out[15] = 1; - return out; -}; - -/** - * Creates a new mat4 initialized with values from an existing matrix - * - * @param {mat4} a matrix to clone - * @returns {mat4} a new 4x4 matrix - */ -mat4.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(16); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - out[9] = a[9]; - out[10] = a[10]; - out[11] = a[11]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - return out; -}; - -/** - * Copy the values from one mat4 to another - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the source matrix - * @returns {mat4} out - */ -mat4.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - out[9] = a[9]; - out[10] = a[10]; - out[11] = a[11]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - return out; -}; - -/** - * Set a mat4 to the identity matrix - * - * @param {mat4} out the receiving matrix - * @returns {mat4} out - */ -mat4.identity = function(out) { - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = 1; - out[6] = 0; - out[7] = 0; - out[8] = 0; - out[9] = 0; - out[10] = 1; - out[11] = 0; - out[12] = 0; - out[13] = 0; - out[14] = 0; - out[15] = 1; - return out; -}; - -/** - * Transpose the values of a mat4 - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the source matrix - * @returns {mat4} out - */ -mat4.transpose = function(out, a) { - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (out === a) { - var a01 = a[1], a02 = a[2], a03 = a[3], - a12 = a[6], a13 = a[7], - a23 = a[11]; - - out[1] = a[4]; - out[2] = a[8]; - out[3] = a[12]; - out[4] = a01; - out[6] = a[9]; - out[7] = a[13]; - out[8] = a02; - out[9] = a12; - out[11] = a[14]; - out[12] = a03; - out[13] = a13; - out[14] = a23; - } else { - out[0] = a[0]; - out[1] = a[4]; - out[2] = a[8]; - out[3] = a[12]; - out[4] = a[1]; - out[5] = a[5]; - out[6] = a[9]; - out[7] = a[13]; - out[8] = a[2]; - out[9] = a[6]; - out[10] = a[10]; - out[11] = a[14]; - out[12] = a[3]; - out[13] = a[7]; - out[14] = a[11]; - out[15] = a[15]; - } - - return out; -}; - -/** - * Inverts a mat4 - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the source matrix - * @returns {mat4} out - */ -mat4.invert = function(out, a) { - var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], - a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], - a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], - a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], - - b00 = a00 * a11 - a01 * a10, - b01 = a00 * a12 - a02 * a10, - b02 = a00 * a13 - a03 * a10, - b03 = a01 * a12 - a02 * a11, - b04 = a01 * a13 - a03 * a11, - b05 = a02 * a13 - a03 * a12, - b06 = a20 * a31 - a21 * a30, - b07 = a20 * a32 - a22 * a30, - b08 = a20 * a33 - a23 * a30, - b09 = a21 * a32 - a22 * a31, - b10 = a21 * a33 - a23 * a31, - b11 = a22 * a33 - a23 * a32, - - // Calculate the determinant - det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; - - if (!det) { - return null; - } - det = 1.0 / det; - - out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; - out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; - out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; - out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; - out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; - out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; - out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; - out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; - out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; - out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; - out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; - out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; - out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; - out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; - out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; - out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; - - return out; -}; - -/** - * Calculates the adjugate of a mat4 - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the source matrix - * @returns {mat4} out - */ -mat4.adjoint = function(out, a) { - var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], - a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], - a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], - a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; - - out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22)); - out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22)); - out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12)); - out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12)); - out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22)); - out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22)); - out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12)); - out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12)); - out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21)); - out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21)); - out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11)); - out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11)); - out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21)); - out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21)); - out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11)); - out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11)); - return out; -}; - -/** - * Calculates the determinant of a mat4 - * - * @param {mat4} a the source matrix - * @returns {Number} determinant of a - */ -mat4.determinant = function (a) { - var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], - a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], - a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], - a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], - - b00 = a00 * a11 - a01 * a10, - b01 = a00 * a12 - a02 * a10, - b02 = a00 * a13 - a03 * a10, - b03 = a01 * a12 - a02 * a11, - b04 = a01 * a13 - a03 * a11, - b05 = a02 * a13 - a03 * a12, - b06 = a20 * a31 - a21 * a30, - b07 = a20 * a32 - a22 * a30, - b08 = a20 * a33 - a23 * a30, - b09 = a21 * a32 - a22 * a31, - b10 = a21 * a33 - a23 * a31, - b11 = a22 * a33 - a23 * a32; - - // Calculate the determinant - return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; -}; - -/** - * Multiplies two mat4's - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the first operand - * @param {mat4} b the second operand - * @returns {mat4} out - */ -mat4.multiply = function (out, a, b) { - var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], - a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], - a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], - a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; - - // Cache only the current line of the second matrix - var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; - out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7]; - out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11]; - out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15]; - out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - return out; -}; - -/** - * Alias for {@link mat4.multiply} - * @function - */ -mat4.mul = mat4.multiply; - -/** - * Translate a mat4 by the given vector - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to translate - * @param {vec3} v vector to translate by - * @returns {mat4} out - */ -mat4.translate = function (out, a, v) { - var x = v[0], y = v[1], z = v[2], - a00, a01, a02, a03, - a10, a11, a12, a13, - a20, a21, a22, a23; - - if (a === out) { - out[12] = a[0] * x + a[4] * y + a[8] * z + a[12]; - out[13] = a[1] * x + a[5] * y + a[9] * z + a[13]; - out[14] = a[2] * x + a[6] * y + a[10] * z + a[14]; - out[15] = a[3] * x + a[7] * y + a[11] * z + a[15]; - } else { - a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; - a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; - a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; - - out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03; - out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13; - out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23; - - out[12] = a00 * x + a10 * y + a20 * z + a[12]; - out[13] = a01 * x + a11 * y + a21 * z + a[13]; - out[14] = a02 * x + a12 * y + a22 * z + a[14]; - out[15] = a03 * x + a13 * y + a23 * z + a[15]; - } - - return out; -}; - -/** - * Scales the mat4 by the dimensions in the given vec3 - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to scale - * @param {vec3} v the vec3 to scale the matrix by - * @returns {mat4} out - **/ -mat4.scale = function(out, a, v) { - var x = v[0], y = v[1], z = v[2]; - - out[0] = a[0] * x; - out[1] = a[1] * x; - out[2] = a[2] * x; - out[3] = a[3] * x; - out[4] = a[4] * y; - out[5] = a[5] * y; - out[6] = a[6] * y; - out[7] = a[7] * y; - out[8] = a[8] * z; - out[9] = a[9] * z; - out[10] = a[10] * z; - out[11] = a[11] * z; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - return out; -}; - -/** - * Rotates a mat4 by the given angle - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @param {vec3} axis the axis to rotate around - * @returns {mat4} out - */ -mat4.rotate = function (out, a, rad, axis) { - var x = axis[0], y = axis[1], z = axis[2], - len = Math.sqrt(x * x + y * y + z * z), - s, c, t, - a00, a01, a02, a03, - a10, a11, a12, a13, - a20, a21, a22, a23, - b00, b01, b02, - b10, b11, b12, - b20, b21, b22; - - if (Math.abs(len) < GLMAT_EPSILON) { return null; } - - len = 1 / len; - x *= len; - y *= len; - z *= len; - - s = Math.sin(rad); - c = Math.cos(rad); - t = 1 - c; - - a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; - a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; - a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; - - // Construct the elements of the rotation matrix - b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s; - b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s; - b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c; - - // Perform rotation-specific matrix multiplication - out[0] = a00 * b00 + a10 * b01 + a20 * b02; - out[1] = a01 * b00 + a11 * b01 + a21 * b02; - out[2] = a02 * b00 + a12 * b01 + a22 * b02; - out[3] = a03 * b00 + a13 * b01 + a23 * b02; - out[4] = a00 * b10 + a10 * b11 + a20 * b12; - out[5] = a01 * b10 + a11 * b11 + a21 * b12; - out[6] = a02 * b10 + a12 * b11 + a22 * b12; - out[7] = a03 * b10 + a13 * b11 + a23 * b12; - out[8] = a00 * b20 + a10 * b21 + a20 * b22; - out[9] = a01 * b20 + a11 * b21 + a21 * b22; - out[10] = a02 * b20 + a12 * b21 + a22 * b22; - out[11] = a03 * b20 + a13 * b21 + a23 * b22; - - if (a !== out) { // If the source and destination differ, copy the unchanged last row - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - } - return out; -}; - -/** - * Rotates a matrix by the given angle around the X axis - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat4} out - */ -mat4.rotateX = function (out, a, rad) { - var s = Math.sin(rad), - c = Math.cos(rad), - a10 = a[4], - a11 = a[5], - a12 = a[6], - a13 = a[7], - a20 = a[8], - a21 = a[9], - a22 = a[10], - a23 = a[11]; - - if (a !== out) { // If the source and destination differ, copy the unchanged rows - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - } - - // Perform axis-specific matrix multiplication - out[4] = a10 * c + a20 * s; - out[5] = a11 * c + a21 * s; - out[6] = a12 * c + a22 * s; - out[7] = a13 * c + a23 * s; - out[8] = a20 * c - a10 * s; - out[9] = a21 * c - a11 * s; - out[10] = a22 * c - a12 * s; - out[11] = a23 * c - a13 * s; - return out; -}; - -/** - * Rotates a matrix by the given angle around the Y axis - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat4} out - */ -mat4.rotateY = function (out, a, rad) { - var s = Math.sin(rad), - c = Math.cos(rad), - a00 = a[0], - a01 = a[1], - a02 = a[2], - a03 = a[3], - a20 = a[8], - a21 = a[9], - a22 = a[10], - a23 = a[11]; - - if (a !== out) { // If the source and destination differ, copy the unchanged rows - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - } - - // Perform axis-specific matrix multiplication - out[0] = a00 * c - a20 * s; - out[1] = a01 * c - a21 * s; - out[2] = a02 * c - a22 * s; - out[3] = a03 * c - a23 * s; - out[8] = a00 * s + a20 * c; - out[9] = a01 * s + a21 * c; - out[10] = a02 * s + a22 * c; - out[11] = a03 * s + a23 * c; - return out; -}; - -/** - * Rotates a matrix by the given angle around the Z axis - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat4} out - */ -mat4.rotateZ = function (out, a, rad) { - var s = Math.sin(rad), - c = Math.cos(rad), - a00 = a[0], - a01 = a[1], - a02 = a[2], - a03 = a[3], - a10 = a[4], - a11 = a[5], - a12 = a[6], - a13 = a[7]; - - if (a !== out) { // If the source and destination differ, copy the unchanged last row - out[8] = a[8]; - out[9] = a[9]; - out[10] = a[10]; - out[11] = a[11]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - } - - // Perform axis-specific matrix multiplication - out[0] = a00 * c + a10 * s; - out[1] = a01 * c + a11 * s; - out[2] = a02 * c + a12 * s; - out[3] = a03 * c + a13 * s; - out[4] = a10 * c - a00 * s; - out[5] = a11 * c - a01 * s; - out[6] = a12 * c - a02 * s; - out[7] = a13 * c - a03 * s; - return out; -}; - -/** - * Creates a matrix from a quaternion rotation and vector translation - * This is equivalent to (but much faster than): - * - * mat4.identity(dest); - * mat4.translate(dest, vec); - * var quatMat = mat4.create(); - * quat4.toMat4(quat, quatMat); - * mat4.multiply(dest, quatMat); - * - * @param {mat4} out mat4 receiving operation result - * @param {quat4} q Rotation quaternion - * @param {vec3} v Translation vector - * @returns {mat4} out - */ -mat4.fromRotationTranslation = function (out, q, v) { - // Quaternion math - var x = q[0], y = q[1], z = q[2], w = q[3], - x2 = x + x, - y2 = y + y, - z2 = z + z, - - xx = x * x2, - xy = x * y2, - xz = x * z2, - yy = y * y2, - yz = y * z2, - zz = z * z2, - wx = w * x2, - wy = w * y2, - wz = w * z2; - - out[0] = 1 - (yy + zz); - out[1] = xy + wz; - out[2] = xz - wy; - out[3] = 0; - out[4] = xy - wz; - out[5] = 1 - (xx + zz); - out[6] = yz + wx; - out[7] = 0; - out[8] = xz + wy; - out[9] = yz - wx; - out[10] = 1 - (xx + yy); - out[11] = 0; - out[12] = v[0]; - out[13] = v[1]; - out[14] = v[2]; - out[15] = 1; - - return out; -}; - -/** -* Calculates a 4x4 matrix from the given quaternion -* -* @param {mat4} out mat4 receiving operation result -* @param {quat} q Quaternion to create matrix from -* -* @returns {mat4} out -*/ -mat4.fromQuat = function (out, q) { - var x = q[0], y = q[1], z = q[2], w = q[3], - x2 = x + x, - y2 = y + y, - z2 = z + z, - - xx = x * x2, - xy = x * y2, - xz = x * z2, - yy = y * y2, - yz = y * z2, - zz = z * z2, - wx = w * x2, - wy = w * y2, - wz = w * z2; - - out[0] = 1 - (yy + zz); - out[1] = xy + wz; - out[2] = xz - wy; - out[3] = 0; - - out[4] = xy - wz; - out[5] = 1 - (xx + zz); - out[6] = yz + wx; - out[7] = 0; - - out[8] = xz + wy; - out[9] = yz - wx; - out[10] = 1 - (xx + yy); - out[11] = 0; - - out[12] = 0; - out[13] = 0; - out[14] = 0; - out[15] = 1; - - return out; -}; - -/** - * Generates a frustum matrix with the given bounds - * - * @param {mat4} out mat4 frustum matrix will be written into - * @param {Number} left Left bound of the frustum - * @param {Number} right Right bound of the frustum - * @param {Number} bottom Bottom bound of the frustum - * @param {Number} top Top bound of the frustum - * @param {Number} near Near bound of the frustum - * @param {Number} far Far bound of the frustum - * @returns {mat4} out - */ -mat4.frustum = function (out, left, right, bottom, top, near, far) { - var rl = 1 / (right - left), - tb = 1 / (top - bottom), - nf = 1 / (near - far); - out[0] = (near * 2) * rl; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = (near * 2) * tb; - out[6] = 0; - out[7] = 0; - out[8] = (right + left) * rl; - out[9] = (top + bottom) * tb; - out[10] = (far + near) * nf; - out[11] = -1; - out[12] = 0; - out[13] = 0; - out[14] = (far * near * 2) * nf; - out[15] = 0; - return out; -}; - -/** - * Generates a perspective projection matrix with the given bounds - * - * @param {mat4} out mat4 frustum matrix will be written into - * @param {number} fovy Vertical field of view in radians - * @param {number} aspect Aspect ratio. typically viewport width/height - * @param {number} near Near bound of the frustum - * @param {number} far Far bound of the frustum - * @returns {mat4} out - */ -mat4.perspective = function (out, fovy, aspect, near, far) { - var f = 1.0 / Math.tan(fovy / 2), - nf = 1 / (near - far); - out[0] = f / aspect; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = f; - out[6] = 0; - out[7] = 0; - out[8] = 0; - out[9] = 0; - out[10] = (far + near) * nf; - out[11] = -1; - out[12] = 0; - out[13] = 0; - out[14] = (2 * far * near) * nf; - out[15] = 0; - return out; -}; - -/** - * Generates a orthogonal projection matrix with the given bounds - * - * @param {mat4} out mat4 frustum matrix will be written into - * @param {number} left Left bound of the frustum - * @param {number} right Right bound of the frustum - * @param {number} bottom Bottom bound of the frustum - * @param {number} top Top bound of the frustum - * @param {number} near Near bound of the frustum - * @param {number} far Far bound of the frustum - * @returns {mat4} out - */ -mat4.ortho = function (out, left, right, bottom, top, near, far) { - var lr = 1 / (left - right), - bt = 1 / (bottom - top), - nf = 1 / (near - far); - out[0] = -2 * lr; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = -2 * bt; - out[6] = 0; - out[7] = 0; - out[8] = 0; - out[9] = 0; - out[10] = 2 * nf; - out[11] = 0; - out[12] = (left + right) * lr; - out[13] = (top + bottom) * bt; - out[14] = (far + near) * nf; - out[15] = 1; - return out; -}; - -/** - * Generates a look-at matrix with the given eye position, focal point, and up axis - * - * @param {mat4} out mat4 frustum matrix will be written into - * @param {vec3} eye Position of the viewer - * @param {vec3} center Point the viewer is looking at - * @param {vec3} up vec3 pointing up - * @returns {mat4} out - */ -mat4.lookAt = function (out, eye, center, up) { - var x0, x1, x2, y0, y1, y2, z0, z1, z2, len, - eyex = eye[0], - eyey = eye[1], - eyez = eye[2], - upx = up[0], - upy = up[1], - upz = up[2], - centerx = center[0], - centery = center[1], - centerz = center[2]; - - if (Math.abs(eyex - centerx) < GLMAT_EPSILON && - Math.abs(eyey - centery) < GLMAT_EPSILON && - Math.abs(eyez - centerz) < GLMAT_EPSILON) { - return mat4.identity(out); - } - - z0 = eyex - centerx; - z1 = eyey - centery; - z2 = eyez - centerz; - - len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); - z0 *= len; - z1 *= len; - z2 *= len; - - x0 = upy * z2 - upz * z1; - x1 = upz * z0 - upx * z2; - x2 = upx * z1 - upy * z0; - len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2); - if (!len) { - x0 = 0; - x1 = 0; - x2 = 0; - } else { - len = 1 / len; - x0 *= len; - x1 *= len; - x2 *= len; - } - - y0 = z1 * x2 - z2 * x1; - y1 = z2 * x0 - z0 * x2; - y2 = z0 * x1 - z1 * x0; - - len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2); - if (!len) { - y0 = 0; - y1 = 0; - y2 = 0; - } else { - len = 1 / len; - y0 *= len; - y1 *= len; - y2 *= len; - } - - out[0] = x0; - out[1] = y0; - out[2] = z0; - out[3] = 0; - out[4] = x1; - out[5] = y1; - out[6] = z1; - out[7] = 0; - out[8] = x2; - out[9] = y2; - out[10] = z2; - out[11] = 0; - out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez); - out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez); - out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez); - out[15] = 1; - - return out; -}; - -/** - * Returns a string representation of a mat4 - * - * @param {mat4} mat matrix to represent as a string - * @returns {String} string representation of the matrix - */ -mat4.str = function (a) { - return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + - a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' + - a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' + - a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.mat4 = mat4; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class Quaternion - * @name quat - */ - -var quat = {}; - -var quatIdentity = new Float32Array([0, 0, 0, 1]); - -/** - * Creates a new identity quat - * - * @returns {quat} a new quaternion - */ -quat.create = function() { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = 0; - out[1] = 0; - out[2] = 0; - out[3] = 1; - return out; -}; - -/** - * Creates a new quat initialized with values from an existing quaternion - * - * @param {quat} a quaternion to clone - * @returns {quat} a new quaternion - * @function - */ -quat.clone = vec4.clone; - -/** - * Creates a new quat initialized with the given values - * - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @param {Number} w W component - * @returns {quat} a new quaternion - * @function - */ -quat.fromValues = vec4.fromValues; - -/** - * Copy the values from one quat to another - * - * @param {quat} out the receiving quaternion - * @param {quat} a the source quaternion - * @returns {quat} out - * @function - */ -quat.copy = vec4.copy; - -/** - * Set the components of a quat to the given values - * - * @param {quat} out the receiving quaternion - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @param {Number} w W component - * @returns {quat} out - * @function - */ -quat.set = vec4.set; - -/** - * Set a quat to the identity quaternion - * - * @param {quat} out the receiving quaternion - * @returns {quat} out - */ -quat.identity = function(out) { - out[0] = 0; - out[1] = 0; - out[2] = 0; - out[3] = 1; - return out; -}; - -/** - * Sets a quat from the given angle and rotation axis, - * then returns it. - * - * @param {quat} out the receiving quaternion - * @param {vec3} axis the axis around which to rotate - * @param {Number} rad the angle in radians - * @returns {quat} out - **/ -quat.setAxisAngle = function(out, axis, rad) { - rad = rad * 0.5; - var s = Math.sin(rad); - out[0] = s * axis[0]; - out[1] = s * axis[1]; - out[2] = s * axis[2]; - out[3] = Math.cos(rad); - return out; -}; - -/** - * Adds two quat's - * - * @param {quat} out the receiving quaternion - * @param {quat} a the first operand - * @param {quat} b the second operand - * @returns {quat} out - * @function - */ -quat.add = vec4.add; - -/** - * Multiplies two quat's - * - * @param {quat} out the receiving quaternion - * @param {quat} a the first operand - * @param {quat} b the second operand - * @returns {quat} out - */ -quat.multiply = function(out, a, b) { - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - bx = b[0], by = b[1], bz = b[2], bw = b[3]; - - out[0] = ax * bw + aw * bx + ay * bz - az * by; - out[1] = ay * bw + aw * by + az * bx - ax * bz; - out[2] = az * bw + aw * bz + ax * by - ay * bx; - out[3] = aw * bw - ax * bx - ay * by - az * bz; - return out; -}; - -/** - * Alias for {@link quat.multiply} - * @function - */ -quat.mul = quat.multiply; - -/** - * Scales a quat by a scalar number - * - * @param {quat} out the receiving vector - * @param {quat} a the vector to scale - * @param {Number} b amount to scale the vector by - * @returns {quat} out - * @function - */ -quat.scale = vec4.scale; - -/** - * Rotates a quaternion by the given angle around the X axis - * - * @param {quat} out quat receiving operation result - * @param {quat} a quat to rotate - * @param {number} rad angle (in radians) to rotate - * @returns {quat} out - */ -quat.rotateX = function (out, a, rad) { - rad *= 0.5; - - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - bx = Math.sin(rad), bw = Math.cos(rad); - - out[0] = ax * bw + aw * bx; - out[1] = ay * bw + az * bx; - out[2] = az * bw - ay * bx; - out[3] = aw * bw - ax * bx; - return out; -}; - -/** - * Rotates a quaternion by the given angle around the Y axis - * - * @param {quat} out quat receiving operation result - * @param {quat} a quat to rotate - * @param {number} rad angle (in radians) to rotate - * @returns {quat} out - */ -quat.rotateY = function (out, a, rad) { - rad *= 0.5; - - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - by = Math.sin(rad), bw = Math.cos(rad); - - out[0] = ax * bw - az * by; - out[1] = ay * bw + aw * by; - out[2] = az * bw + ax * by; - out[3] = aw * bw - ay * by; - return out; -}; - -/** - * Rotates a quaternion by the given angle around the Z axis - * - * @param {quat} out quat receiving operation result - * @param {quat} a quat to rotate - * @param {number} rad angle (in radians) to rotate - * @returns {quat} out - */ -quat.rotateZ = function (out, a, rad) { - rad *= 0.5; - - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - bz = Math.sin(rad), bw = Math.cos(rad); - - out[0] = ax * bw + ay * bz; - out[1] = ay * bw - ax * bz; - out[2] = az * bw + aw * bz; - out[3] = aw * bw - az * bz; - return out; -}; - -/** - * Calculates the W component of a quat from the X, Y, and Z components. - * Assumes that quaternion is 1 unit in length. - * Any existing W component will be ignored. - * - * @param {quat} out the receiving quaternion - * @param {quat} a quat to calculate W component of - * @returns {quat} out - */ -quat.calculateW = function (out, a) { - var x = a[0], y = a[1], z = a[2]; - - out[0] = x; - out[1] = y; - out[2] = z; - out[3] = -Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z)); - return out; -}; - -/** - * Calculates the dot product of two quat's - * - * @param {quat} a the first operand - * @param {quat} b the second operand - * @returns {Number} dot product of a and b - * @function - */ -quat.dot = vec4.dot; - -/** - * Performs a linear interpolation between two quat's - * - * @param {quat} out the receiving quaternion - * @param {quat} a the first operand - * @param {quat} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {quat} out - * @function - */ -quat.lerp = vec4.lerp; - -/** - * Performs a spherical linear interpolation between two quat - * - * @param {quat} out the receiving quaternion - * @param {quat} a the first operand - * @param {quat} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {quat} out - */ -quat.slerp = function (out, a, b, t) { - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - bx = b[0], by = b[1], bz = b[2], bw = b[3]; - - var cosHalfTheta = ax * bx + ay * by + az * bz + aw * bw, - halfTheta, - sinHalfTheta, - ratioA, - ratioB; - - if (Math.abs(cosHalfTheta) >= 1.0) { - if (out !== a) { - out[0] = ax; - out[1] = ay; - out[2] = az; - out[3] = aw; - } - return out; - } - - halfTheta = Math.acos(cosHalfTheta); - sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta); - - if (Math.abs(sinHalfTheta) < 0.001) { - out[0] = (ax * 0.5 + bx * 0.5); - out[1] = (ay * 0.5 + by * 0.5); - out[2] = (az * 0.5 + bz * 0.5); - out[3] = (aw * 0.5 + bw * 0.5); - return out; - } - - ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta; - ratioB = Math.sin(t * halfTheta) / sinHalfTheta; - - out[0] = (ax * ratioA + bx * ratioB); - out[1] = (ay * ratioA + by * ratioB); - out[2] = (az * ratioA + bz * ratioB); - out[3] = (aw * ratioA + bw * ratioB); - - return out; -}; - -/** - * Calculates the inverse of a quat - * - * @param {quat} out the receiving quaternion - * @param {quat} a quat to calculate inverse of - * @returns {quat} out - */ -quat.invert = function(out, a) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], - dot = a0*a0 + a1*a1 + a2*a2 + a3*a3, - invDot = dot ? 1.0/dot : 0; - - // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0 - - out[0] = -a0*invDot; - out[1] = -a1*invDot; - out[2] = -a2*invDot; - out[3] = a3*invDot; - return out; -}; - -/** - * Calculates the conjugate of a quat - * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result. - * - * @param {quat} out the receiving quaternion - * @param {quat} a quat to calculate conjugate of - * @returns {quat} out - */ -quat.conjugate = function (out, a) { - out[0] = -a[0]; - out[1] = -a[1]; - out[2] = -a[2]; - out[3] = a[3]; - return out; -}; - -/** - * Calculates the length of a quat - * - * @param {quat} a vector to calculate length of - * @returns {Number} length of a - * @function - */ -quat.length = vec4.length; - -/** - * Alias for {@link quat.length} - * @function - */ -quat.len = quat.length; - -/** - * Calculates the squared length of a quat - * - * @param {quat} a vector to calculate squared length of - * @returns {Number} squared length of a - * @function - */ -quat.squaredLength = vec4.squaredLength; - -/** - * Alias for {@link quat.squaredLength} - * @function - */ -quat.sqrLen = quat.squaredLength; - -/** - * Normalize a quat - * - * @param {quat} out the receiving quaternion - * @param {quat} a quaternion to normalize - * @returns {quat} out - * @function - */ -quat.normalize = vec4.normalize; - -/** - * Creates a quaternion from the given 3x3 rotation matrix. - * - * @param {quat} out the receiving quaternion - * @param {mat3} m rotation matrix - * @returns {quat} out - * @function - */ -quat.fromMat3 = (function() { - var s_iNext = [1,2,0]; - return function(out, m) { - // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes - // article "Quaternion Calculus and Fast Animation". - var fTrace = m[0] + m[4] + m[8]; - var fRoot; - - if ( fTrace > 0.0 ) { - // |w| > 1/2, may as well choose w > 1/2 - fRoot = Math.sqrt(fTrace + 1.0); // 2w - out[3] = 0.5 * fRoot; - fRoot = 0.5/fRoot; // 1/(4w) - out[0] = (m[7]-m[5])*fRoot; - out[1] = (m[2]-m[6])*fRoot; - out[2] = (m[3]-m[1])*fRoot; - } else { - // |w| <= 1/2 - var i = 0; - if ( m[4] > m[0] ) - i = 1; - if ( m[8] > m[i*3+i] ) - i = 2; - var j = s_iNext[i]; - var k = s_iNext[j]; - - fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0); - out[i] = 0.5 * fRoot; - fRoot = 0.5 / fRoot; - out[3] = (m[k*3+j] - m[j*3+k]) * fRoot; - out[j] = (m[j*3+i] + m[i*3+j]) * fRoot; - out[k] = (m[k*3+i] + m[i*3+k]) * fRoot; - } - - return out; - }; -})(); - -/** - * Returns a string representation of a quatenion - * - * @param {quat} vec vector to represent as a string - * @returns {String} string representation of the vector - */ -quat.str = function (a) { - return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.quat = quat; -} -; - - - - - - - - - - - - - - })(shim.exports); -})(); - -},{}],152:[function(require,module,exports){ -arguments[4][9][0].apply(exports,arguments) -},{"cwise-compiler":153}],153:[function(require,module,exports){ -arguments[4][10][0].apply(exports,arguments) -},{"./lib/thunk.js":155}],154:[function(require,module,exports){ -arguments[4][11][0].apply(exports,arguments) -},{"uniq":156}],155:[function(require,module,exports){ -arguments[4][12][0].apply(exports,arguments) -},{"./compile.js":154}],156:[function(require,module,exports){ -module.exports=require(13) -},{}],157:[function(require,module,exports){ -arguments[4][14][0].apply(exports,arguments) -},{"buffer":189,"iota-array":158}],158:[function(require,module,exports){ -module.exports=require(15) -},{}],159:[function(require,module,exports){ -module.exports=require(16) -},{}],160:[function(require,module,exports){ -module.exports=require(17) -},{}],161:[function(require,module,exports){ -module.exports=require(41) -},{"bit-twiddle":159,"buffer":189,"dup":160}],162:[function(require,module,exports){ -module.exports=require(42) -},{}],163:[function(require,module,exports){ -module.exports=require(43) -},{"weakmap":162}],164:[function(require,module,exports){ -"use strict" - -var ndarray = require("ndarray") -var ops = require("ndarray-ops") -var pool = require("typedarray-pool") -var webglew = require("webglew") - -var linearTypes = null -var filterTypes = null -var wrapTypes = null - -function lazyInitLinearTypes(gl) { - linearTypes = [ - gl.LINEAR, - gl.NEAREST_MIPMAP_LINEAR, - gl.LINEAR_MIPMAP_NEAREST, - gl.LINEAR_MIPMAP_NEAREST - ] - filterTypes = [ - gl.NEAREST, - gl.LINEAR, - gl.NEAREST_MIPMAP_NEAREST, - gl.NEAREST_MIPMAP_LINEAR, - gl.LINEAR_MIPMAP_NEAREST, - gl.LINEAR_MIPMAP_LINEAR - ] - wrapTypes = [ - gl.REPEAT, - gl.CLAMP_TO_EDGE, - gl.MIRRORED_REPEAT - ] -} - -var convertFloatToUint8 = function(out, inp) { - ops.muls(out, inp, 255.0) -} - -function Texture2D(gl, handle, width, height, format, type) { - this.gl = gl - this.handle = handle - this.format = format - this.type = type - this._shape = [height, width] - this._mipLevels = [0] - this._magFilter = gl.NEAREST - this._minFilter = gl.NEAREST - this._wrapS = gl.CLAMP_TO_EDGE - this._wrapT = gl.CLAMP_TO_EDGE - this._anisoSamples = 1 -} - -Object.defineProperty(Texture2D.prototype, "minFilter", { - get: function() { - return this._minFilter - }, - set: function(v) { - this.bind() - var gl = this.gl - if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) { - if(!webglew(gl).OES_texture_float_linear) { - v = gl.NEAREST - } - } - if(filterTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown filter mode " + v) - } - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, v) - return this._minFilter = v - } -}) - -var proto = Texture2D.prototype - -Object.defineProperty(proto, "magFilter", { - get: function() { - return this._magFilter - }, - set: function(v) { - this.bind() - var gl = this.gl - if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) { - if(!webglew(gl).OES_texture_float_linear) { - v = gl.NEAREST - } - } - if(filterTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown filter mode " + v) - } - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, v) - return this._magFilter = v - } -}) - -Object.defineProperty(proto, "wrapS", { - get: function() { - return this._wrapS - }, - set: function(v) { - this.bind() - if(wrapTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown wrap mode " + v) - } - this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, v) - return this._wrapS = v - } -}) - -Object.defineProperty(proto, "wrapT", { - get: function() { - return this._wrapT - }, - set: function(v) { - this.bind() - if(wrapTypes.indexOf(v) < 0) { - throw new Error("gl-texture2d: Unknown wrap mode " + v) - } - this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, v) - return this._wrapT = v - } -}) - - -Object.defineProperty(proto, "wrap", { - get: function() { - return [this._wrapT, this._wrapS] - }, - set: function(v) { - if(!Array.isArray(v)) { - v = [v,v] - } - if(v.length !== 2) { - throw new Error("gl-texture2d: Must specify wrap mode for rows and columns") - } - for(var i=0; i<2; ++i) { - if(wrapTypes.indexOf(v[i]) < 0) { - throw new Error("gl-texture2d: Unknown wrap mode " + v) - } - } - this._wrapT = v[0] - this._wrapS = v[1] - - var gl = this.gl - this.bind() - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this._wrapT) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this._wrapS) - - return v - } -}) - -Object.defineProperty(proto, "mipSamples", { - get: function() { - return this._anisoSamples - }, - set: function(i) { - var psamples = this._anisoSamples - this._anisoSamples = Math.max(i, 1)|0 - if(psamples !== this._anisoSamples) { - var ext = webglew(this.gl).EXT_texture_filter_anisotropic - if(ext) { - this.gl.texParameterf(this.gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, this._anisoSamples) - } - } - return this._anisoSamples - } -}) - -Object.defineProperty(proto, "shape", { - get: function() { - return this._shape - }, - set: function(x) { - if(!Array.isArray(x)) { - x = [x|0,x|0] - } else { - if(x.length !== 2) { - throw new Error("gl-texture2d: Invalid texture shape") - } - } - var r = x[0]|0 - var c = x[1]|0 - if(this.height === r && this.width === c) { - return x - } - var gl = this.gl - var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) - if(c < 0 || c > maxSize || r < 0 || r > maxSize) { - throw new Error("gl-texture2d: Invalid texture size") - } - this._shape = [r, c] - this.bind() - gl.texImage2D(gl.TEXTURE_2D, 0, this.format, c, r, 0, this.format, this.type, null) - this._mipLevels = [0] - return x - } -}) - -proto.bind = function bindTexture2D(unit) { - var gl = this.gl - if(unit !== undefined) { - gl.activeTexture(gl.TEXTURE0 + (unit|0)) - } - gl.bindTexture(gl.TEXTURE_2D, this.handle) - if(unit !== undefined) { - return unit - } - return gl.getParameter(gl.ACTIVE_TEXTURE) - gl.TEXTURE0 -} - -proto.dispose = function disposeTexture2D() { - this.gl.deleteTexture(this.handle) -} - -proto.generateMipmap = function() { - this.bind() - this.gl.generateMipmap(this.gl.TEXTURE_2D) - - //Update mip levels - var l = Math.min(this._shape[0], this._shape[1]) - for(var i=0; l>0; ++i, l>>>=1) { - if(this._mipLevels.indexOf(i) < 0) { - this._mipLevels.push(i) - } - } -} - -proto.setPixels = function(data, x_off, y_off, mip_level) { - var gl = this.gl - this.bind() - if(Array.isArray(x_off)) { - mip_level = y_off - y_off = x_off[0]|0 - x_off = x_off[1]|0 - } else { - x_off = x_off || 0 - y_off = y_off || 0 - } - mip_level = mip_level || 0 - if(data instanceof HTMLCanvasElement || - data instanceof ImageData || - data instanceof HTMLImageElement || - data instanceof HTMLVideoElement) { - var needsMip = this._mipLevels.indexOf(mip_level) < 0 - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, data) - this._mipLevels.push(mip_level) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, this.format, this.type, data) - } - } else if(data.shape && data.stride && data.data) { - if(data.shape.length < 2 || - x_off + data.shape[1] > this._shape[1]>>>mip_level || - y_off + data.shape[0] > this._shape[0]>>>mip_level || - x_off < 0 || - y_off < 0) { - throw new Error("gl-texture2d: Texture dimensions are out of bounds") - } - texSubImageArray(gl, x_off, y_off, mip_level, this.format, this.type, this._mipLevels, data) - } else { - throw new Error("gl-texture2d: Unsupported data type") - } -} - -function texSubImageArray(gl, x_off, y_off, mip_level, cformat, ctype, mipLevels, array) { - var dtype = array.dtype - var shape = array.shape - var packed = isPacked(array) - var type = 0, format = 0 - if(dtype === "float32") { - type = gl.FLOAT - } else if(dtype === "float64") { - type = gl.FLOAT - packed = false - dtype = "float32" - } else if(dtype === "uint8") { - type = gl.UNSIGNED_BYTE - } else { - type = gl.UNSIGNED_BYTE - packed = false - dtype = "uint8" - } - if(shape.length === 2) { - format = gl.LUMINANCE - } else if(shape.length === 3) { - if(shape[2] === 1) { - format = gl.ALPHA - } else if(shape[2] === 2) { - format = gl.LUMINANCE_ALPHA - } else if(shape[2] === 3) { - format = gl.RGB - } else if(shape[2] === 4) { - format = gl.RGBA - } else { - throw new Error("gl-texture2d: Invalid shape for pixel coords") - } - } else { - throw new Error("gl-texture2d: Invalid shape for texture") - } - //For 1-channel textures allow conversion between formats - if((format === gl.LUMINANCE || format === gl.ALPHA) && - (cformat === gl.LUMINANCE || cformat === gl.ALPHA)) { - format = cformat - } - if(format !== cformat) { - throw new Error("gl-texture2d: Incompatible texture format for setPixels") - } - var size = array.size - var needsMip = mipLevels.indexOf(mip_level) < 0 - if(needsMip) { - mipLevels.push(mip_level) - } - if(type === ctype && packed) { - //Array data types are compatible, can directly copy into texture - if(array.offset === 0 && array.data.length === size) { - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[1], shape[0], 0, cformat, ctype, array.data) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[1], shape[0], cformat, ctype, array.data) - } - } else { - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[1], shape[0], 0, cformat, ctype, array.data.subarray(array.offset, array.offset+size)) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[1], shape[0], cformat, ctype, array.data.subarray(array.offset, array.offset+size)) - } - } - } else { - //Need to do type conversion to pack data into buffer - var pack_buffer - if(ctype === gl.FLOAT) { - pack_buffer = pool.mallocFloat32(size) - } else { - pack_buffer = pool.mallocUint8(size) - } - var pack_view = ndarray(pack_buffer, shape) - if(type === gl.FLOAT && ctype === gl.UNSIGNED_BYTE) { - convertFloatToUint8(pack_view, array) - } else { - ops.assign(pack_view, array) - } - if(needsMip) { - gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[1], shape[0], 0, cformat, ctype, pack_buffer.subarray(0, size)) - } else { - gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[1], shape[0], cformat, ctype, pack_buffer.subarray(0, size)) - } - if(ctype === gl.FLOAT) { - pool.freeFloat32(pack_buffer) - } else { - pool.freeUint8(pack_buffer) - } - } -} - -function initTexture(gl) { - var tex = gl.createTexture() - gl.bindTexture(gl.TEXTURE_2D, tex) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) - return tex -} - -function createTextureShape(gl, width, height, format, type) { - var maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) - if(width < 0 || width > maxTextureSize || height < 0 || height > maxTextureSize) { - throw new Error("gl-texture2d: Invalid texture shape") - } - var tex = initTexture(gl) - gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, type, null) - return new Texture2D(gl, tex, width, height, format, type) -} - -function createTextureDOM(gl, element, format, type) { - var tex = initTexture(gl) - gl.texImage2D(gl.TEXTURE_2D, 0, format, format, type, element) - return new Texture2D(gl, tex, element.width|0, element.height|0, format, type) -} - -function isPacked(array) { - var shape = array.shape - var stride = array.stride - var s = 1 - for(var i=shape.length-1; i>=0; --i) { - if(stride[i] !== s) { - return false - } - s *= shape[i] - } - return true -} - -//Creates a texture from an ndarray -function createTextureArray(gl, array) { - var dtype = array.dtype - var shape = array.shape.slice() - var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) - if(shape[0] < 0 || shape[0] > maxSize || shape[1] < 0 || shape[1] > maxSize) { - throw new Error("gl-texture2d: Invalid texture size") - } - - var packed = isPacked(array) - var type = 0 - if(dtype === "float32") { - type = gl.FLOAT - } else if(dtype === "float64") { - type = gl.FLOAT - packed = false - dtype = "float32" - } else if(dtype === "uint8") { - type = gl.UNSIGNED_BYTE - } else { - type = gl.UNSIGNED_BYTE - packed = false - dtype = "uint8" - } - var format = 0 - if(shape.length === 2) { - format = gl.LUMINANCE - } else if(shape.length === 3) { - if(shape[2] === 1) { - format = gl.ALPHA - } else if(shape[2] === 2) { - format = gl.LUMINANCE_ALPHA - } else if(shape[2] === 3) { - format = gl.RGB - } else if(shape[2] === 4) { - format = gl.RGBA - } else { - throw new Error("Invalid shape for pixel coords") - } - } else { - throw new Error("Invalid shape for texture") - } - if(type === gl.FLOAT && !!webglew(gl).texture_float) { - type = gl.UNSIGNED_BYTE - packed = false - } - var buffer, buf_store - if(!packed) { - var sz = 1 - var stride = new Array(shape.length) - for(var i=shape.length-1; i>=0; --i) { - stride[i] = sz - sz *= shape[i] - } - buf_store = pool.malloc(sz, dtype) - var buf_array = ndarray(buf_store, array.shape, stride, 0) - if((dtype === "float32" || dtype === "float64") && type === gl.UNSIGNED_BYTE) { - convertFloatToUint8(buf_array, array) - } else { - ops.assign(buf_array, array) - } - buffer = buf_store.subarray(0, sz) - } else { - var array_size = array.size - buffer = array.data.subarray(array.offset, array.offset + array_size) - } - var tex = initTexture(gl) - gl.texImage2D(gl.TEXTURE_2D, 0, format, shape[1], shape[0], 0, format, type, buffer) - if(!packed) { - pool.free(buf_store) - } - return new Texture2D(gl, tex, shape[1], shape[0], format, type) -} - -function createTexture2D(gl) { - if(arguments.length <= 1) { - throw new Error("Missing arguments for texture2d constructor") - } - if(!linearTypes) { - lazyInitLinearTypes(gl) - } - if(typeof arguments[1] === "number") { - return createTextureShape(gl, arguments[1], arguments[2], arguments[3]||gl.RGBA, arguments[4]||gl.UNSIGNED_BYTE) - } - if(Array.isArray(arguments[1])) { - return createTextureShape(gl, arguments[1][1]|0, arguments[1][0]|0, arguments[2]||gl.RGBA, arguments[4]||gl.UNSIGNED_BYTE) - } - if(typeof arguments[1] === "object") { - var obj = arguments[1] - if(obj instanceof HTMLCanvasElement || - obj instanceof HTMLImageElement || - obj instanceof HTMLVideoElement || - obj instanceof ImageData) { - return createTextureDOM(gl, obj, arguments[2]||gl.RGBA, arguments[3]||gl.UNSIGNED_BYTE) - } else if(obj.shape && obj.data && obj.stride) { - return createTextureArray(gl, obj) - } - } - throw new Error("Invalid arguments for texture2d constructor") -} -module.exports = createTexture2D - -},{"ndarray":157,"ndarray-ops":152,"typedarray-pool":161,"webglew":163}],165:[function(require,module,exports){ -arguments[4][79][0].apply(exports,arguments) -},{"gl-shader-core":171}],166:[function(require,module,exports){ -module.exports=require(80) -},{}],167:[function(require,module,exports){ -module.exports=require(81) -},{}],168:[function(require,module,exports){ -arguments[4][82][0].apply(exports,arguments) -},{"./reflect.js":169,"dup":170}],169:[function(require,module,exports){ -module.exports=require(83) -},{}],170:[function(require,module,exports){ -module.exports=require(17) -},{}],171:[function(require,module,exports){ -module.exports=require(85) -},{"./lib/create-attributes.js":167,"./lib/create-uniforms.js":168,"./lib/reflect.js":169}],172:[function(require,module,exports){ -var slice = require('sliced') - -module.exports = combine - -function combine(meshes) { - var pos = [] - var cel = [] - var p = 0 - var c = 0 - var k = 0 - - for (var i = 0; i < meshes.length; i++) { - var mpos = meshes[i].positions - var mcel = meshes[i].cells - - for (var j = 0; j < mpos.length; j++) { - pos[j + p] = slice(mpos[j]) - } - - for (var j = 0; j < mcel.length; j++) { - cel[k = j + c] = slice(mcel[j]) - cel[k][0] += p - cel[k][1] += p - cel[k][2] += p - } - - p += mpos.length - c += mcel.length - } - - return { - cells: cel - , positions: pos - } -} - -},{"sliced":173}],173:[function(require,module,exports){ -arguments[4][29][0].apply(exports,arguments) -},{"./lib/sliced":174}],174:[function(require,module,exports){ -module.exports=require(30) -},{}],175:[function(require,module,exports){ -arguments[4][14][0].apply(exports,arguments) -},{"buffer":189,"iota-array":176}],176:[function(require,module,exports){ -module.exports=require(15) -},{}],177:[function(require,module,exports){ -module.exports=require(88) -},{"ndarray":175}],178:[function(require,module,exports){ -/** - * @fileoverview gl-matrix - High performance matrix and vector operations - * @author Brandon Jones - * @author Colin MacKenzie IV - * @version 2.2.1 - */ - -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - - -(function(_global) { - "use strict"; - - var shim = {}; - if (typeof(exports) === 'undefined') { - if(typeof define == 'function' && typeof define.amd == 'object' && define.amd) { - shim.exports = {}; - define(function() { - return shim.exports; - }); - } else { - // gl-matrix lives in a browser, define its namespaces in global - shim.exports = typeof(window) !== 'undefined' ? window : _global; - } - } - else { - // gl-matrix lives in commonjs, define its namespaces in exports - shim.exports = exports; - } - - (function(exports) { - /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - - -if(!GLMAT_EPSILON) { - var GLMAT_EPSILON = 0.000001; -} - -if(!GLMAT_ARRAY_TYPE) { - var GLMAT_ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array; -} - -if(!GLMAT_RANDOM) { - var GLMAT_RANDOM = Math.random; -} - -/** - * @class Common utilities - * @name glMatrix - */ -var glMatrix = {}; - -/** - * Sets the type of array used when creating new vectors and matricies - * - * @param {Type} type Array type, such as Float32Array or Array - */ -glMatrix.setMatrixArrayType = function(type) { - GLMAT_ARRAY_TYPE = type; -} - -if(typeof(exports) !== 'undefined') { - exports.glMatrix = glMatrix; -} - -var degree = Math.PI / 180; - -/** -* Convert Degree To Radian -* -* @param {Number} Angle in Degrees -*/ -glMatrix.toRadian = function(a){ - return a * degree; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 2 Dimensional Vector - * @name vec2 - */ - -var vec2 = {}; - -/** - * Creates a new, empty vec2 - * - * @returns {vec2} a new 2D vector - */ -vec2.create = function() { - var out = new GLMAT_ARRAY_TYPE(2); - out[0] = 0; - out[1] = 0; - return out; -}; - -/** - * Creates a new vec2 initialized with values from an existing vector - * - * @param {vec2} a vector to clone - * @returns {vec2} a new 2D vector - */ -vec2.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(2); - out[0] = a[0]; - out[1] = a[1]; - return out; -}; - -/** - * Creates a new vec2 initialized with the given values - * - * @param {Number} x X component - * @param {Number} y Y component - * @returns {vec2} a new 2D vector - */ -vec2.fromValues = function(x, y) { - var out = new GLMAT_ARRAY_TYPE(2); - out[0] = x; - out[1] = y; - return out; -}; - -/** - * Copy the values from one vec2 to another - * - * @param {vec2} out the receiving vector - * @param {vec2} a the source vector - * @returns {vec2} out - */ -vec2.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - return out; -}; - -/** - * Set the components of a vec2 to the given values - * - * @param {vec2} out the receiving vector - * @param {Number} x X component - * @param {Number} y Y component - * @returns {vec2} out - */ -vec2.set = function(out, x, y) { - out[0] = x; - out[1] = y; - return out; -}; - -/** - * Adds two vec2's - * - * @param {vec2} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {vec2} out - */ -vec2.add = function(out, a, b) { - out[0] = a[0] + b[0]; - out[1] = a[1] + b[1]; - return out; -}; - -/** - * Subtracts vector b from vector a - * - * @param {vec2} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {vec2} out - */ -vec2.subtract = function(out, a, b) { - out[0] = a[0] - b[0]; - out[1] = a[1] - b[1]; - return out; -}; - -/** - * Alias for {@link vec2.subtract} - * @function - */ -vec2.sub = vec2.subtract; - -/** - * Multiplies two vec2's - * - * @param {vec2} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {vec2} out - */ -vec2.multiply = function(out, a, b) { - out[0] = a[0] * b[0]; - out[1] = a[1] * b[1]; - return out; -}; - -/** - * Alias for {@link vec2.multiply} - * @function - */ -vec2.mul = vec2.multiply; - -/** - * Divides two vec2's - * - * @param {vec2} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {vec2} out - */ -vec2.divide = function(out, a, b) { - out[0] = a[0] / b[0]; - out[1] = a[1] / b[1]; - return out; -}; - -/** - * Alias for {@link vec2.divide} - * @function - */ -vec2.div = vec2.divide; - -/** - * Returns the minimum of two vec2's - * - * @param {vec2} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {vec2} out - */ -vec2.min = function(out, a, b) { - out[0] = Math.min(a[0], b[0]); - out[1] = Math.min(a[1], b[1]); - return out; -}; - -/** - * Returns the maximum of two vec2's - * - * @param {vec2} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {vec2} out - */ -vec2.max = function(out, a, b) { - out[0] = Math.max(a[0], b[0]); - out[1] = Math.max(a[1], b[1]); - return out; -}; - -/** - * Scales a vec2 by a scalar number - * - * @param {vec2} out the receiving vector - * @param {vec2} a the vector to scale - * @param {Number} b amount to scale the vector by - * @returns {vec2} out - */ -vec2.scale = function(out, a, b) { - out[0] = a[0] * b; - out[1] = a[1] * b; - return out; -}; - -/** - * Adds two vec2's after scaling the second operand by a scalar value - * - * @param {vec2} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @param {Number} scale the amount to scale b by before adding - * @returns {vec2} out - */ -vec2.scaleAndAdd = function(out, a, b, scale) { - out[0] = a[0] + (b[0] * scale); - out[1] = a[1] + (b[1] * scale); - return out; -}; - -/** - * Calculates the euclidian distance between two vec2's - * - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {Number} distance between a and b - */ -vec2.distance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1]; - return Math.sqrt(x*x + y*y); -}; - -/** - * Alias for {@link vec2.distance} - * @function - */ -vec2.dist = vec2.distance; - -/** - * Calculates the squared euclidian distance between two vec2's - * - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {Number} squared distance between a and b - */ -vec2.squaredDistance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1]; - return x*x + y*y; -}; - -/** - * Alias for {@link vec2.squaredDistance} - * @function - */ -vec2.sqrDist = vec2.squaredDistance; - -/** - * Calculates the length of a vec2 - * - * @param {vec2} a vector to calculate length of - * @returns {Number} length of a - */ -vec2.length = function (a) { - var x = a[0], - y = a[1]; - return Math.sqrt(x*x + y*y); -}; - -/** - * Alias for {@link vec2.length} - * @function - */ -vec2.len = vec2.length; - -/** - * Calculates the squared length of a vec2 - * - * @param {vec2} a vector to calculate squared length of - * @returns {Number} squared length of a - */ -vec2.squaredLength = function (a) { - var x = a[0], - y = a[1]; - return x*x + y*y; -}; - -/** - * Alias for {@link vec2.squaredLength} - * @function - */ -vec2.sqrLen = vec2.squaredLength; - -/** - * Negates the components of a vec2 - * - * @param {vec2} out the receiving vector - * @param {vec2} a vector to negate - * @returns {vec2} out - */ -vec2.negate = function(out, a) { - out[0] = -a[0]; - out[1] = -a[1]; - return out; -}; - -/** - * Normalize a vec2 - * - * @param {vec2} out the receiving vector - * @param {vec2} a vector to normalize - * @returns {vec2} out - */ -vec2.normalize = function(out, a) { - var x = a[0], - y = a[1]; - var len = x*x + y*y; - if (len > 0) { - //TODO: evaluate use of glm_invsqrt here? - len = 1 / Math.sqrt(len); - out[0] = a[0] * len; - out[1] = a[1] * len; - } - return out; -}; - -/** - * Calculates the dot product of two vec2's - * - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {Number} dot product of a and b - */ -vec2.dot = function (a, b) { - return a[0] * b[0] + a[1] * b[1]; -}; - -/** - * Computes the cross product of two vec2's - * Note that the cross product must by definition produce a 3D vector - * - * @param {vec3} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {vec3} out - */ -vec2.cross = function(out, a, b) { - var z = a[0] * b[1] - a[1] * b[0]; - out[0] = out[1] = 0; - out[2] = z; - return out; -}; - -/** - * Performs a linear interpolation between two vec2's - * - * @param {vec2} out the receiving vector - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {vec2} out - */ -vec2.lerp = function (out, a, b, t) { - var ax = a[0], - ay = a[1]; - out[0] = ax + t * (b[0] - ax); - out[1] = ay + t * (b[1] - ay); - return out; -}; - -/** - * Generates a random vector with the given scale - * - * @param {vec2} out the receiving vector - * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned - * @returns {vec2} out - */ -vec2.random = function (out, scale) { - scale = scale || 1.0; - var r = GLMAT_RANDOM() * 2.0 * Math.PI; - out[0] = Math.cos(r) * scale; - out[1] = Math.sin(r) * scale; - return out; -}; - -/** - * Transforms the vec2 with a mat2 - * - * @param {vec2} out the receiving vector - * @param {vec2} a the vector to transform - * @param {mat2} m matrix to transform with - * @returns {vec2} out - */ -vec2.transformMat2 = function(out, a, m) { - var x = a[0], - y = a[1]; - out[0] = m[0] * x + m[2] * y; - out[1] = m[1] * x + m[3] * y; - return out; -}; - -/** - * Transforms the vec2 with a mat2d - * - * @param {vec2} out the receiving vector - * @param {vec2} a the vector to transform - * @param {mat2d} m matrix to transform with - * @returns {vec2} out - */ -vec2.transformMat2d = function(out, a, m) { - var x = a[0], - y = a[1]; - out[0] = m[0] * x + m[2] * y + m[4]; - out[1] = m[1] * x + m[3] * y + m[5]; - return out; -}; - -/** - * Transforms the vec2 with a mat3 - * 3rd vector component is implicitly '1' - * - * @param {vec2} out the receiving vector - * @param {vec2} a the vector to transform - * @param {mat3} m matrix to transform with - * @returns {vec2} out - */ -vec2.transformMat3 = function(out, a, m) { - var x = a[0], - y = a[1]; - out[0] = m[0] * x + m[3] * y + m[6]; - out[1] = m[1] * x + m[4] * y + m[7]; - return out; -}; - -/** - * Transforms the vec2 with a mat4 - * 3rd vector component is implicitly '0' - * 4th vector component is implicitly '1' - * - * @param {vec2} out the receiving vector - * @param {vec2} a the vector to transform - * @param {mat4} m matrix to transform with - * @returns {vec2} out - */ -vec2.transformMat4 = function(out, a, m) { - var x = a[0], - y = a[1]; - out[0] = m[0] * x + m[4] * y + m[12]; - out[1] = m[1] * x + m[5] * y + m[13]; - return out; -}; - -/** - * Perform some operation over an array of vec2s. - * - * @param {Array} a the array of vectors to iterate over - * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed - * @param {Number} offset Number of elements to skip at the beginning of the array - * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array - * @param {Function} fn Function to call for each vector in the array - * @param {Object} [arg] additional argument to pass to fn - * @returns {Array} a - * @function - */ -vec2.forEach = (function() { - var vec = vec2.create(); - - return function(a, stride, offset, count, fn, arg) { - var i, l; - if(!stride) { - stride = 2; - } - - if(!offset) { - offset = 0; - } - - if(count) { - l = Math.min((count * stride) + offset, a.length); - } else { - l = a.length; - } - - for(i = offset; i < l; i += stride) { - vec[0] = a[i]; vec[1] = a[i+1]; - fn(vec, vec, arg); - a[i] = vec[0]; a[i+1] = vec[1]; - } - - return a; - }; -})(); - -/** - * Returns a string representation of a vector - * - * @param {vec2} vec vector to represent as a string - * @returns {String} string representation of the vector - */ -vec2.str = function (a) { - return 'vec2(' + a[0] + ', ' + a[1] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.vec2 = vec2; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 3 Dimensional Vector - * @name vec3 - */ - -var vec3 = {}; - -/** - * Creates a new, empty vec3 - * - * @returns {vec3} a new 3D vector - */ -vec3.create = function() { - var out = new GLMAT_ARRAY_TYPE(3); - out[0] = 0; - out[1] = 0; - out[2] = 0; - return out; -}; - -/** - * Creates a new vec3 initialized with values from an existing vector - * - * @param {vec3} a vector to clone - * @returns {vec3} a new 3D vector - */ -vec3.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(3); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - return out; -}; - -/** - * Creates a new vec3 initialized with the given values - * - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @returns {vec3} a new 3D vector - */ -vec3.fromValues = function(x, y, z) { - var out = new GLMAT_ARRAY_TYPE(3); - out[0] = x; - out[1] = y; - out[2] = z; - return out; -}; - -/** - * Copy the values from one vec3 to another - * - * @param {vec3} out the receiving vector - * @param {vec3} a the source vector - * @returns {vec3} out - */ -vec3.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - return out; -}; - -/** - * Set the components of a vec3 to the given values - * - * @param {vec3} out the receiving vector - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @returns {vec3} out - */ -vec3.set = function(out, x, y, z) { - out[0] = x; - out[1] = y; - out[2] = z; - return out; -}; - -/** - * Adds two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.add = function(out, a, b) { - out[0] = a[0] + b[0]; - out[1] = a[1] + b[1]; - out[2] = a[2] + b[2]; - return out; -}; - -/** - * Subtracts vector b from vector a - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.subtract = function(out, a, b) { - out[0] = a[0] - b[0]; - out[1] = a[1] - b[1]; - out[2] = a[2] - b[2]; - return out; -}; - -/** - * Alias for {@link vec3.subtract} - * @function - */ -vec3.sub = vec3.subtract; - -/** - * Multiplies two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.multiply = function(out, a, b) { - out[0] = a[0] * b[0]; - out[1] = a[1] * b[1]; - out[2] = a[2] * b[2]; - return out; -}; - -/** - * Alias for {@link vec3.multiply} - * @function - */ -vec3.mul = vec3.multiply; - -/** - * Divides two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.divide = function(out, a, b) { - out[0] = a[0] / b[0]; - out[1] = a[1] / b[1]; - out[2] = a[2] / b[2]; - return out; -}; - -/** - * Alias for {@link vec3.divide} - * @function - */ -vec3.div = vec3.divide; - -/** - * Returns the minimum of two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.min = function(out, a, b) { - out[0] = Math.min(a[0], b[0]); - out[1] = Math.min(a[1], b[1]); - out[2] = Math.min(a[2], b[2]); - return out; -}; - -/** - * Returns the maximum of two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.max = function(out, a, b) { - out[0] = Math.max(a[0], b[0]); - out[1] = Math.max(a[1], b[1]); - out[2] = Math.max(a[2], b[2]); - return out; -}; - -/** - * Scales a vec3 by a scalar number - * - * @param {vec3} out the receiving vector - * @param {vec3} a the vector to scale - * @param {Number} b amount to scale the vector by - * @returns {vec3} out - */ -vec3.scale = function(out, a, b) { - out[0] = a[0] * b; - out[1] = a[1] * b; - out[2] = a[2] * b; - return out; -}; - -/** - * Adds two vec3's after scaling the second operand by a scalar value - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @param {Number} scale the amount to scale b by before adding - * @returns {vec3} out - */ -vec3.scaleAndAdd = function(out, a, b, scale) { - out[0] = a[0] + (b[0] * scale); - out[1] = a[1] + (b[1] * scale); - out[2] = a[2] + (b[2] * scale); - return out; -}; - -/** - * Calculates the euclidian distance between two vec3's - * - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {Number} distance between a and b - */ -vec3.distance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2]; - return Math.sqrt(x*x + y*y + z*z); -}; - -/** - * Alias for {@link vec3.distance} - * @function - */ -vec3.dist = vec3.distance; - -/** - * Calculates the squared euclidian distance between two vec3's - * - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {Number} squared distance between a and b - */ -vec3.squaredDistance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2]; - return x*x + y*y + z*z; -}; - -/** - * Alias for {@link vec3.squaredDistance} - * @function - */ -vec3.sqrDist = vec3.squaredDistance; - -/** - * Calculates the length of a vec3 - * - * @param {vec3} a vector to calculate length of - * @returns {Number} length of a - */ -vec3.length = function (a) { - var x = a[0], - y = a[1], - z = a[2]; - return Math.sqrt(x*x + y*y + z*z); -}; - -/** - * Alias for {@link vec3.length} - * @function - */ -vec3.len = vec3.length; - -/** - * Calculates the squared length of a vec3 - * - * @param {vec3} a vector to calculate squared length of - * @returns {Number} squared length of a - */ -vec3.squaredLength = function (a) { - var x = a[0], - y = a[1], - z = a[2]; - return x*x + y*y + z*z; -}; - -/** - * Alias for {@link vec3.squaredLength} - * @function - */ -vec3.sqrLen = vec3.squaredLength; - -/** - * Negates the components of a vec3 - * - * @param {vec3} out the receiving vector - * @param {vec3} a vector to negate - * @returns {vec3} out - */ -vec3.negate = function(out, a) { - out[0] = -a[0]; - out[1] = -a[1]; - out[2] = -a[2]; - return out; -}; - -/** - * Normalize a vec3 - * - * @param {vec3} out the receiving vector - * @param {vec3} a vector to normalize - * @returns {vec3} out - */ -vec3.normalize = function(out, a) { - var x = a[0], - y = a[1], - z = a[2]; - var len = x*x + y*y + z*z; - if (len > 0) { - //TODO: evaluate use of glm_invsqrt here? - len = 1 / Math.sqrt(len); - out[0] = a[0] * len; - out[1] = a[1] * len; - out[2] = a[2] * len; - } - return out; -}; - -/** - * Calculates the dot product of two vec3's - * - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {Number} dot product of a and b - */ -vec3.dot = function (a, b) { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; -}; - -/** - * Computes the cross product of two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @returns {vec3} out - */ -vec3.cross = function(out, a, b) { - var ax = a[0], ay = a[1], az = a[2], - bx = b[0], by = b[1], bz = b[2]; - - out[0] = ay * bz - az * by; - out[1] = az * bx - ax * bz; - out[2] = ax * by - ay * bx; - return out; -}; - -/** - * Performs a linear interpolation between two vec3's - * - * @param {vec3} out the receiving vector - * @param {vec3} a the first operand - * @param {vec3} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {vec3} out - */ -vec3.lerp = function (out, a, b, t) { - var ax = a[0], - ay = a[1], - az = a[2]; - out[0] = ax + t * (b[0] - ax); - out[1] = ay + t * (b[1] - ay); - out[2] = az + t * (b[2] - az); - return out; -}; - -/** - * Generates a random vector with the given scale - * - * @param {vec3} out the receiving vector - * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned - * @returns {vec3} out - */ -vec3.random = function (out, scale) { - scale = scale || 1.0; - - var r = GLMAT_RANDOM() * 2.0 * Math.PI; - var z = (GLMAT_RANDOM() * 2.0) - 1.0; - var zScale = Math.sqrt(1.0-z*z) * scale; - - out[0] = Math.cos(r) * zScale; - out[1] = Math.sin(r) * zScale; - out[2] = z * scale; - return out; -}; - -/** - * Transforms the vec3 with a mat4. - * 4th vector component is implicitly '1' - * - * @param {vec3} out the receiving vector - * @param {vec3} a the vector to transform - * @param {mat4} m matrix to transform with - * @returns {vec3} out - */ -vec3.transformMat4 = function(out, a, m) { - var x = a[0], y = a[1], z = a[2]; - out[0] = m[0] * x + m[4] * y + m[8] * z + m[12]; - out[1] = m[1] * x + m[5] * y + m[9] * z + m[13]; - out[2] = m[2] * x + m[6] * y + m[10] * z + m[14]; - return out; -}; - -/** - * Transforms the vec3 with a mat3. - * - * @param {vec3} out the receiving vector - * @param {vec3} a the vector to transform - * @param {mat4} m the 3x3 matrix to transform with - * @returns {vec3} out - */ -vec3.transformMat3 = function(out, a, m) { - var x = a[0], y = a[1], z = a[2]; - out[0] = x * m[0] + y * m[3] + z * m[6]; - out[1] = x * m[1] + y * m[4] + z * m[7]; - out[2] = x * m[2] + y * m[5] + z * m[8]; - return out; -}; - -/** - * Transforms the vec3 with a quat - * - * @param {vec3} out the receiving vector - * @param {vec3} a the vector to transform - * @param {quat} q quaternion to transform with - * @returns {vec3} out - */ -vec3.transformQuat = function(out, a, q) { - // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations - - var x = a[0], y = a[1], z = a[2], - qx = q[0], qy = q[1], qz = q[2], qw = q[3], - - // calculate quat * vec - ix = qw * x + qy * z - qz * y, - iy = qw * y + qz * x - qx * z, - iz = qw * z + qx * y - qy * x, - iw = -qx * x - qy * y - qz * z; - - // calculate result * inverse quat - out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; - out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; - out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; - return out; -}; - -/* -* Rotate a 3D vector around the x-axis -* @param {vec3} out The receiving vec3 -* @param {vec3} a The vec3 point to rotate -* @param {vec3} b The origin of the rotation -* @param {Number} c The angle of rotation -* @returns {vec3} out -*/ -vec3.rotateX = function(out, a, b, c){ - var p = [], r=[]; - //Translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - - //perform rotation - r[0] = p[0]; - r[1] = p[1]*Math.cos(c) - p[2]*Math.sin(c); - r[2] = p[1]*Math.sin(c) + p[2]*Math.cos(c); - - //translate to correct position - out[0] = r[0] + b[0]; - out[1] = r[1] + b[1]; - out[2] = r[2] + b[2]; - - return out; -}; - -/* -* Rotate a 3D vector around the y-axis -* @param {vec3} out The receiving vec3 -* @param {vec3} a The vec3 point to rotate -* @param {vec3} b The origin of the rotation -* @param {Number} c The angle of rotation -* @returns {vec3} out -*/ -vec3.rotateY = function(out, a, b, c){ - var p = [], r=[]; - //Translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - - //perform rotation - r[0] = p[2]*Math.sin(c) + p[0]*Math.cos(c); - r[1] = p[1]; - r[2] = p[2]*Math.cos(c) - p[0]*Math.sin(c); - - //translate to correct position - out[0] = r[0] + b[0]; - out[1] = r[1] + b[1]; - out[2] = r[2] + b[2]; - - return out; -}; - -/* -* Rotate a 3D vector around the z-axis -* @param {vec3} out The receiving vec3 -* @param {vec3} a The vec3 point to rotate -* @param {vec3} b The origin of the rotation -* @param {Number} c The angle of rotation -* @returns {vec3} out -*/ -vec3.rotateZ = function(out, a, b, c){ - var p = [], r=[]; - //Translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - - //perform rotation - r[0] = p[0]*Math.cos(c) - p[1]*Math.sin(c); - r[1] = p[0]*Math.sin(c) + p[1]*Math.cos(c); - r[2] = p[2]; - - //translate to correct position - out[0] = r[0] + b[0]; - out[1] = r[1] + b[1]; - out[2] = r[2] + b[2]; - - return out; -}; - -/** - * Perform some operation over an array of vec3s. - * - * @param {Array} a the array of vectors to iterate over - * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed - * @param {Number} offset Number of elements to skip at the beginning of the array - * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array - * @param {Function} fn Function to call for each vector in the array - * @param {Object} [arg] additional argument to pass to fn - * @returns {Array} a - * @function - */ -vec3.forEach = (function() { - var vec = vec3.create(); - - return function(a, stride, offset, count, fn, arg) { - var i, l; - if(!stride) { - stride = 3; - } - - if(!offset) { - offset = 0; - } - - if(count) { - l = Math.min((count * stride) + offset, a.length); - } else { - l = a.length; - } - - for(i = offset; i < l; i += stride) { - vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; - fn(vec, vec, arg); - a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; - } - - return a; - }; -})(); - -/** - * Returns a string representation of a vector - * - * @param {vec3} vec vector to represent as a string - * @returns {String} string representation of the vector - */ -vec3.str = function (a) { - return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.vec3 = vec3; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 4 Dimensional Vector - * @name vec4 - */ - -var vec4 = {}; - -/** - * Creates a new, empty vec4 - * - * @returns {vec4} a new 4D vector - */ -vec4.create = function() { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = 0; - out[1] = 0; - out[2] = 0; - out[3] = 0; - return out; -}; - -/** - * Creates a new vec4 initialized with values from an existing vector - * - * @param {vec4} a vector to clone - * @returns {vec4} a new 4D vector - */ -vec4.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - return out; -}; - -/** - * Creates a new vec4 initialized with the given values - * - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @param {Number} w W component - * @returns {vec4} a new 4D vector - */ -vec4.fromValues = function(x, y, z, w) { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = x; - out[1] = y; - out[2] = z; - out[3] = w; - return out; -}; - -/** - * Copy the values from one vec4 to another - * - * @param {vec4} out the receiving vector - * @param {vec4} a the source vector - * @returns {vec4} out - */ -vec4.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - return out; -}; - -/** - * Set the components of a vec4 to the given values - * - * @param {vec4} out the receiving vector - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @param {Number} w W component - * @returns {vec4} out - */ -vec4.set = function(out, x, y, z, w) { - out[0] = x; - out[1] = y; - out[2] = z; - out[3] = w; - return out; -}; - -/** - * Adds two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.add = function(out, a, b) { - out[0] = a[0] + b[0]; - out[1] = a[1] + b[1]; - out[2] = a[2] + b[2]; - out[3] = a[3] + b[3]; - return out; -}; - -/** - * Subtracts vector b from vector a - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.subtract = function(out, a, b) { - out[0] = a[0] - b[0]; - out[1] = a[1] - b[1]; - out[2] = a[2] - b[2]; - out[3] = a[3] - b[3]; - return out; -}; - -/** - * Alias for {@link vec4.subtract} - * @function - */ -vec4.sub = vec4.subtract; - -/** - * Multiplies two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.multiply = function(out, a, b) { - out[0] = a[0] * b[0]; - out[1] = a[1] * b[1]; - out[2] = a[2] * b[2]; - out[3] = a[3] * b[3]; - return out; -}; - -/** - * Alias for {@link vec4.multiply} - * @function - */ -vec4.mul = vec4.multiply; - -/** - * Divides two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.divide = function(out, a, b) { - out[0] = a[0] / b[0]; - out[1] = a[1] / b[1]; - out[2] = a[2] / b[2]; - out[3] = a[3] / b[3]; - return out; -}; - -/** - * Alias for {@link vec4.divide} - * @function - */ -vec4.div = vec4.divide; - -/** - * Returns the minimum of two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.min = function(out, a, b) { - out[0] = Math.min(a[0], b[0]); - out[1] = Math.min(a[1], b[1]); - out[2] = Math.min(a[2], b[2]); - out[3] = Math.min(a[3], b[3]); - return out; -}; - -/** - * Returns the maximum of two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {vec4} out - */ -vec4.max = function(out, a, b) { - out[0] = Math.max(a[0], b[0]); - out[1] = Math.max(a[1], b[1]); - out[2] = Math.max(a[2], b[2]); - out[3] = Math.max(a[3], b[3]); - return out; -}; - -/** - * Scales a vec4 by a scalar number - * - * @param {vec4} out the receiving vector - * @param {vec4} a the vector to scale - * @param {Number} b amount to scale the vector by - * @returns {vec4} out - */ -vec4.scale = function(out, a, b) { - out[0] = a[0] * b; - out[1] = a[1] * b; - out[2] = a[2] * b; - out[3] = a[3] * b; - return out; -}; - -/** - * Adds two vec4's after scaling the second operand by a scalar value - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @param {Number} scale the amount to scale b by before adding - * @returns {vec4} out - */ -vec4.scaleAndAdd = function(out, a, b, scale) { - out[0] = a[0] + (b[0] * scale); - out[1] = a[1] + (b[1] * scale); - out[2] = a[2] + (b[2] * scale); - out[3] = a[3] + (b[3] * scale); - return out; -}; - -/** - * Calculates the euclidian distance between two vec4's - * - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {Number} distance between a and b - */ -vec4.distance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2], - w = b[3] - a[3]; - return Math.sqrt(x*x + y*y + z*z + w*w); -}; - -/** - * Alias for {@link vec4.distance} - * @function - */ -vec4.dist = vec4.distance; - -/** - * Calculates the squared euclidian distance between two vec4's - * - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {Number} squared distance between a and b - */ -vec4.squaredDistance = function(a, b) { - var x = b[0] - a[0], - y = b[1] - a[1], - z = b[2] - a[2], - w = b[3] - a[3]; - return x*x + y*y + z*z + w*w; -}; - -/** - * Alias for {@link vec4.squaredDistance} - * @function - */ -vec4.sqrDist = vec4.squaredDistance; - -/** - * Calculates the length of a vec4 - * - * @param {vec4} a vector to calculate length of - * @returns {Number} length of a - */ -vec4.length = function (a) { - var x = a[0], - y = a[1], - z = a[2], - w = a[3]; - return Math.sqrt(x*x + y*y + z*z + w*w); -}; - -/** - * Alias for {@link vec4.length} - * @function - */ -vec4.len = vec4.length; - -/** - * Calculates the squared length of a vec4 - * - * @param {vec4} a vector to calculate squared length of - * @returns {Number} squared length of a - */ -vec4.squaredLength = function (a) { - var x = a[0], - y = a[1], - z = a[2], - w = a[3]; - return x*x + y*y + z*z + w*w; -}; - -/** - * Alias for {@link vec4.squaredLength} - * @function - */ -vec4.sqrLen = vec4.squaredLength; - -/** - * Negates the components of a vec4 - * - * @param {vec4} out the receiving vector - * @param {vec4} a vector to negate - * @returns {vec4} out - */ -vec4.negate = function(out, a) { - out[0] = -a[0]; - out[1] = -a[1]; - out[2] = -a[2]; - out[3] = -a[3]; - return out; -}; - -/** - * Normalize a vec4 - * - * @param {vec4} out the receiving vector - * @param {vec4} a vector to normalize - * @returns {vec4} out - */ -vec4.normalize = function(out, a) { - var x = a[0], - y = a[1], - z = a[2], - w = a[3]; - var len = x*x + y*y + z*z + w*w; - if (len > 0) { - len = 1 / Math.sqrt(len); - out[0] = a[0] * len; - out[1] = a[1] * len; - out[2] = a[2] * len; - out[3] = a[3] * len; - } - return out; -}; - -/** - * Calculates the dot product of two vec4's - * - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @returns {Number} dot product of a and b - */ -vec4.dot = function (a, b) { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; -}; - -/** - * Performs a linear interpolation between two vec4's - * - * @param {vec4} out the receiving vector - * @param {vec4} a the first operand - * @param {vec4} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {vec4} out - */ -vec4.lerp = function (out, a, b, t) { - var ax = a[0], - ay = a[1], - az = a[2], - aw = a[3]; - out[0] = ax + t * (b[0] - ax); - out[1] = ay + t * (b[1] - ay); - out[2] = az + t * (b[2] - az); - out[3] = aw + t * (b[3] - aw); - return out; -}; - -/** - * Generates a random vector with the given scale - * - * @param {vec4} out the receiving vector - * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned - * @returns {vec4} out - */ -vec4.random = function (out, scale) { - scale = scale || 1.0; - - //TODO: This is a pretty awful way of doing this. Find something better. - out[0] = GLMAT_RANDOM(); - out[1] = GLMAT_RANDOM(); - out[2] = GLMAT_RANDOM(); - out[3] = GLMAT_RANDOM(); - vec4.normalize(out, out); - vec4.scale(out, out, scale); - return out; -}; - -/** - * Transforms the vec4 with a mat4. - * - * @param {vec4} out the receiving vector - * @param {vec4} a the vector to transform - * @param {mat4} m matrix to transform with - * @returns {vec4} out - */ -vec4.transformMat4 = function(out, a, m) { - var x = a[0], y = a[1], z = a[2], w = a[3]; - out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w; - out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w; - out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w; - out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w; - return out; -}; - -/** - * Transforms the vec4 with a quat - * - * @param {vec4} out the receiving vector - * @param {vec4} a the vector to transform - * @param {quat} q quaternion to transform with - * @returns {vec4} out - */ -vec4.transformQuat = function(out, a, q) { - var x = a[0], y = a[1], z = a[2], - qx = q[0], qy = q[1], qz = q[2], qw = q[3], - - // calculate quat * vec - ix = qw * x + qy * z - qz * y, - iy = qw * y + qz * x - qx * z, - iz = qw * z + qx * y - qy * x, - iw = -qx * x - qy * y - qz * z; - - // calculate result * inverse quat - out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; - out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; - out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; - return out; -}; - -/** - * Perform some operation over an array of vec4s. - * - * @param {Array} a the array of vectors to iterate over - * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed - * @param {Number} offset Number of elements to skip at the beginning of the array - * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array - * @param {Function} fn Function to call for each vector in the array - * @param {Object} [arg] additional argument to pass to fn - * @returns {Array} a - * @function - */ -vec4.forEach = (function() { - var vec = vec4.create(); - - return function(a, stride, offset, count, fn, arg) { - var i, l; - if(!stride) { - stride = 4; - } - - if(!offset) { - offset = 0; - } - - if(count) { - l = Math.min((count * stride) + offset, a.length); - } else { - l = a.length; - } - - for(i = offset; i < l; i += stride) { - vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3]; - fn(vec, vec, arg); - a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3]; - } - - return a; - }; -})(); - -/** - * Returns a string representation of a vector - * - * @param {vec4} vec vector to represent as a string - * @returns {String} string representation of the vector - */ -vec4.str = function (a) { - return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.vec4 = vec4; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 2x2 Matrix - * @name mat2 - */ - -var mat2 = {}; - -/** - * Creates a new identity mat2 - * - * @returns {mat2} a new 2x2 matrix - */ -mat2.create = function() { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 1; - return out; -}; - -/** - * Creates a new mat2 initialized with values from an existing matrix - * - * @param {mat2} a matrix to clone - * @returns {mat2} a new 2x2 matrix - */ -mat2.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - return out; -}; - -/** - * Copy the values from one mat2 to another - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the source matrix - * @returns {mat2} out - */ -mat2.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - return out; -}; - -/** - * Set a mat2 to the identity matrix - * - * @param {mat2} out the receiving matrix - * @returns {mat2} out - */ -mat2.identity = function(out) { - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 1; - return out; -}; - -/** - * Transpose the values of a mat2 - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the source matrix - * @returns {mat2} out - */ -mat2.transpose = function(out, a) { - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (out === a) { - var a1 = a[1]; - out[1] = a[2]; - out[2] = a1; - } else { - out[0] = a[0]; - out[1] = a[2]; - out[2] = a[1]; - out[3] = a[3]; - } - - return out; -}; - -/** - * Inverts a mat2 - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the source matrix - * @returns {mat2} out - */ -mat2.invert = function(out, a) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], - - // Calculate the determinant - det = a0 * a3 - a2 * a1; - - if (!det) { - return null; - } - det = 1.0 / det; - - out[0] = a3 * det; - out[1] = -a1 * det; - out[2] = -a2 * det; - out[3] = a0 * det; - - return out; -}; - -/** - * Calculates the adjugate of a mat2 - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the source matrix - * @returns {mat2} out - */ -mat2.adjoint = function(out, a) { - // Caching this value is nessecary if out == a - var a0 = a[0]; - out[0] = a[3]; - out[1] = -a[1]; - out[2] = -a[2]; - out[3] = a0; - - return out; -}; - -/** - * Calculates the determinant of a mat2 - * - * @param {mat2} a the source matrix - * @returns {Number} determinant of a - */ -mat2.determinant = function (a) { - return a[0] * a[3] - a[2] * a[1]; -}; - -/** - * Multiplies two mat2's - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the first operand - * @param {mat2} b the second operand - * @returns {mat2} out - */ -mat2.multiply = function (out, a, b) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3]; - var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; - out[0] = a0 * b0 + a2 * b1; - out[1] = a1 * b0 + a3 * b1; - out[2] = a0 * b2 + a2 * b3; - out[3] = a1 * b2 + a3 * b3; - return out; -}; - -/** - * Alias for {@link mat2.multiply} - * @function - */ -mat2.mul = mat2.multiply; - -/** - * Rotates a mat2 by the given angle - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat2} out - */ -mat2.rotate = function (out, a, rad) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], - s = Math.sin(rad), - c = Math.cos(rad); - out[0] = a0 * c + a2 * s; - out[1] = a1 * c + a3 * s; - out[2] = a0 * -s + a2 * c; - out[3] = a1 * -s + a3 * c; - return out; -}; - -/** - * Scales the mat2 by the dimensions in the given vec2 - * - * @param {mat2} out the receiving matrix - * @param {mat2} a the matrix to rotate - * @param {vec2} v the vec2 to scale the matrix by - * @returns {mat2} out - **/ -mat2.scale = function(out, a, v) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], - v0 = v[0], v1 = v[1]; - out[0] = a0 * v0; - out[1] = a1 * v0; - out[2] = a2 * v1; - out[3] = a3 * v1; - return out; -}; - -/** - * Returns a string representation of a mat2 - * - * @param {mat2} mat matrix to represent as a string - * @returns {String} string representation of the matrix - */ -mat2.str = function (a) { - return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; -}; - -/** - * Returns Frobenius norm of a mat2 - * - * @param {mat2} a the matrix to calculate Frobenius norm of - * @returns {Number} Frobenius norm - */ -mat2.frob = function (a) { - return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2))) -}; - -/** - * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix - * @param {mat2} L the lower triangular matrix - * @param {mat2} D the diagonal matrix - * @param {mat2} U the upper triangular matrix - * @param {mat2} a the input matrix to factorize - */ - -mat2.LDU = function (L, D, U, a) { - L[2] = a[2]/a[0]; - U[0] = a[0]; - U[1] = a[1]; - U[3] = a[3] - L[2] * U[1]; - return [L, D, U]; -}; - -if(typeof(exports) !== 'undefined') { - exports.mat2 = mat2; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 2x3 Matrix - * @name mat2d - * - * @description - * A mat2d contains six elements defined as: - *
      - * [a, c, tx,
      - *  b, d, ty]
      - * 
      - * This is a short form for the 3x3 matrix: - *
      - * [a, c, tx,
      - *  b, d, ty,
      - *  0, 0, 1]
      - * 
      - * The last row is ignored so the array is shorter and operations are faster. - */ - -var mat2d = {}; - -/** - * Creates a new identity mat2d - * - * @returns {mat2d} a new 2x3 matrix - */ -mat2d.create = function() { - var out = new GLMAT_ARRAY_TYPE(6); - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 1; - out[4] = 0; - out[5] = 0; - return out; -}; - -/** - * Creates a new mat2d initialized with values from an existing matrix - * - * @param {mat2d} a matrix to clone - * @returns {mat2d} a new 2x3 matrix - */ -mat2d.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(6); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - return out; -}; - -/** - * Copy the values from one mat2d to another - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the source matrix - * @returns {mat2d} out - */ -mat2d.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - return out; -}; - -/** - * Set a mat2d to the identity matrix - * - * @param {mat2d} out the receiving matrix - * @returns {mat2d} out - */ -mat2d.identity = function(out) { - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 1; - out[4] = 0; - out[5] = 0; - return out; -}; - -/** - * Inverts a mat2d - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the source matrix - * @returns {mat2d} out - */ -mat2d.invert = function(out, a) { - var aa = a[0], ab = a[1], ac = a[2], ad = a[3], - atx = a[4], aty = a[5]; - - var det = aa * ad - ab * ac; - if(!det){ - return null; - } - det = 1.0 / det; - - out[0] = ad * det; - out[1] = -ab * det; - out[2] = -ac * det; - out[3] = aa * det; - out[4] = (ac * aty - ad * atx) * det; - out[5] = (ab * atx - aa * aty) * det; - return out; -}; - -/** - * Calculates the determinant of a mat2d - * - * @param {mat2d} a the source matrix - * @returns {Number} determinant of a - */ -mat2d.determinant = function (a) { - return a[0] * a[3] - a[1] * a[2]; -}; - -/** - * Multiplies two mat2d's - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the first operand - * @param {mat2d} b the second operand - * @returns {mat2d} out - */ -mat2d.multiply = function (out, a, b) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], - b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5]; - out[0] = a0 * b0 + a2 * b1; - out[1] = a1 * b0 + a3 * b1; - out[2] = a0 * b2 + a2 * b3; - out[3] = a1 * b2 + a3 * b3; - out[4] = a0 * b4 + a2 * b5 + a4; - out[5] = a1 * b4 + a3 * b5 + a5; - return out; -}; - -/** - * Alias for {@link mat2d.multiply} - * @function - */ -mat2d.mul = mat2d.multiply; - - -/** - * Rotates a mat2d by the given angle - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat2d} out - */ -mat2d.rotate = function (out, a, rad) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], - s = Math.sin(rad), - c = Math.cos(rad); - out[0] = a0 * c + a2 * s; - out[1] = a1 * c + a3 * s; - out[2] = a0 * -s + a2 * c; - out[3] = a1 * -s + a3 * c; - out[4] = a4; - out[5] = a5; - return out; -}; - -/** - * Scales the mat2d by the dimensions in the given vec2 - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the matrix to translate - * @param {vec2} v the vec2 to scale the matrix by - * @returns {mat2d} out - **/ -mat2d.scale = function(out, a, v) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], - v0 = v[0], v1 = v[1]; - out[0] = a0 * v0; - out[1] = a1 * v0; - out[2] = a2 * v1; - out[3] = a3 * v1; - out[4] = a4; - out[5] = a5; - return out; -}; - -/** - * Translates the mat2d by the dimensions in the given vec2 - * - * @param {mat2d} out the receiving matrix - * @param {mat2d} a the matrix to translate - * @param {vec2} v the vec2 to translate the matrix by - * @returns {mat2d} out - **/ -mat2d.translate = function(out, a, v) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], - v0 = v[0], v1 = v[1]; - out[0] = a0; - out[1] = a1; - out[2] = a2; - out[3] = a3; - out[4] = a0 * v0 + a2 * v1 + a4; - out[5] = a1 * v0 + a3 * v1 + a5; - return out; -}; - -/** - * Returns a string representation of a mat2d - * - * @param {mat2d} a matrix to represent as a string - * @returns {String} string representation of the matrix - */ -mat2d.str = function (a) { - return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + - a[3] + ', ' + a[4] + ', ' + a[5] + ')'; -}; - -/** - * Returns Frobenius norm of a mat2d - * - * @param {mat2d} a the matrix to calculate Frobenius norm of - * @returns {Number} Frobenius norm - */ -mat2d.frob = function (a) { - return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + 1)) -}; - -if(typeof(exports) !== 'undefined') { - exports.mat2d = mat2d; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 3x3 Matrix - * @name mat3 - */ - -var mat3 = {}; - -/** - * Creates a new identity mat3 - * - * @returns {mat3} a new 3x3 matrix - */ -mat3.create = function() { - var out = new GLMAT_ARRAY_TYPE(9); - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 1; - out[5] = 0; - out[6] = 0; - out[7] = 0; - out[8] = 1; - return out; -}; - -/** - * Copies the upper-left 3x3 values into the given mat3. - * - * @param {mat3} out the receiving 3x3 matrix - * @param {mat4} a the source 4x4 matrix - * @returns {mat3} out - */ -mat3.fromMat4 = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[4]; - out[4] = a[5]; - out[5] = a[6]; - out[6] = a[8]; - out[7] = a[9]; - out[8] = a[10]; - return out; -}; - -/** - * Creates a new mat3 initialized with values from an existing matrix - * - * @param {mat3} a matrix to clone - * @returns {mat3} a new 3x3 matrix - */ -mat3.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(9); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - return out; -}; - -/** - * Copy the values from one mat3 to another - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - return out; -}; - -/** - * Set a mat3 to the identity matrix - * - * @param {mat3} out the receiving matrix - * @returns {mat3} out - */ -mat3.identity = function(out) { - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 1; - out[5] = 0; - out[6] = 0; - out[7] = 0; - out[8] = 1; - return out; -}; - -/** - * Transpose the values of a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.transpose = function(out, a) { - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (out === a) { - var a01 = a[1], a02 = a[2], a12 = a[5]; - out[1] = a[3]; - out[2] = a[6]; - out[3] = a01; - out[5] = a[7]; - out[6] = a02; - out[7] = a12; - } else { - out[0] = a[0]; - out[1] = a[3]; - out[2] = a[6]; - out[3] = a[1]; - out[4] = a[4]; - out[5] = a[7]; - out[6] = a[2]; - out[7] = a[5]; - out[8] = a[8]; - } - - return out; -}; - -/** - * Inverts a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.invert = function(out, a) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], - - b01 = a22 * a11 - a12 * a21, - b11 = -a22 * a10 + a12 * a20, - b21 = a21 * a10 - a11 * a20, - - // Calculate the determinant - det = a00 * b01 + a01 * b11 + a02 * b21; - - if (!det) { - return null; - } - det = 1.0 / det; - - out[0] = b01 * det; - out[1] = (-a22 * a01 + a02 * a21) * det; - out[2] = (a12 * a01 - a02 * a11) * det; - out[3] = b11 * det; - out[4] = (a22 * a00 - a02 * a20) * det; - out[5] = (-a12 * a00 + a02 * a10) * det; - out[6] = b21 * det; - out[7] = (-a21 * a00 + a01 * a20) * det; - out[8] = (a11 * a00 - a01 * a10) * det; - return out; -}; - -/** - * Calculates the adjugate of a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the source matrix - * @returns {mat3} out - */ -mat3.adjoint = function(out, a) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8]; - - out[0] = (a11 * a22 - a12 * a21); - out[1] = (a02 * a21 - a01 * a22); - out[2] = (a01 * a12 - a02 * a11); - out[3] = (a12 * a20 - a10 * a22); - out[4] = (a00 * a22 - a02 * a20); - out[5] = (a02 * a10 - a00 * a12); - out[6] = (a10 * a21 - a11 * a20); - out[7] = (a01 * a20 - a00 * a21); - out[8] = (a00 * a11 - a01 * a10); - return out; -}; - -/** - * Calculates the determinant of a mat3 - * - * @param {mat3} a the source matrix - * @returns {Number} determinant of a - */ -mat3.determinant = function (a) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8]; - - return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); -}; - -/** - * Multiplies two mat3's - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the first operand - * @param {mat3} b the second operand - * @returns {mat3} out - */ -mat3.multiply = function (out, a, b) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], - - b00 = b[0], b01 = b[1], b02 = b[2], - b10 = b[3], b11 = b[4], b12 = b[5], - b20 = b[6], b21 = b[7], b22 = b[8]; - - out[0] = b00 * a00 + b01 * a10 + b02 * a20; - out[1] = b00 * a01 + b01 * a11 + b02 * a21; - out[2] = b00 * a02 + b01 * a12 + b02 * a22; - - out[3] = b10 * a00 + b11 * a10 + b12 * a20; - out[4] = b10 * a01 + b11 * a11 + b12 * a21; - out[5] = b10 * a02 + b11 * a12 + b12 * a22; - - out[6] = b20 * a00 + b21 * a10 + b22 * a20; - out[7] = b20 * a01 + b21 * a11 + b22 * a21; - out[8] = b20 * a02 + b21 * a12 + b22 * a22; - return out; -}; - -/** - * Alias for {@link mat3.multiply} - * @function - */ -mat3.mul = mat3.multiply; - -/** - * Translate a mat3 by the given vector - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the matrix to translate - * @param {vec2} v vector to translate by - * @returns {mat3} out - */ -mat3.translate = function(out, a, v) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], - x = v[0], y = v[1]; - - out[0] = a00; - out[1] = a01; - out[2] = a02; - - out[3] = a10; - out[4] = a11; - out[5] = a12; - - out[6] = x * a00 + y * a10 + a20; - out[7] = x * a01 + y * a11 + a21; - out[8] = x * a02 + y * a12 + a22; - return out; -}; - -/** - * Rotates a mat3 by the given angle - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat3} out - */ -mat3.rotate = function (out, a, rad) { - var a00 = a[0], a01 = a[1], a02 = a[2], - a10 = a[3], a11 = a[4], a12 = a[5], - a20 = a[6], a21 = a[7], a22 = a[8], - - s = Math.sin(rad), - c = Math.cos(rad); - - out[0] = c * a00 + s * a10; - out[1] = c * a01 + s * a11; - out[2] = c * a02 + s * a12; - - out[3] = c * a10 - s * a00; - out[4] = c * a11 - s * a01; - out[5] = c * a12 - s * a02; - - out[6] = a20; - out[7] = a21; - out[8] = a22; - return out; -}; - -/** - * Scales the mat3 by the dimensions in the given vec2 - * - * @param {mat3} out the receiving matrix - * @param {mat3} a the matrix to rotate - * @param {vec2} v the vec2 to scale the matrix by - * @returns {mat3} out - **/ -mat3.scale = function(out, a, v) { - var x = v[0], y = v[1]; - - out[0] = x * a[0]; - out[1] = x * a[1]; - out[2] = x * a[2]; - - out[3] = y * a[3]; - out[4] = y * a[4]; - out[5] = y * a[5]; - - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - return out; -}; - -/** - * Copies the values from a mat2d into a mat3 - * - * @param {mat3} out the receiving matrix - * @param {mat2d} a the matrix to copy - * @returns {mat3} out - **/ -mat3.fromMat2d = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = 0; - - out[3] = a[2]; - out[4] = a[3]; - out[5] = 0; - - out[6] = a[4]; - out[7] = a[5]; - out[8] = 1; - return out; -}; - -/** -* Calculates a 3x3 matrix from the given quaternion -* -* @param {mat3} out mat3 receiving operation result -* @param {quat} q Quaternion to create matrix from -* -* @returns {mat3} out -*/ -mat3.fromQuat = function (out, q) { - var x = q[0], y = q[1], z = q[2], w = q[3], - x2 = x + x, - y2 = y + y, - z2 = z + z, - - xx = x * x2, - yx = y * x2, - yy = y * y2, - zx = z * x2, - zy = z * y2, - zz = z * z2, - wx = w * x2, - wy = w * y2, - wz = w * z2; - - out[0] = 1 - yy - zz; - out[3] = yx - wz; - out[6] = zx + wy; - - out[1] = yx + wz; - out[4] = 1 - xx - zz; - out[7] = zy - wx; - - out[2] = zx - wy; - out[5] = zy + wx; - out[8] = 1 - xx - yy; - - return out; -}; - -/** -* Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix -* -* @param {mat3} out mat3 receiving operation result -* @param {mat4} a Mat4 to derive the normal matrix from -* -* @returns {mat3} out -*/ -mat3.normalFromMat4 = function (out, a) { - var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], - a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], - a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], - a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], - - b00 = a00 * a11 - a01 * a10, - b01 = a00 * a12 - a02 * a10, - b02 = a00 * a13 - a03 * a10, - b03 = a01 * a12 - a02 * a11, - b04 = a01 * a13 - a03 * a11, - b05 = a02 * a13 - a03 * a12, - b06 = a20 * a31 - a21 * a30, - b07 = a20 * a32 - a22 * a30, - b08 = a20 * a33 - a23 * a30, - b09 = a21 * a32 - a22 * a31, - b10 = a21 * a33 - a23 * a31, - b11 = a22 * a33 - a23 * a32, - - // Calculate the determinant - det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; - - if (!det) { - return null; - } - det = 1.0 / det; - - out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; - out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det; - out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det; - - out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det; - out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det; - out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det; - - out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det; - out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det; - out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det; - - return out; -}; - -/** - * Returns a string representation of a mat3 - * - * @param {mat3} mat matrix to represent as a string - * @returns {String} string representation of the matrix - */ -mat3.str = function (a) { - return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + - a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + - a[6] + ', ' + a[7] + ', ' + a[8] + ')'; -}; - -/** - * Returns Frobenius norm of a mat3 - * - * @param {mat3} a the matrix to calculate Frobenius norm of - * @returns {Number} Frobenius norm - */ -mat3.frob = function (a) { - return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2))) -}; - - -if(typeof(exports) !== 'undefined') { - exports.mat3 = mat3; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class 4x4 Matrix - * @name mat4 - */ - -var mat4 = {}; - -/** - * Creates a new identity mat4 - * - * @returns {mat4} a new 4x4 matrix - */ -mat4.create = function() { - var out = new GLMAT_ARRAY_TYPE(16); - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = 1; - out[6] = 0; - out[7] = 0; - out[8] = 0; - out[9] = 0; - out[10] = 1; - out[11] = 0; - out[12] = 0; - out[13] = 0; - out[14] = 0; - out[15] = 1; - return out; -}; - -/** - * Creates a new mat4 initialized with values from an existing matrix - * - * @param {mat4} a matrix to clone - * @returns {mat4} a new 4x4 matrix - */ -mat4.clone = function(a) { - var out = new GLMAT_ARRAY_TYPE(16); - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - out[9] = a[9]; - out[10] = a[10]; - out[11] = a[11]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - return out; -}; - -/** - * Copy the values from one mat4 to another - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the source matrix - * @returns {mat4} out - */ -mat4.copy = function(out, a) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - out[9] = a[9]; - out[10] = a[10]; - out[11] = a[11]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - return out; -}; - -/** - * Set a mat4 to the identity matrix - * - * @param {mat4} out the receiving matrix - * @returns {mat4} out - */ -mat4.identity = function(out) { - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = 1; - out[6] = 0; - out[7] = 0; - out[8] = 0; - out[9] = 0; - out[10] = 1; - out[11] = 0; - out[12] = 0; - out[13] = 0; - out[14] = 0; - out[15] = 1; - return out; -}; - -/** - * Transpose the values of a mat4 - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the source matrix - * @returns {mat4} out - */ -mat4.transpose = function(out, a) { - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (out === a) { - var a01 = a[1], a02 = a[2], a03 = a[3], - a12 = a[6], a13 = a[7], - a23 = a[11]; - - out[1] = a[4]; - out[2] = a[8]; - out[3] = a[12]; - out[4] = a01; - out[6] = a[9]; - out[7] = a[13]; - out[8] = a02; - out[9] = a12; - out[11] = a[14]; - out[12] = a03; - out[13] = a13; - out[14] = a23; - } else { - out[0] = a[0]; - out[1] = a[4]; - out[2] = a[8]; - out[3] = a[12]; - out[4] = a[1]; - out[5] = a[5]; - out[6] = a[9]; - out[7] = a[13]; - out[8] = a[2]; - out[9] = a[6]; - out[10] = a[10]; - out[11] = a[14]; - out[12] = a[3]; - out[13] = a[7]; - out[14] = a[11]; - out[15] = a[15]; - } - - return out; -}; - -/** - * Inverts a mat4 - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the source matrix - * @returns {mat4} out - */ -mat4.invert = function(out, a) { - var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], - a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], - a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], - a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], - - b00 = a00 * a11 - a01 * a10, - b01 = a00 * a12 - a02 * a10, - b02 = a00 * a13 - a03 * a10, - b03 = a01 * a12 - a02 * a11, - b04 = a01 * a13 - a03 * a11, - b05 = a02 * a13 - a03 * a12, - b06 = a20 * a31 - a21 * a30, - b07 = a20 * a32 - a22 * a30, - b08 = a20 * a33 - a23 * a30, - b09 = a21 * a32 - a22 * a31, - b10 = a21 * a33 - a23 * a31, - b11 = a22 * a33 - a23 * a32, - - // Calculate the determinant - det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; - - if (!det) { - return null; - } - det = 1.0 / det; - - out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; - out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; - out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; - out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; - out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; - out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; - out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; - out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; - out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; - out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; - out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; - out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; - out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; - out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; - out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; - out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; - - return out; -}; - -/** - * Calculates the adjugate of a mat4 - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the source matrix - * @returns {mat4} out - */ -mat4.adjoint = function(out, a) { - var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], - a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], - a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], - a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; - - out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22)); - out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22)); - out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12)); - out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12)); - out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22)); - out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22)); - out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12)); - out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12)); - out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21)); - out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21)); - out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11)); - out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11)); - out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21)); - out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21)); - out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11)); - out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11)); - return out; -}; - -/** - * Calculates the determinant of a mat4 - * - * @param {mat4} a the source matrix - * @returns {Number} determinant of a - */ -mat4.determinant = function (a) { - var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], - a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], - a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], - a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], - - b00 = a00 * a11 - a01 * a10, - b01 = a00 * a12 - a02 * a10, - b02 = a00 * a13 - a03 * a10, - b03 = a01 * a12 - a02 * a11, - b04 = a01 * a13 - a03 * a11, - b05 = a02 * a13 - a03 * a12, - b06 = a20 * a31 - a21 * a30, - b07 = a20 * a32 - a22 * a30, - b08 = a20 * a33 - a23 * a30, - b09 = a21 * a32 - a22 * a31, - b10 = a21 * a33 - a23 * a31, - b11 = a22 * a33 - a23 * a32; - - // Calculate the determinant - return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; -}; - -/** - * Multiplies two mat4's - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the first operand - * @param {mat4} b the second operand - * @returns {mat4} out - */ -mat4.multiply = function (out, a, b) { - var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], - a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], - a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], - a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; - - // Cache only the current line of the second matrix - var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; - out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7]; - out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11]; - out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15]; - out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - return out; -}; - -/** - * Alias for {@link mat4.multiply} - * @function - */ -mat4.mul = mat4.multiply; - -/** - * Translate a mat4 by the given vector - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to translate - * @param {vec3} v vector to translate by - * @returns {mat4} out - */ -mat4.translate = function (out, a, v) { - var x = v[0], y = v[1], z = v[2], - a00, a01, a02, a03, - a10, a11, a12, a13, - a20, a21, a22, a23; - - if (a === out) { - out[12] = a[0] * x + a[4] * y + a[8] * z + a[12]; - out[13] = a[1] * x + a[5] * y + a[9] * z + a[13]; - out[14] = a[2] * x + a[6] * y + a[10] * z + a[14]; - out[15] = a[3] * x + a[7] * y + a[11] * z + a[15]; - } else { - a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; - a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; - a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; - - out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03; - out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13; - out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23; - - out[12] = a00 * x + a10 * y + a20 * z + a[12]; - out[13] = a01 * x + a11 * y + a21 * z + a[13]; - out[14] = a02 * x + a12 * y + a22 * z + a[14]; - out[15] = a03 * x + a13 * y + a23 * z + a[15]; - } - - return out; -}; - -/** - * Scales the mat4 by the dimensions in the given vec3 - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to scale - * @param {vec3} v the vec3 to scale the matrix by - * @returns {mat4} out - **/ -mat4.scale = function(out, a, v) { - var x = v[0], y = v[1], z = v[2]; - - out[0] = a[0] * x; - out[1] = a[1] * x; - out[2] = a[2] * x; - out[3] = a[3] * x; - out[4] = a[4] * y; - out[5] = a[5] * y; - out[6] = a[6] * y; - out[7] = a[7] * y; - out[8] = a[8] * z; - out[9] = a[9] * z; - out[10] = a[10] * z; - out[11] = a[11] * z; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - return out; -}; - -/** - * Rotates a mat4 by the given angle - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @param {vec3} axis the axis to rotate around - * @returns {mat4} out - */ -mat4.rotate = function (out, a, rad, axis) { - var x = axis[0], y = axis[1], z = axis[2], - len = Math.sqrt(x * x + y * y + z * z), - s, c, t, - a00, a01, a02, a03, - a10, a11, a12, a13, - a20, a21, a22, a23, - b00, b01, b02, - b10, b11, b12, - b20, b21, b22; - - if (Math.abs(len) < GLMAT_EPSILON) { return null; } - - len = 1 / len; - x *= len; - y *= len; - z *= len; - - s = Math.sin(rad); - c = Math.cos(rad); - t = 1 - c; - - a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; - a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; - a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; - - // Construct the elements of the rotation matrix - b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s; - b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s; - b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c; - - // Perform rotation-specific matrix multiplication - out[0] = a00 * b00 + a10 * b01 + a20 * b02; - out[1] = a01 * b00 + a11 * b01 + a21 * b02; - out[2] = a02 * b00 + a12 * b01 + a22 * b02; - out[3] = a03 * b00 + a13 * b01 + a23 * b02; - out[4] = a00 * b10 + a10 * b11 + a20 * b12; - out[5] = a01 * b10 + a11 * b11 + a21 * b12; - out[6] = a02 * b10 + a12 * b11 + a22 * b12; - out[7] = a03 * b10 + a13 * b11 + a23 * b12; - out[8] = a00 * b20 + a10 * b21 + a20 * b22; - out[9] = a01 * b20 + a11 * b21 + a21 * b22; - out[10] = a02 * b20 + a12 * b21 + a22 * b22; - out[11] = a03 * b20 + a13 * b21 + a23 * b22; - - if (a !== out) { // If the source and destination differ, copy the unchanged last row - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - } - return out; -}; - -/** - * Rotates a matrix by the given angle around the X axis - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat4} out - */ -mat4.rotateX = function (out, a, rad) { - var s = Math.sin(rad), - c = Math.cos(rad), - a10 = a[4], - a11 = a[5], - a12 = a[6], - a13 = a[7], - a20 = a[8], - a21 = a[9], - a22 = a[10], - a23 = a[11]; - - if (a !== out) { // If the source and destination differ, copy the unchanged rows - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - } - - // Perform axis-specific matrix multiplication - out[4] = a10 * c + a20 * s; - out[5] = a11 * c + a21 * s; - out[6] = a12 * c + a22 * s; - out[7] = a13 * c + a23 * s; - out[8] = a20 * c - a10 * s; - out[9] = a21 * c - a11 * s; - out[10] = a22 * c - a12 * s; - out[11] = a23 * c - a13 * s; - return out; -}; - -/** - * Rotates a matrix by the given angle around the Y axis - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat4} out - */ -mat4.rotateY = function (out, a, rad) { - var s = Math.sin(rad), - c = Math.cos(rad), - a00 = a[0], - a01 = a[1], - a02 = a[2], - a03 = a[3], - a20 = a[8], - a21 = a[9], - a22 = a[10], - a23 = a[11]; - - if (a !== out) { // If the source and destination differ, copy the unchanged rows - out[4] = a[4]; - out[5] = a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - } - - // Perform axis-specific matrix multiplication - out[0] = a00 * c - a20 * s; - out[1] = a01 * c - a21 * s; - out[2] = a02 * c - a22 * s; - out[3] = a03 * c - a23 * s; - out[8] = a00 * s + a20 * c; - out[9] = a01 * s + a21 * c; - out[10] = a02 * s + a22 * c; - out[11] = a03 * s + a23 * c; - return out; -}; - -/** - * Rotates a matrix by the given angle around the Z axis - * - * @param {mat4} out the receiving matrix - * @param {mat4} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat4} out - */ -mat4.rotateZ = function (out, a, rad) { - var s = Math.sin(rad), - c = Math.cos(rad), - a00 = a[0], - a01 = a[1], - a02 = a[2], - a03 = a[3], - a10 = a[4], - a11 = a[5], - a12 = a[6], - a13 = a[7]; - - if (a !== out) { // If the source and destination differ, copy the unchanged last row - out[8] = a[8]; - out[9] = a[9]; - out[10] = a[10]; - out[11] = a[11]; - out[12] = a[12]; - out[13] = a[13]; - out[14] = a[14]; - out[15] = a[15]; - } - - // Perform axis-specific matrix multiplication - out[0] = a00 * c + a10 * s; - out[1] = a01 * c + a11 * s; - out[2] = a02 * c + a12 * s; - out[3] = a03 * c + a13 * s; - out[4] = a10 * c - a00 * s; - out[5] = a11 * c - a01 * s; - out[6] = a12 * c - a02 * s; - out[7] = a13 * c - a03 * s; - return out; -}; - -/** - * Creates a matrix from a quaternion rotation and vector translation - * This is equivalent to (but much faster than): - * - * mat4.identity(dest); - * mat4.translate(dest, vec); - * var quatMat = mat4.create(); - * quat4.toMat4(quat, quatMat); - * mat4.multiply(dest, quatMat); - * - * @param {mat4} out mat4 receiving operation result - * @param {quat4} q Rotation quaternion - * @param {vec3} v Translation vector - * @returns {mat4} out - */ -mat4.fromRotationTranslation = function (out, q, v) { - // Quaternion math - var x = q[0], y = q[1], z = q[2], w = q[3], - x2 = x + x, - y2 = y + y, - z2 = z + z, - - xx = x * x2, - xy = x * y2, - xz = x * z2, - yy = y * y2, - yz = y * z2, - zz = z * z2, - wx = w * x2, - wy = w * y2, - wz = w * z2; - - out[0] = 1 - (yy + zz); - out[1] = xy + wz; - out[2] = xz - wy; - out[3] = 0; - out[4] = xy - wz; - out[5] = 1 - (xx + zz); - out[6] = yz + wx; - out[7] = 0; - out[8] = xz + wy; - out[9] = yz - wx; - out[10] = 1 - (xx + yy); - out[11] = 0; - out[12] = v[0]; - out[13] = v[1]; - out[14] = v[2]; - out[15] = 1; - - return out; -}; - -mat4.fromQuat = function (out, q) { - var x = q[0], y = q[1], z = q[2], w = q[3], - x2 = x + x, - y2 = y + y, - z2 = z + z, - - xx = x * x2, - yx = y * x2, - yy = y * y2, - zx = z * x2, - zy = z * y2, - zz = z * z2, - wx = w * x2, - wy = w * y2, - wz = w * z2; - - out[0] = 1 - yy - zz; - out[1] = yx + wz; - out[2] = zx - wy; - out[3] = 0; - - out[4] = yx - wz; - out[5] = 1 - xx - zz; - out[6] = zy + wx; - out[7] = 0; - - out[8] = zx + wy; - out[9] = zy - wx; - out[10] = 1 - xx - yy; - out[11] = 0; - - out[12] = 0; - out[13] = 0; - out[14] = 0; - out[15] = 1; - - return out; -}; - -/** - * Generates a frustum matrix with the given bounds - * - * @param {mat4} out mat4 frustum matrix will be written into - * @param {Number} left Left bound of the frustum - * @param {Number} right Right bound of the frustum - * @param {Number} bottom Bottom bound of the frustum - * @param {Number} top Top bound of the frustum - * @param {Number} near Near bound of the frustum - * @param {Number} far Far bound of the frustum - * @returns {mat4} out - */ -mat4.frustum = function (out, left, right, bottom, top, near, far) { - var rl = 1 / (right - left), - tb = 1 / (top - bottom), - nf = 1 / (near - far); - out[0] = (near * 2) * rl; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = (near * 2) * tb; - out[6] = 0; - out[7] = 0; - out[8] = (right + left) * rl; - out[9] = (top + bottom) * tb; - out[10] = (far + near) * nf; - out[11] = -1; - out[12] = 0; - out[13] = 0; - out[14] = (far * near * 2) * nf; - out[15] = 0; - return out; -}; - -/** - * Generates a perspective projection matrix with the given bounds - * - * @param {mat4} out mat4 frustum matrix will be written into - * @param {number} fovy Vertical field of view in radians - * @param {number} aspect Aspect ratio. typically viewport width/height - * @param {number} near Near bound of the frustum - * @param {number} far Far bound of the frustum - * @returns {mat4} out - */ -mat4.perspective = function (out, fovy, aspect, near, far) { - var f = 1.0 / Math.tan(fovy / 2), - nf = 1 / (near - far); - out[0] = f / aspect; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = f; - out[6] = 0; - out[7] = 0; - out[8] = 0; - out[9] = 0; - out[10] = (far + near) * nf; - out[11] = -1; - out[12] = 0; - out[13] = 0; - out[14] = (2 * far * near) * nf; - out[15] = 0; - return out; -}; - -/** - * Generates a orthogonal projection matrix with the given bounds - * - * @param {mat4} out mat4 frustum matrix will be written into - * @param {number} left Left bound of the frustum - * @param {number} right Right bound of the frustum - * @param {number} bottom Bottom bound of the frustum - * @param {number} top Top bound of the frustum - * @param {number} near Near bound of the frustum - * @param {number} far Far bound of the frustum - * @returns {mat4} out - */ -mat4.ortho = function (out, left, right, bottom, top, near, far) { - var lr = 1 / (left - right), - bt = 1 / (bottom - top), - nf = 1 / (near - far); - out[0] = -2 * lr; - out[1] = 0; - out[2] = 0; - out[3] = 0; - out[4] = 0; - out[5] = -2 * bt; - out[6] = 0; - out[7] = 0; - out[8] = 0; - out[9] = 0; - out[10] = 2 * nf; - out[11] = 0; - out[12] = (left + right) * lr; - out[13] = (top + bottom) * bt; - out[14] = (far + near) * nf; - out[15] = 1; - return out; -}; - -/** - * Generates a look-at matrix with the given eye position, focal point, and up axis - * - * @param {mat4} out mat4 frustum matrix will be written into - * @param {vec3} eye Position of the viewer - * @param {vec3} center Point the viewer is looking at - * @param {vec3} up vec3 pointing up - * @returns {mat4} out - */ -mat4.lookAt = function (out, eye, center, up) { - var x0, x1, x2, y0, y1, y2, z0, z1, z2, len, - eyex = eye[0], - eyey = eye[1], - eyez = eye[2], - upx = up[0], - upy = up[1], - upz = up[2], - centerx = center[0], - centery = center[1], - centerz = center[2]; - - if (Math.abs(eyex - centerx) < GLMAT_EPSILON && - Math.abs(eyey - centery) < GLMAT_EPSILON && - Math.abs(eyez - centerz) < GLMAT_EPSILON) { - return mat4.identity(out); - } - - z0 = eyex - centerx; - z1 = eyey - centery; - z2 = eyez - centerz; - - len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); - z0 *= len; - z1 *= len; - z2 *= len; - - x0 = upy * z2 - upz * z1; - x1 = upz * z0 - upx * z2; - x2 = upx * z1 - upy * z0; - len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2); - if (!len) { - x0 = 0; - x1 = 0; - x2 = 0; - } else { - len = 1 / len; - x0 *= len; - x1 *= len; - x2 *= len; - } - - y0 = z1 * x2 - z2 * x1; - y1 = z2 * x0 - z0 * x2; - y2 = z0 * x1 - z1 * x0; - - len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2); - if (!len) { - y0 = 0; - y1 = 0; - y2 = 0; - } else { - len = 1 / len; - y0 *= len; - y1 *= len; - y2 *= len; - } - - out[0] = x0; - out[1] = y0; - out[2] = z0; - out[3] = 0; - out[4] = x1; - out[5] = y1; - out[6] = z1; - out[7] = 0; - out[8] = x2; - out[9] = y2; - out[10] = z2; - out[11] = 0; - out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez); - out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez); - out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez); - out[15] = 1; - - return out; -}; - -/** - * Returns a string representation of a mat4 - * - * @param {mat4} mat matrix to represent as a string - * @returns {String} string representation of the matrix - */ -mat4.str = function (a) { - return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + - a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' + - a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' + - a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')'; -}; - -/** - * Returns Frobenius norm of a mat4 - * - * @param {mat4} a the matrix to calculate Frobenius norm of - * @returns {Number} Frobenius norm - */ -mat4.frob = function (a) { - return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2) )) -}; - - -if(typeof(exports) !== 'undefined') { - exports.mat4 = mat4; -} -; -/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @class Quaternion - * @name quat - */ - -var quat = {}; - -/** - * Creates a new identity quat - * - * @returns {quat} a new quaternion - */ -quat.create = function() { - var out = new GLMAT_ARRAY_TYPE(4); - out[0] = 0; - out[1] = 0; - out[2] = 0; - out[3] = 1; - return out; -}; - -/** - * Sets a quaternion to represent the shortest rotation from one - * vector to another. - * - * Both vectors are assumed to be unit length. - * - * @param {quat} out the receiving quaternion. - * @param {vec3} a the initial vector - * @param {vec3} b the destination vector - * @returns {quat} out - */ -quat.rotationTo = (function() { - var tmpvec3 = vec3.create(); - var xUnitVec3 = vec3.fromValues(1,0,0); - var yUnitVec3 = vec3.fromValues(0,1,0); - - return function(out, a, b) { - var dot = vec3.dot(a, b); - if (dot < -0.999999) { - vec3.cross(tmpvec3, xUnitVec3, a); - if (vec3.length(tmpvec3) < 0.000001) - vec3.cross(tmpvec3, yUnitVec3, a); - vec3.normalize(tmpvec3, tmpvec3); - quat.setAxisAngle(out, tmpvec3, Math.PI); - return out; - } else if (dot > 0.999999) { - out[0] = 0; - out[1] = 0; - out[2] = 0; - out[3] = 1; - return out; - } else { - vec3.cross(tmpvec3, a, b); - out[0] = tmpvec3[0]; - out[1] = tmpvec3[1]; - out[2] = tmpvec3[2]; - out[3] = 1 + dot; - return quat.normalize(out, out); - } - }; -})(); - -/** - * Sets the specified quaternion with values corresponding to the given - * axes. Each axis is a vec3 and is expected to be unit length and - * perpendicular to all other specified axes. - * - * @param {vec3} view the vector representing the viewing direction - * @param {vec3} right the vector representing the local "right" direction - * @param {vec3} up the vector representing the local "up" direction - * @returns {quat} out - */ -quat.setAxes = (function() { - var matr = mat3.create(); - - return function(out, view, right, up) { - matr[0] = right[0]; - matr[3] = right[1]; - matr[6] = right[2]; - - matr[1] = up[0]; - matr[4] = up[1]; - matr[7] = up[2]; - - matr[2] = -view[0]; - matr[5] = -view[1]; - matr[8] = -view[2]; - - return quat.normalize(out, quat.fromMat3(out, matr)); - }; -})(); - -/** - * Creates a new quat initialized with values from an existing quaternion - * - * @param {quat} a quaternion to clone - * @returns {quat} a new quaternion - * @function - */ -quat.clone = vec4.clone; - -/** - * Creates a new quat initialized with the given values - * - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @param {Number} w W component - * @returns {quat} a new quaternion - * @function - */ -quat.fromValues = vec4.fromValues; - -/** - * Copy the values from one quat to another - * - * @param {quat} out the receiving quaternion - * @param {quat} a the source quaternion - * @returns {quat} out - * @function - */ -quat.copy = vec4.copy; - -/** - * Set the components of a quat to the given values - * - * @param {quat} out the receiving quaternion - * @param {Number} x X component - * @param {Number} y Y component - * @param {Number} z Z component - * @param {Number} w W component - * @returns {quat} out - * @function - */ -quat.set = vec4.set; - -/** - * Set a quat to the identity quaternion - * - * @param {quat} out the receiving quaternion - * @returns {quat} out - */ -quat.identity = function(out) { - out[0] = 0; - out[1] = 0; - out[2] = 0; - out[3] = 1; - return out; -}; - -/** - * Sets a quat from the given angle and rotation axis, - * then returns it. - * - * @param {quat} out the receiving quaternion - * @param {vec3} axis the axis around which to rotate - * @param {Number} rad the angle in radians - * @returns {quat} out - **/ -quat.setAxisAngle = function(out, axis, rad) { - rad = rad * 0.5; - var s = Math.sin(rad); - out[0] = s * axis[0]; - out[1] = s * axis[1]; - out[2] = s * axis[2]; - out[3] = Math.cos(rad); - return out; -}; - -/** - * Adds two quat's - * - * @param {quat} out the receiving quaternion - * @param {quat} a the first operand - * @param {quat} b the second operand - * @returns {quat} out - * @function - */ -quat.add = vec4.add; - -/** - * Multiplies two quat's - * - * @param {quat} out the receiving quaternion - * @param {quat} a the first operand - * @param {quat} b the second operand - * @returns {quat} out - */ -quat.multiply = function(out, a, b) { - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - bx = b[0], by = b[1], bz = b[2], bw = b[3]; - - out[0] = ax * bw + aw * bx + ay * bz - az * by; - out[1] = ay * bw + aw * by + az * bx - ax * bz; - out[2] = az * bw + aw * bz + ax * by - ay * bx; - out[3] = aw * bw - ax * bx - ay * by - az * bz; - return out; -}; - -/** - * Alias for {@link quat.multiply} - * @function - */ -quat.mul = quat.multiply; - -/** - * Scales a quat by a scalar number - * - * @param {quat} out the receiving vector - * @param {quat} a the vector to scale - * @param {Number} b amount to scale the vector by - * @returns {quat} out - * @function - */ -quat.scale = vec4.scale; - -/** - * Rotates a quaternion by the given angle about the X axis - * - * @param {quat} out quat receiving operation result - * @param {quat} a quat to rotate - * @param {number} rad angle (in radians) to rotate - * @returns {quat} out - */ -quat.rotateX = function (out, a, rad) { - rad *= 0.5; - - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - bx = Math.sin(rad), bw = Math.cos(rad); - - out[0] = ax * bw + aw * bx; - out[1] = ay * bw + az * bx; - out[2] = az * bw - ay * bx; - out[3] = aw * bw - ax * bx; - return out; -}; - -/** - * Rotates a quaternion by the given angle about the Y axis - * - * @param {quat} out quat receiving operation result - * @param {quat} a quat to rotate - * @param {number} rad angle (in radians) to rotate - * @returns {quat} out - */ -quat.rotateY = function (out, a, rad) { - rad *= 0.5; - - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - by = Math.sin(rad), bw = Math.cos(rad); - - out[0] = ax * bw - az * by; - out[1] = ay * bw + aw * by; - out[2] = az * bw + ax * by; - out[3] = aw * bw - ay * by; - return out; -}; - -/** - * Rotates a quaternion by the given angle about the Z axis - * - * @param {quat} out quat receiving operation result - * @param {quat} a quat to rotate - * @param {number} rad angle (in radians) to rotate - * @returns {quat} out - */ -quat.rotateZ = function (out, a, rad) { - rad *= 0.5; - - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - bz = Math.sin(rad), bw = Math.cos(rad); - - out[0] = ax * bw + ay * bz; - out[1] = ay * bw - ax * bz; - out[2] = az * bw + aw * bz; - out[3] = aw * bw - az * bz; - return out; -}; - -/** - * Calculates the W component of a quat from the X, Y, and Z components. - * Assumes that quaternion is 1 unit in length. - * Any existing W component will be ignored. - * - * @param {quat} out the receiving quaternion - * @param {quat} a quat to calculate W component of - * @returns {quat} out - */ -quat.calculateW = function (out, a) { - var x = a[0], y = a[1], z = a[2]; - - out[0] = x; - out[1] = y; - out[2] = z; - out[3] = -Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z)); - return out; -}; - -/** - * Calculates the dot product of two quat's - * - * @param {quat} a the first operand - * @param {quat} b the second operand - * @returns {Number} dot product of a and b - * @function - */ -quat.dot = vec4.dot; - -/** - * Performs a linear interpolation between two quat's - * - * @param {quat} out the receiving quaternion - * @param {quat} a the first operand - * @param {quat} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {quat} out - * @function - */ -quat.lerp = vec4.lerp; - -/** - * Performs a spherical linear interpolation between two quat - * - * @param {quat} out the receiving quaternion - * @param {quat} a the first operand - * @param {quat} b the second operand - * @param {Number} t interpolation amount between the two inputs - * @returns {quat} out - */ -quat.slerp = function (out, a, b, t) { - // benchmarks: - // http://jsperf.com/quaternion-slerp-implementations - - var ax = a[0], ay = a[1], az = a[2], aw = a[3], - bx = b[0], by = b[1], bz = b[2], bw = b[3]; - - var omega, cosom, sinom, scale0, scale1; - - // calc cosine - cosom = ax * bx + ay * by + az * bz + aw * bw; - // adjust signs (if necessary) - if ( cosom < 0.0 ) { - cosom = -cosom; - bx = - bx; - by = - by; - bz = - bz; - bw = - bw; - } - // calculate coefficients - if ( (1.0 - cosom) > 0.000001 ) { - // standard case (slerp) - omega = Math.acos(cosom); - sinom = Math.sin(omega); - scale0 = Math.sin((1.0 - t) * omega) / sinom; - scale1 = Math.sin(t * omega) / sinom; - } else { - // "from" and "to" quaternions are very close - // ... so we can do a linear interpolation - scale0 = 1.0 - t; - scale1 = t; - } - // calculate final values - out[0] = scale0 * ax + scale1 * bx; - out[1] = scale0 * ay + scale1 * by; - out[2] = scale0 * az + scale1 * bz; - out[3] = scale0 * aw + scale1 * bw; - - return out; -}; - -/** - * Calculates the inverse of a quat - * - * @param {quat} out the receiving quaternion - * @param {quat} a quat to calculate inverse of - * @returns {quat} out - */ -quat.invert = function(out, a) { - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], - dot = a0*a0 + a1*a1 + a2*a2 + a3*a3, - invDot = dot ? 1.0/dot : 0; - - // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0 - - out[0] = -a0*invDot; - out[1] = -a1*invDot; - out[2] = -a2*invDot; - out[3] = a3*invDot; - return out; -}; - -/** - * Calculates the conjugate of a quat - * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result. - * - * @param {quat} out the receiving quaternion - * @param {quat} a quat to calculate conjugate of - * @returns {quat} out - */ -quat.conjugate = function (out, a) { - out[0] = -a[0]; - out[1] = -a[1]; - out[2] = -a[2]; - out[3] = a[3]; - return out; -}; - -/** - * Calculates the length of a quat - * - * @param {quat} a vector to calculate length of - * @returns {Number} length of a - * @function - */ -quat.length = vec4.length; - -/** - * Alias for {@link quat.length} - * @function - */ -quat.len = quat.length; - -/** - * Calculates the squared length of a quat - * - * @param {quat} a vector to calculate squared length of - * @returns {Number} squared length of a - * @function - */ -quat.squaredLength = vec4.squaredLength; - -/** - * Alias for {@link quat.squaredLength} - * @function - */ -quat.sqrLen = quat.squaredLength; - -/** - * Normalize a quat - * - * @param {quat} out the receiving quaternion - * @param {quat} a quaternion to normalize - * @returns {quat} out - * @function - */ -quat.normalize = vec4.normalize; - -/** - * Creates a quaternion from the given 3x3 rotation matrix. - * - * NOTE: The resultant quaternion is not normalized, so you should be sure - * to renormalize the quaternion yourself where necessary. - * - * @param {quat} out the receiving quaternion - * @param {mat3} m rotation matrix - * @returns {quat} out - * @function - */ -quat.fromMat3 = function(out, m) { - // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes - // article "Quaternion Calculus and Fast Animation". - var fTrace = m[0] + m[4] + m[8]; - var fRoot; - - if ( fTrace > 0.0 ) { - // |w| > 1/2, may as well choose w > 1/2 - fRoot = Math.sqrt(fTrace + 1.0); // 2w - out[3] = 0.5 * fRoot; - fRoot = 0.5/fRoot; // 1/(4w) - out[0] = (m[7]-m[5])*fRoot; - out[1] = (m[2]-m[6])*fRoot; - out[2] = (m[3]-m[1])*fRoot; - } else { - // |w| <= 1/2 - var i = 0; - if ( m[4] > m[0] ) - i = 1; - if ( m[8] > m[i*3+i] ) - i = 2; - var j = (i+1)%3; - var k = (i+2)%3; - - fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0); - out[i] = 0.5 * fRoot; - fRoot = 0.5 / fRoot; - out[3] = (m[k*3+j] - m[j*3+k]) * fRoot; - out[j] = (m[j*3+i] + m[i*3+j]) * fRoot; - out[k] = (m[k*3+i] + m[i*3+k]) * fRoot; - } - - return out; -}; - -/** - * Returns a string representation of a quatenion - * - * @param {quat} vec vector to represent as a string - * @returns {String} string representation of the vector - */ -quat.str = function (a) { - return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; -}; - -if(typeof(exports) !== 'undefined') { - exports.quat = quat; -} -; - - - - - - - - - - - - - - })(shim.exports); -})(this); - -},{}],179:[function(require,module,exports){ -"use strict" - -var glm = require("gl-matrix") -var vec3 = glm.vec3 -var mat3 = glm.mat3 -var mat4 = glm.mat4 -var quat = glm.quat - -//Scratch variables -var scratch0 = new Float32Array(16) -var scratch1 = new Float32Array(16) - -function OrbitCamera(rotation, center, distance) { - this.rotation = rotation - this.center = center - this.distance = distance -} - -var proto = OrbitCamera.prototype - -proto.view = function(out) { - if(!out) { - out = mat4.create() - } - scratch1[0] = scratch1[1] = 0.0 - scratch1[2] = -this.distance - mat4.fromRotationTranslation(out, - quat.conjugate(scratch0, this.rotation), - scratch1) - mat4.translate(out, out, vec3.negate(scratch0, this.center)) - return out -} - -proto.lookAt = function(eye, center, up) { - mat4.lookAt(scratch0, eye, center, up) - mat3.fromMat4(scratch0, scratch0) - quat.fromMat3(this.rotation, scratch0) - vec3.copy(this.center, center) - this.distance = vec3.distance(eye, center) -} - -proto.pan = function(dpan) { - var d = this.distance - scratch0[0] = -d*(dpan[0]||0) - scratch0[1] = d*(dpan[1]||0) - scratch0[2] = d*(dpan[2]||0) - vec3.transformQuat(scratch0, scratch0, this.rotation) - vec3.add(this.center, this.center, scratch0) -} - -proto.zoom = function(d) { - this.distance += d - if(this.distance < 0.0) { - this.distance = 0.0 - } -} - -function quatFromVec(out, da) { - var x = da[0] - var y = da[1] - var z = da[2] - var s = x*x + y*y - if(s > 1.0) { - s = 1.0 - } - out[0] = -da[0] - out[1] = da[1] - out[2] = da[2] || Math.sqrt(1.0 - s) - out[3] = 0.0 -} - -proto.rotate = function(da, db) { - quatFromVec(scratch0, da) - quatFromVec(scratch1, db) - quat.invert(scratch1, scratch1) - quat.multiply(scratch0, scratch0, scratch1) - if(quat.length(scratch0) < 1e-6) { - return - } - quat.multiply(this.rotation, this.rotation, scratch0) - quat.normalize(this.rotation, this.rotation) -} - -function createOrbitCamera(eye, target, up) { - eye = eye || [0,0,-1] - target = target || [0,0,0] - up = up || [0,1,0] - var camera = new OrbitCamera(quat.create(), vec3.create(), 1.0) - camera.lookAt(eye, target, up) - return camera -} - -module.exports = createOrbitCamera - -},{"gl-matrix":178}],180:[function(require,module,exports){ -(function (global){ -module.exports = - global.performance && - global.performance.now ? function now() { - return performance.now() - } : Date.now || function now() { - return +new Date - } - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],181:[function(require,module,exports){ -module.exports = unindex - -function unindex(positions, cells, out) { - if (positions.positions && positions.cells) { - out = cells - cells = positions.cells - positions = positions.positions - } - - out = out || new Float32Array(cells.length * 9) - - for (var i = 0, n = 0, l = cells.length; i < l; i += 1) { - out[n++] = positions[cells[i][0]][0] - out[n++] = positions[cells[i][0]][1] - out[n++] = positions[cells[i][0]][2] - out[n++] = positions[cells[i][1]][0] - out[n++] = positions[cells[i][1]][1] - out[n++] = positions[cells[i][1]][2] - out[n++] = positions[cells[i][2]][0] - out[n++] = positions[cells[i][2]][1] - out[n++] = positions[cells[i][2]][2] - } - return out -} - -},{}],182:[function(require,module,exports){ - -/** - * Expose `parse`. - */ - -module.exports = parse; - -/** - * Wrap map from jquery. - */ - -var map = { - legend: [1, '
      ', '
      '], - tr: [2, '', '
      '], - col: [2, '', '
      '], - _default: [0, '', ''] -}; - -map.td = -map.th = [3, '', '
      ']; - -map.option = -map.optgroup = [1, '']; - -map.thead = -map.tbody = -map.colgroup = -map.caption = -map.tfoot = [1, '', '
      ']; - -map.text = -map.circle = -map.ellipse = -map.line = -map.path = -map.polygon = -map.polyline = -map.rect = [1, '','']; - -/** - * Parse `html` and return a DOM Node instance, which could be a TextNode, - * HTML DOM Node of some kind (
      for example), or a DocumentFragment - * instance, depending on the contents of the `html` string. - * - * @param {String} html - HTML string to "domify" - * @param {Document} doc - The `document` instance to create the Node for - * @return {DOMNode} the TextNode, DOM Node, or DocumentFragment instance - * @api private - */ - -function parse(html, doc) { - if ('string' != typeof html) throw new TypeError('String expected'); - - // default to the global `document` object - if (!doc) doc = document; - - // tag name - var m = /<([\w:]+)/.exec(html); - if (!m) return doc.createTextNode(html); - - html = html.replace(/^\s+|\s+$/g, ''); // Remove leading/trailing whitespace - - var tag = m[1]; - - // body support - if (tag == 'body') { - var el = doc.createElement('html'); - el.innerHTML = html; - return el.removeChild(el.lastChild); - } - - // wrap map - var wrap = map[tag] || map._default; - var depth = wrap[0]; - var prefix = wrap[1]; - var suffix = wrap[2]; - var el = doc.createElement('div'); - el.innerHTML = prefix + html + suffix; - while (depth--) el = el.lastChild; - - // one element - if (el.firstChild == el.lastChild) { - return el.removeChild(el.firstChild); - } - - // several elements - var fragment = doc.createDocumentFragment(); - while (el.firstChild) { - fragment.appendChild(el.removeChild(el.firstChild)); - } - - return fragment; -} - -},{}],183:[function(require,module,exports){ -module.exports = findup - -function findup(child, check) { - if (typeof check === 'string') check = byName(check) - if (typeof check !== 'function') check = byExact(check) - - while ( - child && - !check(child) - ) child = child.parentNode - - - return child || null -} - -function byName(name) { - name = String(name).toUpperCase() - - return function(element) { - return name === element.nodeName - } -} - -function byExact(el) { - return function(element) { - return el === element - } -} - -},{}],184:[function(require,module,exports){ -arguments[4][27][0].apply(exports,arguments) -},{"_process":192,"raf-component":185,"sliced":187}],185:[function(require,module,exports){ -module.exports=require(28) -},{}],186:[function(require,module,exports){ - -/** - * Expose `render()`.` - */ - -exports = module.exports = render; - -/** - * Expose `compile()`. - */ - -exports.compile = compile; - -/** - * Render the given mustache `str` with `obj`. - * - * @param {String} str - * @param {Object} obj - * @return {String} - * @api public - */ - -function render(str, obj) { - obj = obj || {}; - var fn = compile(str); - return fn(obj); -} - -/** - * Compile the given `str` to a `Function`. - * - * @param {String} str - * @return {Function} - * @api public - */ - -function compile(str) { - var js = []; - var toks = parse(str); - var tok; - - for (var i = 0; i < toks.length; ++i) { - tok = toks[i]; - if (i % 2 == 0) { - js.push('"' + tok.replace(/"/g, '\\"') + '"'); - } else { - switch (tok[0]) { - case '/': - tok = tok.slice(1); - js.push(' }) + '); - break; - case '^': - tok = tok.slice(1); - assertProperty(tok); - js.push(' + section(obj, "' + tok + '", true, function(obj){ return '); - break; - case '#': - tok = tok.slice(1); - assertProperty(tok); - js.push(' + section(obj, "' + tok + '", false, function(obj){ return '); - break; - case '!': - tok = tok.slice(1); - assertProperty(tok); - js.push(' + obj.' + tok + ' + '); - break; - default: - assertProperty(tok); - js.push(' + escape(obj.' + tok + ') + '); - } - } - } - - js = '\n' - + indent(escape.toString()) + ';\n\n' - + indent(section.toString()) + ';\n\n' - + ' return ' + js.join('').replace(/\n/g, '\\n'); - - return new Function('obj', js); -} - -/** - * Assert that `prop` is a valid property. - * - * @param {String} prop - * @api private - */ - -function assertProperty(prop) { - if (!prop.match(/^[\w.]+$/)) throw new Error('invalid property "' + prop + '"'); -} - -/** - * Parse `str`. - * - * @param {String} str - * @return {Array} - * @api private - */ - -function parse(str) { - return str.split(/\{\{|\}\}/); -} - -/** - * Indent `str`. - * - * @param {String} str - * @return {String} - * @api private - */ - -function indent(str) { - return str.replace(/^/gm, ' '); -} - -/** - * Section handler. - * - * @param {Object} context obj - * @param {String} prop - * @param {Function} thunk - * @param {Boolean} negate - * @api private - */ - -function section(obj, prop, negate, thunk) { - var val = obj[prop]; - if (Array.isArray(val)) return val.map(thunk).join(''); - if ('function' == typeof val) return val.call(obj, thunk(obj)); - if (negate) val = !val; - if (val) return thunk(obj); - return ''; -} - -/** - * Escape the given `html`. - * - * @param {String} html - * @return {String} - * @api private - */ - -function escape(html) { - return String(html) - .replace(/&/g, '&') - .replace(/"/g, '"') - .replace(//g, '>'); -} - -},{}],187:[function(require,module,exports){ -arguments[4][29][0].apply(exports,arguments) -},{"./lib/sliced":188}],188:[function(require,module,exports){ -module.exports=require(30) -},{}],189:[function(require,module,exports){ -/*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ - -var base64 = require('base64-js') -var ieee754 = require('ieee754') - -exports.Buffer = Buffer -exports.SlowBuffer = Buffer -exports.INSPECT_MAX_BYTES = 50 -Buffer.poolSize = 8192 - -/** - * If `TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * Note: - * - * - Implementation must support adding new properties to `Uint8Array` instances. - * Firefox 4-29 lacked support, fixed in Firefox 30+. - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. - * - * We detect these buggy browsers and set `TYPED_ARRAY_SUPPORT` to `false` so they will - * get the Object implementation, which is slower but will work correctly. - */ -var TYPED_ARRAY_SUPPORT = (function () { - try { - var buf = new ArrayBuffer(0) - var arr = new Uint8Array(buf) - arr.foo = function () { return 42 } - return 42 === arr.foo() && // typed array instances can be augmented - typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` - } catch (e) { - return false - } -})() - -/** - * Class: Buffer - * ============= - * - * The Buffer constructor returns instances of `Uint8Array` that are augmented - * with function properties for all the node `Buffer` API functions. We use - * `Uint8Array` so that square bracket notation works as expected -- it returns - * a single octet. - * - * By augmenting the instances, we can avoid modifying the `Uint8Array` - * prototype. - */ -function Buffer (subject, encoding, noZero) { - if (!(this instanceof Buffer)) - return new Buffer(subject, encoding, noZero) - - var type = typeof subject - - // Find the length - var length - if (type === 'number') - length = subject > 0 ? subject >>> 0 : 0 - else if (type === 'string') { - if (encoding === 'base64') - subject = base64clean(subject) - length = Buffer.byteLength(subject, encoding) - } else if (type === 'object' && subject !== null) { // assume object is array-like - if (subject.type === 'Buffer' && isArray(subject.data)) - subject = subject.data - length = +subject.length > 0 ? Math.floor(+subject.length) : 0 - } else - throw new Error('First argument needs to be a number, array or string.') - - var buf - if (TYPED_ARRAY_SUPPORT) { - // Preferred: Return an augmented `Uint8Array` instance for best performance - buf = Buffer._augment(new Uint8Array(length)) - } else { - // Fallback: Return THIS instance of Buffer (created by `new`) - buf = this - buf.length = length - buf._isBuffer = true - } - - var i - if (TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') { - // Speed optimization -- use set if we're copying from a typed array - buf._set(subject) - } else if (isArrayish(subject)) { - // Treat array-ish objects as a byte array - if (Buffer.isBuffer(subject)) { - for (i = 0; i < length; i++) - buf[i] = subject.readUInt8(i) - } else { - for (i = 0; i < length; i++) - buf[i] = ((subject[i] % 256) + 256) % 256 - } - } else if (type === 'string') { - buf.write(subject, 0, encoding) - } else if (type === 'number' && !TYPED_ARRAY_SUPPORT && !noZero) { - for (i = 0; i < length; i++) { - buf[i] = 0 - } - } - - return buf -} - -// STATIC METHODS -// ============== - -Buffer.isEncoding = function (encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'binary': - case 'base64': - case 'raw': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true - default: - return false - } -} - -Buffer.isBuffer = function (b) { - return !!(b != null && b._isBuffer) -} - -Buffer.byteLength = function (str, encoding) { - var ret - str = str.toString() - switch (encoding || 'utf8') { - case 'hex': - ret = str.length / 2 - break - case 'utf8': - case 'utf-8': - ret = utf8ToBytes(str).length - break - case 'ascii': - case 'binary': - case 'raw': - ret = str.length - break - case 'base64': - ret = base64ToBytes(str).length - break - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - ret = str.length * 2 - break - default: - throw new Error('Unknown encoding') - } - return ret -} - -Buffer.concat = function (list, totalLength) { - assert(isArray(list), 'Usage: Buffer.concat(list[, length])') - - if (list.length === 0) { - return new Buffer(0) - } else if (list.length === 1) { - return list[0] - } - - var i - if (totalLength === undefined) { - totalLength = 0 - for (i = 0; i < list.length; i++) { - totalLength += list[i].length - } - } - - var buf = new Buffer(totalLength) - var pos = 0 - for (i = 0; i < list.length; i++) { - var item = list[i] - item.copy(buf, pos) - pos += item.length - } - return buf -} - -Buffer.compare = function (a, b) { - assert(Buffer.isBuffer(a) && Buffer.isBuffer(b), 'Arguments must be Buffers') - var x = a.length - var y = b.length - for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {} - if (i !== len) { - x = a[i] - y = b[i] - } - if (x < y) { - return -1 - } - if (y < x) { - return 1 - } - return 0 -} - -// BUFFER INSTANCE METHODS -// ======================= - -function hexWrite (buf, string, offset, length) { - offset = Number(offset) || 0 - var remaining = buf.length - offset - if (!length) { - length = remaining - } else { - length = Number(length) - if (length > remaining) { - length = remaining - } - } - - // must be an even number of digits - var strLen = string.length - assert(strLen % 2 === 0, 'Invalid hex string') - - if (length > strLen / 2) { - length = strLen / 2 - } - for (var i = 0; i < length; i++) { - var byte = parseInt(string.substr(i * 2, 2), 16) - assert(!isNaN(byte), 'Invalid hex string') - buf[offset + i] = byte - } - return i -} - -function utf8Write (buf, string, offset, length) { - var charsWritten = blitBuffer(utf8ToBytes(string), buf, offset, length) - return charsWritten -} - -function asciiWrite (buf, string, offset, length) { - var charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length) - return charsWritten -} - -function binaryWrite (buf, string, offset, length) { - return asciiWrite(buf, string, offset, length) -} - -function base64Write (buf, string, offset, length) { - var charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length) - return charsWritten -} - -function utf16leWrite (buf, string, offset, length) { - var charsWritten = blitBuffer(utf16leToBytes(string), buf, offset, length) - return charsWritten -} - -Buffer.prototype.write = function (string, offset, length, encoding) { - // Support both (string, offset, length, encoding) - // and the legacy (string, encoding, offset, length) - if (isFinite(offset)) { - if (!isFinite(length)) { - encoding = length - length = undefined - } - } else { // legacy - var swap = encoding - encoding = offset - offset = length - length = swap - } - - offset = Number(offset) || 0 - var remaining = this.length - offset - if (!length) { - length = remaining - } else { - length = Number(length) - if (length > remaining) { - length = remaining - } - } - encoding = String(encoding || 'utf8').toLowerCase() - - var ret - switch (encoding) { - case 'hex': - ret = hexWrite(this, string, offset, length) - break - case 'utf8': - case 'utf-8': - ret = utf8Write(this, string, offset, length) - break - case 'ascii': - ret = asciiWrite(this, string, offset, length) - break - case 'binary': - ret = binaryWrite(this, string, offset, length) - break - case 'base64': - ret = base64Write(this, string, offset, length) - break - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - ret = utf16leWrite(this, string, offset, length) - break - default: - throw new Error('Unknown encoding') - } - return ret -} - -Buffer.prototype.toString = function (encoding, start, end) { - var self = this - - encoding = String(encoding || 'utf8').toLowerCase() - start = Number(start) || 0 - end = (end === undefined) ? self.length : Number(end) - - // Fastpath empty strings - if (end === start) - return '' - - var ret - switch (encoding) { - case 'hex': - ret = hexSlice(self, start, end) - break - case 'utf8': - case 'utf-8': - ret = utf8Slice(self, start, end) - break - case 'ascii': - ret = asciiSlice(self, start, end) - break - case 'binary': - ret = binarySlice(self, start, end) - break - case 'base64': - ret = base64Slice(self, start, end) - break - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - ret = utf16leSlice(self, start, end) - break - default: - throw new Error('Unknown encoding') - } - return ret -} - -Buffer.prototype.toJSON = function () { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) - } -} - -Buffer.prototype.equals = function (b) { - assert(Buffer.isBuffer(b), 'Argument must be a Buffer') - return Buffer.compare(this, b) === 0 -} - -Buffer.prototype.compare = function (b) { - assert(Buffer.isBuffer(b), 'Argument must be a Buffer') - return Buffer.compare(this, b) -} - -// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) -Buffer.prototype.copy = function (target, target_start, start, end) { - var source = this - - if (!start) start = 0 - if (!end && end !== 0) end = this.length - if (!target_start) target_start = 0 - - // Copy 0 bytes; we're done - if (end === start) return - if (target.length === 0 || source.length === 0) return - - // Fatal error conditions - assert(end >= start, 'sourceEnd < sourceStart') - assert(target_start >= 0 && target_start < target.length, - 'targetStart out of bounds') - assert(start >= 0 && start < source.length, 'sourceStart out of bounds') - assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds') - - // Are we oob? - if (end > this.length) - end = this.length - if (target.length - target_start < end - start) - end = target.length - target_start + start - - var len = end - start - - if (len < 100 || !TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < len; i++) { - target[i + target_start] = this[i + start] - } - } else { - target._set(this.subarray(start, start + len), target_start) - } -} - -function base64Slice (buf, start, end) { - if (start === 0 && end === buf.length) { - return base64.fromByteArray(buf) - } else { - return base64.fromByteArray(buf.slice(start, end)) - } -} - -function utf8Slice (buf, start, end) { - var res = '' - var tmp = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; i++) { - if (buf[i] <= 0x7F) { - res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i]) - tmp = '' - } else { - tmp += '%' + buf[i].toString(16) - } - } - - return res + decodeUtf8Char(tmp) -} - -function asciiSlice (buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; i++) { - ret += String.fromCharCode(buf[i]) - } - return ret -} - -function binarySlice (buf, start, end) { - return asciiSlice(buf, start, end) -} - -function hexSlice (buf, start, end) { - var len = buf.length - - if (!start || start < 0) start = 0 - if (!end || end < 0 || end > len) end = len - - var out = '' - for (var i = start; i < end; i++) { - out += toHex(buf[i]) - } - return out -} - -function utf16leSlice (buf, start, end) { - var bytes = buf.slice(start, end) - var res = '' - for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) - } - return res -} - -Buffer.prototype.slice = function (start, end) { - var len = this.length - start = ~~start - end = end === undefined ? len : ~~end - - if (start < 0) { - start += len; - if (start < 0) - start = 0 - } else if (start > len) { - start = len - } - - if (end < 0) { - end += len - if (end < 0) - end = 0 - } else if (end > len) { - end = len - } - - if (end < start) - end = start - - if (TYPED_ARRAY_SUPPORT) { - return Buffer._augment(this.subarray(start, end)) - } else { - var sliceLen = end - start - var newBuf = new Buffer(sliceLen, undefined, true) - for (var i = 0; i < sliceLen; i++) { - newBuf[i] = this[i + start] - } - return newBuf - } -} - -// `get` will be removed in Node 0.13+ -Buffer.prototype.get = function (offset) { - console.log('.get() is deprecated. Access using array indexes instead.') - return this.readUInt8(offset) -} - -// `set` will be removed in Node 0.13+ -Buffer.prototype.set = function (v, offset) { - console.log('.set() is deprecated. Access using array indexes instead.') - return this.writeUInt8(v, offset) -} - -Buffer.prototype.readUInt8 = function (offset, noAssert) { - if (!noAssert) { - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset < this.length, 'Trying to read beyond buffer length') - } - - if (offset >= this.length) - return - - return this[offset] -} - -function readUInt16 (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 1 < buf.length, 'Trying to read beyond buffer length') - } - - var len = buf.length - if (offset >= len) - return - - var val - if (littleEndian) { - val = buf[offset] - if (offset + 1 < len) - val |= buf[offset + 1] << 8 - } else { - val = buf[offset] << 8 - if (offset + 1 < len) - val |= buf[offset + 1] - } - return val -} - -Buffer.prototype.readUInt16LE = function (offset, noAssert) { - return readUInt16(this, offset, true, noAssert) -} - -Buffer.prototype.readUInt16BE = function (offset, noAssert) { - return readUInt16(this, offset, false, noAssert) -} - -function readUInt32 (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') - } - - var len = buf.length - if (offset >= len) - return - - var val - if (littleEndian) { - if (offset + 2 < len) - val = buf[offset + 2] << 16 - if (offset + 1 < len) - val |= buf[offset + 1] << 8 - val |= buf[offset] - if (offset + 3 < len) - val = val + (buf[offset + 3] << 24 >>> 0) - } else { - if (offset + 1 < len) - val = buf[offset + 1] << 16 - if (offset + 2 < len) - val |= buf[offset + 2] << 8 - if (offset + 3 < len) - val |= buf[offset + 3] - val = val + (buf[offset] << 24 >>> 0) - } - return val -} - -Buffer.prototype.readUInt32LE = function (offset, noAssert) { - return readUInt32(this, offset, true, noAssert) -} - -Buffer.prototype.readUInt32BE = function (offset, noAssert) { - return readUInt32(this, offset, false, noAssert) -} - -Buffer.prototype.readInt8 = function (offset, noAssert) { - if (!noAssert) { - assert(offset !== undefined && offset !== null, - 'missing offset') - assert(offset < this.length, 'Trying to read beyond buffer length') - } - - if (offset >= this.length) - return - - var neg = this[offset] & 0x80 - if (neg) - return (0xff - this[offset] + 1) * -1 - else - return this[offset] -} - -function readInt16 (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 1 < buf.length, 'Trying to read beyond buffer length') - } - - var len = buf.length - if (offset >= len) - return - - var val = readUInt16(buf, offset, littleEndian, true) - var neg = val & 0x8000 - if (neg) - return (0xffff - val + 1) * -1 - else - return val -} - -Buffer.prototype.readInt16LE = function (offset, noAssert) { - return readInt16(this, offset, true, noAssert) -} - -Buffer.prototype.readInt16BE = function (offset, noAssert) { - return readInt16(this, offset, false, noAssert) -} - -function readInt32 (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') - } - - var len = buf.length - if (offset >= len) - return - - var val = readUInt32(buf, offset, littleEndian, true) - var neg = val & 0x80000000 - if (neg) - return (0xffffffff - val + 1) * -1 - else - return val -} - -Buffer.prototype.readInt32LE = function (offset, noAssert) { - return readInt32(this, offset, true, noAssert) -} - -Buffer.prototype.readInt32BE = function (offset, noAssert) { - return readInt32(this, offset, false, noAssert) -} - -function readFloat (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') - } - - return ieee754.read(buf, offset, littleEndian, 23, 4) -} - -Buffer.prototype.readFloatLE = function (offset, noAssert) { - return readFloat(this, offset, true, noAssert) -} - -Buffer.prototype.readFloatBE = function (offset, noAssert) { - return readFloat(this, offset, false, noAssert) -} - -function readDouble (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset + 7 < buf.length, 'Trying to read beyond buffer length') - } - - return ieee754.read(buf, offset, littleEndian, 52, 8) -} - -Buffer.prototype.readDoubleLE = function (offset, noAssert) { - return readDouble(this, offset, true, noAssert) -} - -Buffer.prototype.readDoubleBE = function (offset, noAssert) { - return readDouble(this, offset, false, noAssert) -} - -Buffer.prototype.writeUInt8 = function (value, offset, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset < this.length, 'trying to write beyond buffer length') - verifuint(value, 0xff) - } - - if (offset >= this.length) return - - this[offset] = value - return offset + 1 -} - -function writeUInt16 (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 1 < buf.length, 'trying to write beyond buffer length') - verifuint(value, 0xffff) - } - - var len = buf.length - if (offset >= len) - return - - for (var i = 0, j = Math.min(len - offset, 2); i < j; i++) { - buf[offset + i] = - (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8 - } - return offset + 2 -} - -Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) { - return writeUInt16(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) { - return writeUInt16(this, value, offset, false, noAssert) -} - -function writeUInt32 (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 3 < buf.length, 'trying to write beyond buffer length') - verifuint(value, 0xffffffff) - } - - var len = buf.length - if (offset >= len) - return - - for (var i = 0, j = Math.min(len - offset, 4); i < j; i++) { - buf[offset + i] = - (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff - } - return offset + 4 -} - -Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) { - return writeUInt32(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) { - return writeUInt32(this, value, offset, false, noAssert) -} - -Buffer.prototype.writeInt8 = function (value, offset, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset < this.length, 'Trying to write beyond buffer length') - verifsint(value, 0x7f, -0x80) - } - - if (offset >= this.length) - return - - if (value >= 0) - this.writeUInt8(value, offset, noAssert) - else - this.writeUInt8(0xff + value + 1, offset, noAssert) - return offset + 1 -} - -function writeInt16 (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 1 < buf.length, 'Trying to write beyond buffer length') - verifsint(value, 0x7fff, -0x8000) - } - - var len = buf.length - if (offset >= len) - return - - if (value >= 0) - writeUInt16(buf, value, offset, littleEndian, noAssert) - else - writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert) - return offset + 2 -} - -Buffer.prototype.writeInt16LE = function (value, offset, noAssert) { - return writeInt16(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeInt16BE = function (value, offset, noAssert) { - return writeInt16(this, value, offset, false, noAssert) -} - -function writeInt32 (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 3 < buf.length, 'Trying to write beyond buffer length') - verifsint(value, 0x7fffffff, -0x80000000) - } - - var len = buf.length - if (offset >= len) - return - - if (value >= 0) - writeUInt32(buf, value, offset, littleEndian, noAssert) - else - writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert) - return offset + 4 -} - -Buffer.prototype.writeInt32LE = function (value, offset, noAssert) { - return writeInt32(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeInt32BE = function (value, offset, noAssert) { - return writeInt32(this, value, offset, false, noAssert) -} - -function writeFloat (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 3 < buf.length, 'Trying to write beyond buffer length') - verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38) - } - - var len = buf.length - if (offset >= len) - return - - ieee754.write(buf, value, offset, littleEndian, 23, 4) - return offset + 4 -} - -Buffer.prototype.writeFloatLE = function (value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeFloatBE = function (value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert) -} - -function writeDouble (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 7 < buf.length, - 'Trying to write beyond buffer length') - verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308) - } - - var len = buf.length - if (offset >= len) - return - - ieee754.write(buf, value, offset, littleEndian, 52, 8) - return offset + 8 -} - -Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert) -} - -// fill(value, start=0, end=buffer.length) -Buffer.prototype.fill = function (value, start, end) { - if (!value) value = 0 - if (!start) start = 0 - if (!end) end = this.length - - assert(end >= start, 'end < start') - - // Fill 0 bytes; we're done - if (end === start) return - if (this.length === 0) return - - assert(start >= 0 && start < this.length, 'start out of bounds') - assert(end >= 0 && end <= this.length, 'end out of bounds') - - var i - if (typeof value === 'number') { - for (i = start; i < end; i++) { - this[i] = value - } - } else { - var bytes = utf8ToBytes(value.toString()) - var len = bytes.length - for (i = start; i < end; i++) { - this[i] = bytes[i % len] - } - } - - return this -} - -Buffer.prototype.inspect = function () { - var out = [] - var len = this.length - for (var i = 0; i < len; i++) { - out[i] = toHex(this[i]) - if (i === exports.INSPECT_MAX_BYTES) { - out[i + 1] = '...' - break - } - } - return '' -} - -/** - * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. - * Added in Node 0.12. Only available in browsers that support ArrayBuffer. - */ -Buffer.prototype.toArrayBuffer = function () { - if (typeof Uint8Array !== 'undefined') { - if (TYPED_ARRAY_SUPPORT) { - return (new Buffer(this)).buffer - } else { - var buf = new Uint8Array(this.length) - for (var i = 0, len = buf.length; i < len; i += 1) { - buf[i] = this[i] - } - return buf.buffer - } - } else { - throw new Error('Buffer.toArrayBuffer not supported in this browser') - } -} - -// HELPER FUNCTIONS -// ================ - -var BP = Buffer.prototype - -/** - * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods - */ -Buffer._augment = function (arr) { - arr._isBuffer = true - - // save reference to original Uint8Array get/set methods before overwriting - arr._get = arr.get - arr._set = arr.set - - // deprecated, will be removed in node 0.13+ - arr.get = BP.get - arr.set = BP.set - - arr.write = BP.write - arr.toString = BP.toString - arr.toLocaleString = BP.toString - arr.toJSON = BP.toJSON - arr.equals = BP.equals - arr.compare = BP.compare - arr.copy = BP.copy - arr.slice = BP.slice - arr.readUInt8 = BP.readUInt8 - arr.readUInt16LE = BP.readUInt16LE - arr.readUInt16BE = BP.readUInt16BE - arr.readUInt32LE = BP.readUInt32LE - arr.readUInt32BE = BP.readUInt32BE - arr.readInt8 = BP.readInt8 - arr.readInt16LE = BP.readInt16LE - arr.readInt16BE = BP.readInt16BE - arr.readInt32LE = BP.readInt32LE - arr.readInt32BE = BP.readInt32BE - arr.readFloatLE = BP.readFloatLE - arr.readFloatBE = BP.readFloatBE - arr.readDoubleLE = BP.readDoubleLE - arr.readDoubleBE = BP.readDoubleBE - arr.writeUInt8 = BP.writeUInt8 - arr.writeUInt16LE = BP.writeUInt16LE - arr.writeUInt16BE = BP.writeUInt16BE - arr.writeUInt32LE = BP.writeUInt32LE - arr.writeUInt32BE = BP.writeUInt32BE - arr.writeInt8 = BP.writeInt8 - arr.writeInt16LE = BP.writeInt16LE - arr.writeInt16BE = BP.writeInt16BE - arr.writeInt32LE = BP.writeInt32LE - arr.writeInt32BE = BP.writeInt32BE - arr.writeFloatLE = BP.writeFloatLE - arr.writeFloatBE = BP.writeFloatBE - arr.writeDoubleLE = BP.writeDoubleLE - arr.writeDoubleBE = BP.writeDoubleBE - arr.fill = BP.fill - arr.inspect = BP.inspect - arr.toArrayBuffer = BP.toArrayBuffer - - return arr -} - -var INVALID_BASE64_RE = /[^+\/0-9A-z]/g - -function base64clean (str) { - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = stringtrim(str).replace(INVALID_BASE64_RE, '') - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '=' - } - return str -} - -function stringtrim (str) { - if (str.trim) return str.trim() - return str.replace(/^\s+|\s+$/g, '') -} - -function isArray (subject) { - return (Array.isArray || function (subject) { - return Object.prototype.toString.call(subject) === '[object Array]' - })(subject) -} - -function isArrayish (subject) { - return isArray(subject) || Buffer.isBuffer(subject) || - subject && typeof subject === 'object' && - typeof subject.length === 'number' -} - -function toHex (n) { - if (n < 16) return '0' + n.toString(16) - return n.toString(16) -} - -function utf8ToBytes (str) { - var byteArray = [] - for (var i = 0; i < str.length; i++) { - var b = str.charCodeAt(i) - if (b <= 0x7F) { - byteArray.push(b) - } else { - var start = i - if (b >= 0xD800 && b <= 0xDFFF) i++ - var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%') - for (var j = 0; j < h.length; j++) { - byteArray.push(parseInt(h[j], 16)) - } - } - } - return byteArray -} - -function asciiToBytes (str) { - var byteArray = [] - for (var i = 0; i < str.length; i++) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 0xFF) - } - return byteArray -} - -function utf16leToBytes (str) { - var c, hi, lo - var byteArray = [] - for (var i = 0; i < str.length; i++) { - c = str.charCodeAt(i) - hi = c >> 8 - lo = c % 256 - byteArray.push(lo) - byteArray.push(hi) - } - - return byteArray -} - -function base64ToBytes (str) { - return base64.toByteArray(str) -} - -function blitBuffer (src, dst, offset, length) { - for (var i = 0; i < length; i++) { - if ((i + offset >= dst.length) || (i >= src.length)) - break - dst[i + offset] = src[i] - } - return i -} - -function decodeUtf8Char (str) { - try { - return decodeURIComponent(str) - } catch (err) { - return String.fromCharCode(0xFFFD) // UTF 8 invalid char - } -} - -/* - * We have to make sure that the value is a valid integer. This means that it - * is non-negative. It has no fractional component and that it does not - * exceed the maximum allowed value. - */ -function verifuint (value, max) { - assert(typeof value === 'number', 'cannot write a non-number as a number') - assert(value >= 0, 'specified a negative value for writing an unsigned value') - assert(value <= max, 'value is larger than maximum value for type') - assert(Math.floor(value) === value, 'value has a fractional component') -} - -function verifsint (value, max, min) { - assert(typeof value === 'number', 'cannot write a non-number as a number') - assert(value <= max, 'value larger than maximum allowed value') - assert(value >= min, 'value smaller than minimum allowed value') - assert(Math.floor(value) === value, 'value has a fractional component') -} - -function verifIEEE754 (value, max, min) { - assert(typeof value === 'number', 'cannot write a non-number as a number') - assert(value <= max, 'value larger than maximum allowed value') - assert(value >= min, 'value smaller than minimum allowed value') -} - -function assert (test, message) { - if (!test) throw new Error(message || 'Failed assertion') -} - -},{"base64-js":190,"ieee754":191}],190:[function(require,module,exports){ -var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - -;(function (exports) { - 'use strict'; - - var Arr = (typeof Uint8Array !== 'undefined') - ? Uint8Array - : Array - - var PLUS = '+'.charCodeAt(0) - var SLASH = '/'.charCodeAt(0) - var NUMBER = '0'.charCodeAt(0) - var LOWER = 'a'.charCodeAt(0) - var UPPER = 'A'.charCodeAt(0) - - function decode (elt) { - var code = elt.charCodeAt(0) - if (code === PLUS) - return 62 // '+' - if (code === SLASH) - return 63 // '/' - if (code < NUMBER) - return -1 //no match - if (code < NUMBER + 10) - return code - NUMBER + 26 + 26 - if (code < UPPER + 26) - return code - UPPER - if (code < LOWER + 26) - return code - LOWER + 26 - } - - function b64ToByteArray (b64) { - var i, j, l, tmp, placeHolders, arr - - if (b64.length % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') - } - - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - var len = b64.length - placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 - - // base64 is 4/3 + up to two characters of the original data - arr = new Arr(b64.length * 3 / 4 - placeHolders) - - // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? b64.length - 4 : b64.length - - var L = 0 - - function push (v) { - arr[L++] = v - } - - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) - push((tmp & 0xFF0000) >> 16) - push((tmp & 0xFF00) >> 8) - push(tmp & 0xFF) - } - - if (placeHolders === 2) { - tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) - push(tmp & 0xFF) - } else if (placeHolders === 1) { - tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) - push((tmp >> 8) & 0xFF) - push(tmp & 0xFF) - } - - return arr - } - - function uint8ToBase64 (uint8) { - var i, - extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes - output = "", - temp, length - - function encode (num) { - return lookup.charAt(num) - } - - function tripletToBase64 (num) { - return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) - } - - // go through the array every three bytes, we'll deal with trailing stuff later - for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { - temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) - output += tripletToBase64(temp) - } - - // pad the end with zeros, but make sure to not forget the extra bytes - switch (extraBytes) { - case 1: - temp = uint8[uint8.length - 1] - output += encode(temp >> 2) - output += encode((temp << 4) & 0x3F) - output += '==' - break - case 2: - temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) - output += encode(temp >> 10) - output += encode((temp >> 4) & 0x3F) - output += encode((temp << 2) & 0x3F) - output += '=' - break - } - - return output - } - - exports.toByteArray = b64ToByteArray - exports.fromByteArray = uint8ToBase64 -}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) - -},{}],191:[function(require,module,exports){ -exports.read = function(buffer, offset, isLE, mLen, nBytes) { - var e, m, - eLen = nBytes * 8 - mLen - 1, - eMax = (1 << eLen) - 1, - eBias = eMax >> 1, - nBits = -7, - i = isLE ? (nBytes - 1) : 0, - d = isLE ? -1 : 1, - s = buffer[offset + i]; - - i += d; - - e = s & ((1 << (-nBits)) - 1); - s >>= (-nBits); - nBits += eLen; - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); - - m = e & ((1 << (-nBits)) - 1); - e >>= (-nBits); - nBits += mLen; - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); - - if (e === 0) { - e = 1 - eBias; - } else if (e === eMax) { - return m ? NaN : ((s ? -1 : 1) * Infinity); - } else { - m = m + Math.pow(2, mLen); - e = e - eBias; - } - return (s ? -1 : 1) * m * Math.pow(2, e - mLen); -}; - -exports.write = function(buffer, value, offset, isLE, mLen, nBytes) { - var e, m, c, - eLen = nBytes * 8 - mLen - 1, - eMax = (1 << eLen) - 1, - eBias = eMax >> 1, - rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0), - i = isLE ? 0 : (nBytes - 1), - d = isLE ? 1 : -1, - s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; - - value = Math.abs(value); - - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0; - e = eMax; - } else { - e = Math.floor(Math.log(value) / Math.LN2); - if (value * (c = Math.pow(2, -e)) < 1) { - e--; - c *= 2; - } - if (e + eBias >= 1) { - value += rt / c; - } else { - value += rt * Math.pow(2, 1 - eBias); - } - if (value * c >= 2) { - e++; - c /= 2; - } - - if (e + eBias >= eMax) { - m = 0; - e = eMax; - } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen); - e = e + eBias; - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); - e = 0; - } - } - - for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); - - e = (e << mLen) | m; - eLen += mLen; - for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); - - buffer[offset + i - d] |= s * 128; -}; - -},{}],192:[function(require,module,exports){ -// shim for using process in browser - -var process = module.exports = {}; - -process.nextTick = (function () { - var canSetImmediate = typeof window !== 'undefined' - && window.setImmediate; - var canPost = typeof window !== 'undefined' - && window.postMessage && window.addEventListener - ; - - if (canSetImmediate) { - return function (f) { return window.setImmediate(f) }; - } - - if (canPost) { - var queue = []; - window.addEventListener('message', function (ev) { - var source = ev.source; - if ((source === window || source === null) && ev.data === 'process-tick') { - ev.stopPropagation(); - if (queue.length > 0) { - var fn = queue.shift(); - fn(); - } - } - }, true); - - return function nextTick(fn) { - queue.push(fn); - window.postMessage('process-tick', '*'); - }; - } - - return function nextTick(fn) { - setTimeout(fn, 0); - }; -})(); - -process.title = 'browser'; -process.browser = true; -process.env = {}; -process.argv = []; - -function noop() {} - -process.on = noop; -process.addListener = noop; -process.once = noop; -process.off = noop; -process.removeListener = noop; -process.removeAllListeners = noop; -process.emit = noop; - -process.binding = function (name) { - throw new Error('process.binding is not supported'); -} - -// TODO(shtylman) -process.cwd = function () { return '/' }; -process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); -}; - -},{}]},{},[3]); +!function t(e,r,n){function i(o,s){if(!r[o]){if(!e[o]){var u="function"==typeof require&&require;if(!s&&u)return u(o,!0);if(a)return a(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=r[o]={exports:{}};e[o][0].call(l.exports,function(t){var r=e[o][1][t];return i(r?r:t)},l,l.exports,t,e,r,n)}return r[o].exports}for(var a="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"raymarch",link:"https://github.com/mikolalysenko/raymarch/",desc:"",thumb:"http://imgur.com/NpvsXIH.png",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(t,e){e.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],Tools:[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2}],Math:[{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:2},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:3}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:5}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0}],Internals:[{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:4},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:5}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4}]}},{}],3:[function(t){var e=t("./lib/filter"),r=t("minstache"),n=t("domify"),i=(t("sliced"),document.getElementById("grid").querySelector("canvas")),a=document.getElementById("community").querySelector("canvas");t("./lib/fill")(document.querySelectorAll("[data-fill]"));try{t("@stackgl/splash-grid")(i),t("@stackgl/splash-flock")(a)}catch(o){console.error(o.message)}var s=r.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),u=t("./build/examples.json").map(function(t){return s(t)}).join("\n"),f=t("./build/packages.json");f=Object.keys(f).reduce(function(t,e){return t.concat(f[e].map(function(t){return t.group=e,t}))},[]).map(function(t){return s(t)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(n(u));var l=document.getElementById("packages");l.querySelector("ul.thumb-list").appendChild(n(f)),l.querySelector("ul.thumb-filter").appendChild(e(l))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(t,e){function r(t){function e(){for(var e=window.innerWidth+"px",r=window.innerHeight+"px",n=0;n{{name}}\n{{/category}}\n');e.exports=function(t){var e=a(t.querySelectorAll("[data-filter]")),n=e.reduce(function(t,e){var r=e.getAttribute("data-filter");return-1===t.indexOf(r)&&t.push(r),t},[]);n.unshift(o),n=n.map(function(t){return{name:t}});var u=i(s({category:n})),f=u.children[0];return f.setAttribute("class","selected"),a(u.children).forEach(function(t){var n=t.getAttribute("data-name");t.addEventListener("click",function(i){i.preventDefault(),i.stopPropagation();var a=r(i.target,"li");if(a!==t)return!1;f.setAttribute("class",""),f=a,f.setAttribute("class","selected");for(var s=0;sb;b++)v[b]=h(l,[d,d],{"float":!0}),v[b].color[0].setPixels(y);window.addEventListener("resize",u(f(e,window))),m.logic=t("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(l),m.render=t("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(l)}function n(t){return t.push(t.shift()),t}function i(t,e){for(var r=new Float32Array(e*e),n=0,i=0;e>i;i++)for(var a=0;e>a;a++)r[n++]=i/e,r[n++]=a/e;var o=l(t,r),s=p(t,[{buffer:o,type:t.FLOAT,size:2}]);return s.length=r.length/2,s}function a(t){for(var e=new Float32Array(t*t*4),r=0;r=a&&i.length>r)return t.bufferData(e,i,n),i.length;if(i.length+a>r)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return t.bufferSubData(e,a,i),r}function i(t,e){for(var r=o.malloc(t.length,e),n=t.length,i=0;n>i;++i)r[i]=t[i];return r}function a(t,e,n,i){void 0===n&&(n=e,e=t.ARRAY_BUFFER),i||(i=t.DYNAMIC_DRAW);var a=0,f=t.createBuffer();if(t.bindBuffer(e,f),"number"==typeof n)t.bufferData(e,n,i),a=n;else if(n instanceof Array)e===t.ELEMENT_ARRAY_BUFFER?t.bufferData(e,new Uint16Array(n),i):t.bufferData(e,new Float32Array(n),i),a=n.length;else if(n.length)t.bufferData(e,n,i),a=n.length;else{if(!n.shape)throw new Error("gl-buffer: Invalid format for buffer data");var l=n.dtype;if(("float64"===l||"array"===l||"generic"===l)&&(l="float32"),e===t.ELEMENT_ARRAY_BUFFER&&(l="uint16"),1!==n.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var a=n.shape[0];if(l===n.type&&1===n.stride[0])t.bufferData(e,n.data.subarray(n.offset,n.offset+a),i);else{var c=o.malloc(n.shape[0],l),h=u(c);s.assign(h,n),t.bufferData(e,c,i),o.free(c)}}if(e!==t.ARRAY_BUFFER&&e!==t.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(i!==t.DYNAMIC_DRAW&&i!==t.STATIC_DRAW&&i!==t.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new r(t,e,f,a,i)}var o=t("typedarray-pool"),s=t("ndarray-ops"),u=t("ndarray");r.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},r.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},r.prototype.update=function(t,e){if(e||(e=0),this.bind(),"number"==typeof t){if(e>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,t,this.usage),this.length=t}else if(t.shape){var r=t.dtype;if(("float64"===r||"array"===r||"generic"===r)&&(r="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(r="uint16"),1!==t.shape.length)throw new Error("gl-buffer: Array length must be 1");if(r===t.dtype&&1===t.stride[0])this.length=0===t.offset&&t.data.length===t.shape[0]?n(this.gl,this.type,this.length,this.usage,t.data,e):n(this.gl,this.type,this.length,this.usage,t.data.subarray(t.offset,t.shape[0]),e);else{var a=o.malloc(t.shape[0],r),f=u(a);s.assign(f,t),this.length=n(this.gl,this.type,this.length,this.usage,a,e),o.free(a)}}else if(Array.isArray(t))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var l=i(t,"uint16");this.length=n(this.gl,this.type,this.length,this.usage,l.subarray(0,t.length),e),o.freeUint16(l)}else{var l=i(t,"float32");this.length=n(this.gl,this.type,this.length,this.usage,l.subarray(0,t.length),e),o.freeFloat32(l)}else this.length=n(this.gl,this.type,this.length,this.usage,t,e)},r.prototype.draw=function(t,e,r){r=r||0;var n=this.gl;if(this.type===n.ARRAY_BUFFER)n.drawArrays(t,r,e);else{if(this.type!==n.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),n.drawElements(t,e,n.UNSIGNED_SHORT,r)}},e.exports=a},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(t,e,r){"use strict";function n(t){if(!t)return s;for(var e=0;e>",rrshift:">>>"};!function(){for(var t in u){var e=u[t];r[t]=a({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+e+"c"},funcName:t}),r[t+"eq"]=a({args:["array","array"],body:{args:["a","b"],body:"a"+e+"=b"},rvalue:!0,funcName:t+"eq"}),r[t+"s"]=a({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+e+"s"},funcName:t+"s"}),r[t+"seq"]=a({args:["array","scalar"],body:{args:["a","s"],body:"a"+e+"=s"},rvalue:!0,funcName:t+"seq"})}}();var f={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var t in f){var e=f[t];r[t]=a({args:["array","array"],body:{args:["a","b"],body:"a="+e+"b"},funcName:t}),r[t+"eq"]=a({args:["array"],body:{args:["a"],body:"a="+e+"a"},rvalue:!0,count:2,funcName:t+"eq"})}}();var l={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var t in l){var e=l[t];r[t]=a({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+e+"c"},funcName:t}),r[t+"s"]=a({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+e+"s"},funcName:t+"s"}),r[t+"eq"]=a({args:["array","array"],body:{args:["a","b"],body:"a=a"+e+"b"},rvalue:!0,count:2,funcName:t+"eq"}),r[t+"seq"]=a({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+e+"s"},rvalue:!0,count:2,funcName:t+"seq"})}}();var c=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var t=0;tthis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),r.norm1=o({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),r.sup=o({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),r.inf=o({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),r.random=a({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),r.assign=a({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),r.assigns=a({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),r.equals=o({args:["array","array"],pre:s,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(t,e){"use strict";function r(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function n(t){var e=new r;e.pre=t.pre,e.body=t.body,e.post=t.post;var n=t.args.slice(0);e.argTypes=n;for(var a=0;a0)throw new Error("cwise: pre() block may not reference array args");if(a0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===o)e.scalarArgs.push(a),e.shimArgs.push("scalar"+a);else if("index"===o){if(e.indexArgs.push(a),a0)throw new Error("cwise: pre() block may not reference array index");if(a0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===o){if(e.shapeArgs.push(a),an.length)throw new Error("cwise: Too many arguments in pre() block");if(e.body.args.length>n.length)throw new Error("cwise: Too many arguments in body() block");if(e.post.args.length>n.length)throw new Error("cwise: Too many arguments in post() block");return e.debug=!!t.printCode||!!t.debug,e.funcName=t.funcName||"cwise",e.blockSize=t.blockSize||64,i(e)}var i=t("./lib/thunk.js");e.exports=n},{"./lib/thunk.js":12}],11:[function(t,e){"use strict";function r(t,e,r){var n,i,a=t.length,o=e.arrayArgs.length,s=e.indexArgs.length>0,u=[],f=[],l=0,c=0;for(n=0;a>n;++n)f.push(["i",n,"=0"].join(""));for(i=0;o>i;++i)for(n=0;a>n;++n)c=l,l=t[n],f.push(0===n?["d",i,"s",n,"=t",i,"p",l].join(""):["d",i,"s",n,"=(t",i,"p",l,"-s",c,"*t",i,"p",c,")"].join(""));for(u.push("var "+f.join(",")),n=a-1;n>=0;--n)l=t[n],u.push(["for(i",n,"=0;i",n,"n;++n){for(c=l,l=t[n],i=0;o>i;++i)u.push(["p",i,"+=d",i,"s",n].join(""));s&&(n>0&&u.push(["index[",c,"]-=s",c].join("")),u.push(["++index[",l,"]"].join(""))),u.push("}")}return u.join("\n")}function n(t,e,n,i){for(var a=e.length,o=n.arrayArgs.length,s=n.blockSize,u=n.indexArgs.length>0,f=[],l=0;o>l;++l)f.push(["var offset",l,"=p",l].join(""));for(var l=t;a>l;++l)f.push(["for(var j"+l+"=SS[",e[l],"]|0;j",l,">0;){"].join("")),f.push(["if(j",l,"<",s,"){"].join("")),f.push(["s",e[l],"=j",l].join("")),f.push(["j",l,"=0"].join("")),f.push(["}else{s",e[l],"=",s].join("")),f.push(["j",l,"-=",s,"}"].join("")),u&&f.push(["index[",e[l],"]=j",l].join(""));for(var l=0;o>l;++l){for(var c=["offset"+l],h=t;a>h;++h)c.push(["j",h,"*t",l,"p",e[h]].join(""));f.push(["p",l,"=(",c.join("+"),")"].join(""))}f.push(r(e,n,i));for(var l=t;a>l;++l)f.push("}");return f.join("\n")}function i(t){for(var e=0,r=t[0].length;r>e;){for(var n=1;n0&&(r=r&&e[n]===e[n-1])}return r?e[0]:e.join("")}function s(t,e){for(var s=0|e[1].length,f=new Array(t.arrayArgs.length),l=new Array(t.arrayArgs.length),c=["SS"],h=["'use strict'"],p=[],d=0;s>d;++d)p.push(["s",d,"=SS[",d,"]"].join(""));for(var g=0;gd;++d)p.push(["t",g,"p",d,"=t",g,"[",d,"]"].join(""))}for(var g=0;g0&&p.push("shape=SS.slice(0)"),t.indexArgs.length>0){for(var m=new Array(s),g=0;s>g;++g)m[g]="0";p.push(["index=[",m.join(","),"]"].join(""))}for(var g=0;g3&&h.push(a(t.pre,t,l));var _=a(t.body,t,l),E=i(f);h.push(s>E?n(E,f[0],t,_):r(f[0],t,_)),t.post.body.length>3&&h.push(a(t.post,t,l)),t.debug&&console.log("Generated cwise routine for ",e,":\n\n",h.join("\n"));var w=[t.funcName||"unnamed","_cwise_loop_",f[0].join("s"),"m",E,o(l)].join(""),A=new Function(["function ",w,"(",c.join(","),"){",h.join("\n"),"} return ",w].join(""));return A()}var u=t("uniq");e.exports=s},{uniq:13}],12:[function(t,e){"use strict";function r(t){var e=["'use strict'","var CACHED={}"],r=[],i=t.funcName+"_cwise_thunk";e.push(["return function ",i,"(",t.shimArgs.join(","),"){"].join(""));for(var a=[],o=[],s=[["array",t.arrayArgs[0],".shape"].join("")],u=0;uo;++o)if(a=i,i=t[o],e(i,a)){if(o===r){r++;continue}t[r++]=i}return t.length=r,t}function n(t){for(var e=1,r=t.length,n=t[0],i=t[0],a=1;r>a;++a,i=n)if(i=n,n=t[a],n!==i){if(a===e){e++;continue}t[e++]=n}return t.length=e,t}function i(t,e,i){return 0===t.length?t:e?(i||t.sort(e),r(t,e)):(i||t.sort(),n(t))}e.exports=i},{}],14:[function(t,e){(function(r){function n(t,e){return t[0]-e[0]}function i(){var t,e=this.stride,r=new Array(e.length);for(t=0;te&&(r="View_Nil"+t);var n="generic"===t;if(-1===e){var a="function "+r+"(a){this.data=a;};var proto="+r+".prototype;proto.dtype='"+t+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+r+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+r+"(a){return new "+r+"(a);}",o=new Function(a);return o()}if(0===e){var a="function "+r+"(a,d) {this.data = a;this.offset = d};var proto="+r+".prototype;proto.dtype='"+t+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+r+"_copy() {return new "+r+"(this.data,this.offset)};proto.pick=function "+r+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+r+"_get(){return "+(n?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+r+"_set(v){return "+(n?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+r+"(a,b,c,d){return new "+r+"(a,d)}",o=new Function("TrivialArray",a);return o(h[t][0])}var a=["'use strict'"],s=u(e),l=s.map(function(t){return"i"+t}),c="this.offset+"+s.map(function(t){return"this._stride"+t+"*i"+t}).join("+");a.push("function "+r+"(a,"+s.map(function(t){return"b"+t}).join(",")+","+s.map(function(t){return"c"+t}).join(",")+",d){this.data=a");for(var p=0;e>p;++p)a.push("this._shape"+p+"=b"+p+"|0");for(var p=0;e>p;++p)a.push("this._stride"+p+"=c"+p+"|0");a.push("this.offset=d|0}","var proto="+r+".prototype","proto.dtype='"+t+"'","proto.dimension="+e);var d="VStride"+e+"d"+t,g="VShape"+e+"d"+t,m={stride:d,shape:g};for(var v in m){var y=m[v];a.push("function "+y+"(v) {this._v=v} var aproto="+y+".prototype","aproto.length="+e);for(var b=[],p=0;e>p;++p)b.push(["this._v._",v,p].join(""));a.push("aproto.toJSON=function "+y+"_toJSON(){return ["+b.join(",")+"]}","aproto.valueOf=aproto.toString=function "+y+"_toString(){return ["+b.join(",")+"].join()}");for(var p=0;e>p;++p)a.push("Object.defineProperty(aproto,"+p+",{get:function(){return this._v._"+v+p+"},set:function(v){return this._v._"+v+p+"=v|0},enumerable:true})");for(var p=0;pp;++p)a.push("this._"+v+p+"=v["+p+"]|0");a.push("return v}})")}a.push("Object.defineProperty(proto,'size',{get:function "+r+"_size(){return "+s.map(function(t){return"this._shape"+t}).join("*"),"}})"),1===e?a.push("proto.order=[0]"):(a.push("Object.defineProperty(proto,'order',{get:"),4>e?(a.push("function "+r+"_order(){"),2===e?a.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===e&&a.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):a.push("ORDER})")),a.push("proto.set=function "+r+"_set("+l.join(",")+",v){"),a.push(n?"return this.data.set("+c+",v)}":"return this.data["+c+"]=v}"),a.push("proto.get=function "+r+"_get("+l.join(",")+"){"),a.push(n?"return this.data.get("+c+")}":"return this.data["+c+"]}"),a.push("proto.index=function "+r+"_index(",l.join(),"){return "+c+"}"),a.push("proto.hi=function "+r+"_hi("+l.join(",")+"){return new "+r+"(this.data,"+s.map(function(t){return["(typeof i",t,"!=='number'||i",t,"<0)?this._shape",t,":i",t,"|0"].join("")}).join(",")+","+s.map(function(t){return"this._stride"+t}).join(",")+",this.offset)}");var _=s.map(function(t){return"a"+t+"=this._shape"+t}),E=s.map(function(t){return"c"+t+"=this._stride"+t});a.push("proto.lo=function "+r+"_lo("+l.join(",")+"){var b=this.offset,d=0,"+_.join(",")+","+E.join(","));for(var p=0;e>p;++p)a.push("if(typeof i"+p+"==='number'&&i"+p+">=0){d=i"+p+"|0;b+=c"+p+"*d;a"+p+"-=d}");a.push("return new "+r+"(this.data,"+s.map(function(t){return"a"+t}).join(",")+","+s.map(function(t){return"c"+t}).join(",")+",b)}"),a.push("proto.step=function "+r+"_step("+l.join(",")+"){var "+s.map(function(t){return"a"+t+"=this._shape"+t}).join(",")+","+s.map(function(t){return"b"+t+"=this._stride"+t}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var p=0;e>p;++p)a.push("if(typeof i"+p+"==='number'){d=i"+p+"|0;if(d<0){c+=b"+p+"*(a"+p+"-1);a"+p+"=ceil(-a"+p+"/d)}else{a"+p+"=ceil(a"+p+"/d)}b"+p+"*=d}");a.push("return new "+r+"(this.data,"+s.map(function(t){return"a"+t}).join(",")+","+s.map(function(t){return"b"+t}).join(",")+",c)}");for(var w=new Array(e),A=new Array(e),p=0;e>p;++p)w[p]="a[i"+p+"]",A[p]="b[i"+p+"]";a.push("proto.transpose=function "+r+"_transpose("+l+"){"+l.map(function(t,e){return t+"=("+t+"===undefined?"+e+":"+t+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+r+"(this.data,"+w.join(",")+","+A.join(",")+",this.offset)}"),a.push("proto.pick=function "+r+"_pick("+l+"){var a=[],b=[],c=this.offset");for(var p=0;e>p;++p)a.push("if(typeof i"+p+"==='number'&&i"+p+">=0){c=(c+this._stride"+p+"*i"+p+")|0}else{a.push(this._shape"+p+");b.push(this._stride"+p+")}");a.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),a.push("return function construct_"+r+"(data,shape,stride,offset){return new "+r+"(data,"+s.map(function(t){return"shape["+t+"]"}).join(",")+","+s.map(function(t){return"stride["+t+"]"}).join(",")+",offset)}");var o=new Function("CTOR_LIST","ORDER",a.join("\n"));return o(h[t],i)}function o(t){if(c&&r.isBuffer(t))return"buffer";if(l)switch(Object.prototype.toString.call(t)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(t)?"array":"generic"}function s(t,e,r,n){if(void 0===t){var i=h.array[0];return i([])}"number"==typeof t&&(t=[t]),void 0===e&&(e=[t.length]);var s=e.length;if(void 0===r){r=new Array(s);for(var u=s-1,f=1;u>=0;--u)r[u]=f,f*=e[u]}if(void 0===n){n=0;for(var u=0;s>u;++u)r[u]<0&&(n-=(e[u]-1)*r[u])}for(var l=o(t),c=h[l];c.length<=s+1;)c.push(a(l,c.length-1));var i=c[s+1];return i(t,e,r,n)}var u=t("iota-array"),f=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],l="undefined"!=typeof Float64Array,c="undefined"!=typeof r,h={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};e.exports=s}).call(this,t("buffer").Buffer)},{buffer:189,"iota-array":15}],15:[function(t,e){"use strict";function r(t){for(var e=new Array(t),r=0;t>r;++r)e[r]=r;return e}e.exports=r},{}],16:[function(t,e,r){"use strict";"use restrict";function n(t){var e=32;return t&=-t,t&&e--,65535&t&&(e-=16),16711935&t&&(e-=8),252645135&t&&(e-=4),858993459&t&&(e-=2),1431655765&t&&(e-=1),e}var i=32;r.INT_BITS=i,r.INT_MAX=2147483647,r.INT_MIN=-1<0)-(0>t)},r.abs=function(t){var e=t>>i-1;return(t^e)-e},r.min=function(t,e){return e^(t^e)&-(e>t)},r.max=function(t,e){return t^(t^e)&-(e>t)},r.isPow2=function(t){return!(t&t-1||!t)},r.log2=function(t){var e,r;return e=(t>65535)<<4,t>>>=e,r=(t>255)<<3,t>>>=r,e|=r,r=(t>15)<<2,t>>>=r,e|=r,r=(t>3)<<1,t>>>=r,e|=r,e|t>>1},r.log10=function(t){return t>=1e9?9:t>=1e8?8:t>=1e7?7:t>=1e6?6:t>=1e5?5:t>=1e4?4:t>=1e3?3:t>=100?2:t>=10?1:0},r.popCount=function(t){return t-=t>>>1&1431655765,t=(858993459&t)+(t>>>2&858993459),16843009*(t+(t>>>4)&252645135)>>>24},r.countTrailingZeros=n,r.nextPow2=function(t){return t+=0===t,--t,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t+1},r.prevPow2=function(t){return t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t-(t>>>1)},r.parity=function(t){return t^=t>>>16,t^=t>>>8,t^=t>>>4,t&=15,27030>>>t&1};var a=new Array(256);!function(t){for(var e=0;256>e;++e){var r=e,n=e,i=7;for(r>>>=1;r;r>>>=1)n<<=1,n|=1&r,--i;t[e]=n<>>8&255]<<16|a[t>>>16&255]<<8|a[t>>>24&255]},r.interleave2=function(t,e){return t&=65535,t=16711935&(t|t<<8),t=252645135&(t|t<<4),t=858993459&(t|t<<2),t=1431655765&(t|t<<1),e&=65535,e=16711935&(e|e<<8),e=252645135&(e|e<<4),e=858993459&(e|e<<2),e=1431655765&(e|e<<1),t|e<<1},r.deinterleave2=function(t,e){return t=t>>>e&1431655765,t=858993459&(t|t>>>1),t=252645135&(t|t>>>2),t=16711935&(t|t>>>4),t=65535&(t|t>>>16),t<<16>>16},r.interleave3=function(t,e,r){return t&=1023,t=4278190335&(t|t<<16),t=251719695&(t|t<<8),t=3272356035&(t|t<<4),t=1227133513&(t|t<<2),e&=1023,e=4278190335&(e|e<<16),e=251719695&(e|e<<8),e=3272356035&(e|e<<4),e=1227133513&(e|e<<2),t|=e<<1,r&=1023,r=4278190335&(r|r<<16),r=251719695&(r|r<<8),r=3272356035&(r|r<<4),r=1227133513&(r|r<<2),t|r<<2},r.deinterleave3=function(t,e){return t=t>>>e&1227133513,t=3272356035&(t|t>>>2),t=251719695&(t|t>>>4),t=4278190335&(t|t>>>8),t=1023&(t|t>>>16),t<<22>>22},r.nextCombination=function(t){var e=t|t-1;return e+1|(~e&-~e)-1>>>n(t)+1}},{}],17:[function(t,e){"use strict";function r(t,e,n){var i=0|t[n];if(0>=i)return[];var a,o=new Array(i);if(n===t.length-1)for(a=0;i>a;++a)o[a]=e;else for(a=0;i>a;++a)o[a]=r(t,e,n+1);return o}function n(t,e){var r,n;for(r=new Array(t),n=0;t>n;++n)r[n]=e;return r}function i(t,e){switch("undefined"==typeof e&&(e=0),typeof t){case"number":if(t>0)return n(0|t,e);break;case"object":if("number"==typeof t.length)return r(t,e,0)}return[]}e.exports=i},{}],18:[function(t,e,r){(function(e){"use strict";var n=t("bit-twiddle"),i=t("dup");e.__TYPEDARRAY_POOL||(e.__TYPEDARRAY_POOL={UINT8:i([32,0]),UINT16:i([32,0]),UINT32:i([32,0]),INT8:i([32,0]),INT16:i([32,0]),INT32:i([32,0]),FLOAT:i([32,0]),DOUBLE:i([32,0]),DATA:i([32,0])});var a=e.__TYPEDARRAY_POOL,o=a.UINT8,s=a.UINT16,u=a.UINT32,f=a.INT8,l=a.INT16,c=a.INT32,h=a.FLOAT,p=a.DOUBLE,d=a.DATA;r.free=function(t){if(t instanceof ArrayBuffer){var e=0|t.byteLength,r=n.log2(e);d[r].push(t)}else{var e=0|t.length,r=n.log2(e);t instanceof Uint8Array?o[r].push(t):t instanceof Uint16Array?s[r].push(t):t instanceof Uint32Array?u[r].push(t):t instanceof Int8Array?f[r].push(t):t instanceof Int16Array?l[r].push(t):t instanceof Int32Array?c[r].push(t):t instanceof Float32Array?h[r].push(t):t instanceof Float64Array&&p[r].push(t)}},r.freeUint8=function(t){o[n.log2(t.length)].push(t)},r.freeUint16=function(t){s[n.log2(t.length)].push(t)},r.freeUint32=function(t){u[n.log2(t.length)].push(t)},r.freeInt8=function(t){f[n.log2(t.length)].push(t)},r.freeInt16=function(t){l[n.log2(t.length)].push(t)},r.freeInt32=function(t){c[n.log2(t.length)].push(t)},r.freeFloat32=r.freeFloat=function(t){h[n.log2(t.length)].push(t)},r.freeFloat64=r.freeDouble=function(t){p[n.log2(t.length)].push(t)},r.freeArrayBuffer=function(t){d[n.log2(t.length)].push(t)},r.malloc=function(t,e){t=n.nextPow2(t);var r=n.log2(t);if(void 0===e){var i=d[r];if(i.length>0){var a=i[i.length-1];return i.pop(),a}return new ArrayBuffer(t)}switch(e){case"uint8":var g=o[r];return g.length>0?g.pop():new Uint8Array(t);case"uint16":var m=s[r];return m.length>0?m.pop():new Uint16Array(t);case"uint32":var v=u[r];return v.length>0?v.pop():new Uint32Array(t);case"int8":var y=f[r];return y.length>0?y.pop():new Int8Array(t);case"int16":var b=l[r];return b.length>0?b.pop():new Int16Array(t);case"int32":var _=c[r];return _.length>0?_.pop():new Int32Array(t);case"float":case"float32":var E=h[r];return E.length>0?E.pop():new Float32Array(t);case"double":case"float64":var w=p[r];return w.length>0?w.pop():new Float64Array(t);default:return null}return null},r.mallocUint8=function(t){t=n.nextPow2(t);var e=n.log2(t),r=o[e];return r.length>0?r.pop():new Uint8Array(t)},r.mallocUint16=function(t){t=n.nextPow2(t);var e=n.log2(t),r=s[e];return r.length>0?r.pop():new Uint16Array(t)},r.mallocUint32=function(t){t=n.nextPow2(t);var e=n.log2(t),r=u[e];return r.length>0?r.pop():new Uint32Array(t)},r.mallocInt8=function(t){t=n.nextPow2(t);var e=n.log2(t),r=f[e];return r.length>0?r.pop():new Int8Array(t)},r.mallocInt16=function(t){t=n.nextPow2(t);var e=n.log2(t),r=l[e];return r.length>0?r.pop():new Int16Array(t)},r.mallocInt32=function(t){t=n.nextPow2(t);var e=n.log2(t),r=c[e];return r.length>0?r.pop():new Int32Array(t)},r.mallocFloat32=r.mallocFloat=function(t){t=n.nextPow2(t);var e=n.log2(t),r=h[e];return r.length>0?r.pop():new Float32Array(t)},r.mallocFloat64=r.mallocDouble=function(t){t=n.nextPow2(t);var e=n.log2(t),r=p[e];return r.length>0?r.pop():new Float64Array(t)},r.mallocArrayBuffer=function(t){t=n.nextPow2(t);var e=n.log2(t),r=d[e];return r.length>0?r.pop():new ArrayBuffer(t)},r.clearCache=function(){for(var t=0;32>t;++t)o[t].length=0,s[t].length=0,u[t].length=0,f[t].length=0,l[t].length=0,c[t].length=0,h[t].length=0,p[t].length=0,d[t].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(t,e){"use strict";function r(t,e,r){e?e.bind():t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null);var n=0|t.getParameter(t.MAX_VERTEX_ATTRIBS);if(r){if(r.length>n)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)t.disableVertexAttribArray(i)}else{t.bindBuffer(t.ARRAY_BUFFER,null);for(var i=0;n>i;++i)t.disableVertexAttribArray(i)}}e.exports=r},{}],20:[function(t,e){"use strict";function r(t){this.gl=t,this.elements=null,this.attributes=null}function n(t){return new r(t)}var i=t("./do-bind.js");r.prototype.bind=function(){i(this.gl,this.elements,this.attributes)},r.prototype.update=function(t,e){this.elements=t,this.attributes=e},r.prototype.dispose=function(){},r.prototype.unbind=function(){},e.exports=n},{"./do-bind.js":19}],21:[function(t,e){"use strict";function r(t,e,r){this.gl=t,this.ext=e,this.handle=r}function n(t,e){return new r(t,e,e.createVertexArrayOES())}var i=t("./do-bind.js");r.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},r.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},r.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},r.prototype.update=function(t,e){this.bind(),i(this.gl,t,e),this.unbind()},e.exports=n},{"./do-bind.js":19}],22:[function(t,e){"use strict";function r(t){for(var e=0;ee?Math.max(0,e+i):e||0;for(void 0!==r&&(i=0>r?r+i:r);i-->a;)n[i-a]=t[i];return n}},{}],31:[function(t,e){"use strict";function r(t,e,r,n,i){this.gl=t,this.type=e,this.handle=r,this.length=n,this.usage=i}function n(t,e,r,n,i,a){var o=i.length*i.BYTES_PER_ELEMENT;if(0>a)return t.bufferData(e,i,n),o;if(o+a>r)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return t.bufferSubData(e,a,i),r}function i(t,e){for(var r=s.malloc(t.length,e),n=t.length,i=0;n>i;++i)r[i]=t[i];return r}function a(t,e){for(var r=1,n=e.length-1;n>=0;--n){if(e[n]!==r)return!1;r*=t[n]}return!0}function o(t,e,n,i){if(l(t),n=n||t.ARRAY_BUFFER,i=i||t.DYNAMIC_DRAW,n!==t.ARRAY_BUFFER&&n!==t.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(i!==t.DYNAMIC_DRAW&&i!==t.STATIC_DRAW&&i!==t.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var a=t.createBuffer(),o=new r(t,n,a,0,i);return o.update(e),o}var s=t("typedarray-pool"),u=t("ndarray-ops"),f=t("ndarray"),l=t("webglew"),c=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],h=r.prototype;h.bind=function(){this.gl.bindBuffer(this.type,this.handle)},h.dispose=function(){this.gl.deleteBuffer(this.handle)},h.update=function(t,e){if("number"!=typeof e&&(e=-1),this.bind(),"object"==typeof t&&"undefined"!=typeof t.shape){var r=t.dtype;if(c.indexOf(r)<0&&(r="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var o=l(this.gl),h=o.OES_element_index_uint;r=h&&"uint16"!==r?"uint32":"uint16"}if(r===t.dtype&&a(t.shape,t.stride))this.length=0===t.offset&&t.data.length===t.shape[0]?n(this.gl,this.type,this.length,this.usage,t.data,e):n(this.gl,this.type,this.length,this.usage,t.data.subarray(t.offset,t.shape[0]),e);else{var p=s.malloc(t.size,r),d=f(p,t.shape);u.assign(d,t),this.length=0>e?n(this.gl,this.type,this.length,this.usage,p,e):n(this.gl,this.type,this.length,this.usage,p.subarray(0,t.size),e),s.free(p)}}else if(Array.isArray(t)){var g;g=this.type===this.gl.ELEMENT_ARRAY_BUFFER?i(t,"uint16"):i(t,"float32"),this.length=0>e?n(this.gl,this.type,this.length,this.usage,g,e):n(this.gl,this.type,this.length,this.usage,g.subarray(0,t.length),e),s.free(g)}else if("object"==typeof t&&"number"==typeof t.length)this.length=n(this.gl,this.type,this.length,this.usage,t,e);else{if("number"!=typeof t&&void 0!==t)throw new Error("gl-buffer: Invalid data type");if(e>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");t=0|t,0>=t&&(t=1),this.gl.bufferData(this.type,0|t,this.usage),this.length=t}},e.exports=o},{ndarray:37,"ndarray-ops":32,"typedarray-pool":41,webglew:43}],32:[function(t,e,r){arguments[4][9][0].apply(r,arguments)},{"cwise-compiler":33}],33:[function(t,e,r){arguments[4][10][0].apply(r,arguments)},{"./lib/thunk.js":35}],34:[function(t,e,r){arguments[4][11][0].apply(r,arguments)},{uniq:36}],35:[function(t,e,r){arguments[4][12][0].apply(r,arguments)},{"./compile.js":34}],36:[function(t,e){e.exports=t(13)},{}],37:[function(t,e,r){arguments[4][14][0].apply(r,arguments)},{buffer:189,"iota-array":38}],38:[function(t,e){e.exports=t(15)},{}],39:[function(t,e){e.exports=t(16)},{}],40:[function(t,e){e.exports=t(17)},{}],41:[function(t,e,r){(function(e,n){var i=t("bit-twiddle"),a=t("dup");e.__TYPEDARRAY_POOL||(e.__TYPEDARRAY_POOL={UINT8:a([32,0]),UINT16:a([32,0]),UINT32:a([32,0]),INT8:a([32,0]),INT16:a([32,0]),INT32:a([32,0]),FLOAT:a([32,0]),DOUBLE:a([32,0]),DATA:a([32,0]),UINT8C:a([32,0]),BUFFER:a([32,0])});var o="undefined"!=typeof Uint8ClampedArray,s=e.__TYPEDARRAY_POOL;s.UINT8C||(s.UINT8C=a([32,0])),s.BUFFER||(s.BUFFER=a([32,0]));var u=s.UINT8,f=s.UINT16,l=s.UINT32,c=s.INT8,h=s.INT16,p=s.INT32,d=s.FLOAT,g=s.DOUBLE,m=s.DATA,v=s.UINT8C,y=s.BUFFER;r.free=function(t){var e=0|t.length,r=i.log2(e);if(n.isBuffer(t))y[r].push(t);else switch(Object.prototype.toString.call(t)){case"[object Uint8Array]":u[r].push(t);break;case"[object Uint16Array]":f[r].push(t);break;case"[object Uint32Array]":l[r].push(t);break;case"[object Int8Array]":c[r].push(t);break;case"[object Int16Array]":h[r].push(t);break;case"[object Int32Array]":p[r].push(t);break;case"[object Uint8ClampedArray]":v[r].push(t);break;case"[object Float32Array]":d[r].push(t);break;case"[object Float64Array]":g[r].push(t);break;case"[object ArrayBuffer]":m[r].push(t);break;default:throw new Error("typedarray-pool: Unspecified array type")}},r.freeUint8=function(t){u[i.log2(t.length)].push(t)},r.freeUint16=function(t){f[i.log2(t.length)].push(t)},r.freeUint32=function(t){l[i.log2(t.length)].push(t)},r.freeInt8=function(t){c[i.log2(t.length)].push(t)},r.freeInt16=function(t){h[i.log2(t.length)].push(t)},r.freeInt32=function(t){p[i.log2(t.length)].push(t)},r.freeFloat32=r.freeFloat=function(t){d[i.log2(t.length)].push(t)},r.freeFloat64=r.freeDouble=function(t){g[i.log2(t.length)].push(t)},r.freeArrayBuffer=function(t){m[i.log2(t.length)].push(t)},r.freeUint8Clamped=o?function(t){v[i.log2(t.length)].push(t)}:r.freeUint8,r.freeBuffer=function(t){y[i.log2(t.length)].push(t)},r.malloc=function(t,e){t=i.nextPow2(t);var r=i.log2(t);if(void 0===e||"arraybuffer"===e){var a=m[r];if(a.length>0){var s=a[a.length-1];return a.pop(),s}return new ArrayBuffer(t)}switch(e){case"uint8":var b=u[r];return b.length>0?b.pop():new Uint8Array(t);case"uint16":var _=f[r];return _.length>0?_.pop():new Uint16Array(t);case"uint32":var E=l[r];return E.length>0?E.pop():new Uint32Array(t);case"int8":var w=c[r];return w.length>0?w.pop():new Int8Array(t);case"int16":var A=h[r];return A.length>0?A.pop():new Int16Array(t);case"int32":var x=p[r];return x.length>0?x.pop():new Int32Array(t);case"float":case"float32":var T=d[r];return T.length>0?T.pop():new Float32Array(t);case"double":case"float64":var R=g[r];return R.length>0?R.pop():new Float64Array(t);case"uint8_clamped":if(o){var M=v[r];return M.length>0?M.pop():new Uint8ClampedArray(t)}var b=u[r];return b.length>0?b.pop():new Uint8Array(t);case"buffer":var I=y[r];return I.length>0?I.pop():new n(t);default:return null}return null},r.mallocUint8=function(t){t=i.nextPow2(t);var e=i.log2(t),r=u[e];return r.length>0?r.pop():new Uint8Array(t)},r.mallocUint16=function(t){t=i.nextPow2(t);var e=i.log2(t),r=f[e];return r.length>0?r.pop():new Uint16Array(t)},r.mallocUint32=function(t){t=i.nextPow2(t);var e=i.log2(t),r=l[e];return r.length>0?r.pop():new Uint32Array(t)},r.mallocInt8=function(t){t=i.nextPow2(t);var e=i.log2(t),r=c[e];return r.length>0?r.pop():new Int8Array(t)},r.mallocInt16=function(t){t=i.nextPow2(t);var e=i.log2(t),r=h[e];return r.length>0?r.pop():new Int16Array(t)},r.mallocInt32=function(t){t=i.nextPow2(t);var e=i.log2(t),r=p[e];return r.length>0?r.pop():new Int32Array(t)},r.mallocFloat32=r.mallocFloat=function(t){t=i.nextPow2(t);var e=i.log2(t),r=d[e];return r.length>0?r.pop():new Float32Array(t)},r.mallocFloat64=r.mallocDouble=function(t){t=i.nextPow2(t);var e=i.log2(t),r=g[e];return r.length>0?r.pop():new Float64Array(t)},r.mallocArrayBuffer=function(t){t=i.nextPow2(t);var e=i.log2(t),r=m[e];return r.length>0?r.pop():new ArrayBuffer(t)},r.mallocUint8Clamped=o?function(t){t=i.nextPow2(t);var e=i.log2(t),r=v[e];return r.length>0?r.pop():new Uint8ClampedArray(t)}:r.mallocUint8,r.mallocBuffer=function(t){t=i.nextPow2(t);var e=i.log2(t),r=y[e]; +return r.length>0?r.pop():new n(t)},r.clearCache=function(){for(var t=0;32>t;++t)u[t].length=0,f[t].length=0,l[t].length=0,c[t].length=0,h[t].length=0,p[t].length=0,d[t].length=0,g[t].length=0,m[t].length=0,v[t].length=0,y[t].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},t("buffer").Buffer)},{"bit-twiddle":39,buffer:189,dup:40}],42:[function(t,e,r){void function(t,n,i){function a(t,e,r){return"function"==typeof e&&(r=e,e=o(r).replace(/_$/,"")),f(t,e,{configurable:!0,writable:!0,value:r})}function o(t){return"function"!=typeof t?"":"name"in t?t.name:l.call(t).match(p)[1]}function s(t){function e(e,n){return n||2===arguments.length?r.set(e,n):(n=r.get(e),n===i&&(n=t(e),r.set(e,n))),n}var r=new g;return t||(t=m),e}var u=Object.getOwnPropertyNames,f=Object.defineProperty,l=Function.prototype.toString,c=Object.create,h=Object.prototype.hasOwnProperty,p=/^\n?function\s?(\w*)?_?\(/,d=function(){function t(){var t=o(),n={};this.unlock=function(i){var a=l(i);if(h.call(a,t))return a[t](n);var o=c(null,e);return f(a,t,{value:new Function("s","l",r)(n,o)}),o}}var e={value:{writable:!0,value:i}},r="return function(k){if(k===s)return l}",n=c(null),o=function(){var t=Math.random().toString(36).slice(2);return t in n?o():n[t]=t},s=o(),l=function(t){if(h.call(t,s))return t[s];if(!Object.isExtensible(t))throw new TypeError("Object must be extensible");var e=c(null);return f(t,s,{value:e}),e};return a(Object,function(t){var e=u(t);return h.call(t,s)&&e.splice(e.indexOf(s),1),e}),a(t.prototype,function(t){return this.unlock(t).value}),a(t.prototype,function(t,e){this.unlock(t).value=e}),t}(),g=function(e){function r(e){return this===t||null==this||this===r.prototype?new r(e):(p(this,new d),void m(this,e))}function s(t){h(t);var e=g(this).get(t);return e===n?i:e}function u(t,e){h(t),g(this).set(t,e===i?n:e)}function f(t){return h(t),g(this).get(t)!==i}function l(t){h(t);var e=g(this),r=e.get(t)!==i;return e.set(t,i),r}function c(){return g(this),"[object WeakMap]"}var h=function(t){if(null==t||"object"!=typeof t&&"function"!=typeof t)throw new TypeError("Invalid WeakMap key")},p=function(t,r){var n=e.unlock(t);if(n.value)throw new TypeError("Object is already a WeakMap");n.value=r},g=function(t){var r=e.unlock(t).value;if(!r)throw new TypeError("WeakMap is not generic");return r},m=function(t,e){null!==e&&"object"==typeof e&&"function"==typeof e.forEach&&e.forEach(function(r,n){r instanceof Array&&2===r.length&&u.call(t,e[n][0],e[n][1])})};try{var v=("return "+l).replace("e_","\\u0065"),y=new Function("unwrap","validate",v)(g,h)}catch(b){var y=l}var v=(""+Object).split("Object"),_=function(){return v[0]+o(this)+v[1]};a(_,_);var E={__proto__:[]}instanceof Array?function(t){t.__proto__=_}:function(t){a(t,_)};return E(r),[c,s,u,f,y].forEach(function(t){a(r.prototype,t),E(t)}),r}(new d),m=Object.create?function(){return Object.create(null)}:function(){return{}};"undefined"!=typeof e?e.exports=g:"undefined"!=typeof r?r.WeakMap=g:"WeakMap"in t||(t.WeakMap=g),g.createStorage=s,t.WeakMap&&(t.WeakMap.createStorage=s)}((0,eval)("this"))},{}],43:[function(t,e){"use strict";function r(t){return t.replace(/^[A-Z]+_/,"")}function n(t){var e=a.get(t);if(e)return e;for(var n={},i=t.getSupportedExtensions(),o=0;o=n;++n){for(var i=new Array(r),a=0;n>a;++a)i[a]=t.COLOR_ATTACHMENT0+a;for(var a=n;r>a;++a)i[a]=t.NONE;y[n]=i}}function a(t){switch(t){case d:throw new Error("gl-fbo: Framebuffer unsupported");case g:throw new Error("gl-fbo: Framebuffer incomplete attachment");case m:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case v:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function o(t,e,r,n,i,a){if(!n)return null;var o=p(t,e,r,i,n);return o.magFilter=t.NEAREST,o.minFilter=t.NEAREST,o.mipSamples=1,o.bind(),t.framebufferTexture2D(t.FRAMEBUFFER,a,t.TEXTURE_2D,o.handle,0),o}function s(t,e,r,n,i){var a=t.createRenderbuffer();return t.bindRenderbuffer(t.RENDERBUFFER,a),t.renderbufferStorage(t.RENDERBUFFER,n,e,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,i,t.RENDERBUFFER,a),a}function u(t){var e=r(t.gl),i=t.gl,u=t.handle=i.createFramebuffer(),f=t._shape[0],l=t._shape[1],c=t.color.length,p=t._ext,d=t._useStencil,g=t._useDepth,m=t._colorType,v=h(i);i.bindFramebuffer(i.FRAMEBUFFER,u);for(var b=0;c>b;++b)t.color[b]=o(i,f,l,m,i.RGBA,i.COLOR_ATTACHMENT0+b);0===c?(t._color_rb=s(i,f,l,i.RGBA4,i.COLOR_ATTACHMENT0),p&&p.drawBuffersWEBGL(y[0])):c>1&&p.drawBuffersWEBGL(y[numColor]),v.WEBGL_depth_texture?d?t.depth=o(i,f,l,v.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,i.DEPTH_STENCIL,i.DEPTH_STENCIL_ATTACHMENT):g&&(t.depth=o(i,f,l,i.UNSIGNED_SHORT,i.DEPTH_COMPONENT,i.DEPTH_ATTACHMENT)):g&&d?t._depth_rb=s(i,f,l,i.DEPTH_STENCIL,i.DEPTH_STENCIL_ATTACHMENT):g?t._depth_rb=s(i,f,l,i.DEPTH_COMPONENT16,i.DEPTH_ATTACHMENT):d&&(t._depth_rb=s(i,f,l,i.STENCIL_INDEX,i.STENCIL_ATTACHMENT));var _=i.checkFramebufferStatus(i.FRAMEBUFFER);if(_!==i.FRAMEBUFFER_COMPLETE){t._destroyed=!0,i.bindFramebuffer(i.FRAMEBUFFER,null),i.deleteFramebuffer(t.handle),t.handle=null,t.depth&&(t.depth.dispose(),t.depth=null),t._depth_rb&&(i.deleteRenderbuffer(t._depth_rb),t._depth_rb=null);for(var b=0;bf;++f)this.color[f]=null;this._color_rb=null,this.depth=null,this._depth_rb=null,this._colorType=n,this._useDepth=a,this._useStencil=o;var l=this,c=[0|e,0|r];Object.defineProperties(c,{0:{get:function(){return l._shape[0]},set:function(t){return l.width=t}},1:{get:function(){return l._shape[1]},set:function(t){return l.height=t}}}),this._shapeVector=c,u(this)}function l(t,e,i){if(t._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(t._shape[0]!==e||t._shape[1]!==i){var o=t.gl,s=o.getParameter(o.MAX_RENDERBUFFER_SIZE);if(0>e||e>s||0>i||i>s)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");t._shape[0]=e,t._shape[1]=i;for(var u=r(o),f=0;fe||e>o||0>r||r>o)throw new Error("gl-fbo: Parameters are too large for FBO");n=n||{};var s=1;if("color"in n){if(s=Math.max(0|n.color,0),0>s)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(s>1){var u=a.WEBGL_draw_buffers;if(!u)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(s>t.getParameter(u.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+s+" draw buffers")}}var l=t.UNSIGNED_BYTE;if(n.float&&s>0){if(!a.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");l=t.FLOAT}else n.preferFloat&&s>0&&a.OES_texture_float&&(l=t.FLOAT);var c=!0;"depth"in n&&(c=!!n.depth);var p=!1;return"stencil"in n&&(p=!!n.stencil),new f(t,e,r,l,s,c,p,a.WEBGL_draw_buffers)}var h=t("webglew"),p=t("gl-texture2d");e.exports=c;var d,g,m,v,y=null,b=f.prototype;Object.defineProperties(b,{shape:{get:function(){return this._destroyed?[0,0]:this._shapeVector},set:function(t){if(Array.isArray(t)||(t=[0|t,0|t]),2!==t.length)throw new Error("gl-fbo: Shape vector must be length 2");var e=0|t[0],r=0|t[1];return l(this,e,r),[e,r]},enumerable:!1},width:{get:function(){return this._destroyed?0:this._shape[0]},set:function(t){return t=0|t,l(this,t,this._shape[1]),t},enumerable:!1},height:{get:function(){return this._destroyed?0:this._shape[1]},set:function(t){return t=0|t,l(this,this._shape[0],t),t},enumerable:!1}}),b.bind=function(){if(!this._destroyed){var t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.handle),t.viewport(0,0,this._shape[0],this._shape[1])}},b.dispose=function(){if(!this._destroyed){this._destroyed=!0;var t=this.gl;t.deleteFramebuffer(this.handle),this.handle=null,this.depth&&(this.depth.dispose(),this.depth=null),this._depth_rb&&(t.deleteRenderbuffer(this._depth_rb),this._depth_rb=null);for(var e=0;ee||e>i||0>r||r>i)throw new Error("gl-texture2d: Invalid texture size");return t._shape=[e,r],t.bind(),n.texImage2D(n.TEXTURE_2D,0,t.format,e,r,0,t.format,t.type,null),t._mipLevels=[0],t}function i(t,e,r,n,i,a){this.gl=t,this.handle=e,this.format=i,this.type=a,this._shape=[r,n],this._mipLevels=[0],this._magFilter=t.NEAREST,this._minFilter=t.NEAREST,this._wrapS=t.CLAMP_TO_EDGE,this._wrapT=t.CLAMP_TO_EDGE,this._anisoSamples=1;var o=this,s=[this._wrapS,this._wrapT];Object.defineProperties(s,{0:{get:function(){return o._wrapS},set:function(t){return o.wrapS=t}},1:{get:function(){return o._wrapT},set:function(t){return o.wrapT=t}}}),this._wrapVector=s;var u=[this._shape[0],this._shape[1]];Object.defineProperties(u,{0:{get:function(){return o._shape[0]},set:function(t){return o.width=t}},1:{get:function(){return o._shape[1]},set:function(t){return o.height=t}}}),this._shapeVector=u}function a(t,e){return 3===t.length?1===e[2]&&e[1]===t[0]*t[2]&&e[0]===t[2]:1===e[0]&&e[1]===t[0]}function o(t,e,r,n,i,o,s,u){var f=u.dtype,l=u.shape.slice();if(l.length<2||l.length>3)throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d");var c=0,g=0,m=a(l,u.stride.slice());"float32"===f?c=t.FLOAT:"float64"===f?(c=t.FLOAT,m=!1,f="float32"):"uint8"===f?c=t.UNSIGNED_BYTE:(c=t.UNSIGNED_BYTE,m=!1,f="uint8");var v=1;if(2===l.length)g=t.LUMINANCE,l=[l[0],l[1],1],u=h(u.data,l,[u.stride[0],u.stride[1],1],u.offset);else{if(3!==l.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===l[2])g=t.ALPHA;else if(2===l[2])g=t.LUMINANCE_ALPHA;else if(3===l[2])g=t.RGB;else{if(4!==l[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");g=t.RGBA}v=l[2]}if(g!==t.LUMINANCE&&g!==t.ALPHA||i!==t.LUMINANCE&&i!==t.ALPHA||(g=i),g!==i)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var y=u.size,_=s.indexOf(n)<0;if(_&&s.push(n),c===o&&m)0===u.offset&&u.data.length===y?_?t.texImage2D(t.TEXTURE_2D,n,i,l[0],l[1],0,i,o,u.data):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[0],l[1],i,o,u.data):_?t.texImage2D(t.TEXTURE_2D,n,i,l[0],l[1],0,i,o,u.data.subarray(u.offset,u.offset+y)):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[0],l[1],i,o,u.data.subarray(u.offset,u.offset+y));else{var E;E=o===t.FLOAT?d.mallocFloat32(y):d.mallocUint8(y);var w=h(E,l,[l[2],l[2]*l[0],1]);c===t.FLOAT&&o===t.UNSIGNED_BYTE?b(w,u):p.assign(w,u),_?t.texImage2D(t.TEXTURE_2D,n,i,l[0],l[1],0,i,o,E.subarray(0,y)):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[0],l[1],i,o,E.subarray(0,y)),o===t.FLOAT?d.freeFloat32(E):d.freeUint8(E)}}function s(t){var e=t.createTexture();return t.bindTexture(t.TEXTURE_2D,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),e}function u(t,e,r,n,a){var o=t.getParameter(t.MAX_TEXTURE_SIZE);if(0>e||e>o||0>r||r>o)throw new Error("gl-texture2d: Invalid texture shape");var u=s(t);return t.texImage2D(t.TEXTURE_2D,0,n,e,r,0,n,a,null),new i(t,u,e,r,n,a)}function f(t,e,r,n){var a=s(t);return t.texImage2D(t.TEXTURE_2D,0,r,r,n,e),new i(t,a,0|e.width,0|e.height,r,n)}function l(t,e){var r=e.dtype,n=e.shape.slice(),o=t.getParameter(t.MAX_TEXTURE_SIZE);if(n[0]<0||n[0]>o||n[1]<0||n[1]>o)throw new Error("gl-texture2d: Invalid texture size");var u=a(n,e.stride.slice()),f=0;"float32"===r?f=t.FLOAT:"float64"===r?(f=t.FLOAT,u=!1,r="float32"):"uint8"===r?f=t.UNSIGNED_BYTE:(f=t.UNSIGNED_BYTE,u=!1,r="uint8");var l=0;if(2===n.length)l=t.LUMINANCE,n=[n[0],n[1],1],e=h(e.data,n,[e.stride[0],e.stride[1],1],e.offset);else{if(3!==n.length)throw new Error("Invalid shape for texture");if(1===n[2])l=t.ALPHA;else if(2===n[2])l=t.LUMINANCE_ALPHA;else if(3===n[2])l=t.RGB;else{if(4!==n[2])throw new Error("Invalid shape for pixel coords");l=t.RGBA}}f!==t.FLOAT||g(t).texture_float||(f=t.UNSIGNED_BYTE,u=!1);var c,m,v=e.size;if(u)c=0===e.offset&&e.data.length===v?e.data:e.data.subarray(e.offset,e.offset+v);else{var y=[n[2],n[2]*n[0],1];m=d.malloc(v,r);var _=h(m,n,y,0);"float32"!==r&&"float64"!==r||f!==t.UNSIGNED_BYTE?p.assign(_,e):b(_,e),c=m.subarray(0,v)}var E=s(t);return t.texImage2D(t.TEXTURE_2D,0,l,n[0],n[1],0,l,f,c),u||d.free(m),new i(t,E,n[1],n[0],l,f)}function c(t){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(m||r(t),"number"==typeof arguments[1])return u(t,arguments[1],arguments[2],arguments[3]||t.RGBA,arguments[4]||t.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return u(t,0|arguments[1][0],0|arguments[1][1],arguments[2]||t.RGBA,arguments[4]||t.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var e=arguments[1];if(e instanceof HTMLCanvasElement||e instanceof HTMLImageElement||e instanceof HTMLVideoElement||e instanceof ImageData)return f(t,e,arguments[2]||t.RGBA,arguments[3]||t.UNSIGNED_BYTE);if(e.shape&&e.data&&e.stride)return l(t,e)}throw new Error("Invalid arguments for texture2d constructor")}var h=t("ndarray"),p=t("ndarray-ops"),d=t("typedarray-pool"),g=t("webglew");e.exports=c;var m=null,v=null,y=null,b=function(t,e){p.muls(t,e,255)},_=i.prototype;Object.defineProperties(_,{minFilter:{get:function(){return this._minFilter},set:function(t){this.bind();var e=this.gl;if(this.type===e.FLOAT&&m.indexOf(t)>=0&&(g(e).OES_texture_float_linear||(t=e.NEAREST)),v.indexOf(t)<0)throw new Error("gl-texture2d: Unknown filter mode "+t);return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t),this._minFilter=t}},magFilter:{get:function(){return this._magFilter},set:function(t){this.bind();var e=this.gl;if(this.type===e.FLOAT&&m.indexOf(t)>=0&&(g(e).OES_texture_float_linear||(t=e.NEAREST)),v.indexOf(t)<0)throw new Error("gl-texture2d: Unknown filter mode "+t);return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,t),this._magFilter=t}},mipSamples:{get:function(){return this._anisoSamples},set:function(t){var e=this._anisoSamples;if(this._anisoSamples=0|Math.max(t,1),e!==this._anisoSamples){var r=g(this.gl).EXT_texture_filter_anisotropic;r&&this.gl.texParameterf(this.gl.TEXTURE_2D,r.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}},wrapS:{get:function(){return this._wrapS},set:function(t){if(this.bind(),y.indexOf(t)<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,t),this._wrapS=t}},wrapT:{get:function(){return this._wrapT},set:function(t){if(this.bind(),y.indexOf(t)<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,t),this._wrapT=t}},wrap:{get:function(){return this._wrapVector},set:function(t){if(Array.isArray(t)||(t=[t,t]),2!==t.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var e=0;2>e;++e)if(y.indexOf(t[e])<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);this._wrapS=t[0],this._wrapT=t[1];var r=this.gl;return this.bind(),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,this._wrapS),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,this._wrapT),t}},shape:{get:function(){return this._shapeVector},set:function(t){if(Array.isArray(t)){if(2!==t.length)throw new Error("gl-texture2d: Invalid texture shape")}else t=[0|t,0|t];return n(this,0|t[0],0|t[1]),[0|t[0],0|t[1]]}},width:{get:function(){return this._shape[0]},set:function(t){return t=0|t,n(this,t,this._shape[1]),t}},height:{get:function(){return this._shape[1]},set:function(t){return t=0|t,n(this,this._shape[0],t),t}}}),_.bind=function(t){var e=this.gl;return void 0!==t&&e.activeTexture(e.TEXTURE0+(0|t)),e.bindTexture(e.TEXTURE_2D,this.handle),void 0!==t?t:e.getParameter(e.ACTIVE_TEXTURE)-e.TEXTURE0},_.dispose=function(){this.gl.deleteTexture(this.handle)},_.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var t=Math.min(this._shape[0],this._shape[1]),e=0;t>0;++e,t>>>=1)this._mipLevels.indexOf(e)<0&&this._mipLevels.push(e)},_.setPixels=function(t,e,r,n){var i=this.gl;if(this.bind(),Array.isArray(e)?(n=r,r=0|e[1],e=0|e[0]):(e=e||0,r=r||0),n=n||0,t instanceof HTMLCanvasElement||t instanceof ImageData||t instanceof HTMLImageElement||t instanceof HTMLVideoElement){var a=this._mipLevels.indexOf(n)<0;a?(i.texImage2D(i.TEXTURE_2D,0,this.format,this.format,this.type,t),this._mipLevels.push(n)):i.texSubImage2D(i.TEXTURE_2D,n,e,r,this.format,this.type,t)}else{if(!(t.shape&&t.stride&&t.data))throw new Error("gl-texture2d: Unsupported data type");if(t.shape.length<2||e+t.shape[1]>this._shape[1]>>>n||r+t.shape[0]>this._shape[0]>>>n||0>e||0>r)throw new Error("gl-texture2d: Texture dimensions are out of bounds");o(i,e,r,n,this.format,this.type,this._mipLevels,t)}}},{ndarray:54,"ndarray-ops":49,"typedarray-pool":58,webglew:61}],60:[function(t,e){e.exports=t(42)},{}],61:[function(t,e){e.exports=t(43)},{weakmap:60}],62:[function(t,e,r){arguments[4][9][0].apply(r,arguments)},{"cwise-compiler":63}],63:[function(t,e,r){arguments[4][10][0].apply(r,arguments)},{"./lib/thunk.js":65}],64:[function(t,e,r){arguments[4][11][0].apply(r,arguments)},{uniq:66}],65:[function(t,e,r){arguments[4][12][0].apply(r,arguments)},{"./compile.js":64}],66:[function(t,e){e.exports=t(13)},{}],67:[function(t,e){e.exports=t(16)},{}],68:[function(t,e){e.exports=t(17)},{}],69:[function(t,e){e.exports=t(41)},{"bit-twiddle":67,buffer:189,dup:68}],70:[function(t,e){e.exports=t(42)},{}],71:[function(t,e){e.exports=t(43)},{weakmap:70}],72:[function(t,e,r){arguments[4][59][0].apply(r,arguments)},{ndarray:86,"ndarray-ops":62,"typedarray-pool":69,webglew:71}],73:[function(t,e){"use strict";function r(t,e,r){e?e.bind():t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null);var n=0|t.getParameter(t.MAX_VERTEX_ATTRIBS);if(r){if(r.length>n)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)t.disableVertexAttribArray(i)}else{t.bindBuffer(t.ARRAY_BUFFER,null);for(var i=0;n>i;++i)t.disableVertexAttribArray(i)}}e.exports=r},{}],74:[function(t,e){"use strict";function r(t){this.gl=t,this._elements=null,this._attributes=null,this._elementsType=t.UNSIGNED_SHORT}function n(t){return new r(t)}var i=t("./do-bind.js");r.prototype.bind=function(){i(this.gl,this._elements,this._attributes)},r.prototype.update=function(t,e,r){this._elements=e,this._attributes=t,this._elementsType=r||this.gl.UNSIGNED_SHORT},r.prototype.dispose=function(){},r.prototype.unbind=function(){},r.prototype.draw=function(t,e,r){r=r||0;var n=this.gl;this._elements?n.drawElements(t,e,this._elementsType,r):n.drawArrays(t,r,e)},e.exports=n},{"./do-bind.js":73}],75:[function(t,e){"use strict";function r(t,e,r,n,i,a){this.location=t,this.dimension=e,this.a=r,this.b=n,this.c=i,this.d=a}function n(t,e,r){this.gl=t,this._ext=e,this.handle=r,this._attribs=[],this._useElements=!1,this._elementsType=t.UNSIGNED_SHORT}function i(t,e){return new n(t,e,e.createVertexArrayOES())}var a=t("./do-bind.js");r.prototype.bind=function(t){switch(this.dimension){case 1:t.vertexAttrib1f(this.location,this.a);break;case 2:t.vertexAttrib2f(this.location,this.a,this.b);break;case 3:t.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:t.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},n.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var t=0;tl;++l)u.push("x"+l),f.push("x"+l);u.push(["if(x0.length===undefined){return gl.vertexAttrib",i,"f(v,",f.join(","),")}else{return gl.vertexAttrib",i,"fv(v,x0)}"].join(""));var c=Function.apply(void 0,u),h=new r(t,e,n,i,o,c,s);Object.defineProperty(a,o,{set:function(e){return t.disableVertexAttribArray(h._location),c(t,h._location,e),e},get:function(){return h},enumerable:!0})}function i(t,e,r,i){for(var a={},o=0,s=r.length;s>o;++o){var u=r[o],f=u.name,l=u.type,c=t.getAttribLocation(e,f);switch(l){case"bool":case"int":case"float":n(t,e,c,1,a,f,i);break;default:if(!(l.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+f+": "+l);var h=l.charCodeAt(l.length-1)-48;if(2>h||h>4)throw new Error("Invalid data type for attribute "+f+": "+l);n(t,e,c,h,a,f,i)}}return a}e.exports=i;var a=r.prototype;a.pointer=function(t,e,r,n){var i=this._gl;i.vertexAttribPointer(this._location,this._dimension,t||i.FLOAT,e?i.TRUE:i.FALSE,r||0,n||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(a,"location",{get:function(){return this._location},set:function(t){t!==this._location&&(this._location=t,this._gl.bindAttribLocation(this._program,t,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],82:[function(t,e){"use strict";function r(t){var e=new Function("y","return function(){return y}");return e(t)}function n(t,e,n,o){function s(r){var n=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+r+"])}");return n(t,e,o)}function u(t,e,r){switch(r){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+e+"],obj"+t+")";case"float":return"gl.uniform1f(locations["+e+"],obj"+t+")";default:var n=r.indexOf("vec");if(!(n>=0&&1>=n&&r.length===4+n)){if(0===r.indexOf("mat")&&4===r.length){var i=r.charCodeAt(r.length-1)-48;if(2>i||i>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+r);return"gl.uniformMatrix"+i+"fv(locations["+e+"],false,obj"+t+")"}throw new Error("Unknown uniform data type for "+name+": "+r)}var i=r.charCodeAt(r.length-1)-48;if(2>i||i>4)throw new Error("Invalid data type");switch(r.charAt(0)){case"b":case"i":return"gl.uniform"+i+"iv(locations["+e+"],obj"+t+")";case"v":return"gl.uniform"+i+"fv(locations["+e+"],obj"+t+")";default:throw new Error("Unrecognized data type for vector "+name+": "+r)}}}function f(t,e){if("object"!=typeof e)return[[t,e]];var r=[];for(var n in e){var i=e[n],a=t;a+=parseInt(n)+""===n?"["+n+"]":"."+n,"object"==typeof i?r.push.apply(r,f(a,i)):r.push([a,i])}return r}function l(r){for(var i=["return function updateProperty(obj){"],a=f("",r),s=0;s=0&&1>=e&&t.length===4+e){var r=t.charCodeAt(t.length-1)-48;if(2>r||r>4)throw new Error("Invalid data type");return"b"===t.charAt(0)?i(r,!1):i(r)}if(0===t.indexOf("mat")&&4===t.length){var r=t.charCodeAt(t.length-1)-48;if(2>r||r>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+t);return i([r,r])}throw new Error("Unknown uniform data type for "+name+": "+t)}}function h(t,e,i){if("object"==typeof i){var a=p(i);Object.defineProperty(t,e,{get:r(a),set:l(i),enumerable:!0,configurable:!1})}else o[i]?Object.defineProperty(t,e,{get:s(i),set:l(i),enumerable:!0,configurable:!1}):t[e]=c(n[i].type)}function p(t){var e;if(Array.isArray(t)){e=new Array(t.length);for(var r=0;r1){u[0]in o||(o[u[0]]=[]),o=o[u[0]];for(var f=1;fr)){var n=b()*E;d.bind(),i.viewport(0,0,w,w),i.disable(i.DEPTH_TEST),i.disable(i.CULL_FACE),I.bind(),I.uniforms.uTime=n,I.uniforms.uResolution=A,h(i),i.bindFramebuffer(i.FRAMEBUFFER,null),i.viewport(0,0,t,r),i.enable(i.DEPTH_TEST),i.enable(i.CULL_FACE),f(i),l.perspective(y,Math.PI/4,t/r,.001,100),c.identity(R.rotation),c.rotateY(R.rotation,R.rotation,2e-4*n),c.rotateX(R.rotation,R.rotation,-.5),R.view(x),c.identity(R.rotation),c.rotateY(R.rotation,R.rotation,2e-4*n),F.bind(M),M.uniforms.uResolution=A,M.uniforms.uViewRotation=l.fromQuat(_,R.rotation),M.uniforms.uProjection=y,M.uniforms.uModel=T,M.uniforms.uView=x,M.uniforms.tHeightmap=d.color[0].bind(0),M.uniforms.tGradient=g.bind(1),F.draw(),F.unbind()}}var i=t("gl-context")(e,n),d=u(i,[w,w],{"float":!0}),g=o(i,t("./gradient-map")),m=r(),y=l.create(),_=l.create(),x=l.create(),T=l.create(),R=a([0,10,30],[0,0,0],[0,1,0]),M=t("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(i),I=t("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(i),F=s(i).attr("aPosition",m.positions).attr("aCentroid",m.centroids).attr("aNormal",m.normals).attr("aEdge",m.edges);R.distance=1.5,d.color[0].wrap=i.CLAMP_TO_EDGE,d.color[0].minFilter=i.NEAREST,d.color[0].maxFilter=i.NEAREST,l.translate(T,T,[-.5,0,-.5]),window.addEventListener("resize",p(v(e,window)),!1)}},{"./gradient-map":89,"a-big-triangle":107,"canvas-fit":108,clone:110,"cube-cube":111,"face-normals":114,"frame-debounce":115,"gl-clear":120,"gl-context":121,"gl-fbo":123,"gl-geometry":126,"gl-matrix":151,"gl-texture2d":164,glslify:166,"glslify/adapter.js":165,"mesh-combine":172,"orbit-camera":179,"right-now":180,"unindex-mesh":181}],91:[function(t,e,r){arguments[4][8][0].apply(r,arguments)},{ndarray:97,"ndarray-ops":92,"typedarray-pool":101}],92:[function(t,e,r){arguments[4][9][0].apply(r,arguments)},{"cwise-compiler":93}],93:[function(t,e,r){arguments[4][10][0].apply(r,arguments)},{"./lib/thunk.js":95}],94:[function(t,e,r){arguments[4][11][0].apply(r,arguments)},{uniq:96}],95:[function(t,e,r){arguments[4][12][0].apply(r,arguments)},{"./compile.js":94}],96:[function(t,e){e.exports=t(13)},{}],97:[function(t,e,r){arguments[4][14][0].apply(r,arguments)},{buffer:189,"iota-array":98}],98:[function(t,e){e.exports=t(15)},{}],99:[function(t,e){e.exports=t(16)},{}],100:[function(t,e){e.exports=t(17)},{}],101:[function(t,e){e.exports=t(18)},{"bit-twiddle":99,dup:100}],102:[function(t,e){e.exports=t(19)},{}],103:[function(t,e){e.exports=t(20)},{"./do-bind.js":102}],104:[function(t,e){e.exports=t(21)},{"./do-bind.js":102}],105:[function(t,e){e.exports=t(22)},{}],106:[function(t,e){e.exports=t(23)},{"./lib/vao-emulated.js":103,"./lib/vao-native.js":104,webglew:105}],107:[function(t,e){e.exports=t(24)},{"gl-buffer":91,"gl-vao":106}],108:[function(t,e,r){arguments[4][25][0].apply(r,arguments)},{"element-size":109}],109:[function(t,e){e.exports=t(26)},{}],110:[function(t,e){(function(t){"use strict";function r(t){return Object.prototype.toString.call(t)}function n(e,r,n,a){function o(e,n){if(null===e)return null;if(0==n)return e;var l;if("object"!=typeof e)return e;if(i.isArray(e))l=[];else if(i.isRegExp(e))l=new RegExp(e.source,i.getRegExpFlags(e)),e.lastIndex&&(l.lastIndex=e.lastIndex);else if(i.isDate(e))l=new Date(e.getTime());else{if(f&&t.isBuffer(e))return l=new t(e.length),e.copy(l),l;l=Object.create("undefined"==typeof a?Object.getPrototypeOf(e):a)}if(r){var c=s.indexOf(e);if(-1!=c)return u[c];s.push(e),u.push(l)}for(var h in e)l[h]=o(e[h],n-1);return l}var s=[],u=[],f="undefined"!=typeof t;return"undefined"==typeof r&&(r=!0),"undefined"==typeof n&&(n=1/0),o(e,n)}var i={isArray:function(t){return Array.isArray(t)||"object"==typeof t&&"[object Array]"===r(t)},isDate:function(t){return"object"==typeof t&&"[object Date]"===r(t)},isRegExp:function(t){return"object"==typeof t&&"[object RegExp]"===r(t)},getRegExpFlags:function(t){var e="";return t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),e}};"object"==typeof e&&(e.exports=n),n.clonePrototype=function(t){if(null===t)return null;var e=function(){};return e.prototype=t,new e}}).call(this,t("buffer").Buffer)},{buffer:189}],111:[function(t,e){function r(t,e,r,a){a=a||i;for(var o=[1/t,1/e,1/r],s=[],u=0;t>u;u++)for(var f=0;e>f;f++)for(var l=0;r>l;l++)if(a(u,f,l)){var c=n(o,[u/t,f/e,l/r]);s.push(c),c.centroid=[(u+.5)/t,(f+.5)/e,(l+.5)/r],c.index=[u,f,l]}return s}var n=t("rectangular-prism"),i=function(){return!0};e.exports=r},{"rectangular-prism":113}],112:[function(t,e){e.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],113:[function(t,e){function r(t,e){e=e||[0,0,0],t=t||[1,1,1],Array.isArray(t)||(t=[t,t,t]);for(var r=n(),i=0;in;n+=9){var i=t[n+3]-t[n],a=t[n+4]-t[n+1],o=t[n+5]-t[n+2],s=t[n+6]-t[n],u=t[n+7]-t[n+1],f=t[n+8]-t[n+2],l=a*f-o*u,c=o*s-i*f,h=i*u-a*s,p=Math.sqrt(l*l+c*c+h*h);0===p?(e[n]=0,e[n+1]=0,e[n+2]=0,e[n+3]=0,e[n+4]=0,e[n+5]=0,e[n+6]=0,e[n+7]=0,e[n+8]=0):(l/=p,c/=p,h/=p,e[n]=l,e[n+1]=c,e[n+2]=h,e[n+3]=l,e[n+4]=c,e[n+5]=h,e[n+6]=l,e[n+7]=c,e[n+8]=h)}return e}e.exports=r},{}],115:[function(t,e,r){arguments[4][27][0].apply(r,arguments)},{_process:192,"raf-component":116,sliced:117}],116:[function(t,e){e.exports=t(28)},{}],117:[function(t,e,r){arguments[4][29][0].apply(r,arguments)},{"./lib/sliced":118}],118:[function(t,e){e.exports=t(30)},{}],119:[function(t,e){e.exports=t(44)},{}],120:[function(t,e){e.exports=t(45)},{"./defaults":119}],121:[function(t,e){function r(t,e,r){function i(){r(a),n(i)}"function"==typeof e?(r=e,e={}):e=e||{};var a=t.getContext("webgl",e)||t.getContext("webgl-experimental",e)||t.getContext("experimental-webgl",e);if(!a)throw new Error("Unable to initialize WebGL");return r&&n(i),a}var n=t("raf-component");e.exports=r},{"raf-component":122}],122:[function(t,e){e.exports=t(28)},{}],123:[function(t,e){"use strict";function r(t,e){var r=t.getParameter(e.MAX_COLOR_ATTACHMENTS_WEBGL);g=new Array(r+1);for(var n=0;r>=n;++n){for(var i=new Array(r),a=0;n>a;++a)i[a]=t.COLOR_ATTACHMENT0+a;for(var a=n;r>a;++a)i[a]=t.NONE;g[n]=i}}function n(t){switch(t){case c:throw new Error("gl-fbo: Framebuffer unsupported");case h:throw new Error("gl-fbo: Framebuffer incomplete attachment");case p:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case d:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function i(t,e,r,n,i,a){if(!n)return null;var o=l(t,e,r,i,n);return o.magFilter=t.NEAREST,o.minFilter=t.NEAREST,o.mipSamples=1,t.framebufferTexture2D(t.FRAMEBUFFER,a,t.TEXTURE_2D,o.handle,0),t.bindTexture(t.TEXTURE_2D,null),o}function a(t,e,r,n,i){var a=t.createRenderbuffer();return t.bindRenderbuffer(t.RENDERBUFFER,a),t.renderbufferStorage(t.RENDERBUFFER,n,e,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,i,t.RENDERBUFFER,a),a}function o(t){var e=t.gl,r=t.handle=e.createFramebuffer(),o=t._shape[0],s=t._shape[1],u=t.color.length,l=t._ext,c=t._useStencil,h=t._useDepth,p=t._colorType,d=f(e);e.bindFramebuffer(e.FRAMEBUFFER,r);for(var m=0;u>m;++m)t.color[m]=i(e,s,o,p,e.RGBA,e.COLOR_ATTACHMENT0+m);0===u?(t._color_rb=a(e,s,o,e.RGBA4,e.COLOR_ATTACHMENT0),l&&l.drawBuffersWEBGL(g[0])):u>1&&l.drawBuffersWEBGL(g[numColor]),d.WEBGL_depth_texture?c?t.depth=i(e,s,o,d.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,e.DEPTH_STENCIL,e.DEPTH_STENCIL_ATTACHMENT):h&&(t.depth=i(e,s,o,e.UNSIGNED_SHORT,e.DEPTH_COMPONENT,e.DEPTH_ATTACHMENT)):h&&c?t._depth_rb=a(e,s,o,e.DEPTH_STENCIL,e.DEPTH_STENCIL_ATTACHMENT):h?t._depth_rb=a(e,s,o,e.DEPTH_COMPONENT16,e.DEPTH_ATTACHMENT):c&&(t._depth_rb=a(e,s,o,e.STENCIL_INDEX,e.STENCIL_ATTACHMENT));var v=e.checkFramebufferStatus(e.FRAMEBUFFER);if(v!==e.FRAMEBUFFER_COMPLETE){t._destroyed=!0,e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteFramebuffer(t.handle),t.handle=null,t.depth&&(t.depth.dispose(),t.depth=null),t._depth_rb&&(e.deleteRenderbuffer(t._depth_rb),t._depth_rb=null);for(var m=0;me||e>o||0>n||n>o)throw new Error("gl-fbo: Parameters are too large for FBO");i=i||{};var u=1;if("color"in i){if(u=Math.max(0|i.color,0),0>u)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(u>1){var l=a.WEBGL_draw_buffers;if(!l)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(u>t.getParameter(l.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+u+" draw buffers")}}var m=t.UNSIGNED_BYTE;if(i.float&&u>0){if(!a.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");m=t.FLOAT}else i.preferFloat&&u>0&&a.OES_texture_float&&(m=t.FLOAT);var v=!0;"depth"in i&&(v=!!i.depth);var y=!1;return"stencil"in i&&(y=!!i.stencil),new s(t,e,n,m,u,v,y,a.WEBGL_draw_buffers)}var f=t("webglew"),l=t("gl-texture2d");e.exports=u;var c,h,p,d,g=null,m=s.prototype;Object.defineProperty(m,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(m,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(t){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===t[0]|0&&this._shape[1]===t[1]|0)){var e=this.gl,r=e.getParameter(e.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(t)||2!==t.length||t[0]<0||t[0]>r||t[1]<0||t[1]>r)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|t[0],this._shape[1]=0|t[1];for(var i=0;iu;u++)a[o++]=t[s][u];return a}var n=t("dtype");e.exports=r},{dtype:128}],128:[function(t,e){e.exports=function(t){switch(t){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],129:[function(t,e){"use strict";function r(t,e,r,n,i){this.gl=t,this.type=e,this.handle=r,this.length=n,this.usage=i}function n(t,e,r,n,i,a){var o=i.length*i.BYTES_PER_ELEMENT;if(0>a)return t.bufferData(e,i,n),o;if(o+a>r)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return t.bufferSubData(e,a,i),r}function i(t,e){for(var r=s.malloc(t.length,e),n=t.length,i=0;n>i;++i)r[i]=t[i];return r}function a(t,e){for(var r=1,n=e.length-1;n>=0;--n){if(e[n]!==r)return!1;r*=t[n]}return!0}function o(t,e,n,i){if(l(t),n=n||t.ARRAY_BUFFER,i=i||t.DYNAMIC_DRAW,n!==t.ARRAY_BUFFER&&n!==t.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(i!==t.DYNAMIC_DRAW&&i!==t.STATIC_DRAW&&i!==t.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var a=t.createBuffer(),o=new r(t,n,a,0,i);return o.update(e),o}var s=t("typedarray-pool"),u=t("ndarray-ops"),f=t("ndarray"),l=t("webglew"),c=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],h=r.prototype;h.bind=function(){this.gl.bindBuffer(this.type,this.handle)},h.dispose=function(){this.gl.deleteBuffer(this.handle)},h.update=function(t,e){if("number"!=typeof e&&(e=-1),this.bind(),"object"==typeof t&&"undefined"!=typeof t.shape){var r=t.dtype;if(c.indexOf(r)<0&&(r="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var o=l(gl),h=o.OES_element_index_uint;r=h&&"uint16"!==r?"uint32":"uint16"}if(r===t.dtype&&a(t.shape,t.stride))this.length=0===t.offset&&t.data.length===t.shape[0]?n(this.gl,this.type,this.length,this.usage,t.data,e):n(this.gl,this.type,this.length,this.usage,t.data.subarray(t.offset,t.shape[0]),e);else{var p=s.malloc(t.size,r),d=f(p,t.shape);u.assign(d,t),this.length=0>e?n(this.gl,this.type,this.length,this.usage,p,e):n(this.gl,this.type,this.length,this.usage,p.subarray(0,t.size),e),s.free(p)}}else if(Array.isArray(t)){var g;g=this.type===this.gl.ELEMENT_ARRAY_BUFFER?i(t,"uint16"):i(t,"float32"),this.length=0>e?n(this.gl,this.type,this.length,this.usage,g,e):n(this.gl,this.type,this.length,this.usage,g.subarray(0,t.length),e),s.free(g)}else if("object"==typeof t&&"number"==typeof t.length)this.length=n(this.gl,this.type,this.length,this.usage,t,e);else{if("number"!=typeof t&&void 0!==t)throw new Error("gl-buffer: Invalid data type");if(e>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");t=0|t,0>=t&&(t=1),this.gl.bufferData(this.type,0|t,this.usage),this.length=t}},e.exports=o},{ndarray:135,"ndarray-ops":130,"typedarray-pool":139,webglew:141}],130:[function(t,e,r){arguments[4][9][0].apply(r,arguments)},{"cwise-compiler":131}],131:[function(t,e,r){arguments[4][10][0].apply(r,arguments)},{"./lib/thunk.js":133}],132:[function(t,e,r){arguments[4][11][0].apply(r,arguments)},{uniq:134}],133:[function(t,e,r){arguments[4][12][0].apply(r,arguments)},{"./compile.js":132}],134:[function(t,e){e.exports=t(13)},{}],135:[function(t,e,r){arguments[4][14][0].apply(r,arguments)},{buffer:189,"iota-array":136}],136:[function(t,e){e.exports=t(15)},{}],137:[function(t,e){e.exports=t(16)},{}],138:[function(t,e){e.exports=t(17)},{}],139:[function(t,e){e.exports=t(41)},{"bit-twiddle":137,buffer:189,dup:138}],140:[function(t,e){e.exports=t(42)},{}],141:[function(t,e){e.exports=t(43)},{weakmap:140}],142:[function(t,e){e.exports=t(73)},{}],143:[function(t,e){"use strict";function r(t){this.gl=t,this._elements=null,this._attributes=null}function n(t){return new r(t)}var i=t("./do-bind.js");r.prototype.bind=function(){i(this.gl,this._elements,this._attributes)},r.prototype.update=function(t,e){this._elements=e,this._attributes=t},r.prototype.dispose=function(){},r.prototype.unbind=function(){},r.prototype.draw=function(t,e,r){r=r||0;var n=this.gl;this._elements?n.drawElements(t,e,n.UNSIGNED_SHORT,r):n.drawArrays(t,r,e)},e.exports=n},{"./do-bind.js":142}],144:[function(t,e){"use strict";function r(t,e,r,n,i,a){this.location=t,this.dimension=e,this.a=r,this.b=n,this.c=i,this.d=a}function n(t,e,r){this.gl=t,this._ext=e,this.handle=r,this._attribs=[],this._useElements=!1}function i(t,e){return new n(t,e,e.createVertexArrayOES())}var a=t("./do-bind.js");r.prototype.bind=function(t){switch(this.dimension){case 1:t.vertexAttrib1f(this.location,this.a);break;case 2:t.vertexAttrib2f(this.location,this.a,this.b);break;case 3:t.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:t.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},n.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var t=0;t0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i),t},i.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]},i.cross=function(t,e,r){var n=e[0]*r[1]-e[1]*r[0];return t[0]=t[1]=0,t[2]=n,t},i.lerp=function(t,e,r,n){var i=e[0],a=e[1];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t},i.transformMat2=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[2]*i,t[1]=r[1]*n+r[3]*i,t},i.transformMat2d=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[2]*i+r[4],t[1]=r[1]*n+r[3]*i+r[5],t},i.transformMat3=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[3]*i+r[6],t[1]=r[1]*n+r[4]*i+r[7],t},i.transformMat4=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[4]*i+r[12],t[1]=r[1]*n+r[5]*i+r[13],t},i.forEach=function(){var t=i.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=2),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],a(t,t,o),e[s]=t[0],e[s+1]=t[1];return e}}(),i.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},"undefined"!=typeof t&&(t.vec2=i);var a={};a.create=function(){var t=new r(3);return t[0]=0,t[1]=0,t[2]=0,t},a.clone=function(t){var e=new r(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e},a.fromValues=function(t,e,n){var i=new r(3);return i[0]=t,i[1]=e,i[2]=n,i},a.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},a.set=function(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t},a.add=function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t},a.subtract=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t},a.sub=a.subtract,a.multiply=function(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t},a.mul=a.multiply,a.divide=function(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t},a.div=a.divide,a.min=function(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t},a.max=function(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t},a.scale=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t},a.distance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(r*r+n*n+i*i)},a.dist=a.distance,a.squaredDistance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i},a.sqrDist=a.squaredDistance,a.length=function(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)},a.len=a.length,a.squaredLength=function(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n},a.sqrLen=a.squaredLength,a.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t},a.normalize=function(t,e){var r=e[0],n=e[1],i=e[2],a=r*r+n*n+i*i;return a>0&&(a=1/Math.sqrt(a),t[0]=e[0]*a,t[1]=e[1]*a,t[2]=e[2]*a),t},a.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]},a.cross=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2];return t[0]=i*u-a*s,t[1]=a*o-n*u,t[2]=n*s-i*o,t},a.lerp=function(t,e,r,n){var i=e[0],a=e[1],o=e[2];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t},a.transformMat4=function(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12],t[1]=r[1]*n+r[5]*i+r[9]*a+r[13],t[2]=r[2]*n+r[6]*i+r[10]*a+r[14],t},a.transformQuat=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2],f=r[3],l=f*n+s*a-u*i,c=f*i+u*n-o*a,h=f*a+o*i-s*n,p=-o*n-s*i-u*a;return t[0]=l*f+p*-o+c*-u-h*-s,t[1]=c*f+p*-s+h*-o-l*-u,t[2]=h*f+p*-u+l*-s-c*-o,t},a.forEach=function(){var t=a.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=3),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2];return e}}(),a.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},"undefined"!=typeof t&&(t.vec3=a);var o={};o.create=function(){var t=new r(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t},o.clone=function(t){var e=new r(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},o.fromValues=function(t,e,n,i){var a=new r(4);return a[0]=t,a[1]=e,a[2]=n,a[3]=i,a},o.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},o.set=function(t,e,r,n,i){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t},o.add=function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t},o.subtract=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t +},o.sub=o.subtract,o.multiply=function(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t[3]=e[3]*r[3],t},o.mul=o.multiply,o.divide=function(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t[3]=e[3]/r[3],t},o.div=o.divide,o.min=function(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t[3]=Math.min(e[3],r[3]),t},o.max=function(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t[3]=Math.max(e[3],r[3]),t},o.scale=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t},o.distance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return Math.sqrt(r*r+n*n+i*i+a*a)},o.dist=o.distance,o.squaredDistance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return r*r+n*n+i*i+a*a},o.sqrDist=o.squaredDistance,o.length=function(t){var e=t[0],r=t[1],n=t[2],i=t[3];return Math.sqrt(e*e+r*r+n*n+i*i)},o.len=o.length,o.squaredLength=function(t){var e=t[0],r=t[1],n=t[2],i=t[3];return e*e+r*r+n*n+i*i},o.sqrLen=o.squaredLength,o.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t},o.normalize=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a;return o>0&&(o=1/Math.sqrt(o),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o,t[3]=e[3]*o),t},o.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]},o.lerp=function(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=e[3];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t[3]=s+n*(r[3]-s),t},o.transformMat4=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12]*o,t[1]=r[1]*n+r[5]*i+r[9]*a+r[13]*o,t[2]=r[2]*n+r[6]*i+r[10]*a+r[14]*o,t[3]=r[3]*n+r[7]*i+r[11]*a+r[15]*o,t},o.transformQuat=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2],f=r[3],l=f*n+s*a-u*i,c=f*i+u*n-o*a,h=f*a+o*i-s*n,p=-o*n-s*i-u*a;return t[0]=l*f+p*-o+c*-u-h*-s,t[1]=c*f+p*-s+h*-o-l*-u,t[2]=h*f+p*-u+l*-s-c*-o,t},o.forEach=function(){var t=o.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=4),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],t[3]=e[s+3],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2],e[s+3]=t[3];return e}}(),o.str=function(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},"undefined"!=typeof t&&(t.vec4=o);{var s={};new Float32Array([1,0,0,1])}s.create=function(){var t=new r(4);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},s.clone=function(t){var e=new r(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},s.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},s.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},s.transpose=function(t,e){if(t===e){var r=e[1];t[1]=e[2],t[2]=r}else t[0]=e[0],t[1]=e[2],t[2]=e[1],t[3]=e[3];return t},s.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*a-i*n;return o?(o=1/o,t[0]=a*o,t[1]=-n*o,t[2]=-i*o,t[3]=r*o,t):null},s.adjoint=function(t,e){var r=e[0];return t[0]=e[3],t[1]=-e[1],t[2]=-e[2],t[3]=r,t},s.determinant=function(t){return t[0]*t[3]-t[2]*t[1]},s.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],u=r[1],f=r[2],l=r[3];return t[0]=n*s+i*f,t[1]=n*u+i*l,t[2]=a*s+o*f,t[3]=a*u+o*l,t},s.mul=s.multiply,s.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),u=Math.cos(r);return t[0]=n*u+i*s,t[1]=n*-s+i*u,t[2]=a*u+o*s,t[3]=a*-s+o*u,t},s.scale=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],u=r[1];return t[0]=n*s,t[1]=i*u,t[2]=a*s,t[3]=o*u,t},s.str=function(t){return"mat2("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},"undefined"!=typeof t&&(t.mat2=s);{var u={};new Float32Array([1,0,0,1,0,0])}u.create=function(){var t=new r(6);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},u.clone=function(t){var e=new r(6);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e},u.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t},u.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},u.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=r*a-n*i;return u?(u=1/u,t[0]=a*u,t[1]=-n*u,t[2]=-i*u,t[3]=r*u,t[4]=(i*s-a*o)*u,t[5]=(n*o-r*s)*u,t):null},u.determinant=function(t){return t[0]*t[3]-t[1]*t[2]},u.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=r[0],l=r[1],c=r[2],h=r[3],p=r[4],d=r[5];return t[0]=n*f+i*c,t[1]=n*l+i*h,t[2]=a*f+o*c,t[3]=a*l+o*h,t[4]=f*s+c*u+p,t[5]=l*s+h*u+d,t},u.mul=u.multiply,u.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=Math.sin(r),l=Math.cos(r);return t[0]=n*l+i*f,t[1]=-n*f+i*l,t[2]=a*l+o*f,t[3]=-a*f+l*o,t[4]=l*s+f*u,t[5]=l*u-f*s,t},u.scale=function(t,e,r){var n=r[0],i=r[1];return t[0]=e[0]*n,t[1]=e[1]*i,t[2]=e[2]*n,t[3]=e[3]*i,t[4]=e[4]*n,t[5]=e[5]*i,t},u.translate=function(t,e,r){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4]+r[0],t[5]=e[5]+r[1],t},u.str=function(t){return"mat2d("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+")"},"undefined"!=typeof t&&(t.mat2d=u);{var f={};new Float32Array([1,0,0,0,1,0,0,0,1])}f.create=function(){var t=new r(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},f.clone=function(t){var e=new r(9);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e},f.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t},f.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},f.transpose=function(t,e){if(t===e){var r=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=r,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},f.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=l*o-s*f,h=-l*a+s*u,p=f*a-o*u,d=r*c+n*h+i*p;return d?(d=1/d,t[0]=c*d,t[1]=(-l*n+i*f)*d,t[2]=(s*n-i*o)*d,t[3]=h*d,t[4]=(l*r-i*u)*d,t[5]=(-s*r+i*a)*d,t[6]=p*d,t[7]=(-f*r+n*u)*d,t[8]=(o*r-n*a)*d,t):null},f.adjoint=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8];return t[0]=o*l-s*f,t[1]=i*f-n*l,t[2]=n*s-i*o,t[3]=s*u-a*l,t[4]=r*l-i*u,t[5]=i*a-r*s,t[6]=a*f-o*u,t[7]=n*u-r*f,t[8]=r*o-n*a,t},f.determinant=function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],u=t[7],f=t[8];return e*(f*a-o*u)+r*(-f*i+o*s)+n*(u*i-a*s)},f.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=r[0],p=r[1],d=r[2],g=r[3],m=r[4],v=r[5],y=r[6],b=r[7],_=r[8];return t[0]=h*n+p*o+d*f,t[1]=h*i+p*s+d*l,t[2]=h*a+p*u+d*c,t[3]=g*n+m*o+v*f,t[4]=g*i+m*s+v*l,t[5]=g*a+m*u+v*c,t[6]=y*n+b*o+_*f,t[7]=y*i+b*s+_*l,t[8]=y*a+b*u+_*c,t},f.mul=f.multiply,f.translate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=r[0],p=r[1];return t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=u,t[6]=h*n+p*o+f,t[7]=h*i+p*s+l,t[8]=h*a+p*u+c,t},f.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=Math.sin(r),p=Math.cos(r);return t[0]=p*n+h*o,t[1]=p*i+h*s,t[2]=p*a+h*u,t[3]=p*o-h*n,t[4]=p*s-h*i,t[5]=p*u-h*a,t[6]=f,t[7]=l,t[8]=c,t},f.scale=function(t,e,r){var n=r[0],i=r[2];return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=i*e[3],t[4]=i*e[4],t[5]=i*e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t},f.fromMat2d=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=0,t[3]=e[2],t[4]=e[3],t[5]=0,t[6]=e[4],t[7]=e[5],t[8]=1,t},f.fromQuat=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r+r,s=n+n,u=i+i,f=r*o,l=r*s,c=r*u,h=n*s,p=n*u,d=i*u,g=a*o,m=a*s,v=a*u;return t[0]=1-(h+d),t[1]=l+v,t[2]=c-m,t[3]=l-v,t[4]=1-(f+d),t[5]=p+g,t[6]=c+m,t[7]=p-g,t[8]=1-(f+h),t},f.str=function(t){return"mat3("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+")"},"undefined"!=typeof t&&(t.mat3=f);{var l={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}l.create=function(){var t=new r(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},l.clone=function(t){var e=new r(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},l.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},l.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},l.transpose=function(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],a=e[6],o=e[7],s=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=a,t[11]=e[14],t[12]=i,t[13]=o,t[14]=s}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t},l.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=e[9],h=e[10],p=e[11],d=e[12],g=e[13],m=e[14],v=e[15],y=r*s-n*o,b=r*u-i*o,_=r*f-a*o,E=n*u-i*s,w=n*f-a*s,A=i*f-a*u,x=l*g-c*d,T=l*m-h*d,R=l*v-p*d,M=c*m-h*g,I=c*v-p*g,F=h*v-p*m,N=y*F-b*I+_*M+E*R-w*T+A*x;return N?(N=1/N,t[0]=(s*F-u*I+f*M)*N,t[1]=(i*I-n*F-a*M)*N,t[2]=(g*A-m*w+v*E)*N,t[3]=(h*w-c*A-p*E)*N,t[4]=(u*R-o*F-f*T)*N,t[5]=(r*F-i*R+a*T)*N,t[6]=(m*_-d*A-v*b)*N,t[7]=(l*A-h*_+p*b)*N,t[8]=(o*I-s*R+f*x)*N,t[9]=(n*R-r*I-a*x)*N,t[10]=(d*w-g*_+v*y)*N,t[11]=(c*_-l*w-p*y)*N,t[12]=(s*T-o*M-u*x)*N,t[13]=(r*M-n*T+i*x)*N,t[14]=(g*b-d*E-m*y)*N,t[15]=(l*E-c*b+h*y)*N,t):null},l.adjoint=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=e[9],h=e[10],p=e[11],d=e[12],g=e[13],m=e[14],v=e[15];return t[0]=s*(h*v-p*m)-c*(u*v-f*m)+g*(u*p-f*h),t[1]=-(n*(h*v-p*m)-c*(i*v-a*m)+g*(i*p-a*h)),t[2]=n*(u*v-f*m)-s*(i*v-a*m)+g*(i*f-a*u),t[3]=-(n*(u*p-f*h)-s*(i*p-a*h)+c*(i*f-a*u)),t[4]=-(o*(h*v-p*m)-l*(u*v-f*m)+d*(u*p-f*h)),t[5]=r*(h*v-p*m)-l*(i*v-a*m)+d*(i*p-a*h),t[6]=-(r*(u*v-f*m)-o*(i*v-a*m)+d*(i*f-a*u)),t[7]=r*(u*p-f*h)-o*(i*p-a*h)+l*(i*f-a*u),t[8]=o*(c*v-p*g)-l*(s*v-f*g)+d*(s*p-f*c),t[9]=-(r*(c*v-p*g)-l*(n*v-a*g)+d*(n*p-a*c)),t[10]=r*(s*v-f*g)-o*(n*v-a*g)+d*(n*f-a*s),t[11]=-(r*(s*p-f*c)-o*(n*p-a*c)+l*(n*f-a*s)),t[12]=-(o*(c*m-h*g)-l*(s*m-u*g)+d*(s*h-u*c)),t[13]=r*(c*m-h*g)-l*(n*m-i*g)+d*(n*h-i*c),t[14]=-(r*(s*m-u*g)-o*(n*m-i*g)+d*(n*u-i*s)),t[15]=r*(s*h-u*c)-o*(n*h-i*c)+l*(n*u-i*s),t},l.determinant=function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],u=t[7],f=t[8],l=t[9],c=t[10],h=t[11],p=t[12],d=t[13],g=t[14],m=t[15],v=e*o-r*a,y=e*s-n*a,b=e*u-i*a,_=r*s-n*o,E=r*u-i*o,w=n*u-i*s,A=f*d-l*p,x=f*g-c*p,T=f*m-h*p,R=l*g-c*d,M=l*m-h*d,I=c*m-h*g;return v*I-y*M+b*R+_*T-E*x+w*A},l.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=e[9],p=e[10],d=e[11],g=e[12],m=e[13],v=e[14],y=e[15],b=r[0],_=r[1],E=r[2],w=r[3];return t[0]=b*n+_*s+E*c+w*g,t[1]=b*i+_*u+E*h+w*m,t[2]=b*a+_*f+E*p+w*v,t[3]=b*o+_*l+E*d+w*y,b=r[4],_=r[5],E=r[6],w=r[7],t[4]=b*n+_*s+E*c+w*g,t[5]=b*i+_*u+E*h+w*m,t[6]=b*a+_*f+E*p+w*v,t[7]=b*o+_*l+E*d+w*y,b=r[8],_=r[9],E=r[10],w=r[11],t[8]=b*n+_*s+E*c+w*g,t[9]=b*i+_*u+E*h+w*m,t[10]=b*a+_*f+E*p+w*v,t[11]=b*o+_*l+E*d+w*y,b=r[12],_=r[13],E=r[14],w=r[15],t[12]=b*n+_*s+E*c+w*g,t[13]=b*i+_*u+E*h+w*m,t[14]=b*a+_*f+E*p+w*v,t[15]=b*o+_*l+E*d+w*y,t},l.mul=l.multiply,l.translate=function(t,e,r){var n,i,a,o,s,u,f,l,c,h,p,d,g=r[0],m=r[1],v=r[2];return e===t?(t[12]=e[0]*g+e[4]*m+e[8]*v+e[12],t[13]=e[1]*g+e[5]*m+e[9]*v+e[13],t[14]=e[2]*g+e[6]*m+e[10]*v+e[14],t[15]=e[3]*g+e[7]*m+e[11]*v+e[15]):(n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=e[9],p=e[10],d=e[11],t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=u,t[6]=f,t[7]=l,t[8]=c,t[9]=h,t[10]=p,t[11]=d,t[12]=n*g+s*m+c*v+e[12],t[13]=i*g+u*m+h*v+e[13],t[14]=a*g+f*m+p*v+e[14],t[15]=o*g+l*m+d*v+e[15]),t},l.scale=function(t,e,r){var n=r[0],i=r[1],a=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*a,t[9]=e[9]*a,t[10]=e[10]*a,t[11]=e[11]*a,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},l.rotate=function(t,r,n,i){var a,o,s,u,f,l,c,h,p,d,g,m,v,y,b,_,E,w,A,x,T,R,M,I,F=i[0],N=i[1],U=i[2],S=Math.sqrt(F*F+N*N+U*U);return Math.abs(S)=1?(t!==e&&(t[0]=u,t[1]=f,t[2]=l,t[3]=c),t):(i=Math.acos(m),a=Math.sqrt(1-m*m),Math.abs(a)<.001?(t[0]=.5*u+.5*h,t[1]=.5*f+.5*p,t[2]=.5*l+.5*d,t[3]=.5*c+.5*g,t):(o=Math.sin((1-n)*i)/a,s=Math.sin(n*i)/a,t[0]=u*o+h*s,t[1]=f*o+p*s,t[2]=l*o+d*s,t[3]=c*o+g*s,t))},c.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a,s=o?1/o:0;return t[0]=-r*s,t[1]=-n*s,t[2]=-i*s,t[3]=a*s,t},c.conjugate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},c.length=o.length,c.len=c.length,c.squaredLength=o.squaredLength,c.sqrLen=c.squaredLength,c.normalize=o.normalize,c.fromMat3=function(){var t=[1,2,0];return function(e,r){var n,i=r[0]+r[4]+r[8];if(i>0)n=Math.sqrt(i+1),e[3]=.5*n,n=.5/n,e[0]=(r[7]-r[5])*n,e[1]=(r[2]-r[6])*n,e[2]=(r[3]-r[1])*n;else{var a=0;r[4]>r[0]&&(a=1),r[8]>r[3*a+a]&&(a=2);var o=t[a],s=t[o];n=Math.sqrt(r[3*a+a]-r[3*o+o]-r[3*s+s]+1),e[a]=.5*n,n=.5/n,e[3]=(r[3*s+o]-r[3*o+s])*n,e[o]=(r[3*o+a]+r[3*a+o])*n,e[s]=(r[3*s+a]+r[3*a+s])*n}return e}}(),c.str=function(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},"undefined"!=typeof t&&(t.quat=c)}(t.exports)}()},{}],152:[function(t,e,r){arguments[4][9][0].apply(r,arguments)},{"cwise-compiler":153}],153:[function(t,e,r){arguments[4][10][0].apply(r,arguments)},{"./lib/thunk.js":155}],154:[function(t,e,r){arguments[4][11][0].apply(r,arguments)},{uniq:156}],155:[function(t,e,r){arguments[4][12][0].apply(r,arguments)},{"./compile.js":154}],156:[function(t,e){e.exports=t(13)},{}],157:[function(t,e,r){arguments[4][14][0].apply(r,arguments)},{buffer:189,"iota-array":158}],158:[function(t,e){e.exports=t(15)},{}],159:[function(t,e){e.exports=t(16)},{}],160:[function(t,e){e.exports=t(17)},{}],161:[function(t,e){e.exports=t(41)},{"bit-twiddle":159,buffer:189,dup:160}],162:[function(t,e){e.exports=t(42)},{}],163:[function(t,e){e.exports=t(43)},{weakmap:162}],164:[function(t,e){"use strict";function r(t){g=[t.LINEAR,t.NEAREST_MIPMAP_LINEAR,t.LINEAR_MIPMAP_NEAREST,t.LINEAR_MIPMAP_NEAREST],m=[t.NEAREST,t.LINEAR,t.NEAREST_MIPMAP_NEAREST,t.NEAREST_MIPMAP_LINEAR,t.LINEAR_MIPMAP_NEAREST,t.LINEAR_MIPMAP_LINEAR],v=[t.REPEAT,t.CLAMP_TO_EDGE,t.MIRRORED_REPEAT]}function n(t,e,r,n,i,a){this.gl=t,this.handle=e,this.format=i,this.type=a,this._shape=[n,r],this._mipLevels=[0],this._magFilter=t.NEAREST,this._minFilter=t.NEAREST,this._wrapS=t.CLAMP_TO_EDGE,this._wrapT=t.CLAMP_TO_EDGE,this._anisoSamples=1}function i(t,e,r,n,i,a,o,s){var f=s.dtype,l=s.shape,d=u(s),g=0,m=0;if("float32"===f?g=t.FLOAT:"float64"===f?(g=t.FLOAT,d=!1,f="float32"):"uint8"===f?g=t.UNSIGNED_BYTE:(g=t.UNSIGNED_BYTE,d=!1,f="uint8"),2===l.length)m=t.LUMINANCE;else{if(3!==l.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===l[2])m=t.ALPHA;else if(2===l[2])m=t.LUMINANCE_ALPHA;else if(3===l[2])m=t.RGB;else{if(4!==l[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");m=t.RGBA}}if(m!==t.LUMINANCE&&m!==t.ALPHA||i!==t.LUMINANCE&&i!==t.ALPHA||(m=i),m!==i)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var v=s.size,b=o.indexOf(n)<0;if(b&&o.push(n),g===a&&d)0===s.offset&&s.data.length===v?b?t.texImage2D(t.TEXTURE_2D,n,i,l[1],l[0],0,i,a,s.data):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[1],l[0],i,a,s.data):b?t.texImage2D(t.TEXTURE_2D,n,i,l[1],l[0],0,i,a,s.data.subarray(s.offset,s.offset+v)):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[1],l[0],i,a,s.data.subarray(s.offset,s.offset+v));else{var _;_=a===t.FLOAT?p.mallocFloat32(v):p.mallocUint8(v);var E=c(_,l);g===t.FLOAT&&a===t.UNSIGNED_BYTE?y(E,s):h.assign(E,s),b?t.texImage2D(t.TEXTURE_2D,n,i,l[1],l[0],0,i,a,_.subarray(0,v)):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[1],l[0],i,a,_.subarray(0,v)),a===t.FLOAT?p.freeFloat32(_):p.freeUint8(_)}}function a(t){var e=t.createTexture();return t.bindTexture(t.TEXTURE_2D,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),e}function o(t,e,r,i,o){var s=t.getParameter(t.MAX_TEXTURE_SIZE);if(0>e||e>s||0>r||r>s)throw new Error("gl-texture2d: Invalid texture shape");var u=a(t);return t.texImage2D(t.TEXTURE_2D,0,i,e,r,0,i,o,null),new n(t,u,e,r,i,o)}function s(t,e,r,i){var o=a(t);return t.texImage2D(t.TEXTURE_2D,0,r,r,i,e),new n(t,o,0|e.width,0|e.height,r,i)}function u(t){for(var e=t.shape,r=t.stride,n=1,i=e.length-1;i>=0;--i){if(r[i]!==n)return!1;n*=e[i]}return!0}function f(t,e){var r=e.dtype,i=e.shape.slice(),o=t.getParameter(t.MAX_TEXTURE_SIZE);if(i[0]<0||i[0]>o||i[1]<0||i[1]>o)throw new Error("gl-texture2d: Invalid texture size");var s=u(e),f=0;"float32"===r?f=t.FLOAT:"float64"===r?(f=t.FLOAT,s=!1,r="float32"):"uint8"===r?f=t.UNSIGNED_BYTE:(f=t.UNSIGNED_BYTE,s=!1,r="uint8");var l=0;if(2===i.length)l=t.LUMINANCE;else{if(3!==i.length)throw new Error("Invalid shape for texture");if(1===i[2])l=t.ALPHA;else if(2===i[2])l=t.LUMINANCE_ALPHA;else if(3===i[2])l=t.RGB;else{if(4!==i[2])throw new Error("Invalid shape for pixel coords");l=t.RGBA}}f===t.FLOAT&&d(t).texture_float&&(f=t.UNSIGNED_BYTE,s=!1);var g,m;if(s){var v=e.size;g=e.data.subarray(e.offset,e.offset+v)}else{for(var b=1,_=new Array(i.length),E=i.length-1;E>=0;--E)_[E]=b,b*=i[E];m=p.malloc(b,r);var w=c(m,e.shape,_,0);"float32"!==r&&"float64"!==r||f!==t.UNSIGNED_BYTE?h.assign(w,e):y(w,e),g=m.subarray(0,b)}var A=a(t);return t.texImage2D(t.TEXTURE_2D,0,l,i[1],i[0],0,l,f,g),s||p.free(m),new n(t,A,i[1],i[0],l,f)}function l(t){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(g||r(t),"number"==typeof arguments[1])return o(t,arguments[1],arguments[2],arguments[3]||t.RGBA,arguments[4]||t.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return o(t,0|arguments[1][1],0|arguments[1][0],arguments[2]||t.RGBA,arguments[4]||t.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var e=arguments[1];if(e instanceof HTMLCanvasElement||e instanceof HTMLImageElement||e instanceof HTMLVideoElement||e instanceof ImageData)return s(t,e,arguments[2]||t.RGBA,arguments[3]||t.UNSIGNED_BYTE);if(e.shape&&e.data&&e.stride)return f(t,e)}throw new Error("Invalid arguments for texture2d constructor")}var c=t("ndarray"),h=t("ndarray-ops"),p=t("typedarray-pool"),d=t("webglew"),g=null,m=null,v=null,y=function(t,e){h.muls(t,e,255)};Object.defineProperty(n.prototype,"minFilter",{get:function(){return this._minFilter},set:function(t){this.bind();var e=this.gl;if(this.type===e.FLOAT&&g.indexOf(t)>=0&&(d(e).OES_texture_float_linear||(t=e.NEAREST)),m.indexOf(t)<0)throw new Error("gl-texture2d: Unknown filter mode "+t);return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t),this._minFilter=t}});var b=n.prototype;Object.defineProperty(b,"magFilter",{get:function(){return this._magFilter},set:function(t){this.bind();var e=this.gl;if(this.type===e.FLOAT&&g.indexOf(t)>=0&&(d(e).OES_texture_float_linear||(t=e.NEAREST)),m.indexOf(t)<0)throw new Error("gl-texture2d: Unknown filter mode "+t);return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,t),this._magFilter=t}}),Object.defineProperty(b,"wrapS",{get:function(){return this._wrapS},set:function(t){if(this.bind(),v.indexOf(t)<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,t),this._wrapS=t}}),Object.defineProperty(b,"wrapT",{get:function(){return this._wrapT},set:function(t){if(this.bind(),v.indexOf(t)<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,t),this._wrapT=t}}),Object.defineProperty(b,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(t){if(Array.isArray(t)||(t=[t,t]),2!==t.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var e=0;2>e;++e)if(v.indexOf(t[e])<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);this._wrapT=t[0],this._wrapS=t[1];var r=this.gl;return this.bind(),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,this._wrapT),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,this._wrapS),t}}),Object.defineProperty(b,"mipSamples",{get:function(){return this._anisoSamples},set:function(t){var e=this._anisoSamples;if(this._anisoSamples=0|Math.max(t,1),e!==this._anisoSamples){var r=d(this.gl).EXT_texture_filter_anisotropic;r&&this.gl.texParameterf(this.gl.TEXTURE_2D,r.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(b,"shape",{get:function(){return this._shape},set:function(t){if(Array.isArray(t)){if(2!==t.length)throw new Error("gl-texture2d: Invalid texture shape")}else t=[0|t,0|t];var e=0|t[0],r=0|t[1];if(this.height===e&&this.width===r)return t;var n=this.gl,i=n.getParameter(n.MAX_TEXTURE_SIZE);if(0>r||r>i||0>e||e>i)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[e,r],this.bind(),n.texImage2D(n.TEXTURE_2D,0,this.format,r,e,0,this.format,this.type,null),this._mipLevels=[0],t}}),b.bind=function(t){var e=this.gl;return void 0!==t&&e.activeTexture(e.TEXTURE0+(0|t)),e.bindTexture(e.TEXTURE_2D,this.handle),void 0!==t?t:e.getParameter(e.ACTIVE_TEXTURE)-e.TEXTURE0},b.dispose=function(){this.gl.deleteTexture(this.handle)},b.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var t=Math.min(this._shape[0],this._shape[1]),e=0;t>0;++e,t>>>=1)this._mipLevels.indexOf(e)<0&&this._mipLevels.push(e)},b.setPixels=function(t,e,r,n){var a=this.gl;if(this.bind(),Array.isArray(e)?(n=r,r=0|e[0],e=0|e[1]):(e=e||0,r=r||0),n=n||0,t instanceof HTMLCanvasElement||t instanceof ImageData||t instanceof HTMLImageElement||t instanceof HTMLVideoElement){var o=this._mipLevels.indexOf(n)<0;o?(a.texImage2D(a.TEXTURE_2D,0,this.format,this.format,this.type,t),this._mipLevels.push(n)):a.texSubImage2D(a.TEXTURE_2D,n,e,r,this.format,this.type,t)}else{if(!(t.shape&&t.stride&&t.data))throw new Error("gl-texture2d: Unsupported data type");if(t.shape.length<2||e+t.shape[1]>this._shape[1]>>>n||r+t.shape[0]>this._shape[0]>>>n||0>e||0>r)throw new Error("gl-texture2d: Texture dimensions are out of bounds");i(a,e,r,n,this.format,this.type,this._mipLevels,t)}},e.exports=l},{ndarray:157,"ndarray-ops":152,"typedarray-pool":161,webglew:163}],165:[function(t,e,r){arguments[4][79][0].apply(r,arguments)},{"gl-shader-core":171}],166:[function(t,e){e.exports=t(80)},{}],167:[function(t,e){e.exports=t(81)},{}],168:[function(t,e,r){arguments[4][82][0].apply(r,arguments)},{"./reflect.js":169,dup:170}],169:[function(t,e){e.exports=t(83)},{}],170:[function(t,e){e.exports=t(17)},{}],171:[function(t,e){e.exports=t(85)},{"./lib/create-attributes.js":167,"./lib/create-uniforms.js":168,"./lib/reflect.js":169}],172:[function(t,e){function r(t){for(var e=[],r=[],i=0,a=0,o=0,s=0;s0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i),t},o.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]},o.cross=function(t,e,r){var n=e[0]*r[1]-e[1]*r[0];return t[0]=t[1]=0,t[2]=n,t},o.lerp=function(t,e,r,n){var i=e[0],a=e[1];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t},o.random=function(t,e){e=e||1;var r=2*n()*Math.PI;return t[0]=Math.cos(r)*e,t[1]=Math.sin(r)*e,t},o.transformMat2=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[2]*i,t[1]=r[1]*n+r[3]*i,t},o.transformMat2d=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[2]*i+r[4],t[1]=r[1]*n+r[3]*i+r[5],t},o.transformMat3=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[3]*i+r[6],t[1]=r[1]*n+r[4]*i+r[7],t},o.transformMat4=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[4]*i+r[12],t[1]=r[1]*n+r[5]*i+r[13],t},o.forEach=function(){var t=o.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=2),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],a(t,t,o),e[s]=t[0],e[s+1]=t[1];return e}}(),o.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},"undefined"!=typeof t&&(t.vec2=o);var s={};s.create=function(){var t=new r(3);return t[0]=0,t[1]=0,t[2]=0,t},s.clone=function(t){var e=new r(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e},s.fromValues=function(t,e,n){var i=new r(3);return i[0]=t,i[1]=e,i[2]=n,i},s.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},s.set=function(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t},s.add=function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t},s.subtract=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t +},s.sub=s.subtract,s.multiply=function(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t},s.mul=s.multiply,s.divide=function(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t},s.div=s.divide,s.min=function(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t},s.max=function(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t},s.scale=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t},s.scaleAndAdd=function(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t},s.distance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(r*r+n*n+i*i)},s.dist=s.distance,s.squaredDistance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i},s.sqrDist=s.squaredDistance,s.length=function(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)},s.len=s.length,s.squaredLength=function(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n},s.sqrLen=s.squaredLength,s.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t},s.normalize=function(t,e){var r=e[0],n=e[1],i=e[2],a=r*r+n*n+i*i;return a>0&&(a=1/Math.sqrt(a),t[0]=e[0]*a,t[1]=e[1]*a,t[2]=e[2]*a),t},s.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]},s.cross=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2];return t[0]=i*u-a*s,t[1]=a*o-n*u,t[2]=n*s-i*o,t},s.lerp=function(t,e,r,n){var i=e[0],a=e[1],o=e[2];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t},s.random=function(t,e){e=e||1;var r=2*n()*Math.PI,i=2*n()-1,a=Math.sqrt(1-i*i)*e;return t[0]=Math.cos(r)*a,t[1]=Math.sin(r)*a,t[2]=i*e,t},s.transformMat4=function(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12],t[1]=r[1]*n+r[5]*i+r[9]*a+r[13],t[2]=r[2]*n+r[6]*i+r[10]*a+r[14],t},s.transformMat3=function(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=n*r[0]+i*r[3]+a*r[6],t[1]=n*r[1]+i*r[4]+a*r[7],t[2]=n*r[2]+i*r[5]+a*r[8],t},s.transformQuat=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2],f=r[3],l=f*n+s*a-u*i,c=f*i+u*n-o*a,h=f*a+o*i-s*n,p=-o*n-s*i-u*a;return t[0]=l*f+p*-o+c*-u-h*-s,t[1]=c*f+p*-s+h*-o-l*-u,t[2]=h*f+p*-u+l*-s-c*-o,t},s.rotateX=function(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[0],a[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),a[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t},s.rotateY=function(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),a[1]=i[1],a[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t},s.rotateZ=function(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),a[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),a[2]=i[2],t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t},s.forEach=function(){var t=s.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=3),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2];return e}}(),s.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},"undefined"!=typeof t&&(t.vec3=s);var u={};u.create=function(){var t=new r(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t},u.clone=function(t){var e=new r(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},u.fromValues=function(t,e,n,i){var a=new r(4);return a[0]=t,a[1]=e,a[2]=n,a[3]=i,a},u.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},u.set=function(t,e,r,n,i){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t},u.add=function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t},u.subtract=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t},u.sub=u.subtract,u.multiply=function(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t[3]=e[3]*r[3],t},u.mul=u.multiply,u.divide=function(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t[3]=e[3]/r[3],t},u.div=u.divide,u.min=function(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t[3]=Math.min(e[3],r[3]),t},u.max=function(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t[3]=Math.max(e[3],r[3]),t},u.scale=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t},u.scaleAndAdd=function(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t},u.distance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return Math.sqrt(r*r+n*n+i*i+a*a)},u.dist=u.distance,u.squaredDistance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return r*r+n*n+i*i+a*a},u.sqrDist=u.squaredDistance,u.length=function(t){var e=t[0],r=t[1],n=t[2],i=t[3];return Math.sqrt(e*e+r*r+n*n+i*i)},u.len=u.length,u.squaredLength=function(t){var e=t[0],r=t[1],n=t[2],i=t[3];return e*e+r*r+n*n+i*i},u.sqrLen=u.squaredLength,u.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t},u.normalize=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a;return o>0&&(o=1/Math.sqrt(o),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o,t[3]=e[3]*o),t},u.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]},u.lerp=function(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=e[3];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t[3]=s+n*(r[3]-s),t},u.random=function(t,e){return e=e||1,t[0]=n(),t[1]=n(),t[2]=n(),t[3]=n(),u.normalize(t,t),u.scale(t,t,e),t},u.transformMat4=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12]*o,t[1]=r[1]*n+r[5]*i+r[9]*a+r[13]*o,t[2]=r[2]*n+r[6]*i+r[10]*a+r[14]*o,t[3]=r[3]*n+r[7]*i+r[11]*a+r[15]*o,t},u.transformQuat=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2],f=r[3],l=f*n+s*a-u*i,c=f*i+u*n-o*a,h=f*a+o*i-s*n,p=-o*n-s*i-u*a;return t[0]=l*f+p*-o+c*-u-h*-s,t[1]=c*f+p*-s+h*-o-l*-u,t[2]=h*f+p*-u+l*-s-c*-o,t},u.forEach=function(){var t=u.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=4),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],t[3]=e[s+3],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2],e[s+3]=t[3];return e}}(),u.str=function(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},"undefined"!=typeof t&&(t.vec4=u);var f={};f.create=function(){var t=new r(4);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},f.clone=function(t){var e=new r(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},f.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},f.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},f.transpose=function(t,e){if(t===e){var r=e[1];t[1]=e[2],t[2]=r}else t[0]=e[0],t[1]=e[2],t[2]=e[1],t[3]=e[3];return t},f.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*a-i*n;return o?(o=1/o,t[0]=a*o,t[1]=-n*o,t[2]=-i*o,t[3]=r*o,t):null},f.adjoint=function(t,e){var r=e[0];return t[0]=e[3],t[1]=-e[1],t[2]=-e[2],t[3]=r,t},f.determinant=function(t){return t[0]*t[3]-t[2]*t[1]},f.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],u=r[1],f=r[2],l=r[3];return t[0]=n*s+a*u,t[1]=i*s+o*u,t[2]=n*f+a*l,t[3]=i*f+o*l,t},f.mul=f.multiply,f.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),u=Math.cos(r);return t[0]=n*u+a*s,t[1]=i*u+o*s,t[2]=n*-s+a*u,t[3]=i*-s+o*u,t},f.scale=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],u=r[1];return t[0]=n*s,t[1]=i*s,t[2]=a*u,t[3]=o*u,t},f.str=function(t){return"mat2("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},f.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))},f.LDU=function(t,e,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,e,r]},"undefined"!=typeof t&&(t.mat2=f);var l={};l.create=function(){var t=new r(6);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},l.clone=function(t){var e=new r(6);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e},l.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t},l.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},l.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=r*a-n*i;return u?(u=1/u,t[0]=a*u,t[1]=-n*u,t[2]=-i*u,t[3]=r*u,t[4]=(i*s-a*o)*u,t[5]=(n*o-r*s)*u,t):null},l.determinant=function(t){return t[0]*t[3]-t[1]*t[2]},l.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=r[0],l=r[1],c=r[2],h=r[3],p=r[4],d=r[5];return t[0]=n*f+a*l,t[1]=i*f+o*l,t[2]=n*c+a*h,t[3]=i*c+o*h,t[4]=n*p+a*d+s,t[5]=i*p+o*d+u,t},l.mul=l.multiply,l.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=Math.sin(r),l=Math.cos(r);return t[0]=n*l+a*f,t[1]=i*l+o*f,t[2]=n*-f+a*l,t[3]=i*-f+o*l,t[4]=s,t[5]=u,t},l.scale=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=r[0],l=r[1];return t[0]=n*f,t[1]=i*f,t[2]=a*l,t[3]=o*l,t[4]=s,t[5]=u,t},l.translate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=r[0],l=r[1];return t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=n*f+a*l+s,t[5]=i*f+o*l+u,t},l.str=function(t){return"mat2d("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+")"},l.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)},"undefined"!=typeof t&&(t.mat2d=l);var c={};c.create=function(){var t=new r(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},c.fromMat4=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t},c.clone=function(t){var e=new r(9);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e},c.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t},c.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},c.transpose=function(t,e){if(t===e){var r=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=r,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},c.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=l*o-s*f,h=-l*a+s*u,p=f*a-o*u,d=r*c+n*h+i*p;return d?(d=1/d,t[0]=c*d,t[1]=(-l*n+i*f)*d,t[2]=(s*n-i*o)*d,t[3]=h*d,t[4]=(l*r-i*u)*d,t[5]=(-s*r+i*a)*d,t[6]=p*d,t[7]=(-f*r+n*u)*d,t[8]=(o*r-n*a)*d,t):null},c.adjoint=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8];return t[0]=o*l-s*f,t[1]=i*f-n*l,t[2]=n*s-i*o,t[3]=s*u-a*l,t[4]=r*l-i*u,t[5]=i*a-r*s,t[6]=a*f-o*u,t[7]=n*u-r*f,t[8]=r*o-n*a,t},c.determinant=function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],u=t[7],f=t[8];return e*(f*a-o*u)+r*(-f*i+o*s)+n*(u*i-a*s)},c.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=r[0],p=r[1],d=r[2],g=r[3],m=r[4],v=r[5],y=r[6],b=r[7],_=r[8];return t[0]=h*n+p*o+d*f,t[1]=h*i+p*s+d*l,t[2]=h*a+p*u+d*c,t[3]=g*n+m*o+v*f,t[4]=g*i+m*s+v*l,t[5]=g*a+m*u+v*c,t[6]=y*n+b*o+_*f,t[7]=y*i+b*s+_*l,t[8]=y*a+b*u+_*c,t},c.mul=c.multiply,c.translate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=r[0],p=r[1];return t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=u,t[6]=h*n+p*o+f,t[7]=h*i+p*s+l,t[8]=h*a+p*u+c,t},c.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=Math.sin(r),p=Math.cos(r);return t[0]=p*n+h*o,t[1]=p*i+h*s,t[2]=p*a+h*u,t[3]=p*o-h*n,t[4]=p*s-h*i,t[5]=p*u-h*a,t[6]=f,t[7]=l,t[8]=c,t},c.scale=function(t,e,r){var n=r[0],i=r[1];return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=i*e[3],t[4]=i*e[4],t[5]=i*e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t},c.fromMat2d=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=0,t[3]=e[2],t[4]=e[3],t[5]=0,t[6]=e[4],t[7]=e[5],t[8]=1,t},c.fromQuat=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r+r,s=n+n,u=i+i,f=r*o,l=n*o,c=n*s,h=i*o,p=i*s,d=i*u,g=a*o,m=a*s,v=a*u;return t[0]=1-c-d,t[3]=l-v,t[6]=h+m,t[1]=l+v,t[4]=1-f-d,t[7]=p-g,t[2]=h-m,t[5]=p+g,t[8]=1-f-c,t},c.normalFromMat4=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=e[9],h=e[10],p=e[11],d=e[12],g=e[13],m=e[14],v=e[15],y=r*s-n*o,b=r*u-i*o,_=r*f-a*o,E=n*u-i*s,w=n*f-a*s,A=i*f-a*u,x=l*g-c*d,T=l*m-h*d,R=l*v-p*d,M=c*m-h*g,I=c*v-p*g,F=h*v-p*m,N=y*F-b*I+_*M+E*R-w*T+A*x;return N?(N=1/N,t[0]=(s*F-u*I+f*M)*N,t[1]=(u*R-o*F-f*T)*N,t[2]=(o*I-s*R+f*x)*N,t[3]=(i*I-n*F-a*M)*N,t[4]=(r*F-i*R+a*T)*N,t[5]=(n*R-r*I-a*x)*N,t[6]=(g*A-m*w+v*E)*N,t[7]=(m*_-d*A-v*b)*N,t[8]=(d*w-g*_+v*y)*N,t):null},c.str=function(t){return"mat3("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+")"},c.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))},"undefined"!=typeof t&&(t.mat3=c);var h={};h.create=function(){var t=new r(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},h.clone=function(t){var e=new r(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},h.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},h.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},h.transpose=function(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],a=e[6],o=e[7],s=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=a,t[11]=e[14],t[12]=i,t[13]=o,t[14]=s}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t},h.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=e[9],h=e[10],p=e[11],d=e[12],g=e[13],m=e[14],v=e[15],y=r*s-n*o,b=r*u-i*o,_=r*f-a*o,E=n*u-i*s,w=n*f-a*s,A=i*f-a*u,x=l*g-c*d,T=l*m-h*d,R=l*v-p*d,M=c*m-h*g,I=c*v-p*g,F=h*v-p*m,N=y*F-b*I+_*M+E*R-w*T+A*x;return N?(N=1/N,t[0]=(s*F-u*I+f*M)*N,t[1]=(i*I-n*F-a*M)*N,t[2]=(g*A-m*w+v*E)*N,t[3]=(h*w-c*A-p*E)*N,t[4]=(u*R-o*F-f*T)*N,t[5]=(r*F-i*R+a*T)*N,t[6]=(m*_-d*A-v*b)*N,t[7]=(l*A-h*_+p*b)*N,t[8]=(o*I-s*R+f*x)*N,t[9]=(n*R-r*I-a*x)*N,t[10]=(d*w-g*_+v*y)*N,t[11]=(c*_-l*w-p*y)*N,t[12]=(s*T-o*M-u*x)*N,t[13]=(r*M-n*T+i*x)*N,t[14]=(g*b-d*E-m*y)*N,t[15]=(l*E-c*b+h*y)*N,t):null},h.adjoint=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=e[9],h=e[10],p=e[11],d=e[12],g=e[13],m=e[14],v=e[15];return t[0]=s*(h*v-p*m)-c*(u*v-f*m)+g*(u*p-f*h),t[1]=-(n*(h*v-p*m)-c*(i*v-a*m)+g*(i*p-a*h)),t[2]=n*(u*v-f*m)-s*(i*v-a*m)+g*(i*f-a*u),t[3]=-(n*(u*p-f*h)-s*(i*p-a*h)+c*(i*f-a*u)),t[4]=-(o*(h*v-p*m)-l*(u*v-f*m)+d*(u*p-f*h)),t[5]=r*(h*v-p*m)-l*(i*v-a*m)+d*(i*p-a*h),t[6]=-(r*(u*v-f*m)-o*(i*v-a*m)+d*(i*f-a*u)),t[7]=r*(u*p-f*h)-o*(i*p-a*h)+l*(i*f-a*u),t[8]=o*(c*v-p*g)-l*(s*v-f*g)+d*(s*p-f*c),t[9]=-(r*(c*v-p*g)-l*(n*v-a*g)+d*(n*p-a*c)),t[10]=r*(s*v-f*g)-o*(n*v-a*g)+d*(n*f-a*s),t[11]=-(r*(s*p-f*c)-o*(n*p-a*c)+l*(n*f-a*s)),t[12]=-(o*(c*m-h*g)-l*(s*m-u*g)+d*(s*h-u*c)),t[13]=r*(c*m-h*g)-l*(n*m-i*g)+d*(n*h-i*c),t[14]=-(r*(s*m-u*g)-o*(n*m-i*g)+d*(n*u-i*s)),t[15]=r*(s*h-u*c)-o*(n*h-i*c)+l*(n*u-i*s),t},h.determinant=function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],u=t[7],f=t[8],l=t[9],c=t[10],h=t[11],p=t[12],d=t[13],g=t[14],m=t[15],v=e*o-r*a,y=e*s-n*a,b=e*u-i*a,_=r*s-n*o,E=r*u-i*o,w=n*u-i*s,A=f*d-l*p,x=f*g-c*p,T=f*m-h*p,R=l*g-c*d,M=l*m-h*d,I=c*m-h*g;return v*I-y*M+b*R+_*T-E*x+w*A},h.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=e[9],p=e[10],d=e[11],g=e[12],m=e[13],v=e[14],y=e[15],b=r[0],_=r[1],E=r[2],w=r[3];return t[0]=b*n+_*s+E*c+w*g,t[1]=b*i+_*u+E*h+w*m,t[2]=b*a+_*f+E*p+w*v,t[3]=b*o+_*l+E*d+w*y,b=r[4],_=r[5],E=r[6],w=r[7],t[4]=b*n+_*s+E*c+w*g,t[5]=b*i+_*u+E*h+w*m,t[6]=b*a+_*f+E*p+w*v,t[7]=b*o+_*l+E*d+w*y,b=r[8],_=r[9],E=r[10],w=r[11],t[8]=b*n+_*s+E*c+w*g,t[9]=b*i+_*u+E*h+w*m,t[10]=b*a+_*f+E*p+w*v,t[11]=b*o+_*l+E*d+w*y,b=r[12],_=r[13],E=r[14],w=r[15],t[12]=b*n+_*s+E*c+w*g,t[13]=b*i+_*u+E*h+w*m,t[14]=b*a+_*f+E*p+w*v,t[15]=b*o+_*l+E*d+w*y,t},h.mul=h.multiply,h.translate=function(t,e,r){var n,i,a,o,s,u,f,l,c,h,p,d,g=r[0],m=r[1],v=r[2];return e===t?(t[12]=e[0]*g+e[4]*m+e[8]*v+e[12],t[13]=e[1]*g+e[5]*m+e[9]*v+e[13],t[14]=e[2]*g+e[6]*m+e[10]*v+e[14],t[15]=e[3]*g+e[7]*m+e[11]*v+e[15]):(n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=e[9],p=e[10],d=e[11],t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=u,t[6]=f,t[7]=l,t[8]=c,t[9]=h,t[10]=p,t[11]=d,t[12]=n*g+s*m+c*v+e[12],t[13]=i*g+u*m+h*v+e[13],t[14]=a*g+f*m+p*v+e[14],t[15]=o*g+l*m+d*v+e[15]),t},h.scale=function(t,e,r){var n=r[0],i=r[1],a=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*a,t[9]=e[9]*a,t[10]=e[10]*a,t[11]=e[11]*a,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},h.rotate=function(t,r,n,i){var a,o,s,u,f,l,c,h,p,d,g,m,v,y,b,_,E,w,A,x,T,R,M,I,F=i[0],N=i[1],U=i[2],S=Math.sqrt(F*F+N*N+U*U);return Math.abs(S)o?(s.cross(t,e,i),s.length(t)<1e-6&&s.cross(t,r,i),s.normalize(t,t),p.setAxisAngle(n,t,Math.PI),n):o>.999999?(n[0]=0,n[1]=0,n[2]=0,n[3]=1,n):(s.cross(t,i,a),n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=1+o,p.normalize(n,n))}}(),p.setAxes=function(){var t=c.create();return function(e,r,n,i){return t[0]=n[0],t[3]=n[1],t[6]=n[2],t[1]=i[0],t[4]=i[1],t[7]=i[2],t[2]=-r[0],t[5]=-r[1],t[8]=-r[2],p.normalize(e,p.fromMat3(e,t))}}(),p.clone=u.clone,p.fromValues=u.fromValues,p.copy=u.copy,p.set=u.set,p.identity=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t},p.setAxisAngle=function(t,e,r){r=.5*r;var n=Math.sin(r);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(r),t},p.add=u.add,p.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],u=r[1],f=r[2],l=r[3];return t[0]=n*l+o*s+i*f-a*u,t[1]=i*l+o*u+a*s-n*f,t[2]=a*l+o*f+n*u-i*s,t[3]=o*l-n*s-i*u-a*f,t},p.mul=p.multiply,p.scale=u.scale,p.rotateX=function(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),u=Math.cos(r);return t[0]=n*u+o*s,t[1]=i*u+a*s,t[2]=a*u-i*s,t[3]=o*u-n*s,t},p.rotateY=function(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),u=Math.cos(r);return t[0]=n*u-a*s,t[1]=i*u+o*s,t[2]=a*u+n*s,t[3]=o*u-i*s,t},p.rotateZ=function(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),u=Math.cos(r);return t[0]=n*u+i*s,t[1]=i*u-n*s,t[2]=a*u+o*s,t[3]=o*u-a*s,t},p.calculateW=function(t,e){var r=e[0],n=e[1],i=e[2];return t[0]=r,t[1]=n,t[2]=i,t[3]=-Math.sqrt(Math.abs(1-r*r-n*n-i*i)),t},p.dot=u.dot,p.lerp=u.lerp,p.slerp=function(t,e,r,n){var i,a,o,s,u,f=e[0],l=e[1],c=e[2],h=e[3],p=r[0],d=r[1],g=r[2],m=r[3];return a=f*p+l*d+c*g+h*m,0>a&&(a=-a,p=-p,d=-d,g=-g,m=-m),1-a>1e-6?(i=Math.acos(a),o=Math.sin(i),s=Math.sin((1-n)*i)/o,u=Math.sin(n*i)/o):(s=1-n,u=n),t[0]=s*f+u*p,t[1]=s*l+u*d,t[2]=s*c+u*g,t[3]=s*h+u*m,t},p.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a,s=o?1/o:0;return t[0]=-r*s,t[1]=-n*s,t[2]=-i*s,t[3]=a*s,t},p.conjugate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},p.length=u.length,p.len=p.length,p.squaredLength=u.squaredLength,p.sqrLen=p.squaredLength,p.normalize=u.normalize,p.fromMat3=function(t,e){var r,n=e[0]+e[4]+e[8];if(n>0)r=Math.sqrt(n+1),t[3]=.5*r,r=.5/r,t[0]=(e[7]-e[5])*r,t[1]=(e[2]-e[6])*r,t[2]=(e[3]-e[1])*r;else{var i=0;e[4]>e[0]&&(i=1),e[8]>e[3*i+i]&&(i=2);var a=(i+1)%3,o=(i+2)%3;r=Math.sqrt(e[3*i+i]-e[3*a+a]-e[3*o+o]+1),t[i]=.5*r,r=.5/r,t[3]=(e[3*o+a]-e[3*a+o])*r,t[a]=(e[3*a+i]+e[3*i+a])*r,t[o]=(e[3*o+i]+e[3*i+o])*r}return t},p.str=function(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},"undefined"!=typeof t&&(t.quat=p)}(e.exports)}(this)},{}],179:[function(t,e){"use strict";function r(t,e,r){this.rotation=t,this.center=e,this.distance=r}function n(t,e){var r=e[0],n=e[1],i=(e[2],r*r+n*n);i>1&&(i=1),t[0]=-e[0],t[1]=e[1],t[2]=e[2]||Math.sqrt(1-i),t[3]=0}function i(t,e,n){t=t||[0,0,-1],e=e||[0,0,0],n=n||[0,1,0];var i=new r(f.create(),o.create(),1);return i.lookAt(t,e,n),i}var a=t("gl-matrix"),o=a.vec3,s=a.mat3,u=a.mat4,f=a.quat,l=new Float32Array(16),c=new Float32Array(16),h=r.prototype;h.view=function(t){return t||(t=u.create()),c[0]=c[1]=0,c[2]=-this.distance,u.fromRotationTranslation(t,f.conjugate(l,this.rotation),c),u.translate(t,t,o.negate(l,this.center)),t},h.lookAt=function(t,e,r){u.lookAt(l,t,e,r),s.fromMat4(l,l),f.fromMat3(this.rotation,l),o.copy(this.center,e),this.distance=o.distance(t,e)},h.pan=function(t){var e=this.distance;l[0]=-e*(t[0]||0),l[1]=e*(t[1]||0),l[2]=e*(t[2]||0),o.transformQuat(l,l,this.rotation),o.add(this.center,this.center,l)},h.zoom=function(t){this.distance+=t,this.distance<0&&(this.distance=0)},h.rotate=function(t,e){n(l,t),n(c,e),f.invert(c,c),f.multiply(l,l,c),f.length(l)<1e-6||(f.multiply(this.rotation,this.rotation,l),f.normalize(this.rotation,this.rotation))},e.exports=i},{"gl-matrix":178}],180:[function(t,e){(function(t){e.exports=t.performance&&t.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],181:[function(t,e){function r(t,e,r){t.positions&&t.cells&&(r=e,e=t.cells,t=t.positions),r=r||new Float32Array(9*e.length);for(var n=0,i=0,a=e.length;a>n;n+=1)r[i++]=t[e[n][0]][0],r[i++]=t[e[n][0]][1],r[i++]=t[e[n][0]][2],r[i++]=t[e[n][1]][0],r[i++]=t[e[n][1]][1],r[i++]=t[e[n][1]][2],r[i++]=t[e[n][2]][0],r[i++]=t[e[n][2]][1],r[i++]=t[e[n][2]][2];return r}e.exports=r},{}],182:[function(t,e){function r(t,e){if("string"!=typeof t)throw new TypeError("String expected");e||(e=document);var r=/<([\w:]+)/.exec(t);if(!r)return e.createTextNode(t);t=t.replace(/^\s+|\s+$/g,"");var i=r[1];if("body"==i){var a=e.createElement("html");return a.innerHTML=t,a.removeChild(a.lastChild)}var o=n[i]||n._default,s=o[0],u=o[1],f=o[2],a=e.createElement("div");for(a.innerHTML=u+t+f;s--;)a=a.lastChild;if(a.firstChild==a.lastChild)return a.removeChild(a.firstChild);for(var l=e.createDocumentFragment();a.firstChild;)l.appendChild(a.removeChild(a.firstChild));return l}e.exports=r;var n={legend:[1,"
      ","
      "],tr:[2,"","
      "],col:[2,"","
      "],_default:[0,"",""]};n.td=n.th=[3,"","
      "],n.option=n.optgroup=[1,'"],n.thead=n.tbody=n.colgroup=n.caption=n.tfoot=[1,"","
      "],n.text=n.circle=n.ellipse=n.line=n.path=n.polygon=n.polyline=n.rect=[1,'',""]},{}],183:[function(t,e){function r(t,e){for("string"==typeof e&&(e=n(e)),"function"!=typeof e&&(e=i(e));t&&!e(t);)t=t.parentNode;return t||null}function n(t){return t=String(t).toUpperCase(),function(e){return t===e.nodeName}}function i(t){return function(e){return t===e}}e.exports=r},{}],184:[function(t,e,r){arguments[4][27][0].apply(r,arguments)},{_process:192,"raf-component":185,sliced:187}],185:[function(t,e){e.exports=t(28)},{}],186:[function(t,e,r){function n(t,e){e=e||{};var r=i(t);return r(e)}function i(t){for(var e,r=[],n=o(t),i=0;i/g,">")}r=e.exports=n,r.compile=i},{}],187:[function(t,e,r){arguments[4][29][0].apply(r,arguments)},{"./lib/sliced":188}],188:[function(t,e){e.exports=t(30)},{}],189:[function(t,e,r){function n(t,e,r){if(!(this instanceof n))return new n(t,e,r);var i,a=typeof t;if("number"===a)i=t>0?t>>>0:0;else if("string"===a)"base64"===e&&(t=I(t)),i=n.byteLength(t,e);else{if("object"!==a||null===t)throw new Error("First argument needs to be a number, array or string.");"Buffer"===t.type&&N(t.data)&&(t=t.data),i=+t.length>0?Math.floor(+t.length):0}var o;X?o=n._augment(new Uint8Array(i)):(o=this,o.length=i,o._isBuffer=!0);var s;if(X&&"number"==typeof t.byteLength)o._set(t);else if(U(t))if(n.isBuffer(t))for(s=0;i>s;s++)o[s]=t.readUInt8(s);else for(s=0;i>s;s++)o[s]=(t[s]%256+256)%256;else if("string"===a)o.write(t,0,e);else if("number"===a&&!X&&!r)for(s=0;i>s;s++)o[s]=0;return o}function i(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var a=e.length;q(a%2===0,"Invalid hex string"),n>a/2&&(n=a/2);for(var o=0;n>o;o++){var s=parseInt(e.substr(2*o,2),16);q(!isNaN(s),"Invalid hex string"),t[r+o]=s}return o}function a(t,e,r,n){var i=P(D(e),t,r,n);return i}function o(t,e,r,n){var i=P(L(e),t,r,n);return i}function s(t,e,r,n){return o(t,e,r,n)}function u(t,e,r,n){var i=P(B(e),t,r,n);return i}function f(t,e,r,n){var i=P(j(e),t,r,n);return i}function l(t,e,r){return G.fromByteArray(0===e&&r===t.length?t:t.slice(e,r))}function c(t,e,r){var n="",i="";r=Math.min(t.length,r);for(var a=e;r>a;a++)t[a]<=127?(n+=O(i)+String.fromCharCode(t[a]),i=""):i+="%"+t[a].toString(16);return n+O(i)}function h(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;r>i;i++)n+=String.fromCharCode(t[i]);return n}function p(t,e,r){return h(t,e,r)}function d(t,e,r){var n=t.length;(!e||0>e)&&(e=0),(!r||0>r||r>n)&&(r=n);for(var i="",a=e;r>a;a++)i+=S(t[a]);return i}function g(t,e,r){for(var n=t.slice(e,r),i="",a=0;a=i)){var a;return r?(a=t[e],i>e+1&&(a|=t[e+1]<<8)):(a=t[e]<<8,i>e+1&&(a|=t[e+1])),a}}function v(t,e,r,n){n||(q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+3=i)){var a;return r?(i>e+2&&(a=t[e+2]<<16),i>e+1&&(a|=t[e+1]<<8),a|=t[e],i>e+3&&(a+=t[e+3]<<24>>>0)):(i>e+1&&(a=t[e+1]<<16),i>e+2&&(a|=t[e+2]<<8),i>e+3&&(a|=t[e+3]),a+=t[e]<<24>>>0),a}}function y(t,e,r,n){n||(q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+1=i)){var a=m(t,e,r,!0),o=32768&a;return o?-1*(65535-a+1):a}}function b(t,e,r,n){n||(q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+3=i)){var a=v(t,e,r,!0),o=2147483648&a;return o?-1*(4294967295-a+1):a}}function _(t,e,r,n){return n||(q("boolean"==typeof r,"missing or invalid endian"),q(e+3=a)){for(var o=0,s=Math.min(a-r,2);s>o;o++)t[r+o]=(e&255<<8*(n?o:1-o))>>>8*(n?o:1-o);return r+2}}function A(t,e,r,n,i){i||(q(void 0!==e&&null!==e,"missing value"),q("boolean"==typeof n,"missing or invalid endian"),q(void 0!==r&&null!==r,"missing offset"),q(r+3=a)){for(var o=0,s=Math.min(a-r,4);s>o;o++)t[r+o]=e>>>8*(n?o:3-o)&255;return r+4}}function x(t,e,r,n,i){i||(q(void 0!==e&&null!==e,"missing value"),q("boolean"==typeof n,"missing or invalid endian"),q(void 0!==r&&null!==r,"missing offset"),q(r+1=a))return e>=0?w(t,e,r,n,i):w(t,65535+e+1,r,n,i),r+2}function T(t,e,r,n,i){i||(q(void 0!==e&&null!==e,"missing value"),q("boolean"==typeof n,"missing or invalid endian"),q(void 0!==r&&null!==r,"missing offset"),q(r+3=a))return e>=0?A(t,e,r,n,i):A(t,4294967295+e+1,r,n,i),r+4}function R(t,e,r,n,i){i||(q(void 0!==e&&null!==e,"missing value"),q("boolean"==typeof n,"missing or invalid endian"),q(void 0!==r&&null!==r,"missing offset"),q(r+3=a))return z.write(t,e,r,n,23,4),r+4}function M(t,e,r,n,i){i||(q(void 0!==e&&null!==e,"missing value"),q("boolean"==typeof n,"missing or invalid endian"),q(void 0!==r&&null!==r,"missing offset"),q(r+7=a))return z.write(t,e,r,n,52,8),r+8}function I(t){for(t=F(t).replace(H,"");t.length%4!==0;)t+="=";return t}function F(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function N(t){return(Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)})(t)}function U(t){return N(t)||n.isBuffer(t)||t&&"object"==typeof t&&"number"==typeof t.length}function S(t){return 16>t?"0"+t.toString(16):t.toString(16)}function D(t){for(var e=[],r=0;r=n)e.push(n);else{var i=r;n>=55296&&57343>=n&&r++;for(var a=encodeURIComponent(t.slice(i,r+1)).substr(1).split("%"),o=0;o>8,n=e%256,i.push(n),i.push(r);return i}function B(t){return G.toByteArray(t)}function P(t,e,r,n){for(var i=0;n>i&&!(i+r>=e.length||i>=t.length);i++)e[i+r]=t[i];return i}function O(t){try{return decodeURIComponent(t)}catch(e){return String.fromCharCode(65533)}}function C(t,e){q("number"==typeof t,"cannot write a non-number as a number"),q(t>=0,"specified a negative value for writing an unsigned value"),q(e>=t,"value is larger than maximum value for type"),q(Math.floor(t)===t,"value has a fractional component")}function k(t,e,r){q("number"==typeof t,"cannot write a non-number as a number"),q(e>=t,"value larger than maximum allowed value"),q(t>=r,"value smaller than minimum allowed value"),q(Math.floor(t)===t,"value has a fractional component")}function V(t,e,r){q("number"==typeof t,"cannot write a non-number as a number"),q(e>=t,"value larger than maximum allowed value"),q(t>=r,"value smaller than minimum allowed value")}function q(t,e){if(!t)throw new Error(e||"Failed assertion")}var G=t("base64-js"),z=t("ieee754");r.Buffer=n,r.SlowBuffer=n,r.INSPECT_MAX_BYTES=50,n.poolSize=8192;var X=function(){try{var t=new ArrayBuffer(0),e=new Uint8Array(t);return e.foo=function(){return 42},42===e.foo()&&"function"==typeof e.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(r){return!1}}();n.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},n.isBuffer=function(t){return!(null==t||!t._isBuffer)},n.byteLength=function(t,e){var r;switch(t=t.toString(),e||"utf8"){case"hex":r=t.length/2;break;case"utf8":case"utf-8":r=D(t).length;break;case"ascii":case"binary":case"raw":r=t.length;break;case"base64":r=B(t).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":r=2*t.length;break;default:throw new Error("Unknown encoding")}return r},n.concat=function(t,e){if(q(N(t),"Usage: Buffer.concat(list[, length])"),0===t.length)return new n(0);if(1===t.length)return t[0];var r;if(void 0===e)for(e=0,r=0;ra&&t[a]===e[a];a++);return a!==o&&(r=t[a],i=e[a]),i>r?-1:r>i?1:0},n.prototype.write=function(t,e,r,n){if(isFinite(e))isFinite(r)||(n=r,r=void 0);else{var l=n;n=e,e=r,r=l}e=Number(e)||0;var c=this.length-e;r?(r=Number(r),r>c&&(r=c)):r=c,n=String(n||"utf8").toLowerCase();var h;switch(n){case"hex":h=i(this,t,e,r);break;case"utf8":case"utf-8":h=a(this,t,e,r);break;case"ascii":h=o(this,t,e,r);break;case"binary":h=s(this,t,e,r);break;case"base64":h=u(this,t,e,r);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":h=f(this,t,e,r);break;default:throw new Error("Unknown encoding")}return h},n.prototype.toString=function(t,e,r){var n=this;if(t=String(t||"utf8").toLowerCase(),e=Number(e)||0,r=void 0===r?n.length:Number(r),r===e)return"";var i;switch(t){case"hex":i=d(n,e,r);break;case"utf8":case"utf-8":i=c(n,e,r);break;case"ascii":i=h(n,e,r);break;case"binary":i=p(n,e,r);break;case"base64":i=l(n,e,r);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":i=g(n,e,r);break;default:throw new Error("Unknown encoding")}return i},n.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},n.prototype.equals=function(t){return q(n.isBuffer(t),"Argument must be a Buffer"),0===n.compare(this,t)},n.prototype.compare=function(t){return q(n.isBuffer(t),"Argument must be a Buffer"),n.compare(this,t)},n.prototype.copy=function(t,e,r,n){var i=this;if(r||(r=0),n||0===n||(n=this.length),e||(e=0),n!==r&&0!==t.length&&0!==i.length){q(n>=r,"sourceEnd < sourceStart"),q(e>=0&&e=0&&r=0&&n<=i.length,"sourceEnd out of bounds"),n>this.length&&(n=this.length),t.length-ea||!X)for(var o=0;a>o;o++)t[o+e]=this[o+r];else t._set(this.subarray(r,r+a),e)}},n.prototype.slice=function(t,e){var r=this.length;if(t=~~t,e=void 0===e?r:~~e,0>t?(t+=r,0>t&&(t=0)):t>r&&(t=r),0>e?(e+=r,0>e&&(e=0)):e>r&&(e=r),t>e&&(e=t),X)return n._augment(this.subarray(t,e));for(var i=e-t,a=new n(i,void 0,!0),o=0;i>o;o++)a[o]=this[o+t];return a},n.prototype.get=function(t){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(t)},n.prototype.set=function(t,e){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(t,e)},n.prototype.readUInt8=function(t,e){return e||(q(void 0!==t&&null!==t,"missing offset"),q(t=this.length?void 0:this[t]},n.prototype.readUInt16LE=function(t,e){return m(this,t,!0,e)},n.prototype.readUInt16BE=function(t,e){return m(this,t,!1,e)},n.prototype.readUInt32LE=function(t,e){return v(this,t,!0,e)},n.prototype.readUInt32BE=function(t,e){return v(this,t,!1,e)},n.prototype.readInt8=function(t,e){if(e||(q(void 0!==t&&null!==t,"missing offset"),q(t=this.length)){var r=128&this[t];return r?-1*(255-this[t]+1):this[t]}},n.prototype.readInt16LE=function(t,e){return y(this,t,!0,e)},n.prototype.readInt16BE=function(t,e){return y(this,t,!1,e)},n.prototype.readInt32LE=function(t,e){return b(this,t,!0,e)},n.prototype.readInt32BE=function(t,e){return b(this,t,!1,e)},n.prototype.readFloatLE=function(t,e){return _(this,t,!0,e)},n.prototype.readFloatBE=function(t,e){return _(this,t,!1,e)},n.prototype.readDoubleLE=function(t,e){return E(this,t,!0,e)},n.prototype.readDoubleBE=function(t,e){return E(this,t,!1,e)},n.prototype.writeUInt8=function(t,e,r){return r||(q(void 0!==t&&null!==t,"missing value"),q(void 0!==e&&null!==e,"missing offset"),q(e=this.length?void 0:(this[e]=t,e+1)},n.prototype.writeUInt16LE=function(t,e,r){return w(this,t,e,!0,r)},n.prototype.writeUInt16BE=function(t,e,r){return w(this,t,e,!1,r)},n.prototype.writeUInt32LE=function(t,e,r){return A(this,t,e,!0,r)},n.prototype.writeUInt32BE=function(t,e,r){return A(this,t,e,!1,r)},n.prototype.writeInt8=function(t,e,r){return r||(q(void 0!==t&&null!==t,"missing value"),q(void 0!==e&&null!==e,"missing offset"),q(e=this.length?void 0:(t>=0?this.writeUInt8(t,e,r):this.writeUInt8(255+t+1,e,r),e+1)},n.prototype.writeInt16LE=function(t,e,r){return x(this,t,e,!0,r)},n.prototype.writeInt16BE=function(t,e,r){return x(this,t,e,!1,r)},n.prototype.writeInt32LE=function(t,e,r){return T(this,t,e,!0,r)},n.prototype.writeInt32BE=function(t,e,r){return T(this,t,e,!1,r)},n.prototype.writeFloatLE=function(t,e,r){return R(this,t,e,!0,r)},n.prototype.writeFloatBE=function(t,e,r){return R(this,t,e,!1,r)},n.prototype.writeDoubleLE=function(t,e,r){return M(this,t,e,!0,r)},n.prototype.writeDoubleBE=function(t,e,r){return M(this,t,e,!1,r)},n.prototype.fill=function(t,e,r){if(t||(t=0),e||(e=0),r||(r=this.length),q(r>=e,"end < start"),r!==e&&0!==this.length){q(e>=0&&e=0&&r<=this.length,"end out of bounds");var n;if("number"==typeof t)for(n=e;r>n;n++)this[n]=t;else{var i=D(t.toString()),a=i.length;for(n=e;r>n;n++)this[n]=i[n%a]}return this}},n.prototype.inspect=function(){for(var t=[],e=this.length,n=0;e>n;n++)if(t[n]=S(this[n]),n===r.INSPECT_MAX_BYTES){t[n+1]="...";break}return""},n.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(X)return new n(this).buffer;for(var t=new Uint8Array(this.length),e=0,r=t.length;r>e;e+=1)t[e]=this[e];return t.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var Y=n.prototype;n._augment=function(t){return t._isBuffer=!0,t._get=t.get,t._set=t.set,t.get=Y.get,t.set=Y.set,t.write=Y.write,t.toString=Y.toString,t.toLocaleString=Y.toString,t.toJSON=Y.toJSON,t.equals=Y.equals,t.compare=Y.compare,t.copy=Y.copy,t.slice=Y.slice,t.readUInt8=Y.readUInt8,t.readUInt16LE=Y.readUInt16LE,t.readUInt16BE=Y.readUInt16BE,t.readUInt32LE=Y.readUInt32LE,t.readUInt32BE=Y.readUInt32BE,t.readInt8=Y.readInt8,t.readInt16LE=Y.readInt16LE,t.readInt16BE=Y.readInt16BE,t.readInt32LE=Y.readInt32LE,t.readInt32BE=Y.readInt32BE,t.readFloatLE=Y.readFloatLE,t.readFloatBE=Y.readFloatBE,t.readDoubleLE=Y.readDoubleLE,t.readDoubleBE=Y.readDoubleBE,t.writeUInt8=Y.writeUInt8,t.writeUInt16LE=Y.writeUInt16LE,t.writeUInt16BE=Y.writeUInt16BE,t.writeUInt32LE=Y.writeUInt32LE,t.writeUInt32BE=Y.writeUInt32BE,t.writeInt8=Y.writeInt8,t.writeInt16LE=Y.writeInt16LE,t.writeInt16BE=Y.writeInt16BE,t.writeInt32LE=Y.writeInt32LE,t.writeInt32BE=Y.writeInt32BE,t.writeFloatLE=Y.writeFloatLE,t.writeFloatBE=Y.writeFloatBE,t.writeDoubleLE=Y.writeDoubleLE,t.writeDoubleBE=Y.writeDoubleBE,t.fill=Y.fill,t.inspect=Y.inspect,t.toArrayBuffer=Y.toArrayBuffer,t};var H=/[^+\/0-9A-z]/g},{"base64-js":190,ieee754:191}],190:[function(t,e,r){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(t){"use strict";function e(t){var e=t.charCodeAt(0);return e===o?62:e===s?63:u>e?-1:u+10>e?e-u+26+26:l+26>e?e-l:f+26>e?e-f+26:void 0}function r(t){function r(t){f[c++]=t}var n,i,o,s,u,f;if(t.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var l=t.length;u="="===t.charAt(l-2)?2:"="===t.charAt(l-1)?1:0,f=new a(3*t.length/4-u),o=u>0?t.length-4:t.length;var c=0;for(n=0,i=0;o>n;n+=4,i+=3)s=e(t.charAt(n))<<18|e(t.charAt(n+1))<<12|e(t.charAt(n+2))<<6|e(t.charAt(n+3)),r((16711680&s)>>16),r((65280&s)>>8),r(255&s);return 2===u?(s=e(t.charAt(n))<<2|e(t.charAt(n+1))>>4,r(255&s)):1===u&&(s=e(t.charAt(n))<<10|e(t.charAt(n+1))<<4|e(t.charAt(n+2))>>2,r(s>>8&255),r(255&s)),f}function i(t){function e(t){return n.charAt(t)}function r(t){return e(t>>18&63)+e(t>>12&63)+e(t>>6&63)+e(63&t)}var i,a,o,s=t.length%3,u="";for(i=0,o=t.length-s;o>i;i+=3)a=(t[i]<<16)+(t[i+1]<<8)+t[i+2],u+=r(a);switch(s){case 1:a=t[t.length-1],u+=e(a>>2),u+=e(a<<4&63),u+="==";break;case 2:a=(t[t.length-2]<<8)+t[t.length-1],u+=e(a>>10),u+=e(a>>4&63),u+=e(a<<2&63),u+="="}return u}var a="undefined"!=typeof Uint8Array?Uint8Array:Array,o="+".charCodeAt(0),s="/".charCodeAt(0),u="0".charCodeAt(0),f="a".charCodeAt(0),l="A".charCodeAt(0);t.toByteArray=r,t.fromByteArray=i}("undefined"==typeof r?this.base64js={}:r)},{}],191:[function(t,e,r){r.read=function(t,e,r,n,i){var a,o,s=8*i-n-1,u=(1<>1,l=-7,c=r?i-1:0,h=r?-1:1,p=t[e+c];for(c+=h,a=p&(1<<-l)-1,p>>=-l,l+=s;l>0;a=256*a+t[e+c],c+=h,l-=8);for(o=a&(1<<-l)-1,a>>=-l,l+=n;l>0;o=256*o+t[e+c],c+=h,l-=8);if(0===a)a=1-f;else{if(a===u)return o?0/0:1/0*(p?-1:1);o+=Math.pow(2,n),a-=f}return(p?-1:1)*o*Math.pow(2,a-n)},r.write=function(t,e,r,n,i,a){var o,s,u,f=8*a-i-1,l=(1<>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:a-1,d=n?1:-1,g=0>e||0===e&&0>1/e?1:0;for(e=Math.abs(e),isNaN(e)||1/0===e?(s=isNaN(e)?1:0,o=l):(o=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-o))<1&&(o--,u*=2),e+=o+c>=1?h/u:h*Math.pow(2,1-c),e*u>=2&&(o++,u/=2),o+c>=l?(s=0,o=l):o+c>=1?(s=(e*u-1)*Math.pow(2,i),o+=c):(s=e*Math.pow(2,c-1)*Math.pow(2,i),o=0));i>=8;t[r+p]=255&s,p+=d,s/=256,i-=8);for(o=o<0;t[r+p]=255&o,p+=d,o/=256,f-=8);t[r+p-d]|=128*g}},{}],192:[function(t,e){function r(){}var n=e.exports={};n.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var r=[];return window.addEventListener("message",function(t){var e=t.source;if((e===window||null===e)&&"process-tick"===t.data&&(t.stopPropagation(),r.length>0)){var n=r.shift();n()}},!0),function(t){r.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.on=r,n.addListener=r,n.once=r,n.off=r,n.removeListener=r,n.removeAllListeners=r,n.emit=r,n.binding=function(){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file diff --git a/index.css b/index.css index 8dbb581..ad6d015 100644 --- a/index.css +++ b/index.css @@ -91,6 +91,11 @@ h1 .lighter { z-index: 1; } +#grid { + background-image: url(bg.jpg); + background-size: cover; +} + /** * Section Layout */ diff --git a/index.js b/index.js index d51be74..eb00ee9 100644 --- a/index.js +++ b/index.js @@ -8,8 +8,13 @@ var grid = document.getElementById('grid').querySelector('canvas') var flock = document.getElementById('community').querySelector('canvas') require('./lib/fill')(document.querySelectorAll('[data-fill]')) -require('@stackgl/splash-grid')(grid) -require('@stackgl/splash-flock')(flock) + +try { + require('@stackgl/splash-grid')(grid) + require('@stackgl/splash-flock')(flock) +} catch(e) { + console.error(e.message) +} var thumb = minstache.compile(fs.readFileSync( __dirname + '/lib/thumb.html' diff --git a/package.json b/package.json index 6081f76..053aa80 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "prestart": "npm run links && node data/regenerate", "start": "beefy index.js:bundle.js --open", "postinstall": "npm run links && scoped-bulk stackgl npm install && npm dedupe", - "bundle": "npm run prestart && browserify index.js -o bundle.js", + "bundle": "npm run prestart && browserify index.js | uglifyjs -cm > bundle.js", "links": "district stackgl splash-grid splash-flock" }, "repository": { @@ -48,6 +48,7 @@ }, "homepage": "https://github.com/gl-modules/gl-modules.github.io", "devDependencies": { - "beefy": "^2.0.3" + "beefy": "^2.0.3", + "uglify-js": "^2.4.15" } } diff --git a/splash-grid/index.js b/splash-grid/index.js index 01c34f8..2756acd 100644 --- a/splash-grid/index.js +++ b/splash-grid/index.js @@ -60,7 +60,7 @@ module.exports = function(canvas) { mat4.translate(model, model, [-0.5, 0, -0.5]) window.addEventListener('resize' - , debounce(fit(canvas)) + , debounce(fit(canvas, window)) , false ) diff --git a/splash-grid/package.json b/splash-grid/package.json index c431a00..c31619b 100644 --- a/splash-grid/package.json +++ b/splash-grid/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "a-big-triangle": "0.0.0", - "canvas-fit": "^1.0.0", + "canvas-fit": "^1.2.0", "canvas-orbit-camera": "0.0.0", "clone": "^0.1.17", "cube-cube": "^1.0.0", From 5ed69b36e499fc0d51c6f3e2d5dd2f9101d64b3a Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 15 Sep 2014 03:15:19 +0200 Subject: [PATCH 12/64] disable mangling, was breaking templates --- bundle.js | 16 +++++++++------- package.json | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bundle.js b/bundle.js index b831ab7..d518659 100644 --- a/bundle.js +++ b/bundle.js @@ -1,7 +1,9 @@ -!function t(e,r,n){function i(o,s){if(!r[o]){if(!e[o]){var u="function"==typeof require&&require;if(!s&&u)return u(o,!0);if(a)return a(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=r[o]={exports:{}};e[o][0].call(l.exports,function(t){var r=e[o][1][t];return i(r?r:t)},l,l.exports,t,e,r,n)}return r[o].exports}for(var a="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"raymarch",link:"https://github.com/mikolalysenko/raymarch/",desc:"",thumb:"http://imgur.com/NpvsXIH.png",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(t,e){e.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],Tools:[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2}],Math:[{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:2},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:3}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:5}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0}],Internals:[{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:4},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:5}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4}]}},{}],3:[function(t){var e=t("./lib/filter"),r=t("minstache"),n=t("domify"),i=(t("sliced"),document.getElementById("grid").querySelector("canvas")),a=document.getElementById("community").querySelector("canvas");t("./lib/fill")(document.querySelectorAll("[data-fill]"));try{t("@stackgl/splash-grid")(i),t("@stackgl/splash-flock")(a)}catch(o){console.error(o.message)}var s=r.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),u=t("./build/examples.json").map(function(t){return s(t)}).join("\n"),f=t("./build/packages.json");f=Object.keys(f).reduce(function(t,e){return t.concat(f[e].map(function(t){return t.group=e,t}))},[]).map(function(t){return s(t)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(n(u));var l=document.getElementById("packages");l.querySelector("ul.thumb-list").appendChild(n(f)),l.querySelector("ul.thumb-filter").appendChild(e(l))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(t,e){function r(t){function e(){for(var e=window.innerWidth+"px",r=window.innerHeight+"px",n=0;n{{name}}\n{{/category}}\n');e.exports=function(t){var e=a(t.querySelectorAll("[data-filter]")),n=e.reduce(function(t,e){var r=e.getAttribute("data-filter");return-1===t.indexOf(r)&&t.push(r),t},[]);n.unshift(o),n=n.map(function(t){return{name:t}});var u=i(s({category:n})),f=u.children[0];return f.setAttribute("class","selected"),a(u.children).forEach(function(t){var n=t.getAttribute("data-name");t.addEventListener("click",function(i){i.preventDefault(),i.stopPropagation();var a=r(i.target,"li");if(a!==t)return!1;f.setAttribute("class",""),f=a,f.setAttribute("class","selected");for(var s=0;sb;b++)v[b]=h(l,[d,d],{"float":!0}),v[b].color[0].setPixels(y);window.addEventListener("resize",u(f(e,window))),m.logic=t("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(l),m.render=t("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(l)}function n(t){return t.push(t.shift()),t}function i(t,e){for(var r=new Float32Array(e*e),n=0,i=0;e>i;i++)for(var a=0;e>a;a++)r[n++]=i/e,r[n++]=a/e;var o=l(t,r),s=p(t,[{buffer:o,type:t.FLOAT,size:2}]);return s.length=r.length/2,s}function a(t){for(var e=new Float32Array(t*t*4),r=0;r=a&&i.length>r)return t.bufferData(e,i,n),i.length;if(i.length+a>r)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return t.bufferSubData(e,a,i),r}function i(t,e){for(var r=o.malloc(t.length,e),n=t.length,i=0;n>i;++i)r[i]=t[i];return r}function a(t,e,n,i){void 0===n&&(n=e,e=t.ARRAY_BUFFER),i||(i=t.DYNAMIC_DRAW);var a=0,f=t.createBuffer();if(t.bindBuffer(e,f),"number"==typeof n)t.bufferData(e,n,i),a=n;else if(n instanceof Array)e===t.ELEMENT_ARRAY_BUFFER?t.bufferData(e,new Uint16Array(n),i):t.bufferData(e,new Float32Array(n),i),a=n.length;else if(n.length)t.bufferData(e,n,i),a=n.length;else{if(!n.shape)throw new Error("gl-buffer: Invalid format for buffer data");var l=n.dtype;if(("float64"===l||"array"===l||"generic"===l)&&(l="float32"),e===t.ELEMENT_ARRAY_BUFFER&&(l="uint16"),1!==n.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var a=n.shape[0];if(l===n.type&&1===n.stride[0])t.bufferData(e,n.data.subarray(n.offset,n.offset+a),i);else{var c=o.malloc(n.shape[0],l),h=u(c);s.assign(h,n),t.bufferData(e,c,i),o.free(c)}}if(e!==t.ARRAY_BUFFER&&e!==t.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(i!==t.DYNAMIC_DRAW&&i!==t.STATIC_DRAW&&i!==t.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new r(t,e,f,a,i)}var o=t("typedarray-pool"),s=t("ndarray-ops"),u=t("ndarray");r.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},r.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},r.prototype.update=function(t,e){if(e||(e=0),this.bind(),"number"==typeof t){if(e>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,t,this.usage),this.length=t}else if(t.shape){var r=t.dtype;if(("float64"===r||"array"===r||"generic"===r)&&(r="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(r="uint16"),1!==t.shape.length)throw new Error("gl-buffer: Array length must be 1");if(r===t.dtype&&1===t.stride[0])this.length=0===t.offset&&t.data.length===t.shape[0]?n(this.gl,this.type,this.length,this.usage,t.data,e):n(this.gl,this.type,this.length,this.usage,t.data.subarray(t.offset,t.shape[0]),e);else{var a=o.malloc(t.shape[0],r),f=u(a);s.assign(f,t),this.length=n(this.gl,this.type,this.length,this.usage,a,e),o.free(a)}}else if(Array.isArray(t))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var l=i(t,"uint16");this.length=n(this.gl,this.type,this.length,this.usage,l.subarray(0,t.length),e),o.freeUint16(l)}else{var l=i(t,"float32");this.length=n(this.gl,this.type,this.length,this.usage,l.subarray(0,t.length),e),o.freeFloat32(l)}else this.length=n(this.gl,this.type,this.length,this.usage,t,e)},r.prototype.draw=function(t,e,r){r=r||0;var n=this.gl;if(this.type===n.ARRAY_BUFFER)n.drawArrays(t,r,e);else{if(this.type!==n.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),n.drawElements(t,e,n.UNSIGNED_SHORT,r)}},e.exports=a},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(t,e,r){"use strict";function n(t){if(!t)return s;for(var e=0;e>",rrshift:">>>"};!function(){for(var t in u){var e=u[t];r[t]=a({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+e+"c"},funcName:t}),r[t+"eq"]=a({args:["array","array"],body:{args:["a","b"],body:"a"+e+"=b"},rvalue:!0,funcName:t+"eq"}),r[t+"s"]=a({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+e+"s"},funcName:t+"s"}),r[t+"seq"]=a({args:["array","scalar"],body:{args:["a","s"],body:"a"+e+"=s"},rvalue:!0,funcName:t+"seq"})}}();var f={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var t in f){var e=f[t];r[t]=a({args:["array","array"],body:{args:["a","b"],body:"a="+e+"b"},funcName:t}),r[t+"eq"]=a({args:["array"],body:{args:["a"],body:"a="+e+"a"},rvalue:!0,count:2,funcName:t+"eq"})}}();var l={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var t in l){var e=l[t];r[t]=a({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+e+"c"},funcName:t}),r[t+"s"]=a({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+e+"s"},funcName:t+"s"}),r[t+"eq"]=a({args:["array","array"],body:{args:["a","b"],body:"a=a"+e+"b"},rvalue:!0,count:2,funcName:t+"eq"}),r[t+"seq"]=a({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+e+"s"},rvalue:!0,count:2,funcName:t+"seq"})}}();var c=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var t=0;tthis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),r.norm1=o({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),r.sup=o({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),r.inf=o({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),r.random=a({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),r.assign=a({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),r.assigns=a({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),r.equals=o({args:["array","array"],pre:s,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(t,e){"use strict";function r(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function n(t){var e=new r;e.pre=t.pre,e.body=t.body,e.post=t.post;var n=t.args.slice(0);e.argTypes=n;for(var a=0;a0)throw new Error("cwise: pre() block may not reference array args");if(a0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===o)e.scalarArgs.push(a),e.shimArgs.push("scalar"+a);else if("index"===o){if(e.indexArgs.push(a),a0)throw new Error("cwise: pre() block may not reference array index");if(a0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===o){if(e.shapeArgs.push(a),an.length)throw new Error("cwise: Too many arguments in pre() block");if(e.body.args.length>n.length)throw new Error("cwise: Too many arguments in body() block");if(e.post.args.length>n.length)throw new Error("cwise: Too many arguments in post() block");return e.debug=!!t.printCode||!!t.debug,e.funcName=t.funcName||"cwise",e.blockSize=t.blockSize||64,i(e)}var i=t("./lib/thunk.js");e.exports=n},{"./lib/thunk.js":12}],11:[function(t,e){"use strict";function r(t,e,r){var n,i,a=t.length,o=e.arrayArgs.length,s=e.indexArgs.length>0,u=[],f=[],l=0,c=0;for(n=0;a>n;++n)f.push(["i",n,"=0"].join(""));for(i=0;o>i;++i)for(n=0;a>n;++n)c=l,l=t[n],f.push(0===n?["d",i,"s",n,"=t",i,"p",l].join(""):["d",i,"s",n,"=(t",i,"p",l,"-s",c,"*t",i,"p",c,")"].join(""));for(u.push("var "+f.join(",")),n=a-1;n>=0;--n)l=t[n],u.push(["for(i",n,"=0;i",n,"n;++n){for(c=l,l=t[n],i=0;o>i;++i)u.push(["p",i,"+=d",i,"s",n].join(""));s&&(n>0&&u.push(["index[",c,"]-=s",c].join("")),u.push(["++index[",l,"]"].join(""))),u.push("}")}return u.join("\n")}function n(t,e,n,i){for(var a=e.length,o=n.arrayArgs.length,s=n.blockSize,u=n.indexArgs.length>0,f=[],l=0;o>l;++l)f.push(["var offset",l,"=p",l].join(""));for(var l=t;a>l;++l)f.push(["for(var j"+l+"=SS[",e[l],"]|0;j",l,">0;){"].join("")),f.push(["if(j",l,"<",s,"){"].join("")),f.push(["s",e[l],"=j",l].join("")),f.push(["j",l,"=0"].join("")),f.push(["}else{s",e[l],"=",s].join("")),f.push(["j",l,"-=",s,"}"].join("")),u&&f.push(["index[",e[l],"]=j",l].join(""));for(var l=0;o>l;++l){for(var c=["offset"+l],h=t;a>h;++h)c.push(["j",h,"*t",l,"p",e[h]].join(""));f.push(["p",l,"=(",c.join("+"),")"].join(""))}f.push(r(e,n,i));for(var l=t;a>l;++l)f.push("}");return f.join("\n")}function i(t){for(var e=0,r=t[0].length;r>e;){for(var n=1;n0&&(r=r&&e[n]===e[n-1])}return r?e[0]:e.join("")}function s(t,e){for(var s=0|e[1].length,f=new Array(t.arrayArgs.length),l=new Array(t.arrayArgs.length),c=["SS"],h=["'use strict'"],p=[],d=0;s>d;++d)p.push(["s",d,"=SS[",d,"]"].join(""));for(var g=0;gd;++d)p.push(["t",g,"p",d,"=t",g,"[",d,"]"].join(""))}for(var g=0;g0&&p.push("shape=SS.slice(0)"),t.indexArgs.length>0){for(var m=new Array(s),g=0;s>g;++g)m[g]="0";p.push(["index=[",m.join(","),"]"].join(""))}for(var g=0;g3&&h.push(a(t.pre,t,l));var _=a(t.body,t,l),E=i(f);h.push(s>E?n(E,f[0],t,_):r(f[0],t,_)),t.post.body.length>3&&h.push(a(t.post,t,l)),t.debug&&console.log("Generated cwise routine for ",e,":\n\n",h.join("\n"));var w=[t.funcName||"unnamed","_cwise_loop_",f[0].join("s"),"m",E,o(l)].join(""),A=new Function(["function ",w,"(",c.join(","),"){",h.join("\n"),"} return ",w].join(""));return A()}var u=t("uniq");e.exports=s},{uniq:13}],12:[function(t,e){"use strict";function r(t){var e=["'use strict'","var CACHED={}"],r=[],i=t.funcName+"_cwise_thunk";e.push(["return function ",i,"(",t.shimArgs.join(","),"){"].join(""));for(var a=[],o=[],s=[["array",t.arrayArgs[0],".shape"].join("")],u=0;uo;++o)if(a=i,i=t[o],e(i,a)){if(o===r){r++;continue}t[r++]=i}return t.length=r,t}function n(t){for(var e=1,r=t.length,n=t[0],i=t[0],a=1;r>a;++a,i=n)if(i=n,n=t[a],n!==i){if(a===e){e++;continue}t[e++]=n}return t.length=e,t}function i(t,e,i){return 0===t.length?t:e?(i||t.sort(e),r(t,e)):(i||t.sort(),n(t))}e.exports=i},{}],14:[function(t,e){(function(r){function n(t,e){return t[0]-e[0]}function i(){var t,e=this.stride,r=new Array(e.length);for(t=0;te&&(r="View_Nil"+t);var n="generic"===t;if(-1===e){var a="function "+r+"(a){this.data=a;};var proto="+r+".prototype;proto.dtype='"+t+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+r+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+r+"(a){return new "+r+"(a);}",o=new Function(a);return o()}if(0===e){var a="function "+r+"(a,d) {this.data = a;this.offset = d};var proto="+r+".prototype;proto.dtype='"+t+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+r+"_copy() {return new "+r+"(this.data,this.offset)};proto.pick=function "+r+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+r+"_get(){return "+(n?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+r+"_set(v){return "+(n?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+r+"(a,b,c,d){return new "+r+"(a,d)}",o=new Function("TrivialArray",a);return o(h[t][0])}var a=["'use strict'"],s=u(e),l=s.map(function(t){return"i"+t}),c="this.offset+"+s.map(function(t){return"this._stride"+t+"*i"+t}).join("+");a.push("function "+r+"(a,"+s.map(function(t){return"b"+t}).join(",")+","+s.map(function(t){return"c"+t}).join(",")+",d){this.data=a");for(var p=0;e>p;++p)a.push("this._shape"+p+"=b"+p+"|0");for(var p=0;e>p;++p)a.push("this._stride"+p+"=c"+p+"|0");a.push("this.offset=d|0}","var proto="+r+".prototype","proto.dtype='"+t+"'","proto.dimension="+e);var d="VStride"+e+"d"+t,g="VShape"+e+"d"+t,m={stride:d,shape:g};for(var v in m){var y=m[v];a.push("function "+y+"(v) {this._v=v} var aproto="+y+".prototype","aproto.length="+e);for(var b=[],p=0;e>p;++p)b.push(["this._v._",v,p].join(""));a.push("aproto.toJSON=function "+y+"_toJSON(){return ["+b.join(",")+"]}","aproto.valueOf=aproto.toString=function "+y+"_toString(){return ["+b.join(",")+"].join()}");for(var p=0;e>p;++p)a.push("Object.defineProperty(aproto,"+p+",{get:function(){return this._v._"+v+p+"},set:function(v){return this._v._"+v+p+"=v|0},enumerable:true})");for(var p=0;pp;++p)a.push("this._"+v+p+"=v["+p+"]|0");a.push("return v}})")}a.push("Object.defineProperty(proto,'size',{get:function "+r+"_size(){return "+s.map(function(t){return"this._shape"+t}).join("*"),"}})"),1===e?a.push("proto.order=[0]"):(a.push("Object.defineProperty(proto,'order',{get:"),4>e?(a.push("function "+r+"_order(){"),2===e?a.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===e&&a.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):a.push("ORDER})")),a.push("proto.set=function "+r+"_set("+l.join(",")+",v){"),a.push(n?"return this.data.set("+c+",v)}":"return this.data["+c+"]=v}"),a.push("proto.get=function "+r+"_get("+l.join(",")+"){"),a.push(n?"return this.data.get("+c+")}":"return this.data["+c+"]}"),a.push("proto.index=function "+r+"_index(",l.join(),"){return "+c+"}"),a.push("proto.hi=function "+r+"_hi("+l.join(",")+"){return new "+r+"(this.data,"+s.map(function(t){return["(typeof i",t,"!=='number'||i",t,"<0)?this._shape",t,":i",t,"|0"].join("")}).join(",")+","+s.map(function(t){return"this._stride"+t}).join(",")+",this.offset)}");var _=s.map(function(t){return"a"+t+"=this._shape"+t}),E=s.map(function(t){return"c"+t+"=this._stride"+t});a.push("proto.lo=function "+r+"_lo("+l.join(",")+"){var b=this.offset,d=0,"+_.join(",")+","+E.join(","));for(var p=0;e>p;++p)a.push("if(typeof i"+p+"==='number'&&i"+p+">=0){d=i"+p+"|0;b+=c"+p+"*d;a"+p+"-=d}");a.push("return new "+r+"(this.data,"+s.map(function(t){return"a"+t}).join(",")+","+s.map(function(t){return"c"+t}).join(",")+",b)}"),a.push("proto.step=function "+r+"_step("+l.join(",")+"){var "+s.map(function(t){return"a"+t+"=this._shape"+t}).join(",")+","+s.map(function(t){return"b"+t+"=this._stride"+t}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var p=0;e>p;++p)a.push("if(typeof i"+p+"==='number'){d=i"+p+"|0;if(d<0){c+=b"+p+"*(a"+p+"-1);a"+p+"=ceil(-a"+p+"/d)}else{a"+p+"=ceil(a"+p+"/d)}b"+p+"*=d}");a.push("return new "+r+"(this.data,"+s.map(function(t){return"a"+t}).join(",")+","+s.map(function(t){return"b"+t}).join(",")+",c)}");for(var w=new Array(e),A=new Array(e),p=0;e>p;++p)w[p]="a[i"+p+"]",A[p]="b[i"+p+"]";a.push("proto.transpose=function "+r+"_transpose("+l+"){"+l.map(function(t,e){return t+"=("+t+"===undefined?"+e+":"+t+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+r+"(this.data,"+w.join(",")+","+A.join(",")+",this.offset)}"),a.push("proto.pick=function "+r+"_pick("+l+"){var a=[],b=[],c=this.offset");for(var p=0;e>p;++p)a.push("if(typeof i"+p+"==='number'&&i"+p+">=0){c=(c+this._stride"+p+"*i"+p+")|0}else{a.push(this._shape"+p+");b.push(this._stride"+p+")}");a.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),a.push("return function construct_"+r+"(data,shape,stride,offset){return new "+r+"(data,"+s.map(function(t){return"shape["+t+"]"}).join(",")+","+s.map(function(t){return"stride["+t+"]"}).join(",")+",offset)}");var o=new Function("CTOR_LIST","ORDER",a.join("\n"));return o(h[t],i)}function o(t){if(c&&r.isBuffer(t))return"buffer";if(l)switch(Object.prototype.toString.call(t)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(t)?"array":"generic"}function s(t,e,r,n){if(void 0===t){var i=h.array[0];return i([])}"number"==typeof t&&(t=[t]),void 0===e&&(e=[t.length]);var s=e.length;if(void 0===r){r=new Array(s);for(var u=s-1,f=1;u>=0;--u)r[u]=f,f*=e[u]}if(void 0===n){n=0;for(var u=0;s>u;++u)r[u]<0&&(n-=(e[u]-1)*r[u])}for(var l=o(t),c=h[l];c.length<=s+1;)c.push(a(l,c.length-1));var i=c[s+1];return i(t,e,r,n)}var u=t("iota-array"),f=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],l="undefined"!=typeof Float64Array,c="undefined"!=typeof r,h={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};e.exports=s}).call(this,t("buffer").Buffer)},{buffer:189,"iota-array":15}],15:[function(t,e){"use strict";function r(t){for(var e=new Array(t),r=0;t>r;++r)e[r]=r;return e}e.exports=r},{}],16:[function(t,e,r){"use strict";"use restrict";function n(t){var e=32;return t&=-t,t&&e--,65535&t&&(e-=16),16711935&t&&(e-=8),252645135&t&&(e-=4),858993459&t&&(e-=2),1431655765&t&&(e-=1),e}var i=32;r.INT_BITS=i,r.INT_MAX=2147483647,r.INT_MIN=-1<0)-(0>t)},r.abs=function(t){var e=t>>i-1;return(t^e)-e},r.min=function(t,e){return e^(t^e)&-(e>t)},r.max=function(t,e){return t^(t^e)&-(e>t)},r.isPow2=function(t){return!(t&t-1||!t)},r.log2=function(t){var e,r;return e=(t>65535)<<4,t>>>=e,r=(t>255)<<3,t>>>=r,e|=r,r=(t>15)<<2,t>>>=r,e|=r,r=(t>3)<<1,t>>>=r,e|=r,e|t>>1},r.log10=function(t){return t>=1e9?9:t>=1e8?8:t>=1e7?7:t>=1e6?6:t>=1e5?5:t>=1e4?4:t>=1e3?3:t>=100?2:t>=10?1:0},r.popCount=function(t){return t-=t>>>1&1431655765,t=(858993459&t)+(t>>>2&858993459),16843009*(t+(t>>>4)&252645135)>>>24},r.countTrailingZeros=n,r.nextPow2=function(t){return t+=0===t,--t,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t+1},r.prevPow2=function(t){return t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t-(t>>>1)},r.parity=function(t){return t^=t>>>16,t^=t>>>8,t^=t>>>4,t&=15,27030>>>t&1};var a=new Array(256);!function(t){for(var e=0;256>e;++e){var r=e,n=e,i=7;for(r>>>=1;r;r>>>=1)n<<=1,n|=1&r,--i;t[e]=n<>>8&255]<<16|a[t>>>16&255]<<8|a[t>>>24&255]},r.interleave2=function(t,e){return t&=65535,t=16711935&(t|t<<8),t=252645135&(t|t<<4),t=858993459&(t|t<<2),t=1431655765&(t|t<<1),e&=65535,e=16711935&(e|e<<8),e=252645135&(e|e<<4),e=858993459&(e|e<<2),e=1431655765&(e|e<<1),t|e<<1},r.deinterleave2=function(t,e){return t=t>>>e&1431655765,t=858993459&(t|t>>>1),t=252645135&(t|t>>>2),t=16711935&(t|t>>>4),t=65535&(t|t>>>16),t<<16>>16},r.interleave3=function(t,e,r){return t&=1023,t=4278190335&(t|t<<16),t=251719695&(t|t<<8),t=3272356035&(t|t<<4),t=1227133513&(t|t<<2),e&=1023,e=4278190335&(e|e<<16),e=251719695&(e|e<<8),e=3272356035&(e|e<<4),e=1227133513&(e|e<<2),t|=e<<1,r&=1023,r=4278190335&(r|r<<16),r=251719695&(r|r<<8),r=3272356035&(r|r<<4),r=1227133513&(r|r<<2),t|r<<2},r.deinterleave3=function(t,e){return t=t>>>e&1227133513,t=3272356035&(t|t>>>2),t=251719695&(t|t>>>4),t=4278190335&(t|t>>>8),t=1023&(t|t>>>16),t<<22>>22},r.nextCombination=function(t){var e=t|t-1;return e+1|(~e&-~e)-1>>>n(t)+1}},{}],17:[function(t,e){"use strict";function r(t,e,n){var i=0|t[n];if(0>=i)return[];var a,o=new Array(i);if(n===t.length-1)for(a=0;i>a;++a)o[a]=e;else for(a=0;i>a;++a)o[a]=r(t,e,n+1);return o}function n(t,e){var r,n;for(r=new Array(t),n=0;t>n;++n)r[n]=e;return r}function i(t,e){switch("undefined"==typeof e&&(e=0),typeof t){case"number":if(t>0)return n(0|t,e);break;case"object":if("number"==typeof t.length)return r(t,e,0)}return[]}e.exports=i},{}],18:[function(t,e,r){(function(e){"use strict";var n=t("bit-twiddle"),i=t("dup");e.__TYPEDARRAY_POOL||(e.__TYPEDARRAY_POOL={UINT8:i([32,0]),UINT16:i([32,0]),UINT32:i([32,0]),INT8:i([32,0]),INT16:i([32,0]),INT32:i([32,0]),FLOAT:i([32,0]),DOUBLE:i([32,0]),DATA:i([32,0])});var a=e.__TYPEDARRAY_POOL,o=a.UINT8,s=a.UINT16,u=a.UINT32,f=a.INT8,l=a.INT16,c=a.INT32,h=a.FLOAT,p=a.DOUBLE,d=a.DATA;r.free=function(t){if(t instanceof ArrayBuffer){var e=0|t.byteLength,r=n.log2(e);d[r].push(t)}else{var e=0|t.length,r=n.log2(e);t instanceof Uint8Array?o[r].push(t):t instanceof Uint16Array?s[r].push(t):t instanceof Uint32Array?u[r].push(t):t instanceof Int8Array?f[r].push(t):t instanceof Int16Array?l[r].push(t):t instanceof Int32Array?c[r].push(t):t instanceof Float32Array?h[r].push(t):t instanceof Float64Array&&p[r].push(t)}},r.freeUint8=function(t){o[n.log2(t.length)].push(t)},r.freeUint16=function(t){s[n.log2(t.length)].push(t)},r.freeUint32=function(t){u[n.log2(t.length)].push(t)},r.freeInt8=function(t){f[n.log2(t.length)].push(t)},r.freeInt16=function(t){l[n.log2(t.length)].push(t)},r.freeInt32=function(t){c[n.log2(t.length)].push(t)},r.freeFloat32=r.freeFloat=function(t){h[n.log2(t.length)].push(t)},r.freeFloat64=r.freeDouble=function(t){p[n.log2(t.length)].push(t)},r.freeArrayBuffer=function(t){d[n.log2(t.length)].push(t)},r.malloc=function(t,e){t=n.nextPow2(t);var r=n.log2(t);if(void 0===e){var i=d[r];if(i.length>0){var a=i[i.length-1];return i.pop(),a}return new ArrayBuffer(t)}switch(e){case"uint8":var g=o[r];return g.length>0?g.pop():new Uint8Array(t);case"uint16":var m=s[r];return m.length>0?m.pop():new Uint16Array(t);case"uint32":var v=u[r];return v.length>0?v.pop():new Uint32Array(t);case"int8":var y=f[r];return y.length>0?y.pop():new Int8Array(t);case"int16":var b=l[r];return b.length>0?b.pop():new Int16Array(t);case"int32":var _=c[r];return _.length>0?_.pop():new Int32Array(t);case"float":case"float32":var E=h[r];return E.length>0?E.pop():new Float32Array(t);case"double":case"float64":var w=p[r];return w.length>0?w.pop():new Float64Array(t);default:return null}return null},r.mallocUint8=function(t){t=n.nextPow2(t);var e=n.log2(t),r=o[e];return r.length>0?r.pop():new Uint8Array(t)},r.mallocUint16=function(t){t=n.nextPow2(t);var e=n.log2(t),r=s[e];return r.length>0?r.pop():new Uint16Array(t)},r.mallocUint32=function(t){t=n.nextPow2(t);var e=n.log2(t),r=u[e];return r.length>0?r.pop():new Uint32Array(t)},r.mallocInt8=function(t){t=n.nextPow2(t);var e=n.log2(t),r=f[e];return r.length>0?r.pop():new Int8Array(t)},r.mallocInt16=function(t){t=n.nextPow2(t);var e=n.log2(t),r=l[e];return r.length>0?r.pop():new Int16Array(t)},r.mallocInt32=function(t){t=n.nextPow2(t);var e=n.log2(t),r=c[e];return r.length>0?r.pop():new Int32Array(t)},r.mallocFloat32=r.mallocFloat=function(t){t=n.nextPow2(t);var e=n.log2(t),r=h[e];return r.length>0?r.pop():new Float32Array(t)},r.mallocFloat64=r.mallocDouble=function(t){t=n.nextPow2(t);var e=n.log2(t),r=p[e];return r.length>0?r.pop():new Float64Array(t)},r.mallocArrayBuffer=function(t){t=n.nextPow2(t);var e=n.log2(t),r=d[e];return r.length>0?r.pop():new ArrayBuffer(t)},r.clearCache=function(){for(var t=0;32>t;++t)o[t].length=0,s[t].length=0,u[t].length=0,f[t].length=0,l[t].length=0,c[t].length=0,h[t].length=0,p[t].length=0,d[t].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(t,e){"use strict";function r(t,e,r){e?e.bind():t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null);var n=0|t.getParameter(t.MAX_VERTEX_ATTRIBS);if(r){if(r.length>n)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)t.disableVertexAttribArray(i)}else{t.bindBuffer(t.ARRAY_BUFFER,null);for(var i=0;n>i;++i)t.disableVertexAttribArray(i)}}e.exports=r},{}],20:[function(t,e){"use strict";function r(t){this.gl=t,this.elements=null,this.attributes=null}function n(t){return new r(t)}var i=t("./do-bind.js");r.prototype.bind=function(){i(this.gl,this.elements,this.attributes)},r.prototype.update=function(t,e){this.elements=t,this.attributes=e},r.prototype.dispose=function(){},r.prototype.unbind=function(){},e.exports=n},{"./do-bind.js":19}],21:[function(t,e){"use strict";function r(t,e,r){this.gl=t,this.ext=e,this.handle=r}function n(t,e){return new r(t,e,e.createVertexArrayOES())}var i=t("./do-bind.js");r.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},r.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},r.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},r.prototype.update=function(t,e){this.bind(),i(this.gl,t,e),this.unbind()},e.exports=n},{"./do-bind.js":19}],22:[function(t,e){"use strict";function r(t){for(var e=0;ee?Math.max(0,e+i):e||0;for(void 0!==r&&(i=0>r?r+i:r);i-->a;)n[i-a]=t[i];return n}},{}],31:[function(t,e){"use strict";function r(t,e,r,n,i){this.gl=t,this.type=e,this.handle=r,this.length=n,this.usage=i}function n(t,e,r,n,i,a){var o=i.length*i.BYTES_PER_ELEMENT;if(0>a)return t.bufferData(e,i,n),o;if(o+a>r)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return t.bufferSubData(e,a,i),r}function i(t,e){for(var r=s.malloc(t.length,e),n=t.length,i=0;n>i;++i)r[i]=t[i];return r}function a(t,e){for(var r=1,n=e.length-1;n>=0;--n){if(e[n]!==r)return!1;r*=t[n]}return!0}function o(t,e,n,i){if(l(t),n=n||t.ARRAY_BUFFER,i=i||t.DYNAMIC_DRAW,n!==t.ARRAY_BUFFER&&n!==t.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(i!==t.DYNAMIC_DRAW&&i!==t.STATIC_DRAW&&i!==t.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var a=t.createBuffer(),o=new r(t,n,a,0,i);return o.update(e),o}var s=t("typedarray-pool"),u=t("ndarray-ops"),f=t("ndarray"),l=t("webglew"),c=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],h=r.prototype;h.bind=function(){this.gl.bindBuffer(this.type,this.handle)},h.dispose=function(){this.gl.deleteBuffer(this.handle)},h.update=function(t,e){if("number"!=typeof e&&(e=-1),this.bind(),"object"==typeof t&&"undefined"!=typeof t.shape){var r=t.dtype;if(c.indexOf(r)<0&&(r="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var o=l(this.gl),h=o.OES_element_index_uint;r=h&&"uint16"!==r?"uint32":"uint16"}if(r===t.dtype&&a(t.shape,t.stride))this.length=0===t.offset&&t.data.length===t.shape[0]?n(this.gl,this.type,this.length,this.usage,t.data,e):n(this.gl,this.type,this.length,this.usage,t.data.subarray(t.offset,t.shape[0]),e);else{var p=s.malloc(t.size,r),d=f(p,t.shape);u.assign(d,t),this.length=0>e?n(this.gl,this.type,this.length,this.usage,p,e):n(this.gl,this.type,this.length,this.usage,p.subarray(0,t.size),e),s.free(p)}}else if(Array.isArray(t)){var g;g=this.type===this.gl.ELEMENT_ARRAY_BUFFER?i(t,"uint16"):i(t,"float32"),this.length=0>e?n(this.gl,this.type,this.length,this.usage,g,e):n(this.gl,this.type,this.length,this.usage,g.subarray(0,t.length),e),s.free(g)}else if("object"==typeof t&&"number"==typeof t.length)this.length=n(this.gl,this.type,this.length,this.usage,t,e);else{if("number"!=typeof t&&void 0!==t)throw new Error("gl-buffer: Invalid data type");if(e>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");t=0|t,0>=t&&(t=1),this.gl.bufferData(this.type,0|t,this.usage),this.length=t}},e.exports=o},{ndarray:37,"ndarray-ops":32,"typedarray-pool":41,webglew:43}],32:[function(t,e,r){arguments[4][9][0].apply(r,arguments)},{"cwise-compiler":33}],33:[function(t,e,r){arguments[4][10][0].apply(r,arguments)},{"./lib/thunk.js":35}],34:[function(t,e,r){arguments[4][11][0].apply(r,arguments)},{uniq:36}],35:[function(t,e,r){arguments[4][12][0].apply(r,arguments)},{"./compile.js":34}],36:[function(t,e){e.exports=t(13)},{}],37:[function(t,e,r){arguments[4][14][0].apply(r,arguments)},{buffer:189,"iota-array":38}],38:[function(t,e){e.exports=t(15)},{}],39:[function(t,e){e.exports=t(16)},{}],40:[function(t,e){e.exports=t(17)},{}],41:[function(t,e,r){(function(e,n){var i=t("bit-twiddle"),a=t("dup");e.__TYPEDARRAY_POOL||(e.__TYPEDARRAY_POOL={UINT8:a([32,0]),UINT16:a([32,0]),UINT32:a([32,0]),INT8:a([32,0]),INT16:a([32,0]),INT32:a([32,0]),FLOAT:a([32,0]),DOUBLE:a([32,0]),DATA:a([32,0]),UINT8C:a([32,0]),BUFFER:a([32,0])});var o="undefined"!=typeof Uint8ClampedArray,s=e.__TYPEDARRAY_POOL;s.UINT8C||(s.UINT8C=a([32,0])),s.BUFFER||(s.BUFFER=a([32,0]));var u=s.UINT8,f=s.UINT16,l=s.UINT32,c=s.INT8,h=s.INT16,p=s.INT32,d=s.FLOAT,g=s.DOUBLE,m=s.DATA,v=s.UINT8C,y=s.BUFFER;r.free=function(t){var e=0|t.length,r=i.log2(e);if(n.isBuffer(t))y[r].push(t);else switch(Object.prototype.toString.call(t)){case"[object Uint8Array]":u[r].push(t);break;case"[object Uint16Array]":f[r].push(t);break;case"[object Uint32Array]":l[r].push(t);break;case"[object Int8Array]":c[r].push(t);break;case"[object Int16Array]":h[r].push(t);break;case"[object Int32Array]":p[r].push(t);break;case"[object Uint8ClampedArray]":v[r].push(t);break;case"[object Float32Array]":d[r].push(t);break;case"[object Float64Array]":g[r].push(t);break;case"[object ArrayBuffer]":m[r].push(t);break;default:throw new Error("typedarray-pool: Unspecified array type")}},r.freeUint8=function(t){u[i.log2(t.length)].push(t)},r.freeUint16=function(t){f[i.log2(t.length)].push(t)},r.freeUint32=function(t){l[i.log2(t.length)].push(t)},r.freeInt8=function(t){c[i.log2(t.length)].push(t)},r.freeInt16=function(t){h[i.log2(t.length)].push(t)},r.freeInt32=function(t){p[i.log2(t.length)].push(t)},r.freeFloat32=r.freeFloat=function(t){d[i.log2(t.length)].push(t)},r.freeFloat64=r.freeDouble=function(t){g[i.log2(t.length)].push(t)},r.freeArrayBuffer=function(t){m[i.log2(t.length)].push(t)},r.freeUint8Clamped=o?function(t){v[i.log2(t.length)].push(t)}:r.freeUint8,r.freeBuffer=function(t){y[i.log2(t.length)].push(t)},r.malloc=function(t,e){t=i.nextPow2(t);var r=i.log2(t);if(void 0===e||"arraybuffer"===e){var a=m[r];if(a.length>0){var s=a[a.length-1];return a.pop(),s}return new ArrayBuffer(t)}switch(e){case"uint8":var b=u[r];return b.length>0?b.pop():new Uint8Array(t);case"uint16":var _=f[r];return _.length>0?_.pop():new Uint16Array(t);case"uint32":var E=l[r];return E.length>0?E.pop():new Uint32Array(t);case"int8":var w=c[r];return w.length>0?w.pop():new Int8Array(t);case"int16":var A=h[r];return A.length>0?A.pop():new Int16Array(t);case"int32":var x=p[r];return x.length>0?x.pop():new Int32Array(t);case"float":case"float32":var T=d[r];return T.length>0?T.pop():new Float32Array(t);case"double":case"float64":var R=g[r];return R.length>0?R.pop():new Float64Array(t);case"uint8_clamped":if(o){var M=v[r];return M.length>0?M.pop():new Uint8ClampedArray(t)}var b=u[r];return b.length>0?b.pop():new Uint8Array(t);case"buffer":var I=y[r];return I.length>0?I.pop():new n(t);default:return null}return null},r.mallocUint8=function(t){t=i.nextPow2(t);var e=i.log2(t),r=u[e];return r.length>0?r.pop():new Uint8Array(t)},r.mallocUint16=function(t){t=i.nextPow2(t);var e=i.log2(t),r=f[e];return r.length>0?r.pop():new Uint16Array(t)},r.mallocUint32=function(t){t=i.nextPow2(t);var e=i.log2(t),r=l[e];return r.length>0?r.pop():new Uint32Array(t)},r.mallocInt8=function(t){t=i.nextPow2(t);var e=i.log2(t),r=c[e];return r.length>0?r.pop():new Int8Array(t)},r.mallocInt16=function(t){t=i.nextPow2(t);var e=i.log2(t),r=h[e];return r.length>0?r.pop():new Int16Array(t)},r.mallocInt32=function(t){t=i.nextPow2(t);var e=i.log2(t),r=p[e];return r.length>0?r.pop():new Int32Array(t)},r.mallocFloat32=r.mallocFloat=function(t){t=i.nextPow2(t);var e=i.log2(t),r=d[e];return r.length>0?r.pop():new Float32Array(t)},r.mallocFloat64=r.mallocDouble=function(t){t=i.nextPow2(t);var e=i.log2(t),r=g[e];return r.length>0?r.pop():new Float64Array(t)},r.mallocArrayBuffer=function(t){t=i.nextPow2(t);var e=i.log2(t),r=m[e];return r.length>0?r.pop():new ArrayBuffer(t)},r.mallocUint8Clamped=o?function(t){t=i.nextPow2(t);var e=i.log2(t),r=v[e];return r.length>0?r.pop():new Uint8ClampedArray(t)}:r.mallocUint8,r.mallocBuffer=function(t){t=i.nextPow2(t);var e=i.log2(t),r=y[e]; -return r.length>0?r.pop():new n(t)},r.clearCache=function(){for(var t=0;32>t;++t)u[t].length=0,f[t].length=0,l[t].length=0,c[t].length=0,h[t].length=0,p[t].length=0,d[t].length=0,g[t].length=0,m[t].length=0,v[t].length=0,y[t].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},t("buffer").Buffer)},{"bit-twiddle":39,buffer:189,dup:40}],42:[function(t,e,r){void function(t,n,i){function a(t,e,r){return"function"==typeof e&&(r=e,e=o(r).replace(/_$/,"")),f(t,e,{configurable:!0,writable:!0,value:r})}function o(t){return"function"!=typeof t?"":"name"in t?t.name:l.call(t).match(p)[1]}function s(t){function e(e,n){return n||2===arguments.length?r.set(e,n):(n=r.get(e),n===i&&(n=t(e),r.set(e,n))),n}var r=new g;return t||(t=m),e}var u=Object.getOwnPropertyNames,f=Object.defineProperty,l=Function.prototype.toString,c=Object.create,h=Object.prototype.hasOwnProperty,p=/^\n?function\s?(\w*)?_?\(/,d=function(){function t(){var t=o(),n={};this.unlock=function(i){var a=l(i);if(h.call(a,t))return a[t](n);var o=c(null,e);return f(a,t,{value:new Function("s","l",r)(n,o)}),o}}var e={value:{writable:!0,value:i}},r="return function(k){if(k===s)return l}",n=c(null),o=function(){var t=Math.random().toString(36).slice(2);return t in n?o():n[t]=t},s=o(),l=function(t){if(h.call(t,s))return t[s];if(!Object.isExtensible(t))throw new TypeError("Object must be extensible");var e=c(null);return f(t,s,{value:e}),e};return a(Object,function(t){var e=u(t);return h.call(t,s)&&e.splice(e.indexOf(s),1),e}),a(t.prototype,function(t){return this.unlock(t).value}),a(t.prototype,function(t,e){this.unlock(t).value=e}),t}(),g=function(e){function r(e){return this===t||null==this||this===r.prototype?new r(e):(p(this,new d),void m(this,e))}function s(t){h(t);var e=g(this).get(t);return e===n?i:e}function u(t,e){h(t),g(this).set(t,e===i?n:e)}function f(t){return h(t),g(this).get(t)!==i}function l(t){h(t);var e=g(this),r=e.get(t)!==i;return e.set(t,i),r}function c(){return g(this),"[object WeakMap]"}var h=function(t){if(null==t||"object"!=typeof t&&"function"!=typeof t)throw new TypeError("Invalid WeakMap key")},p=function(t,r){var n=e.unlock(t);if(n.value)throw new TypeError("Object is already a WeakMap");n.value=r},g=function(t){var r=e.unlock(t).value;if(!r)throw new TypeError("WeakMap is not generic");return r},m=function(t,e){null!==e&&"object"==typeof e&&"function"==typeof e.forEach&&e.forEach(function(r,n){r instanceof Array&&2===r.length&&u.call(t,e[n][0],e[n][1])})};try{var v=("return "+l).replace("e_","\\u0065"),y=new Function("unwrap","validate",v)(g,h)}catch(b){var y=l}var v=(""+Object).split("Object"),_=function(){return v[0]+o(this)+v[1]};a(_,_);var E={__proto__:[]}instanceof Array?function(t){t.__proto__=_}:function(t){a(t,_)};return E(r),[c,s,u,f,y].forEach(function(t){a(r.prototype,t),E(t)}),r}(new d),m=Object.create?function(){return Object.create(null)}:function(){return{}};"undefined"!=typeof e?e.exports=g:"undefined"!=typeof r?r.WeakMap=g:"WeakMap"in t||(t.WeakMap=g),g.createStorage=s,t.WeakMap&&(t.WeakMap.createStorage=s)}((0,eval)("this"))},{}],43:[function(t,e){"use strict";function r(t){return t.replace(/^[A-Z]+_/,"")}function n(t){var e=a.get(t);if(e)return e;for(var n={},i=t.getSupportedExtensions(),o=0;o=n;++n){for(var i=new Array(r),a=0;n>a;++a)i[a]=t.COLOR_ATTACHMENT0+a;for(var a=n;r>a;++a)i[a]=t.NONE;y[n]=i}}function a(t){switch(t){case d:throw new Error("gl-fbo: Framebuffer unsupported");case g:throw new Error("gl-fbo: Framebuffer incomplete attachment");case m:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case v:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function o(t,e,r,n,i,a){if(!n)return null;var o=p(t,e,r,i,n);return o.magFilter=t.NEAREST,o.minFilter=t.NEAREST,o.mipSamples=1,o.bind(),t.framebufferTexture2D(t.FRAMEBUFFER,a,t.TEXTURE_2D,o.handle,0),o}function s(t,e,r,n,i){var a=t.createRenderbuffer();return t.bindRenderbuffer(t.RENDERBUFFER,a),t.renderbufferStorage(t.RENDERBUFFER,n,e,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,i,t.RENDERBUFFER,a),a}function u(t){var e=r(t.gl),i=t.gl,u=t.handle=i.createFramebuffer(),f=t._shape[0],l=t._shape[1],c=t.color.length,p=t._ext,d=t._useStencil,g=t._useDepth,m=t._colorType,v=h(i);i.bindFramebuffer(i.FRAMEBUFFER,u);for(var b=0;c>b;++b)t.color[b]=o(i,f,l,m,i.RGBA,i.COLOR_ATTACHMENT0+b);0===c?(t._color_rb=s(i,f,l,i.RGBA4,i.COLOR_ATTACHMENT0),p&&p.drawBuffersWEBGL(y[0])):c>1&&p.drawBuffersWEBGL(y[numColor]),v.WEBGL_depth_texture?d?t.depth=o(i,f,l,v.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,i.DEPTH_STENCIL,i.DEPTH_STENCIL_ATTACHMENT):g&&(t.depth=o(i,f,l,i.UNSIGNED_SHORT,i.DEPTH_COMPONENT,i.DEPTH_ATTACHMENT)):g&&d?t._depth_rb=s(i,f,l,i.DEPTH_STENCIL,i.DEPTH_STENCIL_ATTACHMENT):g?t._depth_rb=s(i,f,l,i.DEPTH_COMPONENT16,i.DEPTH_ATTACHMENT):d&&(t._depth_rb=s(i,f,l,i.STENCIL_INDEX,i.STENCIL_ATTACHMENT));var _=i.checkFramebufferStatus(i.FRAMEBUFFER);if(_!==i.FRAMEBUFFER_COMPLETE){t._destroyed=!0,i.bindFramebuffer(i.FRAMEBUFFER,null),i.deleteFramebuffer(t.handle),t.handle=null,t.depth&&(t.depth.dispose(),t.depth=null),t._depth_rb&&(i.deleteRenderbuffer(t._depth_rb),t._depth_rb=null);for(var b=0;bf;++f)this.color[f]=null;this._color_rb=null,this.depth=null,this._depth_rb=null,this._colorType=n,this._useDepth=a,this._useStencil=o;var l=this,c=[0|e,0|r];Object.defineProperties(c,{0:{get:function(){return l._shape[0]},set:function(t){return l.width=t}},1:{get:function(){return l._shape[1]},set:function(t){return l.height=t}}}),this._shapeVector=c,u(this)}function l(t,e,i){if(t._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(t._shape[0]!==e||t._shape[1]!==i){var o=t.gl,s=o.getParameter(o.MAX_RENDERBUFFER_SIZE);if(0>e||e>s||0>i||i>s)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");t._shape[0]=e,t._shape[1]=i;for(var u=r(o),f=0;fe||e>o||0>r||r>o)throw new Error("gl-fbo: Parameters are too large for FBO");n=n||{};var s=1;if("color"in n){if(s=Math.max(0|n.color,0),0>s)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(s>1){var u=a.WEBGL_draw_buffers;if(!u)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(s>t.getParameter(u.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+s+" draw buffers")}}var l=t.UNSIGNED_BYTE;if(n.float&&s>0){if(!a.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");l=t.FLOAT}else n.preferFloat&&s>0&&a.OES_texture_float&&(l=t.FLOAT);var c=!0;"depth"in n&&(c=!!n.depth);var p=!1;return"stencil"in n&&(p=!!n.stencil),new f(t,e,r,l,s,c,p,a.WEBGL_draw_buffers)}var h=t("webglew"),p=t("gl-texture2d");e.exports=c;var d,g,m,v,y=null,b=f.prototype;Object.defineProperties(b,{shape:{get:function(){return this._destroyed?[0,0]:this._shapeVector},set:function(t){if(Array.isArray(t)||(t=[0|t,0|t]),2!==t.length)throw new Error("gl-fbo: Shape vector must be length 2");var e=0|t[0],r=0|t[1];return l(this,e,r),[e,r]},enumerable:!1},width:{get:function(){return this._destroyed?0:this._shape[0]},set:function(t){return t=0|t,l(this,t,this._shape[1]),t},enumerable:!1},height:{get:function(){return this._destroyed?0:this._shape[1]},set:function(t){return t=0|t,l(this,this._shape[0],t),t},enumerable:!1}}),b.bind=function(){if(!this._destroyed){var t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.handle),t.viewport(0,0,this._shape[0],this._shape[1])}},b.dispose=function(){if(!this._destroyed){this._destroyed=!0;var t=this.gl;t.deleteFramebuffer(this.handle),this.handle=null,this.depth&&(this.depth.dispose(),this.depth=null),this._depth_rb&&(t.deleteRenderbuffer(this._depth_rb),this._depth_rb=null);for(var e=0;ee||e>i||0>r||r>i)throw new Error("gl-texture2d: Invalid texture size");return t._shape=[e,r],t.bind(),n.texImage2D(n.TEXTURE_2D,0,t.format,e,r,0,t.format,t.type,null),t._mipLevels=[0],t}function i(t,e,r,n,i,a){this.gl=t,this.handle=e,this.format=i,this.type=a,this._shape=[r,n],this._mipLevels=[0],this._magFilter=t.NEAREST,this._minFilter=t.NEAREST,this._wrapS=t.CLAMP_TO_EDGE,this._wrapT=t.CLAMP_TO_EDGE,this._anisoSamples=1;var o=this,s=[this._wrapS,this._wrapT];Object.defineProperties(s,{0:{get:function(){return o._wrapS},set:function(t){return o.wrapS=t}},1:{get:function(){return o._wrapT},set:function(t){return o.wrapT=t}}}),this._wrapVector=s;var u=[this._shape[0],this._shape[1]];Object.defineProperties(u,{0:{get:function(){return o._shape[0]},set:function(t){return o.width=t}},1:{get:function(){return o._shape[1]},set:function(t){return o.height=t}}}),this._shapeVector=u}function a(t,e){return 3===t.length?1===e[2]&&e[1]===t[0]*t[2]&&e[0]===t[2]:1===e[0]&&e[1]===t[0]}function o(t,e,r,n,i,o,s,u){var f=u.dtype,l=u.shape.slice();if(l.length<2||l.length>3)throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d");var c=0,g=0,m=a(l,u.stride.slice());"float32"===f?c=t.FLOAT:"float64"===f?(c=t.FLOAT,m=!1,f="float32"):"uint8"===f?c=t.UNSIGNED_BYTE:(c=t.UNSIGNED_BYTE,m=!1,f="uint8");var v=1;if(2===l.length)g=t.LUMINANCE,l=[l[0],l[1],1],u=h(u.data,l,[u.stride[0],u.stride[1],1],u.offset);else{if(3!==l.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===l[2])g=t.ALPHA;else if(2===l[2])g=t.LUMINANCE_ALPHA;else if(3===l[2])g=t.RGB;else{if(4!==l[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");g=t.RGBA}v=l[2]}if(g!==t.LUMINANCE&&g!==t.ALPHA||i!==t.LUMINANCE&&i!==t.ALPHA||(g=i),g!==i)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var y=u.size,_=s.indexOf(n)<0;if(_&&s.push(n),c===o&&m)0===u.offset&&u.data.length===y?_?t.texImage2D(t.TEXTURE_2D,n,i,l[0],l[1],0,i,o,u.data):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[0],l[1],i,o,u.data):_?t.texImage2D(t.TEXTURE_2D,n,i,l[0],l[1],0,i,o,u.data.subarray(u.offset,u.offset+y)):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[0],l[1],i,o,u.data.subarray(u.offset,u.offset+y));else{var E;E=o===t.FLOAT?d.mallocFloat32(y):d.mallocUint8(y);var w=h(E,l,[l[2],l[2]*l[0],1]);c===t.FLOAT&&o===t.UNSIGNED_BYTE?b(w,u):p.assign(w,u),_?t.texImage2D(t.TEXTURE_2D,n,i,l[0],l[1],0,i,o,E.subarray(0,y)):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[0],l[1],i,o,E.subarray(0,y)),o===t.FLOAT?d.freeFloat32(E):d.freeUint8(E)}}function s(t){var e=t.createTexture();return t.bindTexture(t.TEXTURE_2D,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),e}function u(t,e,r,n,a){var o=t.getParameter(t.MAX_TEXTURE_SIZE);if(0>e||e>o||0>r||r>o)throw new Error("gl-texture2d: Invalid texture shape");var u=s(t);return t.texImage2D(t.TEXTURE_2D,0,n,e,r,0,n,a,null),new i(t,u,e,r,n,a)}function f(t,e,r,n){var a=s(t);return t.texImage2D(t.TEXTURE_2D,0,r,r,n,e),new i(t,a,0|e.width,0|e.height,r,n)}function l(t,e){var r=e.dtype,n=e.shape.slice(),o=t.getParameter(t.MAX_TEXTURE_SIZE);if(n[0]<0||n[0]>o||n[1]<0||n[1]>o)throw new Error("gl-texture2d: Invalid texture size");var u=a(n,e.stride.slice()),f=0;"float32"===r?f=t.FLOAT:"float64"===r?(f=t.FLOAT,u=!1,r="float32"):"uint8"===r?f=t.UNSIGNED_BYTE:(f=t.UNSIGNED_BYTE,u=!1,r="uint8");var l=0;if(2===n.length)l=t.LUMINANCE,n=[n[0],n[1],1],e=h(e.data,n,[e.stride[0],e.stride[1],1],e.offset);else{if(3!==n.length)throw new Error("Invalid shape for texture");if(1===n[2])l=t.ALPHA;else if(2===n[2])l=t.LUMINANCE_ALPHA;else if(3===n[2])l=t.RGB;else{if(4!==n[2])throw new Error("Invalid shape for pixel coords");l=t.RGBA}}f!==t.FLOAT||g(t).texture_float||(f=t.UNSIGNED_BYTE,u=!1);var c,m,v=e.size;if(u)c=0===e.offset&&e.data.length===v?e.data:e.data.subarray(e.offset,e.offset+v);else{var y=[n[2],n[2]*n[0],1];m=d.malloc(v,r);var _=h(m,n,y,0);"float32"!==r&&"float64"!==r||f!==t.UNSIGNED_BYTE?p.assign(_,e):b(_,e),c=m.subarray(0,v)}var E=s(t);return t.texImage2D(t.TEXTURE_2D,0,l,n[0],n[1],0,l,f,c),u||d.free(m),new i(t,E,n[1],n[0],l,f)}function c(t){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(m||r(t),"number"==typeof arguments[1])return u(t,arguments[1],arguments[2],arguments[3]||t.RGBA,arguments[4]||t.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return u(t,0|arguments[1][0],0|arguments[1][1],arguments[2]||t.RGBA,arguments[4]||t.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var e=arguments[1];if(e instanceof HTMLCanvasElement||e instanceof HTMLImageElement||e instanceof HTMLVideoElement||e instanceof ImageData)return f(t,e,arguments[2]||t.RGBA,arguments[3]||t.UNSIGNED_BYTE);if(e.shape&&e.data&&e.stride)return l(t,e)}throw new Error("Invalid arguments for texture2d constructor")}var h=t("ndarray"),p=t("ndarray-ops"),d=t("typedarray-pool"),g=t("webglew");e.exports=c;var m=null,v=null,y=null,b=function(t,e){p.muls(t,e,255)},_=i.prototype;Object.defineProperties(_,{minFilter:{get:function(){return this._minFilter},set:function(t){this.bind();var e=this.gl;if(this.type===e.FLOAT&&m.indexOf(t)>=0&&(g(e).OES_texture_float_linear||(t=e.NEAREST)),v.indexOf(t)<0)throw new Error("gl-texture2d: Unknown filter mode "+t);return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t),this._minFilter=t}},magFilter:{get:function(){return this._magFilter},set:function(t){this.bind();var e=this.gl;if(this.type===e.FLOAT&&m.indexOf(t)>=0&&(g(e).OES_texture_float_linear||(t=e.NEAREST)),v.indexOf(t)<0)throw new Error("gl-texture2d: Unknown filter mode "+t);return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,t),this._magFilter=t}},mipSamples:{get:function(){return this._anisoSamples},set:function(t){var e=this._anisoSamples;if(this._anisoSamples=0|Math.max(t,1),e!==this._anisoSamples){var r=g(this.gl).EXT_texture_filter_anisotropic;r&&this.gl.texParameterf(this.gl.TEXTURE_2D,r.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}},wrapS:{get:function(){return this._wrapS},set:function(t){if(this.bind(),y.indexOf(t)<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,t),this._wrapS=t}},wrapT:{get:function(){return this._wrapT},set:function(t){if(this.bind(),y.indexOf(t)<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,t),this._wrapT=t}},wrap:{get:function(){return this._wrapVector},set:function(t){if(Array.isArray(t)||(t=[t,t]),2!==t.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var e=0;2>e;++e)if(y.indexOf(t[e])<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);this._wrapS=t[0],this._wrapT=t[1];var r=this.gl;return this.bind(),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,this._wrapS),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,this._wrapT),t}},shape:{get:function(){return this._shapeVector},set:function(t){if(Array.isArray(t)){if(2!==t.length)throw new Error("gl-texture2d: Invalid texture shape")}else t=[0|t,0|t];return n(this,0|t[0],0|t[1]),[0|t[0],0|t[1]]}},width:{get:function(){return this._shape[0]},set:function(t){return t=0|t,n(this,t,this._shape[1]),t}},height:{get:function(){return this._shape[1]},set:function(t){return t=0|t,n(this,this._shape[0],t),t}}}),_.bind=function(t){var e=this.gl;return void 0!==t&&e.activeTexture(e.TEXTURE0+(0|t)),e.bindTexture(e.TEXTURE_2D,this.handle),void 0!==t?t:e.getParameter(e.ACTIVE_TEXTURE)-e.TEXTURE0},_.dispose=function(){this.gl.deleteTexture(this.handle)},_.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var t=Math.min(this._shape[0],this._shape[1]),e=0;t>0;++e,t>>>=1)this._mipLevels.indexOf(e)<0&&this._mipLevels.push(e)},_.setPixels=function(t,e,r,n){var i=this.gl;if(this.bind(),Array.isArray(e)?(n=r,r=0|e[1],e=0|e[0]):(e=e||0,r=r||0),n=n||0,t instanceof HTMLCanvasElement||t instanceof ImageData||t instanceof HTMLImageElement||t instanceof HTMLVideoElement){var a=this._mipLevels.indexOf(n)<0;a?(i.texImage2D(i.TEXTURE_2D,0,this.format,this.format,this.type,t),this._mipLevels.push(n)):i.texSubImage2D(i.TEXTURE_2D,n,e,r,this.format,this.type,t)}else{if(!(t.shape&&t.stride&&t.data))throw new Error("gl-texture2d: Unsupported data type");if(t.shape.length<2||e+t.shape[1]>this._shape[1]>>>n||r+t.shape[0]>this._shape[0]>>>n||0>e||0>r)throw new Error("gl-texture2d: Texture dimensions are out of bounds");o(i,e,r,n,this.format,this.type,this._mipLevels,t)}}},{ndarray:54,"ndarray-ops":49,"typedarray-pool":58,webglew:61}],60:[function(t,e){e.exports=t(42)},{}],61:[function(t,e){e.exports=t(43)},{weakmap:60}],62:[function(t,e,r){arguments[4][9][0].apply(r,arguments)},{"cwise-compiler":63}],63:[function(t,e,r){arguments[4][10][0].apply(r,arguments)},{"./lib/thunk.js":65}],64:[function(t,e,r){arguments[4][11][0].apply(r,arguments)},{uniq:66}],65:[function(t,e,r){arguments[4][12][0].apply(r,arguments)},{"./compile.js":64}],66:[function(t,e){e.exports=t(13)},{}],67:[function(t,e){e.exports=t(16)},{}],68:[function(t,e){e.exports=t(17)},{}],69:[function(t,e){e.exports=t(41)},{"bit-twiddle":67,buffer:189,dup:68}],70:[function(t,e){e.exports=t(42)},{}],71:[function(t,e){e.exports=t(43)},{weakmap:70}],72:[function(t,e,r){arguments[4][59][0].apply(r,arguments)},{ndarray:86,"ndarray-ops":62,"typedarray-pool":69,webglew:71}],73:[function(t,e){"use strict";function r(t,e,r){e?e.bind():t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null);var n=0|t.getParameter(t.MAX_VERTEX_ATTRIBS);if(r){if(r.length>n)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)t.disableVertexAttribArray(i)}else{t.bindBuffer(t.ARRAY_BUFFER,null);for(var i=0;n>i;++i)t.disableVertexAttribArray(i)}}e.exports=r},{}],74:[function(t,e){"use strict";function r(t){this.gl=t,this._elements=null,this._attributes=null,this._elementsType=t.UNSIGNED_SHORT}function n(t){return new r(t)}var i=t("./do-bind.js");r.prototype.bind=function(){i(this.gl,this._elements,this._attributes)},r.prototype.update=function(t,e,r){this._elements=e,this._attributes=t,this._elementsType=r||this.gl.UNSIGNED_SHORT},r.prototype.dispose=function(){},r.prototype.unbind=function(){},r.prototype.draw=function(t,e,r){r=r||0;var n=this.gl;this._elements?n.drawElements(t,e,this._elementsType,r):n.drawArrays(t,r,e)},e.exports=n},{"./do-bind.js":73}],75:[function(t,e){"use strict";function r(t,e,r,n,i,a){this.location=t,this.dimension=e,this.a=r,this.b=n,this.c=i,this.d=a}function n(t,e,r){this.gl=t,this._ext=e,this.handle=r,this._attribs=[],this._useElements=!1,this._elementsType=t.UNSIGNED_SHORT}function i(t,e){return new n(t,e,e.createVertexArrayOES())}var a=t("./do-bind.js");r.prototype.bind=function(t){switch(this.dimension){case 1:t.vertexAttrib1f(this.location,this.a);break;case 2:t.vertexAttrib2f(this.location,this.a,this.b);break;case 3:t.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:t.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},n.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var t=0;tl;++l)u.push("x"+l),f.push("x"+l);u.push(["if(x0.length===undefined){return gl.vertexAttrib",i,"f(v,",f.join(","),")}else{return gl.vertexAttrib",i,"fv(v,x0)}"].join(""));var c=Function.apply(void 0,u),h=new r(t,e,n,i,o,c,s);Object.defineProperty(a,o,{set:function(e){return t.disableVertexAttribArray(h._location),c(t,h._location,e),e},get:function(){return h},enumerable:!0})}function i(t,e,r,i){for(var a={},o=0,s=r.length;s>o;++o){var u=r[o],f=u.name,l=u.type,c=t.getAttribLocation(e,f);switch(l){case"bool":case"int":case"float":n(t,e,c,1,a,f,i);break;default:if(!(l.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+f+": "+l);var h=l.charCodeAt(l.length-1)-48;if(2>h||h>4)throw new Error("Invalid data type for attribute "+f+": "+l);n(t,e,c,h,a,f,i)}}return a}e.exports=i;var a=r.prototype;a.pointer=function(t,e,r,n){var i=this._gl;i.vertexAttribPointer(this._location,this._dimension,t||i.FLOAT,e?i.TRUE:i.FALSE,r||0,n||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(a,"location",{get:function(){return this._location},set:function(t){t!==this._location&&(this._location=t,this._gl.bindAttribLocation(this._program,t,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],82:[function(t,e){"use strict";function r(t){var e=new Function("y","return function(){return y}");return e(t)}function n(t,e,n,o){function s(r){var n=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+r+"])}");return n(t,e,o)}function u(t,e,r){switch(r){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+e+"],obj"+t+")";case"float":return"gl.uniform1f(locations["+e+"],obj"+t+")";default:var n=r.indexOf("vec");if(!(n>=0&&1>=n&&r.length===4+n)){if(0===r.indexOf("mat")&&4===r.length){var i=r.charCodeAt(r.length-1)-48;if(2>i||i>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+r);return"gl.uniformMatrix"+i+"fv(locations["+e+"],false,obj"+t+")"}throw new Error("Unknown uniform data type for "+name+": "+r)}var i=r.charCodeAt(r.length-1)-48;if(2>i||i>4)throw new Error("Invalid data type");switch(r.charAt(0)){case"b":case"i":return"gl.uniform"+i+"iv(locations["+e+"],obj"+t+")";case"v":return"gl.uniform"+i+"fv(locations["+e+"],obj"+t+")";default:throw new Error("Unrecognized data type for vector "+name+": "+r)}}}function f(t,e){if("object"!=typeof e)return[[t,e]];var r=[];for(var n in e){var i=e[n],a=t;a+=parseInt(n)+""===n?"["+n+"]":"."+n,"object"==typeof i?r.push.apply(r,f(a,i)):r.push([a,i])}return r}function l(r){for(var i=["return function updateProperty(obj){"],a=f("",r),s=0;s=0&&1>=e&&t.length===4+e){var r=t.charCodeAt(t.length-1)-48;if(2>r||r>4)throw new Error("Invalid data type");return"b"===t.charAt(0)?i(r,!1):i(r)}if(0===t.indexOf("mat")&&4===t.length){var r=t.charCodeAt(t.length-1)-48;if(2>r||r>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+t);return i([r,r])}throw new Error("Unknown uniform data type for "+name+": "+t)}}function h(t,e,i){if("object"==typeof i){var a=p(i);Object.defineProperty(t,e,{get:r(a),set:l(i),enumerable:!0,configurable:!1})}else o[i]?Object.defineProperty(t,e,{get:s(i),set:l(i),enumerable:!0,configurable:!1}):t[e]=c(n[i].type)}function p(t){var e;if(Array.isArray(t)){e=new Array(t.length);for(var r=0;r1){u[0]in o||(o[u[0]]=[]),o=o[u[0]];for(var f=1;fr)){var n=b()*E;d.bind(),i.viewport(0,0,w,w),i.disable(i.DEPTH_TEST),i.disable(i.CULL_FACE),I.bind(),I.uniforms.uTime=n,I.uniforms.uResolution=A,h(i),i.bindFramebuffer(i.FRAMEBUFFER,null),i.viewport(0,0,t,r),i.enable(i.DEPTH_TEST),i.enable(i.CULL_FACE),f(i),l.perspective(y,Math.PI/4,t/r,.001,100),c.identity(R.rotation),c.rotateY(R.rotation,R.rotation,2e-4*n),c.rotateX(R.rotation,R.rotation,-.5),R.view(x),c.identity(R.rotation),c.rotateY(R.rotation,R.rotation,2e-4*n),F.bind(M),M.uniforms.uResolution=A,M.uniforms.uViewRotation=l.fromQuat(_,R.rotation),M.uniforms.uProjection=y,M.uniforms.uModel=T,M.uniforms.uView=x,M.uniforms.tHeightmap=d.color[0].bind(0),M.uniforms.tGradient=g.bind(1),F.draw(),F.unbind()}}var i=t("gl-context")(e,n),d=u(i,[w,w],{"float":!0}),g=o(i,t("./gradient-map")),m=r(),y=l.create(),_=l.create(),x=l.create(),T=l.create(),R=a([0,10,30],[0,0,0],[0,1,0]),M=t("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(i),I=t("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(i),F=s(i).attr("aPosition",m.positions).attr("aCentroid",m.centroids).attr("aNormal",m.normals).attr("aEdge",m.edges);R.distance=1.5,d.color[0].wrap=i.CLAMP_TO_EDGE,d.color[0].minFilter=i.NEAREST,d.color[0].maxFilter=i.NEAREST,l.translate(T,T,[-.5,0,-.5]),window.addEventListener("resize",p(v(e,window)),!1)}},{"./gradient-map":89,"a-big-triangle":107,"canvas-fit":108,clone:110,"cube-cube":111,"face-normals":114,"frame-debounce":115,"gl-clear":120,"gl-context":121,"gl-fbo":123,"gl-geometry":126,"gl-matrix":151,"gl-texture2d":164,glslify:166,"glslify/adapter.js":165,"mesh-combine":172,"orbit-camera":179,"right-now":180,"unindex-mesh":181}],91:[function(t,e,r){arguments[4][8][0].apply(r,arguments)},{ndarray:97,"ndarray-ops":92,"typedarray-pool":101}],92:[function(t,e,r){arguments[4][9][0].apply(r,arguments)},{"cwise-compiler":93}],93:[function(t,e,r){arguments[4][10][0].apply(r,arguments)},{"./lib/thunk.js":95}],94:[function(t,e,r){arguments[4][11][0].apply(r,arguments)},{uniq:96}],95:[function(t,e,r){arguments[4][12][0].apply(r,arguments)},{"./compile.js":94}],96:[function(t,e){e.exports=t(13)},{}],97:[function(t,e,r){arguments[4][14][0].apply(r,arguments)},{buffer:189,"iota-array":98}],98:[function(t,e){e.exports=t(15)},{}],99:[function(t,e){e.exports=t(16)},{}],100:[function(t,e){e.exports=t(17)},{}],101:[function(t,e){e.exports=t(18)},{"bit-twiddle":99,dup:100}],102:[function(t,e){e.exports=t(19)},{}],103:[function(t,e){e.exports=t(20)},{"./do-bind.js":102}],104:[function(t,e){e.exports=t(21)},{"./do-bind.js":102}],105:[function(t,e){e.exports=t(22)},{}],106:[function(t,e){e.exports=t(23)},{"./lib/vao-emulated.js":103,"./lib/vao-native.js":104,webglew:105}],107:[function(t,e){e.exports=t(24)},{"gl-buffer":91,"gl-vao":106}],108:[function(t,e,r){arguments[4][25][0].apply(r,arguments)},{"element-size":109}],109:[function(t,e){e.exports=t(26)},{}],110:[function(t,e){(function(t){"use strict";function r(t){return Object.prototype.toString.call(t)}function n(e,r,n,a){function o(e,n){if(null===e)return null;if(0==n)return e;var l;if("object"!=typeof e)return e;if(i.isArray(e))l=[];else if(i.isRegExp(e))l=new RegExp(e.source,i.getRegExpFlags(e)),e.lastIndex&&(l.lastIndex=e.lastIndex);else if(i.isDate(e))l=new Date(e.getTime());else{if(f&&t.isBuffer(e))return l=new t(e.length),e.copy(l),l;l=Object.create("undefined"==typeof a?Object.getPrototypeOf(e):a)}if(r){var c=s.indexOf(e);if(-1!=c)return u[c];s.push(e),u.push(l)}for(var h in e)l[h]=o(e[h],n-1);return l}var s=[],u=[],f="undefined"!=typeof t;return"undefined"==typeof r&&(r=!0),"undefined"==typeof n&&(n=1/0),o(e,n)}var i={isArray:function(t){return Array.isArray(t)||"object"==typeof t&&"[object Array]"===r(t)},isDate:function(t){return"object"==typeof t&&"[object Date]"===r(t)},isRegExp:function(t){return"object"==typeof t&&"[object RegExp]"===r(t)},getRegExpFlags:function(t){var e="";return t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),e}};"object"==typeof e&&(e.exports=n),n.clonePrototype=function(t){if(null===t)return null;var e=function(){};return e.prototype=t,new e}}).call(this,t("buffer").Buffer)},{buffer:189}],111:[function(t,e){function r(t,e,r,a){a=a||i;for(var o=[1/t,1/e,1/r],s=[],u=0;t>u;u++)for(var f=0;e>f;f++)for(var l=0;r>l;l++)if(a(u,f,l)){var c=n(o,[u/t,f/e,l/r]);s.push(c),c.centroid=[(u+.5)/t,(f+.5)/e,(l+.5)/r],c.index=[u,f,l]}return s}var n=t("rectangular-prism"),i=function(){return!0};e.exports=r},{"rectangular-prism":113}],112:[function(t,e){e.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],113:[function(t,e){function r(t,e){e=e||[0,0,0],t=t||[1,1,1],Array.isArray(t)||(t=[t,t,t]);for(var r=n(),i=0;in;n+=9){var i=t[n+3]-t[n],a=t[n+4]-t[n+1],o=t[n+5]-t[n+2],s=t[n+6]-t[n],u=t[n+7]-t[n+1],f=t[n+8]-t[n+2],l=a*f-o*u,c=o*s-i*f,h=i*u-a*s,p=Math.sqrt(l*l+c*c+h*h);0===p?(e[n]=0,e[n+1]=0,e[n+2]=0,e[n+3]=0,e[n+4]=0,e[n+5]=0,e[n+6]=0,e[n+7]=0,e[n+8]=0):(l/=p,c/=p,h/=p,e[n]=l,e[n+1]=c,e[n+2]=h,e[n+3]=l,e[n+4]=c,e[n+5]=h,e[n+6]=l,e[n+7]=c,e[n+8]=h)}return e}e.exports=r},{}],115:[function(t,e,r){arguments[4][27][0].apply(r,arguments)},{_process:192,"raf-component":116,sliced:117}],116:[function(t,e){e.exports=t(28)},{}],117:[function(t,e,r){arguments[4][29][0].apply(r,arguments)},{"./lib/sliced":118}],118:[function(t,e){e.exports=t(30)},{}],119:[function(t,e){e.exports=t(44)},{}],120:[function(t,e){e.exports=t(45)},{"./defaults":119}],121:[function(t,e){function r(t,e,r){function i(){r(a),n(i)}"function"==typeof e?(r=e,e={}):e=e||{};var a=t.getContext("webgl",e)||t.getContext("webgl-experimental",e)||t.getContext("experimental-webgl",e);if(!a)throw new Error("Unable to initialize WebGL");return r&&n(i),a}var n=t("raf-component");e.exports=r},{"raf-component":122}],122:[function(t,e){e.exports=t(28)},{}],123:[function(t,e){"use strict";function r(t,e){var r=t.getParameter(e.MAX_COLOR_ATTACHMENTS_WEBGL);g=new Array(r+1);for(var n=0;r>=n;++n){for(var i=new Array(r),a=0;n>a;++a)i[a]=t.COLOR_ATTACHMENT0+a;for(var a=n;r>a;++a)i[a]=t.NONE;g[n]=i}}function n(t){switch(t){case c:throw new Error("gl-fbo: Framebuffer unsupported");case h:throw new Error("gl-fbo: Framebuffer incomplete attachment");case p:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case d:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function i(t,e,r,n,i,a){if(!n)return null;var o=l(t,e,r,i,n);return o.magFilter=t.NEAREST,o.minFilter=t.NEAREST,o.mipSamples=1,t.framebufferTexture2D(t.FRAMEBUFFER,a,t.TEXTURE_2D,o.handle,0),t.bindTexture(t.TEXTURE_2D,null),o}function a(t,e,r,n,i){var a=t.createRenderbuffer();return t.bindRenderbuffer(t.RENDERBUFFER,a),t.renderbufferStorage(t.RENDERBUFFER,n,e,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,i,t.RENDERBUFFER,a),a}function o(t){var e=t.gl,r=t.handle=e.createFramebuffer(),o=t._shape[0],s=t._shape[1],u=t.color.length,l=t._ext,c=t._useStencil,h=t._useDepth,p=t._colorType,d=f(e);e.bindFramebuffer(e.FRAMEBUFFER,r);for(var m=0;u>m;++m)t.color[m]=i(e,s,o,p,e.RGBA,e.COLOR_ATTACHMENT0+m);0===u?(t._color_rb=a(e,s,o,e.RGBA4,e.COLOR_ATTACHMENT0),l&&l.drawBuffersWEBGL(g[0])):u>1&&l.drawBuffersWEBGL(g[numColor]),d.WEBGL_depth_texture?c?t.depth=i(e,s,o,d.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,e.DEPTH_STENCIL,e.DEPTH_STENCIL_ATTACHMENT):h&&(t.depth=i(e,s,o,e.UNSIGNED_SHORT,e.DEPTH_COMPONENT,e.DEPTH_ATTACHMENT)):h&&c?t._depth_rb=a(e,s,o,e.DEPTH_STENCIL,e.DEPTH_STENCIL_ATTACHMENT):h?t._depth_rb=a(e,s,o,e.DEPTH_COMPONENT16,e.DEPTH_ATTACHMENT):c&&(t._depth_rb=a(e,s,o,e.STENCIL_INDEX,e.STENCIL_ATTACHMENT));var v=e.checkFramebufferStatus(e.FRAMEBUFFER);if(v!==e.FRAMEBUFFER_COMPLETE){t._destroyed=!0,e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteFramebuffer(t.handle),t.handle=null,t.depth&&(t.depth.dispose(),t.depth=null),t._depth_rb&&(e.deleteRenderbuffer(t._depth_rb),t._depth_rb=null);for(var m=0;me||e>o||0>n||n>o)throw new Error("gl-fbo: Parameters are too large for FBO");i=i||{};var u=1;if("color"in i){if(u=Math.max(0|i.color,0),0>u)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(u>1){var l=a.WEBGL_draw_buffers;if(!l)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(u>t.getParameter(l.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+u+" draw buffers")}}var m=t.UNSIGNED_BYTE;if(i.float&&u>0){if(!a.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");m=t.FLOAT}else i.preferFloat&&u>0&&a.OES_texture_float&&(m=t.FLOAT);var v=!0;"depth"in i&&(v=!!i.depth);var y=!1;return"stencil"in i&&(y=!!i.stencil),new s(t,e,n,m,u,v,y,a.WEBGL_draw_buffers)}var f=t("webglew"),l=t("gl-texture2d");e.exports=u;var c,h,p,d,g=null,m=s.prototype;Object.defineProperty(m,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(m,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(t){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===t[0]|0&&this._shape[1]===t[1]|0)){var e=this.gl,r=e.getParameter(e.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(t)||2!==t.length||t[0]<0||t[0]>r||t[1]<0||t[1]>r)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|t[0],this._shape[1]=0|t[1];for(var i=0;iu;u++)a[o++]=t[s][u];return a}var n=t("dtype");e.exports=r},{dtype:128}],128:[function(t,e){e.exports=function(t){switch(t){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],129:[function(t,e){"use strict";function r(t,e,r,n,i){this.gl=t,this.type=e,this.handle=r,this.length=n,this.usage=i}function n(t,e,r,n,i,a){var o=i.length*i.BYTES_PER_ELEMENT;if(0>a)return t.bufferData(e,i,n),o;if(o+a>r)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return t.bufferSubData(e,a,i),r}function i(t,e){for(var r=s.malloc(t.length,e),n=t.length,i=0;n>i;++i)r[i]=t[i];return r}function a(t,e){for(var r=1,n=e.length-1;n>=0;--n){if(e[n]!==r)return!1;r*=t[n]}return!0}function o(t,e,n,i){if(l(t),n=n||t.ARRAY_BUFFER,i=i||t.DYNAMIC_DRAW,n!==t.ARRAY_BUFFER&&n!==t.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(i!==t.DYNAMIC_DRAW&&i!==t.STATIC_DRAW&&i!==t.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var a=t.createBuffer(),o=new r(t,n,a,0,i);return o.update(e),o}var s=t("typedarray-pool"),u=t("ndarray-ops"),f=t("ndarray"),l=t("webglew"),c=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],h=r.prototype;h.bind=function(){this.gl.bindBuffer(this.type,this.handle)},h.dispose=function(){this.gl.deleteBuffer(this.handle)},h.update=function(t,e){if("number"!=typeof e&&(e=-1),this.bind(),"object"==typeof t&&"undefined"!=typeof t.shape){var r=t.dtype;if(c.indexOf(r)<0&&(r="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var o=l(gl),h=o.OES_element_index_uint;r=h&&"uint16"!==r?"uint32":"uint16"}if(r===t.dtype&&a(t.shape,t.stride))this.length=0===t.offset&&t.data.length===t.shape[0]?n(this.gl,this.type,this.length,this.usage,t.data,e):n(this.gl,this.type,this.length,this.usage,t.data.subarray(t.offset,t.shape[0]),e);else{var p=s.malloc(t.size,r),d=f(p,t.shape);u.assign(d,t),this.length=0>e?n(this.gl,this.type,this.length,this.usage,p,e):n(this.gl,this.type,this.length,this.usage,p.subarray(0,t.size),e),s.free(p)}}else if(Array.isArray(t)){var g;g=this.type===this.gl.ELEMENT_ARRAY_BUFFER?i(t,"uint16"):i(t,"float32"),this.length=0>e?n(this.gl,this.type,this.length,this.usage,g,e):n(this.gl,this.type,this.length,this.usage,g.subarray(0,t.length),e),s.free(g)}else if("object"==typeof t&&"number"==typeof t.length)this.length=n(this.gl,this.type,this.length,this.usage,t,e);else{if("number"!=typeof t&&void 0!==t)throw new Error("gl-buffer: Invalid data type");if(e>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");t=0|t,0>=t&&(t=1),this.gl.bufferData(this.type,0|t,this.usage),this.length=t}},e.exports=o},{ndarray:135,"ndarray-ops":130,"typedarray-pool":139,webglew:141}],130:[function(t,e,r){arguments[4][9][0].apply(r,arguments)},{"cwise-compiler":131}],131:[function(t,e,r){arguments[4][10][0].apply(r,arguments)},{"./lib/thunk.js":133}],132:[function(t,e,r){arguments[4][11][0].apply(r,arguments)},{uniq:134}],133:[function(t,e,r){arguments[4][12][0].apply(r,arguments)},{"./compile.js":132}],134:[function(t,e){e.exports=t(13)},{}],135:[function(t,e,r){arguments[4][14][0].apply(r,arguments)},{buffer:189,"iota-array":136}],136:[function(t,e){e.exports=t(15)},{}],137:[function(t,e){e.exports=t(16)},{}],138:[function(t,e){e.exports=t(17)},{}],139:[function(t,e){e.exports=t(41)},{"bit-twiddle":137,buffer:189,dup:138}],140:[function(t,e){e.exports=t(42)},{}],141:[function(t,e){e.exports=t(43)},{weakmap:140}],142:[function(t,e){e.exports=t(73)},{}],143:[function(t,e){"use strict";function r(t){this.gl=t,this._elements=null,this._attributes=null}function n(t){return new r(t)}var i=t("./do-bind.js");r.prototype.bind=function(){i(this.gl,this._elements,this._attributes)},r.prototype.update=function(t,e){this._elements=e,this._attributes=t},r.prototype.dispose=function(){},r.prototype.unbind=function(){},r.prototype.draw=function(t,e,r){r=r||0;var n=this.gl;this._elements?n.drawElements(t,e,n.UNSIGNED_SHORT,r):n.drawArrays(t,r,e)},e.exports=n},{"./do-bind.js":142}],144:[function(t,e){"use strict";function r(t,e,r,n,i,a){this.location=t,this.dimension=e,this.a=r,this.b=n,this.c=i,this.d=a}function n(t,e,r){this.gl=t,this._ext=e,this.handle=r,this._attribs=[],this._useElements=!1}function i(t,e){return new n(t,e,e.createVertexArrayOES())}var a=t("./do-bind.js");r.prototype.bind=function(t){switch(this.dimension){case 1:t.vertexAttrib1f(this.location,this.a);break;case 2:t.vertexAttrib2f(this.location,this.a,this.b);break;case 3:t.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:t.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},n.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var t=0;t0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i),t},i.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]},i.cross=function(t,e,r){var n=e[0]*r[1]-e[1]*r[0];return t[0]=t[1]=0,t[2]=n,t},i.lerp=function(t,e,r,n){var i=e[0],a=e[1];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t},i.transformMat2=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[2]*i,t[1]=r[1]*n+r[3]*i,t},i.transformMat2d=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[2]*i+r[4],t[1]=r[1]*n+r[3]*i+r[5],t},i.transformMat3=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[3]*i+r[6],t[1]=r[1]*n+r[4]*i+r[7],t},i.transformMat4=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[4]*i+r[12],t[1]=r[1]*n+r[5]*i+r[13],t},i.forEach=function(){var t=i.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=2),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],a(t,t,o),e[s]=t[0],e[s+1]=t[1];return e}}(),i.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},"undefined"!=typeof t&&(t.vec2=i);var a={};a.create=function(){var t=new r(3);return t[0]=0,t[1]=0,t[2]=0,t},a.clone=function(t){var e=new r(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e},a.fromValues=function(t,e,n){var i=new r(3);return i[0]=t,i[1]=e,i[2]=n,i},a.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},a.set=function(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t},a.add=function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t},a.subtract=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t},a.sub=a.subtract,a.multiply=function(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t},a.mul=a.multiply,a.divide=function(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t},a.div=a.divide,a.min=function(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t},a.max=function(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t},a.scale=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t},a.distance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(r*r+n*n+i*i)},a.dist=a.distance,a.squaredDistance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i},a.sqrDist=a.squaredDistance,a.length=function(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)},a.len=a.length,a.squaredLength=function(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n},a.sqrLen=a.squaredLength,a.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t},a.normalize=function(t,e){var r=e[0],n=e[1],i=e[2],a=r*r+n*n+i*i;return a>0&&(a=1/Math.sqrt(a),t[0]=e[0]*a,t[1]=e[1]*a,t[2]=e[2]*a),t},a.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]},a.cross=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2];return t[0]=i*u-a*s,t[1]=a*o-n*u,t[2]=n*s-i*o,t},a.lerp=function(t,e,r,n){var i=e[0],a=e[1],o=e[2];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t},a.transformMat4=function(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12],t[1]=r[1]*n+r[5]*i+r[9]*a+r[13],t[2]=r[2]*n+r[6]*i+r[10]*a+r[14],t},a.transformQuat=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2],f=r[3],l=f*n+s*a-u*i,c=f*i+u*n-o*a,h=f*a+o*i-s*n,p=-o*n-s*i-u*a;return t[0]=l*f+p*-o+c*-u-h*-s,t[1]=c*f+p*-s+h*-o-l*-u,t[2]=h*f+p*-u+l*-s-c*-o,t},a.forEach=function(){var t=a.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=3),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2];return e}}(),a.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},"undefined"!=typeof t&&(t.vec3=a);var o={};o.create=function(){var t=new r(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t},o.clone=function(t){var e=new r(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},o.fromValues=function(t,e,n,i){var a=new r(4);return a[0]=t,a[1]=e,a[2]=n,a[3]=i,a},o.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},o.set=function(t,e,r,n,i){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t},o.add=function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t},o.subtract=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t -},o.sub=o.subtract,o.multiply=function(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t[3]=e[3]*r[3],t},o.mul=o.multiply,o.divide=function(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t[3]=e[3]/r[3],t},o.div=o.divide,o.min=function(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t[3]=Math.min(e[3],r[3]),t},o.max=function(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t[3]=Math.max(e[3],r[3]),t},o.scale=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t},o.distance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return Math.sqrt(r*r+n*n+i*i+a*a)},o.dist=o.distance,o.squaredDistance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return r*r+n*n+i*i+a*a},o.sqrDist=o.squaredDistance,o.length=function(t){var e=t[0],r=t[1],n=t[2],i=t[3];return Math.sqrt(e*e+r*r+n*n+i*i)},o.len=o.length,o.squaredLength=function(t){var e=t[0],r=t[1],n=t[2],i=t[3];return e*e+r*r+n*n+i*i},o.sqrLen=o.squaredLength,o.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t},o.normalize=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a;return o>0&&(o=1/Math.sqrt(o),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o,t[3]=e[3]*o),t},o.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]},o.lerp=function(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=e[3];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t[3]=s+n*(r[3]-s),t},o.transformMat4=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12]*o,t[1]=r[1]*n+r[5]*i+r[9]*a+r[13]*o,t[2]=r[2]*n+r[6]*i+r[10]*a+r[14]*o,t[3]=r[3]*n+r[7]*i+r[11]*a+r[15]*o,t},o.transformQuat=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2],f=r[3],l=f*n+s*a-u*i,c=f*i+u*n-o*a,h=f*a+o*i-s*n,p=-o*n-s*i-u*a;return t[0]=l*f+p*-o+c*-u-h*-s,t[1]=c*f+p*-s+h*-o-l*-u,t[2]=h*f+p*-u+l*-s-c*-o,t},o.forEach=function(){var t=o.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=4),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],t[3]=e[s+3],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2],e[s+3]=t[3];return e}}(),o.str=function(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},"undefined"!=typeof t&&(t.vec4=o);{var s={};new Float32Array([1,0,0,1])}s.create=function(){var t=new r(4);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},s.clone=function(t){var e=new r(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},s.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},s.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},s.transpose=function(t,e){if(t===e){var r=e[1];t[1]=e[2],t[2]=r}else t[0]=e[0],t[1]=e[2],t[2]=e[1],t[3]=e[3];return t},s.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*a-i*n;return o?(o=1/o,t[0]=a*o,t[1]=-n*o,t[2]=-i*o,t[3]=r*o,t):null},s.adjoint=function(t,e){var r=e[0];return t[0]=e[3],t[1]=-e[1],t[2]=-e[2],t[3]=r,t},s.determinant=function(t){return t[0]*t[3]-t[2]*t[1]},s.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],u=r[1],f=r[2],l=r[3];return t[0]=n*s+i*f,t[1]=n*u+i*l,t[2]=a*s+o*f,t[3]=a*u+o*l,t},s.mul=s.multiply,s.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),u=Math.cos(r);return t[0]=n*u+i*s,t[1]=n*-s+i*u,t[2]=a*u+o*s,t[3]=a*-s+o*u,t},s.scale=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],u=r[1];return t[0]=n*s,t[1]=i*u,t[2]=a*s,t[3]=o*u,t},s.str=function(t){return"mat2("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},"undefined"!=typeof t&&(t.mat2=s);{var u={};new Float32Array([1,0,0,1,0,0])}u.create=function(){var t=new r(6);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},u.clone=function(t){var e=new r(6);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e},u.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t},u.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},u.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=r*a-n*i;return u?(u=1/u,t[0]=a*u,t[1]=-n*u,t[2]=-i*u,t[3]=r*u,t[4]=(i*s-a*o)*u,t[5]=(n*o-r*s)*u,t):null},u.determinant=function(t){return t[0]*t[3]-t[1]*t[2]},u.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=r[0],l=r[1],c=r[2],h=r[3],p=r[4],d=r[5];return t[0]=n*f+i*c,t[1]=n*l+i*h,t[2]=a*f+o*c,t[3]=a*l+o*h,t[4]=f*s+c*u+p,t[5]=l*s+h*u+d,t},u.mul=u.multiply,u.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=Math.sin(r),l=Math.cos(r);return t[0]=n*l+i*f,t[1]=-n*f+i*l,t[2]=a*l+o*f,t[3]=-a*f+l*o,t[4]=l*s+f*u,t[5]=l*u-f*s,t},u.scale=function(t,e,r){var n=r[0],i=r[1];return t[0]=e[0]*n,t[1]=e[1]*i,t[2]=e[2]*n,t[3]=e[3]*i,t[4]=e[4]*n,t[5]=e[5]*i,t},u.translate=function(t,e,r){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4]+r[0],t[5]=e[5]+r[1],t},u.str=function(t){return"mat2d("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+")"},"undefined"!=typeof t&&(t.mat2d=u);{var f={};new Float32Array([1,0,0,0,1,0,0,0,1])}f.create=function(){var t=new r(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},f.clone=function(t){var e=new r(9);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e},f.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t},f.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},f.transpose=function(t,e){if(t===e){var r=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=r,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},f.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=l*o-s*f,h=-l*a+s*u,p=f*a-o*u,d=r*c+n*h+i*p;return d?(d=1/d,t[0]=c*d,t[1]=(-l*n+i*f)*d,t[2]=(s*n-i*o)*d,t[3]=h*d,t[4]=(l*r-i*u)*d,t[5]=(-s*r+i*a)*d,t[6]=p*d,t[7]=(-f*r+n*u)*d,t[8]=(o*r-n*a)*d,t):null},f.adjoint=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8];return t[0]=o*l-s*f,t[1]=i*f-n*l,t[2]=n*s-i*o,t[3]=s*u-a*l,t[4]=r*l-i*u,t[5]=i*a-r*s,t[6]=a*f-o*u,t[7]=n*u-r*f,t[8]=r*o-n*a,t},f.determinant=function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],u=t[7],f=t[8];return e*(f*a-o*u)+r*(-f*i+o*s)+n*(u*i-a*s)},f.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=r[0],p=r[1],d=r[2],g=r[3],m=r[4],v=r[5],y=r[6],b=r[7],_=r[8];return t[0]=h*n+p*o+d*f,t[1]=h*i+p*s+d*l,t[2]=h*a+p*u+d*c,t[3]=g*n+m*o+v*f,t[4]=g*i+m*s+v*l,t[5]=g*a+m*u+v*c,t[6]=y*n+b*o+_*f,t[7]=y*i+b*s+_*l,t[8]=y*a+b*u+_*c,t},f.mul=f.multiply,f.translate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=r[0],p=r[1];return t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=u,t[6]=h*n+p*o+f,t[7]=h*i+p*s+l,t[8]=h*a+p*u+c,t},f.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=Math.sin(r),p=Math.cos(r);return t[0]=p*n+h*o,t[1]=p*i+h*s,t[2]=p*a+h*u,t[3]=p*o-h*n,t[4]=p*s-h*i,t[5]=p*u-h*a,t[6]=f,t[7]=l,t[8]=c,t},f.scale=function(t,e,r){var n=r[0],i=r[2];return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=i*e[3],t[4]=i*e[4],t[5]=i*e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t},f.fromMat2d=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=0,t[3]=e[2],t[4]=e[3],t[5]=0,t[6]=e[4],t[7]=e[5],t[8]=1,t},f.fromQuat=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r+r,s=n+n,u=i+i,f=r*o,l=r*s,c=r*u,h=n*s,p=n*u,d=i*u,g=a*o,m=a*s,v=a*u;return t[0]=1-(h+d),t[1]=l+v,t[2]=c-m,t[3]=l-v,t[4]=1-(f+d),t[5]=p+g,t[6]=c+m,t[7]=p-g,t[8]=1-(f+h),t},f.str=function(t){return"mat3("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+")"},"undefined"!=typeof t&&(t.mat3=f);{var l={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}l.create=function(){var t=new r(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},l.clone=function(t){var e=new r(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},l.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},l.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},l.transpose=function(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],a=e[6],o=e[7],s=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=a,t[11]=e[14],t[12]=i,t[13]=o,t[14]=s}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t},l.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=e[9],h=e[10],p=e[11],d=e[12],g=e[13],m=e[14],v=e[15],y=r*s-n*o,b=r*u-i*o,_=r*f-a*o,E=n*u-i*s,w=n*f-a*s,A=i*f-a*u,x=l*g-c*d,T=l*m-h*d,R=l*v-p*d,M=c*m-h*g,I=c*v-p*g,F=h*v-p*m,N=y*F-b*I+_*M+E*R-w*T+A*x;return N?(N=1/N,t[0]=(s*F-u*I+f*M)*N,t[1]=(i*I-n*F-a*M)*N,t[2]=(g*A-m*w+v*E)*N,t[3]=(h*w-c*A-p*E)*N,t[4]=(u*R-o*F-f*T)*N,t[5]=(r*F-i*R+a*T)*N,t[6]=(m*_-d*A-v*b)*N,t[7]=(l*A-h*_+p*b)*N,t[8]=(o*I-s*R+f*x)*N,t[9]=(n*R-r*I-a*x)*N,t[10]=(d*w-g*_+v*y)*N,t[11]=(c*_-l*w-p*y)*N,t[12]=(s*T-o*M-u*x)*N,t[13]=(r*M-n*T+i*x)*N,t[14]=(g*b-d*E-m*y)*N,t[15]=(l*E-c*b+h*y)*N,t):null},l.adjoint=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=e[9],h=e[10],p=e[11],d=e[12],g=e[13],m=e[14],v=e[15];return t[0]=s*(h*v-p*m)-c*(u*v-f*m)+g*(u*p-f*h),t[1]=-(n*(h*v-p*m)-c*(i*v-a*m)+g*(i*p-a*h)),t[2]=n*(u*v-f*m)-s*(i*v-a*m)+g*(i*f-a*u),t[3]=-(n*(u*p-f*h)-s*(i*p-a*h)+c*(i*f-a*u)),t[4]=-(o*(h*v-p*m)-l*(u*v-f*m)+d*(u*p-f*h)),t[5]=r*(h*v-p*m)-l*(i*v-a*m)+d*(i*p-a*h),t[6]=-(r*(u*v-f*m)-o*(i*v-a*m)+d*(i*f-a*u)),t[7]=r*(u*p-f*h)-o*(i*p-a*h)+l*(i*f-a*u),t[8]=o*(c*v-p*g)-l*(s*v-f*g)+d*(s*p-f*c),t[9]=-(r*(c*v-p*g)-l*(n*v-a*g)+d*(n*p-a*c)),t[10]=r*(s*v-f*g)-o*(n*v-a*g)+d*(n*f-a*s),t[11]=-(r*(s*p-f*c)-o*(n*p-a*c)+l*(n*f-a*s)),t[12]=-(o*(c*m-h*g)-l*(s*m-u*g)+d*(s*h-u*c)),t[13]=r*(c*m-h*g)-l*(n*m-i*g)+d*(n*h-i*c),t[14]=-(r*(s*m-u*g)-o*(n*m-i*g)+d*(n*u-i*s)),t[15]=r*(s*h-u*c)-o*(n*h-i*c)+l*(n*u-i*s),t},l.determinant=function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],u=t[7],f=t[8],l=t[9],c=t[10],h=t[11],p=t[12],d=t[13],g=t[14],m=t[15],v=e*o-r*a,y=e*s-n*a,b=e*u-i*a,_=r*s-n*o,E=r*u-i*o,w=n*u-i*s,A=f*d-l*p,x=f*g-c*p,T=f*m-h*p,R=l*g-c*d,M=l*m-h*d,I=c*m-h*g;return v*I-y*M+b*R+_*T-E*x+w*A},l.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=e[9],p=e[10],d=e[11],g=e[12],m=e[13],v=e[14],y=e[15],b=r[0],_=r[1],E=r[2],w=r[3];return t[0]=b*n+_*s+E*c+w*g,t[1]=b*i+_*u+E*h+w*m,t[2]=b*a+_*f+E*p+w*v,t[3]=b*o+_*l+E*d+w*y,b=r[4],_=r[5],E=r[6],w=r[7],t[4]=b*n+_*s+E*c+w*g,t[5]=b*i+_*u+E*h+w*m,t[6]=b*a+_*f+E*p+w*v,t[7]=b*o+_*l+E*d+w*y,b=r[8],_=r[9],E=r[10],w=r[11],t[8]=b*n+_*s+E*c+w*g,t[9]=b*i+_*u+E*h+w*m,t[10]=b*a+_*f+E*p+w*v,t[11]=b*o+_*l+E*d+w*y,b=r[12],_=r[13],E=r[14],w=r[15],t[12]=b*n+_*s+E*c+w*g,t[13]=b*i+_*u+E*h+w*m,t[14]=b*a+_*f+E*p+w*v,t[15]=b*o+_*l+E*d+w*y,t},l.mul=l.multiply,l.translate=function(t,e,r){var n,i,a,o,s,u,f,l,c,h,p,d,g=r[0],m=r[1],v=r[2];return e===t?(t[12]=e[0]*g+e[4]*m+e[8]*v+e[12],t[13]=e[1]*g+e[5]*m+e[9]*v+e[13],t[14]=e[2]*g+e[6]*m+e[10]*v+e[14],t[15]=e[3]*g+e[7]*m+e[11]*v+e[15]):(n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=e[9],p=e[10],d=e[11],t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=u,t[6]=f,t[7]=l,t[8]=c,t[9]=h,t[10]=p,t[11]=d,t[12]=n*g+s*m+c*v+e[12],t[13]=i*g+u*m+h*v+e[13],t[14]=a*g+f*m+p*v+e[14],t[15]=o*g+l*m+d*v+e[15]),t},l.scale=function(t,e,r){var n=r[0],i=r[1],a=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*a,t[9]=e[9]*a,t[10]=e[10]*a,t[11]=e[11]*a,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},l.rotate=function(t,r,n,i){var a,o,s,u,f,l,c,h,p,d,g,m,v,y,b,_,E,w,A,x,T,R,M,I,F=i[0],N=i[1],U=i[2],S=Math.sqrt(F*F+N*N+U*U);return Math.abs(S)=1?(t!==e&&(t[0]=u,t[1]=f,t[2]=l,t[3]=c),t):(i=Math.acos(m),a=Math.sqrt(1-m*m),Math.abs(a)<.001?(t[0]=.5*u+.5*h,t[1]=.5*f+.5*p,t[2]=.5*l+.5*d,t[3]=.5*c+.5*g,t):(o=Math.sin((1-n)*i)/a,s=Math.sin(n*i)/a,t[0]=u*o+h*s,t[1]=f*o+p*s,t[2]=l*o+d*s,t[3]=c*o+g*s,t))},c.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a,s=o?1/o:0;return t[0]=-r*s,t[1]=-n*s,t[2]=-i*s,t[3]=a*s,t},c.conjugate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},c.length=o.length,c.len=c.length,c.squaredLength=o.squaredLength,c.sqrLen=c.squaredLength,c.normalize=o.normalize,c.fromMat3=function(){var t=[1,2,0];return function(e,r){var n,i=r[0]+r[4]+r[8];if(i>0)n=Math.sqrt(i+1),e[3]=.5*n,n=.5/n,e[0]=(r[7]-r[5])*n,e[1]=(r[2]-r[6])*n,e[2]=(r[3]-r[1])*n;else{var a=0;r[4]>r[0]&&(a=1),r[8]>r[3*a+a]&&(a=2);var o=t[a],s=t[o];n=Math.sqrt(r[3*a+a]-r[3*o+o]-r[3*s+s]+1),e[a]=.5*n,n=.5/n,e[3]=(r[3*s+o]-r[3*o+s])*n,e[o]=(r[3*o+a]+r[3*a+o])*n,e[s]=(r[3*s+a]+r[3*a+s])*n}return e}}(),c.str=function(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},"undefined"!=typeof t&&(t.quat=c)}(t.exports)}()},{}],152:[function(t,e,r){arguments[4][9][0].apply(r,arguments)},{"cwise-compiler":153}],153:[function(t,e,r){arguments[4][10][0].apply(r,arguments)},{"./lib/thunk.js":155}],154:[function(t,e,r){arguments[4][11][0].apply(r,arguments)},{uniq:156}],155:[function(t,e,r){arguments[4][12][0].apply(r,arguments)},{"./compile.js":154}],156:[function(t,e){e.exports=t(13)},{}],157:[function(t,e,r){arguments[4][14][0].apply(r,arguments)},{buffer:189,"iota-array":158}],158:[function(t,e){e.exports=t(15)},{}],159:[function(t,e){e.exports=t(16)},{}],160:[function(t,e){e.exports=t(17)},{}],161:[function(t,e){e.exports=t(41)},{"bit-twiddle":159,buffer:189,dup:160}],162:[function(t,e){e.exports=t(42)},{}],163:[function(t,e){e.exports=t(43)},{weakmap:162}],164:[function(t,e){"use strict";function r(t){g=[t.LINEAR,t.NEAREST_MIPMAP_LINEAR,t.LINEAR_MIPMAP_NEAREST,t.LINEAR_MIPMAP_NEAREST],m=[t.NEAREST,t.LINEAR,t.NEAREST_MIPMAP_NEAREST,t.NEAREST_MIPMAP_LINEAR,t.LINEAR_MIPMAP_NEAREST,t.LINEAR_MIPMAP_LINEAR],v=[t.REPEAT,t.CLAMP_TO_EDGE,t.MIRRORED_REPEAT]}function n(t,e,r,n,i,a){this.gl=t,this.handle=e,this.format=i,this.type=a,this._shape=[n,r],this._mipLevels=[0],this._magFilter=t.NEAREST,this._minFilter=t.NEAREST,this._wrapS=t.CLAMP_TO_EDGE,this._wrapT=t.CLAMP_TO_EDGE,this._anisoSamples=1}function i(t,e,r,n,i,a,o,s){var f=s.dtype,l=s.shape,d=u(s),g=0,m=0;if("float32"===f?g=t.FLOAT:"float64"===f?(g=t.FLOAT,d=!1,f="float32"):"uint8"===f?g=t.UNSIGNED_BYTE:(g=t.UNSIGNED_BYTE,d=!1,f="uint8"),2===l.length)m=t.LUMINANCE;else{if(3!==l.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===l[2])m=t.ALPHA;else if(2===l[2])m=t.LUMINANCE_ALPHA;else if(3===l[2])m=t.RGB;else{if(4!==l[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");m=t.RGBA}}if(m!==t.LUMINANCE&&m!==t.ALPHA||i!==t.LUMINANCE&&i!==t.ALPHA||(m=i),m!==i)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var v=s.size,b=o.indexOf(n)<0;if(b&&o.push(n),g===a&&d)0===s.offset&&s.data.length===v?b?t.texImage2D(t.TEXTURE_2D,n,i,l[1],l[0],0,i,a,s.data):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[1],l[0],i,a,s.data):b?t.texImage2D(t.TEXTURE_2D,n,i,l[1],l[0],0,i,a,s.data.subarray(s.offset,s.offset+v)):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[1],l[0],i,a,s.data.subarray(s.offset,s.offset+v));else{var _;_=a===t.FLOAT?p.mallocFloat32(v):p.mallocUint8(v);var E=c(_,l);g===t.FLOAT&&a===t.UNSIGNED_BYTE?y(E,s):h.assign(E,s),b?t.texImage2D(t.TEXTURE_2D,n,i,l[1],l[0],0,i,a,_.subarray(0,v)):t.texSubImage2D(t.TEXTURE_2D,n,e,r,l[1],l[0],i,a,_.subarray(0,v)),a===t.FLOAT?p.freeFloat32(_):p.freeUint8(_)}}function a(t){var e=t.createTexture();return t.bindTexture(t.TEXTURE_2D,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),e}function o(t,e,r,i,o){var s=t.getParameter(t.MAX_TEXTURE_SIZE);if(0>e||e>s||0>r||r>s)throw new Error("gl-texture2d: Invalid texture shape");var u=a(t);return t.texImage2D(t.TEXTURE_2D,0,i,e,r,0,i,o,null),new n(t,u,e,r,i,o)}function s(t,e,r,i){var o=a(t);return t.texImage2D(t.TEXTURE_2D,0,r,r,i,e),new n(t,o,0|e.width,0|e.height,r,i)}function u(t){for(var e=t.shape,r=t.stride,n=1,i=e.length-1;i>=0;--i){if(r[i]!==n)return!1;n*=e[i]}return!0}function f(t,e){var r=e.dtype,i=e.shape.slice(),o=t.getParameter(t.MAX_TEXTURE_SIZE);if(i[0]<0||i[0]>o||i[1]<0||i[1]>o)throw new Error("gl-texture2d: Invalid texture size");var s=u(e),f=0;"float32"===r?f=t.FLOAT:"float64"===r?(f=t.FLOAT,s=!1,r="float32"):"uint8"===r?f=t.UNSIGNED_BYTE:(f=t.UNSIGNED_BYTE,s=!1,r="uint8");var l=0;if(2===i.length)l=t.LUMINANCE;else{if(3!==i.length)throw new Error("Invalid shape for texture");if(1===i[2])l=t.ALPHA;else if(2===i[2])l=t.LUMINANCE_ALPHA;else if(3===i[2])l=t.RGB;else{if(4!==i[2])throw new Error("Invalid shape for pixel coords");l=t.RGBA}}f===t.FLOAT&&d(t).texture_float&&(f=t.UNSIGNED_BYTE,s=!1);var g,m;if(s){var v=e.size;g=e.data.subarray(e.offset,e.offset+v)}else{for(var b=1,_=new Array(i.length),E=i.length-1;E>=0;--E)_[E]=b,b*=i[E];m=p.malloc(b,r);var w=c(m,e.shape,_,0);"float32"!==r&&"float64"!==r||f!==t.UNSIGNED_BYTE?h.assign(w,e):y(w,e),g=m.subarray(0,b)}var A=a(t);return t.texImage2D(t.TEXTURE_2D,0,l,i[1],i[0],0,l,f,g),s||p.free(m),new n(t,A,i[1],i[0],l,f)}function l(t){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(g||r(t),"number"==typeof arguments[1])return o(t,arguments[1],arguments[2],arguments[3]||t.RGBA,arguments[4]||t.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return o(t,0|arguments[1][1],0|arguments[1][0],arguments[2]||t.RGBA,arguments[4]||t.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var e=arguments[1];if(e instanceof HTMLCanvasElement||e instanceof HTMLImageElement||e instanceof HTMLVideoElement||e instanceof ImageData)return s(t,e,arguments[2]||t.RGBA,arguments[3]||t.UNSIGNED_BYTE);if(e.shape&&e.data&&e.stride)return f(t,e)}throw new Error("Invalid arguments for texture2d constructor")}var c=t("ndarray"),h=t("ndarray-ops"),p=t("typedarray-pool"),d=t("webglew"),g=null,m=null,v=null,y=function(t,e){h.muls(t,e,255)};Object.defineProperty(n.prototype,"minFilter",{get:function(){return this._minFilter},set:function(t){this.bind();var e=this.gl;if(this.type===e.FLOAT&&g.indexOf(t)>=0&&(d(e).OES_texture_float_linear||(t=e.NEAREST)),m.indexOf(t)<0)throw new Error("gl-texture2d: Unknown filter mode "+t);return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t),this._minFilter=t}});var b=n.prototype;Object.defineProperty(b,"magFilter",{get:function(){return this._magFilter},set:function(t){this.bind();var e=this.gl;if(this.type===e.FLOAT&&g.indexOf(t)>=0&&(d(e).OES_texture_float_linear||(t=e.NEAREST)),m.indexOf(t)<0)throw new Error("gl-texture2d: Unknown filter mode "+t);return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,t),this._magFilter=t}}),Object.defineProperty(b,"wrapS",{get:function(){return this._wrapS},set:function(t){if(this.bind(),v.indexOf(t)<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,t),this._wrapS=t}}),Object.defineProperty(b,"wrapT",{get:function(){return this._wrapT},set:function(t){if(this.bind(),v.indexOf(t)<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,t),this._wrapT=t}}),Object.defineProperty(b,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(t){if(Array.isArray(t)||(t=[t,t]),2!==t.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var e=0;2>e;++e)if(v.indexOf(t[e])<0)throw new Error("gl-texture2d: Unknown wrap mode "+t);this._wrapT=t[0],this._wrapS=t[1];var r=this.gl;return this.bind(),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,this._wrapT),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,this._wrapS),t}}),Object.defineProperty(b,"mipSamples",{get:function(){return this._anisoSamples},set:function(t){var e=this._anisoSamples;if(this._anisoSamples=0|Math.max(t,1),e!==this._anisoSamples){var r=d(this.gl).EXT_texture_filter_anisotropic;r&&this.gl.texParameterf(this.gl.TEXTURE_2D,r.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(b,"shape",{get:function(){return this._shape},set:function(t){if(Array.isArray(t)){if(2!==t.length)throw new Error("gl-texture2d: Invalid texture shape")}else t=[0|t,0|t];var e=0|t[0],r=0|t[1];if(this.height===e&&this.width===r)return t;var n=this.gl,i=n.getParameter(n.MAX_TEXTURE_SIZE);if(0>r||r>i||0>e||e>i)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[e,r],this.bind(),n.texImage2D(n.TEXTURE_2D,0,this.format,r,e,0,this.format,this.type,null),this._mipLevels=[0],t}}),b.bind=function(t){var e=this.gl;return void 0!==t&&e.activeTexture(e.TEXTURE0+(0|t)),e.bindTexture(e.TEXTURE_2D,this.handle),void 0!==t?t:e.getParameter(e.ACTIVE_TEXTURE)-e.TEXTURE0},b.dispose=function(){this.gl.deleteTexture(this.handle)},b.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var t=Math.min(this._shape[0],this._shape[1]),e=0;t>0;++e,t>>>=1)this._mipLevels.indexOf(e)<0&&this._mipLevels.push(e)},b.setPixels=function(t,e,r,n){var a=this.gl;if(this.bind(),Array.isArray(e)?(n=r,r=0|e[0],e=0|e[1]):(e=e||0,r=r||0),n=n||0,t instanceof HTMLCanvasElement||t instanceof ImageData||t instanceof HTMLImageElement||t instanceof HTMLVideoElement){var o=this._mipLevels.indexOf(n)<0;o?(a.texImage2D(a.TEXTURE_2D,0,this.format,this.format,this.type,t),this._mipLevels.push(n)):a.texSubImage2D(a.TEXTURE_2D,n,e,r,this.format,this.type,t)}else{if(!(t.shape&&t.stride&&t.data))throw new Error("gl-texture2d: Unsupported data type");if(t.shape.length<2||e+t.shape[1]>this._shape[1]>>>n||r+t.shape[0]>this._shape[0]>>>n||0>e||0>r)throw new Error("gl-texture2d: Texture dimensions are out of bounds");i(a,e,r,n,this.format,this.type,this._mipLevels,t)}},e.exports=l},{ndarray:157,"ndarray-ops":152,"typedarray-pool":161,webglew:163}],165:[function(t,e,r){arguments[4][79][0].apply(r,arguments)},{"gl-shader-core":171}],166:[function(t,e){e.exports=t(80)},{}],167:[function(t,e){e.exports=t(81)},{}],168:[function(t,e,r){arguments[4][82][0].apply(r,arguments)},{"./reflect.js":169,dup:170}],169:[function(t,e){e.exports=t(83)},{}],170:[function(t,e){e.exports=t(17)},{}],171:[function(t,e){e.exports=t(85)},{"./lib/create-attributes.js":167,"./lib/create-uniforms.js":168,"./lib/reflect.js":169}],172:[function(t,e){function r(t){for(var e=[],r=[],i=0,a=0,o=0,s=0;s0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i),t},o.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]},o.cross=function(t,e,r){var n=e[0]*r[1]-e[1]*r[0];return t[0]=t[1]=0,t[2]=n,t},o.lerp=function(t,e,r,n){var i=e[0],a=e[1];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t},o.random=function(t,e){e=e||1;var r=2*n()*Math.PI;return t[0]=Math.cos(r)*e,t[1]=Math.sin(r)*e,t},o.transformMat2=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[2]*i,t[1]=r[1]*n+r[3]*i,t},o.transformMat2d=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[2]*i+r[4],t[1]=r[1]*n+r[3]*i+r[5],t},o.transformMat3=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[3]*i+r[6],t[1]=r[1]*n+r[4]*i+r[7],t},o.transformMat4=function(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[4]*i+r[12],t[1]=r[1]*n+r[5]*i+r[13],t},o.forEach=function(){var t=o.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=2),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],a(t,t,o),e[s]=t[0],e[s+1]=t[1];return e}}(),o.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},"undefined"!=typeof t&&(t.vec2=o);var s={};s.create=function(){var t=new r(3);return t[0]=0,t[1]=0,t[2]=0,t},s.clone=function(t){var e=new r(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e},s.fromValues=function(t,e,n){var i=new r(3);return i[0]=t,i[1]=e,i[2]=n,i},s.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},s.set=function(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t},s.add=function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t},s.subtract=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t -},s.sub=s.subtract,s.multiply=function(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t},s.mul=s.multiply,s.divide=function(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t},s.div=s.divide,s.min=function(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t},s.max=function(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t},s.scale=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t},s.scaleAndAdd=function(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t},s.distance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(r*r+n*n+i*i)},s.dist=s.distance,s.squaredDistance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i},s.sqrDist=s.squaredDistance,s.length=function(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)},s.len=s.length,s.squaredLength=function(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n},s.sqrLen=s.squaredLength,s.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t},s.normalize=function(t,e){var r=e[0],n=e[1],i=e[2],a=r*r+n*n+i*i;return a>0&&(a=1/Math.sqrt(a),t[0]=e[0]*a,t[1]=e[1]*a,t[2]=e[2]*a),t},s.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]},s.cross=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2];return t[0]=i*u-a*s,t[1]=a*o-n*u,t[2]=n*s-i*o,t},s.lerp=function(t,e,r,n){var i=e[0],a=e[1],o=e[2];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t},s.random=function(t,e){e=e||1;var r=2*n()*Math.PI,i=2*n()-1,a=Math.sqrt(1-i*i)*e;return t[0]=Math.cos(r)*a,t[1]=Math.sin(r)*a,t[2]=i*e,t},s.transformMat4=function(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12],t[1]=r[1]*n+r[5]*i+r[9]*a+r[13],t[2]=r[2]*n+r[6]*i+r[10]*a+r[14],t},s.transformMat3=function(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=n*r[0]+i*r[3]+a*r[6],t[1]=n*r[1]+i*r[4]+a*r[7],t[2]=n*r[2]+i*r[5]+a*r[8],t},s.transformQuat=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2],f=r[3],l=f*n+s*a-u*i,c=f*i+u*n-o*a,h=f*a+o*i-s*n,p=-o*n-s*i-u*a;return t[0]=l*f+p*-o+c*-u-h*-s,t[1]=c*f+p*-s+h*-o-l*-u,t[2]=h*f+p*-u+l*-s-c*-o,t},s.rotateX=function(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[0],a[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),a[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t},s.rotateY=function(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),a[1]=i[1],a[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t},s.rotateZ=function(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),a[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),a[2]=i[2],t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t},s.forEach=function(){var t=s.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=3),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2];return e}}(),s.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},"undefined"!=typeof t&&(t.vec3=s);var u={};u.create=function(){var t=new r(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t},u.clone=function(t){var e=new r(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},u.fromValues=function(t,e,n,i){var a=new r(4);return a[0]=t,a[1]=e,a[2]=n,a[3]=i,a},u.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},u.set=function(t,e,r,n,i){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t},u.add=function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t},u.subtract=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t},u.sub=u.subtract,u.multiply=function(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t[3]=e[3]*r[3],t},u.mul=u.multiply,u.divide=function(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t[3]=e[3]/r[3],t},u.div=u.divide,u.min=function(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t[3]=Math.min(e[3],r[3]),t},u.max=function(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t[3]=Math.max(e[3],r[3]),t},u.scale=function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t},u.scaleAndAdd=function(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t},u.distance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return Math.sqrt(r*r+n*n+i*i+a*a)},u.dist=u.distance,u.squaredDistance=function(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return r*r+n*n+i*i+a*a},u.sqrDist=u.squaredDistance,u.length=function(t){var e=t[0],r=t[1],n=t[2],i=t[3];return Math.sqrt(e*e+r*r+n*n+i*i)},u.len=u.length,u.squaredLength=function(t){var e=t[0],r=t[1],n=t[2],i=t[3];return e*e+r*r+n*n+i*i},u.sqrLen=u.squaredLength,u.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t},u.normalize=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a;return o>0&&(o=1/Math.sqrt(o),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o,t[3]=e[3]*o),t},u.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]},u.lerp=function(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=e[3];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t[3]=s+n*(r[3]-s),t},u.random=function(t,e){return e=e||1,t[0]=n(),t[1]=n(),t[2]=n(),t[3]=n(),u.normalize(t,t),u.scale(t,t,e),t},u.transformMat4=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12]*o,t[1]=r[1]*n+r[5]*i+r[9]*a+r[13]*o,t[2]=r[2]*n+r[6]*i+r[10]*a+r[14]*o,t[3]=r[3]*n+r[7]*i+r[11]*a+r[15]*o,t},u.transformQuat=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2],f=r[3],l=f*n+s*a-u*i,c=f*i+u*n-o*a,h=f*a+o*i-s*n,p=-o*n-s*i-u*a;return t[0]=l*f+p*-o+c*-u-h*-s,t[1]=c*f+p*-s+h*-o-l*-u,t[2]=h*f+p*-u+l*-s-c*-o,t},u.forEach=function(){var t=u.create();return function(e,r,n,i,a,o){var s,u;for(r||(r=4),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,s=n;u>s;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],t[3]=e[s+3],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2],e[s+3]=t[3];return e}}(),u.str=function(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},"undefined"!=typeof t&&(t.vec4=u);var f={};f.create=function(){var t=new r(4);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},f.clone=function(t){var e=new r(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},f.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},f.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},f.transpose=function(t,e){if(t===e){var r=e[1];t[1]=e[2],t[2]=r}else t[0]=e[0],t[1]=e[2],t[2]=e[1],t[3]=e[3];return t},f.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*a-i*n;return o?(o=1/o,t[0]=a*o,t[1]=-n*o,t[2]=-i*o,t[3]=r*o,t):null},f.adjoint=function(t,e){var r=e[0];return t[0]=e[3],t[1]=-e[1],t[2]=-e[2],t[3]=r,t},f.determinant=function(t){return t[0]*t[3]-t[2]*t[1]},f.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],u=r[1],f=r[2],l=r[3];return t[0]=n*s+a*u,t[1]=i*s+o*u,t[2]=n*f+a*l,t[3]=i*f+o*l,t},f.mul=f.multiply,f.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),u=Math.cos(r);return t[0]=n*u+a*s,t[1]=i*u+o*s,t[2]=n*-s+a*u,t[3]=i*-s+o*u,t},f.scale=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],u=r[1];return t[0]=n*s,t[1]=i*s,t[2]=a*u,t[3]=o*u,t},f.str=function(t){return"mat2("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},f.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))},f.LDU=function(t,e,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,e,r]},"undefined"!=typeof t&&(t.mat2=f);var l={};l.create=function(){var t=new r(6);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},l.clone=function(t){var e=new r(6);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e},l.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t},l.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},l.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=r*a-n*i;return u?(u=1/u,t[0]=a*u,t[1]=-n*u,t[2]=-i*u,t[3]=r*u,t[4]=(i*s-a*o)*u,t[5]=(n*o-r*s)*u,t):null},l.determinant=function(t){return t[0]*t[3]-t[1]*t[2]},l.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=r[0],l=r[1],c=r[2],h=r[3],p=r[4],d=r[5];return t[0]=n*f+a*l,t[1]=i*f+o*l,t[2]=n*c+a*h,t[3]=i*c+o*h,t[4]=n*p+a*d+s,t[5]=i*p+o*d+u,t},l.mul=l.multiply,l.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=Math.sin(r),l=Math.cos(r);return t[0]=n*l+a*f,t[1]=i*l+o*f,t[2]=n*-f+a*l,t[3]=i*-f+o*l,t[4]=s,t[5]=u,t},l.scale=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=r[0],l=r[1];return t[0]=n*f,t[1]=i*f,t[2]=a*l,t[3]=o*l,t[4]=s,t[5]=u,t},l.translate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=r[0],l=r[1];return t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=n*f+a*l+s,t[5]=i*f+o*l+u,t},l.str=function(t){return"mat2d("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+")"},l.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)},"undefined"!=typeof t&&(t.mat2d=l);var c={};c.create=function(){var t=new r(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},c.fromMat4=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t},c.clone=function(t){var e=new r(9);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e},c.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t},c.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},c.transpose=function(t,e){if(t===e){var r=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=r,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},c.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=l*o-s*f,h=-l*a+s*u,p=f*a-o*u,d=r*c+n*h+i*p;return d?(d=1/d,t[0]=c*d,t[1]=(-l*n+i*f)*d,t[2]=(s*n-i*o)*d,t[3]=h*d,t[4]=(l*r-i*u)*d,t[5]=(-s*r+i*a)*d,t[6]=p*d,t[7]=(-f*r+n*u)*d,t[8]=(o*r-n*a)*d,t):null},c.adjoint=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8];return t[0]=o*l-s*f,t[1]=i*f-n*l,t[2]=n*s-i*o,t[3]=s*u-a*l,t[4]=r*l-i*u,t[5]=i*a-r*s,t[6]=a*f-o*u,t[7]=n*u-r*f,t[8]=r*o-n*a,t},c.determinant=function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],u=t[7],f=t[8];return e*(f*a-o*u)+r*(-f*i+o*s)+n*(u*i-a*s)},c.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=r[0],p=r[1],d=r[2],g=r[3],m=r[4],v=r[5],y=r[6],b=r[7],_=r[8];return t[0]=h*n+p*o+d*f,t[1]=h*i+p*s+d*l,t[2]=h*a+p*u+d*c,t[3]=g*n+m*o+v*f,t[4]=g*i+m*s+v*l,t[5]=g*a+m*u+v*c,t[6]=y*n+b*o+_*f,t[7]=y*i+b*s+_*l,t[8]=y*a+b*u+_*c,t},c.mul=c.multiply,c.translate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=r[0],p=r[1];return t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=u,t[6]=h*n+p*o+f,t[7]=h*i+p*s+l,t[8]=h*a+p*u+c,t},c.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=Math.sin(r),p=Math.cos(r);return t[0]=p*n+h*o,t[1]=p*i+h*s,t[2]=p*a+h*u,t[3]=p*o-h*n,t[4]=p*s-h*i,t[5]=p*u-h*a,t[6]=f,t[7]=l,t[8]=c,t},c.scale=function(t,e,r){var n=r[0],i=r[1];return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=i*e[3],t[4]=i*e[4],t[5]=i*e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t},c.fromMat2d=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=0,t[3]=e[2],t[4]=e[3],t[5]=0,t[6]=e[4],t[7]=e[5],t[8]=1,t},c.fromQuat=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r+r,s=n+n,u=i+i,f=r*o,l=n*o,c=n*s,h=i*o,p=i*s,d=i*u,g=a*o,m=a*s,v=a*u;return t[0]=1-c-d,t[3]=l-v,t[6]=h+m,t[1]=l+v,t[4]=1-f-d,t[7]=p-g,t[2]=h-m,t[5]=p+g,t[8]=1-f-c,t},c.normalFromMat4=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=e[9],h=e[10],p=e[11],d=e[12],g=e[13],m=e[14],v=e[15],y=r*s-n*o,b=r*u-i*o,_=r*f-a*o,E=n*u-i*s,w=n*f-a*s,A=i*f-a*u,x=l*g-c*d,T=l*m-h*d,R=l*v-p*d,M=c*m-h*g,I=c*v-p*g,F=h*v-p*m,N=y*F-b*I+_*M+E*R-w*T+A*x;return N?(N=1/N,t[0]=(s*F-u*I+f*M)*N,t[1]=(u*R-o*F-f*T)*N,t[2]=(o*I-s*R+f*x)*N,t[3]=(i*I-n*F-a*M)*N,t[4]=(r*F-i*R+a*T)*N,t[5]=(n*R-r*I-a*x)*N,t[6]=(g*A-m*w+v*E)*N,t[7]=(m*_-d*A-v*b)*N,t[8]=(d*w-g*_+v*y)*N,t):null},c.str=function(t){return"mat3("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+")"},c.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))},"undefined"!=typeof t&&(t.mat3=c);var h={};h.create=function(){var t=new r(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},h.clone=function(t){var e=new r(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},h.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},h.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},h.transpose=function(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],a=e[6],o=e[7],s=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=a,t[11]=e[14],t[12]=i,t[13]=o,t[14]=s}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t},h.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=e[9],h=e[10],p=e[11],d=e[12],g=e[13],m=e[14],v=e[15],y=r*s-n*o,b=r*u-i*o,_=r*f-a*o,E=n*u-i*s,w=n*f-a*s,A=i*f-a*u,x=l*g-c*d,T=l*m-h*d,R=l*v-p*d,M=c*m-h*g,I=c*v-p*g,F=h*v-p*m,N=y*F-b*I+_*M+E*R-w*T+A*x;return N?(N=1/N,t[0]=(s*F-u*I+f*M)*N,t[1]=(i*I-n*F-a*M)*N,t[2]=(g*A-m*w+v*E)*N,t[3]=(h*w-c*A-p*E)*N,t[4]=(u*R-o*F-f*T)*N,t[5]=(r*F-i*R+a*T)*N,t[6]=(m*_-d*A-v*b)*N,t[7]=(l*A-h*_+p*b)*N,t[8]=(o*I-s*R+f*x)*N,t[9]=(n*R-r*I-a*x)*N,t[10]=(d*w-g*_+v*y)*N,t[11]=(c*_-l*w-p*y)*N,t[12]=(s*T-o*M-u*x)*N,t[13]=(r*M-n*T+i*x)*N,t[14]=(g*b-d*E-m*y)*N,t[15]=(l*E-c*b+h*y)*N,t):null},h.adjoint=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],f=e[7],l=e[8],c=e[9],h=e[10],p=e[11],d=e[12],g=e[13],m=e[14],v=e[15];return t[0]=s*(h*v-p*m)-c*(u*v-f*m)+g*(u*p-f*h),t[1]=-(n*(h*v-p*m)-c*(i*v-a*m)+g*(i*p-a*h)),t[2]=n*(u*v-f*m)-s*(i*v-a*m)+g*(i*f-a*u),t[3]=-(n*(u*p-f*h)-s*(i*p-a*h)+c*(i*f-a*u)),t[4]=-(o*(h*v-p*m)-l*(u*v-f*m)+d*(u*p-f*h)),t[5]=r*(h*v-p*m)-l*(i*v-a*m)+d*(i*p-a*h),t[6]=-(r*(u*v-f*m)-o*(i*v-a*m)+d*(i*f-a*u)),t[7]=r*(u*p-f*h)-o*(i*p-a*h)+l*(i*f-a*u),t[8]=o*(c*v-p*g)-l*(s*v-f*g)+d*(s*p-f*c),t[9]=-(r*(c*v-p*g)-l*(n*v-a*g)+d*(n*p-a*c)),t[10]=r*(s*v-f*g)-o*(n*v-a*g)+d*(n*f-a*s),t[11]=-(r*(s*p-f*c)-o*(n*p-a*c)+l*(n*f-a*s)),t[12]=-(o*(c*m-h*g)-l*(s*m-u*g)+d*(s*h-u*c)),t[13]=r*(c*m-h*g)-l*(n*m-i*g)+d*(n*h-i*c),t[14]=-(r*(s*m-u*g)-o*(n*m-i*g)+d*(n*u-i*s)),t[15]=r*(s*h-u*c)-o*(n*h-i*c)+l*(n*u-i*s),t},h.determinant=function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],u=t[7],f=t[8],l=t[9],c=t[10],h=t[11],p=t[12],d=t[13],g=t[14],m=t[15],v=e*o-r*a,y=e*s-n*a,b=e*u-i*a,_=r*s-n*o,E=r*u-i*o,w=n*u-i*s,A=f*d-l*p,x=f*g-c*p,T=f*m-h*p,R=l*g-c*d,M=l*m-h*d,I=c*m-h*g;return v*I-y*M+b*R+_*T-E*x+w*A},h.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=e[9],p=e[10],d=e[11],g=e[12],m=e[13],v=e[14],y=e[15],b=r[0],_=r[1],E=r[2],w=r[3];return t[0]=b*n+_*s+E*c+w*g,t[1]=b*i+_*u+E*h+w*m,t[2]=b*a+_*f+E*p+w*v,t[3]=b*o+_*l+E*d+w*y,b=r[4],_=r[5],E=r[6],w=r[7],t[4]=b*n+_*s+E*c+w*g,t[5]=b*i+_*u+E*h+w*m,t[6]=b*a+_*f+E*p+w*v,t[7]=b*o+_*l+E*d+w*y,b=r[8],_=r[9],E=r[10],w=r[11],t[8]=b*n+_*s+E*c+w*g,t[9]=b*i+_*u+E*h+w*m,t[10]=b*a+_*f+E*p+w*v,t[11]=b*o+_*l+E*d+w*y,b=r[12],_=r[13],E=r[14],w=r[15],t[12]=b*n+_*s+E*c+w*g,t[13]=b*i+_*u+E*h+w*m,t[14]=b*a+_*f+E*p+w*v,t[15]=b*o+_*l+E*d+w*y,t},h.mul=h.multiply,h.translate=function(t,e,r){var n,i,a,o,s,u,f,l,c,h,p,d,g=r[0],m=r[1],v=r[2];return e===t?(t[12]=e[0]*g+e[4]*m+e[8]*v+e[12],t[13]=e[1]*g+e[5]*m+e[9]*v+e[13],t[14]=e[2]*g+e[6]*m+e[10]*v+e[14],t[15]=e[3]*g+e[7]*m+e[11]*v+e[15]):(n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],f=e[6],l=e[7],c=e[8],h=e[9],p=e[10],d=e[11],t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=u,t[6]=f,t[7]=l,t[8]=c,t[9]=h,t[10]=p,t[11]=d,t[12]=n*g+s*m+c*v+e[12],t[13]=i*g+u*m+h*v+e[13],t[14]=a*g+f*m+p*v+e[14],t[15]=o*g+l*m+d*v+e[15]),t},h.scale=function(t,e,r){var n=r[0],i=r[1],a=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*a,t[9]=e[9]*a,t[10]=e[10]*a,t[11]=e[11]*a,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},h.rotate=function(t,r,n,i){var a,o,s,u,f,l,c,h,p,d,g,m,v,y,b,_,E,w,A,x,T,R,M,I,F=i[0],N=i[1],U=i[2],S=Math.sqrt(F*F+N*N+U*U);return Math.abs(S)o?(s.cross(t,e,i),s.length(t)<1e-6&&s.cross(t,r,i),s.normalize(t,t),p.setAxisAngle(n,t,Math.PI),n):o>.999999?(n[0]=0,n[1]=0,n[2]=0,n[3]=1,n):(s.cross(t,i,a),n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=1+o,p.normalize(n,n))}}(),p.setAxes=function(){var t=c.create();return function(e,r,n,i){return t[0]=n[0],t[3]=n[1],t[6]=n[2],t[1]=i[0],t[4]=i[1],t[7]=i[2],t[2]=-r[0],t[5]=-r[1],t[8]=-r[2],p.normalize(e,p.fromMat3(e,t))}}(),p.clone=u.clone,p.fromValues=u.fromValues,p.copy=u.copy,p.set=u.set,p.identity=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t},p.setAxisAngle=function(t,e,r){r=.5*r;var n=Math.sin(r);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(r),t},p.add=u.add,p.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],u=r[1],f=r[2],l=r[3];return t[0]=n*l+o*s+i*f-a*u,t[1]=i*l+o*u+a*s-n*f,t[2]=a*l+o*f+n*u-i*s,t[3]=o*l-n*s-i*u-a*f,t},p.mul=p.multiply,p.scale=u.scale,p.rotateX=function(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),u=Math.cos(r);return t[0]=n*u+o*s,t[1]=i*u+a*s,t[2]=a*u-i*s,t[3]=o*u-n*s,t},p.rotateY=function(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),u=Math.cos(r);return t[0]=n*u-a*s,t[1]=i*u+o*s,t[2]=a*u+n*s,t[3]=o*u-i*s,t},p.rotateZ=function(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),u=Math.cos(r);return t[0]=n*u+i*s,t[1]=i*u-n*s,t[2]=a*u+o*s,t[3]=o*u-a*s,t},p.calculateW=function(t,e){var r=e[0],n=e[1],i=e[2];return t[0]=r,t[1]=n,t[2]=i,t[3]=-Math.sqrt(Math.abs(1-r*r-n*n-i*i)),t},p.dot=u.dot,p.lerp=u.lerp,p.slerp=function(t,e,r,n){var i,a,o,s,u,f=e[0],l=e[1],c=e[2],h=e[3],p=r[0],d=r[1],g=r[2],m=r[3];return a=f*p+l*d+c*g+h*m,0>a&&(a=-a,p=-p,d=-d,g=-g,m=-m),1-a>1e-6?(i=Math.acos(a),o=Math.sin(i),s=Math.sin((1-n)*i)/o,u=Math.sin(n*i)/o):(s=1-n,u=n),t[0]=s*f+u*p,t[1]=s*l+u*d,t[2]=s*c+u*g,t[3]=s*h+u*m,t},p.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a,s=o?1/o:0;return t[0]=-r*s,t[1]=-n*s,t[2]=-i*s,t[3]=a*s,t},p.conjugate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},p.length=u.length,p.len=p.length,p.squaredLength=u.squaredLength,p.sqrLen=p.squaredLength,p.normalize=u.normalize,p.fromMat3=function(t,e){var r,n=e[0]+e[4]+e[8];if(n>0)r=Math.sqrt(n+1),t[3]=.5*r,r=.5/r,t[0]=(e[7]-e[5])*r,t[1]=(e[2]-e[6])*r,t[2]=(e[3]-e[1])*r;else{var i=0;e[4]>e[0]&&(i=1),e[8]>e[3*i+i]&&(i=2);var a=(i+1)%3,o=(i+2)%3;r=Math.sqrt(e[3*i+i]-e[3*a+a]-e[3*o+o]+1),t[i]=.5*r,r=.5/r,t[3]=(e[3*o+a]-e[3*a+o])*r,t[a]=(e[3*a+i]+e[3*i+a])*r,t[o]=(e[3*o+i]+e[3*i+o])*r}return t},p.str=function(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},"undefined"!=typeof t&&(t.quat=p)}(e.exports)}(this)},{}],179:[function(t,e){"use strict";function r(t,e,r){this.rotation=t,this.center=e,this.distance=r}function n(t,e){var r=e[0],n=e[1],i=(e[2],r*r+n*n);i>1&&(i=1),t[0]=-e[0],t[1]=e[1],t[2]=e[2]||Math.sqrt(1-i),t[3]=0}function i(t,e,n){t=t||[0,0,-1],e=e||[0,0,0],n=n||[0,1,0];var i=new r(f.create(),o.create(),1);return i.lookAt(t,e,n),i}var a=t("gl-matrix"),o=a.vec3,s=a.mat3,u=a.mat4,f=a.quat,l=new Float32Array(16),c=new Float32Array(16),h=r.prototype;h.view=function(t){return t||(t=u.create()),c[0]=c[1]=0,c[2]=-this.distance,u.fromRotationTranslation(t,f.conjugate(l,this.rotation),c),u.translate(t,t,o.negate(l,this.center)),t},h.lookAt=function(t,e,r){u.lookAt(l,t,e,r),s.fromMat4(l,l),f.fromMat3(this.rotation,l),o.copy(this.center,e),this.distance=o.distance(t,e)},h.pan=function(t){var e=this.distance;l[0]=-e*(t[0]||0),l[1]=e*(t[1]||0),l[2]=e*(t[2]||0),o.transformQuat(l,l,this.rotation),o.add(this.center,this.center,l)},h.zoom=function(t){this.distance+=t,this.distance<0&&(this.distance=0)},h.rotate=function(t,e){n(l,t),n(c,e),f.invert(c,c),f.multiply(l,l,c),f.length(l)<1e-6||(f.multiply(this.rotation,this.rotation,l),f.normalize(this.rotation,this.rotation))},e.exports=i},{"gl-matrix":178}],180:[function(t,e){(function(t){e.exports=t.performance&&t.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],181:[function(t,e){function r(t,e,r){t.positions&&t.cells&&(r=e,e=t.cells,t=t.positions),r=r||new Float32Array(9*e.length);for(var n=0,i=0,a=e.length;a>n;n+=1)r[i++]=t[e[n][0]][0],r[i++]=t[e[n][0]][1],r[i++]=t[e[n][0]][2],r[i++]=t[e[n][1]][0],r[i++]=t[e[n][1]][1],r[i++]=t[e[n][1]][2],r[i++]=t[e[n][2]][0],r[i++]=t[e[n][2]][1],r[i++]=t[e[n][2]][2];return r}e.exports=r},{}],182:[function(t,e){function r(t,e){if("string"!=typeof t)throw new TypeError("String expected");e||(e=document);var r=/<([\w:]+)/.exec(t);if(!r)return e.createTextNode(t);t=t.replace(/^\s+|\s+$/g,"");var i=r[1];if("body"==i){var a=e.createElement("html");return a.innerHTML=t,a.removeChild(a.lastChild)}var o=n[i]||n._default,s=o[0],u=o[1],f=o[2],a=e.createElement("div");for(a.innerHTML=u+t+f;s--;)a=a.lastChild;if(a.firstChild==a.lastChild)return a.removeChild(a.firstChild);for(var l=e.createDocumentFragment();a.firstChild;)l.appendChild(a.removeChild(a.firstChild));return l}e.exports=r;var n={legend:[1,"
      ","
      "],tr:[2,"","
      "],col:[2,"","
      "],_default:[0,"",""]};n.td=n.th=[3,"","
      "],n.option=n.optgroup=[1,'"],n.thead=n.tbody=n.colgroup=n.caption=n.tfoot=[1,"","
      "],n.text=n.circle=n.ellipse=n.line=n.path=n.polygon=n.polyline=n.rect=[1,'',""]},{}],183:[function(t,e){function r(t,e){for("string"==typeof e&&(e=n(e)),"function"!=typeof e&&(e=i(e));t&&!e(t);)t=t.parentNode;return t||null}function n(t){return t=String(t).toUpperCase(),function(e){return t===e.nodeName}}function i(t){return function(e){return t===e}}e.exports=r},{}],184:[function(t,e,r){arguments[4][27][0].apply(r,arguments)},{_process:192,"raf-component":185,sliced:187}],185:[function(t,e){e.exports=t(28)},{}],186:[function(t,e,r){function n(t,e){e=e||{};var r=i(t);return r(e)}function i(t){for(var e,r=[],n=o(t),i=0;i/g,">")}r=e.exports=n,r.compile=i},{}],187:[function(t,e,r){arguments[4][29][0].apply(r,arguments)},{"./lib/sliced":188}],188:[function(t,e){e.exports=t(30)},{}],189:[function(t,e,r){function n(t,e,r){if(!(this instanceof n))return new n(t,e,r);var i,a=typeof t;if("number"===a)i=t>0?t>>>0:0;else if("string"===a)"base64"===e&&(t=I(t)),i=n.byteLength(t,e);else{if("object"!==a||null===t)throw new Error("First argument needs to be a number, array or string.");"Buffer"===t.type&&N(t.data)&&(t=t.data),i=+t.length>0?Math.floor(+t.length):0}var o;X?o=n._augment(new Uint8Array(i)):(o=this,o.length=i,o._isBuffer=!0);var s;if(X&&"number"==typeof t.byteLength)o._set(t);else if(U(t))if(n.isBuffer(t))for(s=0;i>s;s++)o[s]=t.readUInt8(s);else for(s=0;i>s;s++)o[s]=(t[s]%256+256)%256;else if("string"===a)o.write(t,0,e);else if("number"===a&&!X&&!r)for(s=0;i>s;s++)o[s]=0;return o}function i(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var a=e.length;q(a%2===0,"Invalid hex string"),n>a/2&&(n=a/2);for(var o=0;n>o;o++){var s=parseInt(e.substr(2*o,2),16);q(!isNaN(s),"Invalid hex string"),t[r+o]=s}return o}function a(t,e,r,n){var i=P(D(e),t,r,n);return i}function o(t,e,r,n){var i=P(L(e),t,r,n);return i}function s(t,e,r,n){return o(t,e,r,n)}function u(t,e,r,n){var i=P(B(e),t,r,n);return i}function f(t,e,r,n){var i=P(j(e),t,r,n);return i}function l(t,e,r){return G.fromByteArray(0===e&&r===t.length?t:t.slice(e,r))}function c(t,e,r){var n="",i="";r=Math.min(t.length,r);for(var a=e;r>a;a++)t[a]<=127?(n+=O(i)+String.fromCharCode(t[a]),i=""):i+="%"+t[a].toString(16);return n+O(i)}function h(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;r>i;i++)n+=String.fromCharCode(t[i]);return n}function p(t,e,r){return h(t,e,r)}function d(t,e,r){var n=t.length;(!e||0>e)&&(e=0),(!r||0>r||r>n)&&(r=n);for(var i="",a=e;r>a;a++)i+=S(t[a]);return i}function g(t,e,r){for(var n=t.slice(e,r),i="",a=0;a=i)){var a;return r?(a=t[e],i>e+1&&(a|=t[e+1]<<8)):(a=t[e]<<8,i>e+1&&(a|=t[e+1])),a}}function v(t,e,r,n){n||(q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+3=i)){var a;return r?(i>e+2&&(a=t[e+2]<<16),i>e+1&&(a|=t[e+1]<<8),a|=t[e],i>e+3&&(a+=t[e+3]<<24>>>0)):(i>e+1&&(a=t[e+1]<<16),i>e+2&&(a|=t[e+2]<<8),i>e+3&&(a|=t[e+3]),a+=t[e]<<24>>>0),a}}function y(t,e,r,n){n||(q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+1=i)){var a=m(t,e,r,!0),o=32768&a;return o?-1*(65535-a+1):a}}function b(t,e,r,n){n||(q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+3=i)){var a=v(t,e,r,!0),o=2147483648&a;return o?-1*(4294967295-a+1):a}}function _(t,e,r,n){return n||(q("boolean"==typeof r,"missing or invalid endian"),q(e+3=a)){for(var o=0,s=Math.min(a-r,2);s>o;o++)t[r+o]=(e&255<<8*(n?o:1-o))>>>8*(n?o:1-o);return r+2}}function A(t,e,r,n,i){i||(q(void 0!==e&&null!==e,"missing value"),q("boolean"==typeof n,"missing or invalid endian"),q(void 0!==r&&null!==r,"missing offset"),q(r+3=a)){for(var o=0,s=Math.min(a-r,4);s>o;o++)t[r+o]=e>>>8*(n?o:3-o)&255;return r+4}}function x(t,e,r,n,i){i||(q(void 0!==e&&null!==e,"missing value"),q("boolean"==typeof n,"missing or invalid endian"),q(void 0!==r&&null!==r,"missing offset"),q(r+1=a))return e>=0?w(t,e,r,n,i):w(t,65535+e+1,r,n,i),r+2}function T(t,e,r,n,i){i||(q(void 0!==e&&null!==e,"missing value"),q("boolean"==typeof n,"missing or invalid endian"),q(void 0!==r&&null!==r,"missing offset"),q(r+3=a))return e>=0?A(t,e,r,n,i):A(t,4294967295+e+1,r,n,i),r+4}function R(t,e,r,n,i){i||(q(void 0!==e&&null!==e,"missing value"),q("boolean"==typeof n,"missing or invalid endian"),q(void 0!==r&&null!==r,"missing offset"),q(r+3=a))return z.write(t,e,r,n,23,4),r+4}function M(t,e,r,n,i){i||(q(void 0!==e&&null!==e,"missing value"),q("boolean"==typeof n,"missing or invalid endian"),q(void 0!==r&&null!==r,"missing offset"),q(r+7=a))return z.write(t,e,r,n,52,8),r+8}function I(t){for(t=F(t).replace(H,"");t.length%4!==0;)t+="=";return t}function F(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function N(t){return(Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)})(t)}function U(t){return N(t)||n.isBuffer(t)||t&&"object"==typeof t&&"number"==typeof t.length}function S(t){return 16>t?"0"+t.toString(16):t.toString(16)}function D(t){for(var e=[],r=0;r=n)e.push(n);else{var i=r;n>=55296&&57343>=n&&r++;for(var a=encodeURIComponent(t.slice(i,r+1)).substr(1).split("%"),o=0;o>8,n=e%256,i.push(n),i.push(r);return i}function B(t){return G.toByteArray(t)}function P(t,e,r,n){for(var i=0;n>i&&!(i+r>=e.length||i>=t.length);i++)e[i+r]=t[i];return i}function O(t){try{return decodeURIComponent(t)}catch(e){return String.fromCharCode(65533)}}function C(t,e){q("number"==typeof t,"cannot write a non-number as a number"),q(t>=0,"specified a negative value for writing an unsigned value"),q(e>=t,"value is larger than maximum value for type"),q(Math.floor(t)===t,"value has a fractional component")}function k(t,e,r){q("number"==typeof t,"cannot write a non-number as a number"),q(e>=t,"value larger than maximum allowed value"),q(t>=r,"value smaller than minimum allowed value"),q(Math.floor(t)===t,"value has a fractional component")}function V(t,e,r){q("number"==typeof t,"cannot write a non-number as a number"),q(e>=t,"value larger than maximum allowed value"),q(t>=r,"value smaller than minimum allowed value")}function q(t,e){if(!t)throw new Error(e||"Failed assertion")}var G=t("base64-js"),z=t("ieee754");r.Buffer=n,r.SlowBuffer=n,r.INSPECT_MAX_BYTES=50,n.poolSize=8192;var X=function(){try{var t=new ArrayBuffer(0),e=new Uint8Array(t);return e.foo=function(){return 42},42===e.foo()&&"function"==typeof e.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(r){return!1}}();n.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},n.isBuffer=function(t){return!(null==t||!t._isBuffer)},n.byteLength=function(t,e){var r;switch(t=t.toString(),e||"utf8"){case"hex":r=t.length/2;break;case"utf8":case"utf-8":r=D(t).length;break;case"ascii":case"binary":case"raw":r=t.length;break;case"base64":r=B(t).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":r=2*t.length;break;default:throw new Error("Unknown encoding")}return r},n.concat=function(t,e){if(q(N(t),"Usage: Buffer.concat(list[, length])"),0===t.length)return new n(0);if(1===t.length)return t[0];var r;if(void 0===e)for(e=0,r=0;ra&&t[a]===e[a];a++);return a!==o&&(r=t[a],i=e[a]),i>r?-1:r>i?1:0},n.prototype.write=function(t,e,r,n){if(isFinite(e))isFinite(r)||(n=r,r=void 0);else{var l=n;n=e,e=r,r=l}e=Number(e)||0;var c=this.length-e;r?(r=Number(r),r>c&&(r=c)):r=c,n=String(n||"utf8").toLowerCase();var h;switch(n){case"hex":h=i(this,t,e,r);break;case"utf8":case"utf-8":h=a(this,t,e,r);break;case"ascii":h=o(this,t,e,r);break;case"binary":h=s(this,t,e,r);break;case"base64":h=u(this,t,e,r);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":h=f(this,t,e,r);break;default:throw new Error("Unknown encoding")}return h},n.prototype.toString=function(t,e,r){var n=this;if(t=String(t||"utf8").toLowerCase(),e=Number(e)||0,r=void 0===r?n.length:Number(r),r===e)return"";var i;switch(t){case"hex":i=d(n,e,r);break;case"utf8":case"utf-8":i=c(n,e,r);break;case"ascii":i=h(n,e,r);break;case"binary":i=p(n,e,r);break;case"base64":i=l(n,e,r);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":i=g(n,e,r);break;default:throw new Error("Unknown encoding")}return i},n.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},n.prototype.equals=function(t){return q(n.isBuffer(t),"Argument must be a Buffer"),0===n.compare(this,t)},n.prototype.compare=function(t){return q(n.isBuffer(t),"Argument must be a Buffer"),n.compare(this,t)},n.prototype.copy=function(t,e,r,n){var i=this;if(r||(r=0),n||0===n||(n=this.length),e||(e=0),n!==r&&0!==t.length&&0!==i.length){q(n>=r,"sourceEnd < sourceStart"),q(e>=0&&e=0&&r=0&&n<=i.length,"sourceEnd out of bounds"),n>this.length&&(n=this.length),t.length-ea||!X)for(var o=0;a>o;o++)t[o+e]=this[o+r];else t._set(this.subarray(r,r+a),e)}},n.prototype.slice=function(t,e){var r=this.length;if(t=~~t,e=void 0===e?r:~~e,0>t?(t+=r,0>t&&(t=0)):t>r&&(t=r),0>e?(e+=r,0>e&&(e=0)):e>r&&(e=r),t>e&&(e=t),X)return n._augment(this.subarray(t,e));for(var i=e-t,a=new n(i,void 0,!0),o=0;i>o;o++)a[o]=this[o+t];return a},n.prototype.get=function(t){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(t)},n.prototype.set=function(t,e){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(t,e)},n.prototype.readUInt8=function(t,e){return e||(q(void 0!==t&&null!==t,"missing offset"),q(t=this.length?void 0:this[t]},n.prototype.readUInt16LE=function(t,e){return m(this,t,!0,e)},n.prototype.readUInt16BE=function(t,e){return m(this,t,!1,e)},n.prototype.readUInt32LE=function(t,e){return v(this,t,!0,e)},n.prototype.readUInt32BE=function(t,e){return v(this,t,!1,e)},n.prototype.readInt8=function(t,e){if(e||(q(void 0!==t&&null!==t,"missing offset"),q(t=this.length)){var r=128&this[t];return r?-1*(255-this[t]+1):this[t]}},n.prototype.readInt16LE=function(t,e){return y(this,t,!0,e)},n.prototype.readInt16BE=function(t,e){return y(this,t,!1,e)},n.prototype.readInt32LE=function(t,e){return b(this,t,!0,e)},n.prototype.readInt32BE=function(t,e){return b(this,t,!1,e)},n.prototype.readFloatLE=function(t,e){return _(this,t,!0,e)},n.prototype.readFloatBE=function(t,e){return _(this,t,!1,e)},n.prototype.readDoubleLE=function(t,e){return E(this,t,!0,e)},n.prototype.readDoubleBE=function(t,e){return E(this,t,!1,e)},n.prototype.writeUInt8=function(t,e,r){return r||(q(void 0!==t&&null!==t,"missing value"),q(void 0!==e&&null!==e,"missing offset"),q(e=this.length?void 0:(this[e]=t,e+1)},n.prototype.writeUInt16LE=function(t,e,r){return w(this,t,e,!0,r)},n.prototype.writeUInt16BE=function(t,e,r){return w(this,t,e,!1,r)},n.prototype.writeUInt32LE=function(t,e,r){return A(this,t,e,!0,r)},n.prototype.writeUInt32BE=function(t,e,r){return A(this,t,e,!1,r)},n.prototype.writeInt8=function(t,e,r){return r||(q(void 0!==t&&null!==t,"missing value"),q(void 0!==e&&null!==e,"missing offset"),q(e=this.length?void 0:(t>=0?this.writeUInt8(t,e,r):this.writeUInt8(255+t+1,e,r),e+1)},n.prototype.writeInt16LE=function(t,e,r){return x(this,t,e,!0,r)},n.prototype.writeInt16BE=function(t,e,r){return x(this,t,e,!1,r)},n.prototype.writeInt32LE=function(t,e,r){return T(this,t,e,!0,r)},n.prototype.writeInt32BE=function(t,e,r){return T(this,t,e,!1,r)},n.prototype.writeFloatLE=function(t,e,r){return R(this,t,e,!0,r)},n.prototype.writeFloatBE=function(t,e,r){return R(this,t,e,!1,r)},n.prototype.writeDoubleLE=function(t,e,r){return M(this,t,e,!0,r)},n.prototype.writeDoubleBE=function(t,e,r){return M(this,t,e,!1,r)},n.prototype.fill=function(t,e,r){if(t||(t=0),e||(e=0),r||(r=this.length),q(r>=e,"end < start"),r!==e&&0!==this.length){q(e>=0&&e=0&&r<=this.length,"end out of bounds");var n;if("number"==typeof t)for(n=e;r>n;n++)this[n]=t;else{var i=D(t.toString()),a=i.length;for(n=e;r>n;n++)this[n]=i[n%a]}return this}},n.prototype.inspect=function(){for(var t=[],e=this.length,n=0;e>n;n++)if(t[n]=S(this[n]),n===r.INSPECT_MAX_BYTES){t[n+1]="...";break}return""},n.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(X)return new n(this).buffer;for(var t=new Uint8Array(this.length),e=0,r=t.length;r>e;e+=1)t[e]=this[e];return t.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var Y=n.prototype;n._augment=function(t){return t._isBuffer=!0,t._get=t.get,t._set=t.set,t.get=Y.get,t.set=Y.set,t.write=Y.write,t.toString=Y.toString,t.toLocaleString=Y.toString,t.toJSON=Y.toJSON,t.equals=Y.equals,t.compare=Y.compare,t.copy=Y.copy,t.slice=Y.slice,t.readUInt8=Y.readUInt8,t.readUInt16LE=Y.readUInt16LE,t.readUInt16BE=Y.readUInt16BE,t.readUInt32LE=Y.readUInt32LE,t.readUInt32BE=Y.readUInt32BE,t.readInt8=Y.readInt8,t.readInt16LE=Y.readInt16LE,t.readInt16BE=Y.readInt16BE,t.readInt32LE=Y.readInt32LE,t.readInt32BE=Y.readInt32BE,t.readFloatLE=Y.readFloatLE,t.readFloatBE=Y.readFloatBE,t.readDoubleLE=Y.readDoubleLE,t.readDoubleBE=Y.readDoubleBE,t.writeUInt8=Y.writeUInt8,t.writeUInt16LE=Y.writeUInt16LE,t.writeUInt16BE=Y.writeUInt16BE,t.writeUInt32LE=Y.writeUInt32LE,t.writeUInt32BE=Y.writeUInt32BE,t.writeInt8=Y.writeInt8,t.writeInt16LE=Y.writeInt16LE,t.writeInt16BE=Y.writeInt16BE,t.writeInt32LE=Y.writeInt32LE,t.writeInt32BE=Y.writeInt32BE,t.writeFloatLE=Y.writeFloatLE,t.writeFloatBE=Y.writeFloatBE,t.writeDoubleLE=Y.writeDoubleLE,t.writeDoubleBE=Y.writeDoubleBE,t.fill=Y.fill,t.inspect=Y.inspect,t.toArrayBuffer=Y.toArrayBuffer,t};var H=/[^+\/0-9A-z]/g},{"base64-js":190,ieee754:191}],190:[function(t,e,r){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(t){"use strict";function e(t){var e=t.charCodeAt(0);return e===o?62:e===s?63:u>e?-1:u+10>e?e-u+26+26:l+26>e?e-l:f+26>e?e-f+26:void 0}function r(t){function r(t){f[c++]=t}var n,i,o,s,u,f;if(t.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var l=t.length;u="="===t.charAt(l-2)?2:"="===t.charAt(l-1)?1:0,f=new a(3*t.length/4-u),o=u>0?t.length-4:t.length;var c=0;for(n=0,i=0;o>n;n+=4,i+=3)s=e(t.charAt(n))<<18|e(t.charAt(n+1))<<12|e(t.charAt(n+2))<<6|e(t.charAt(n+3)),r((16711680&s)>>16),r((65280&s)>>8),r(255&s);return 2===u?(s=e(t.charAt(n))<<2|e(t.charAt(n+1))>>4,r(255&s)):1===u&&(s=e(t.charAt(n))<<10|e(t.charAt(n+1))<<4|e(t.charAt(n+2))>>2,r(s>>8&255),r(255&s)),f}function i(t){function e(t){return n.charAt(t)}function r(t){return e(t>>18&63)+e(t>>12&63)+e(t>>6&63)+e(63&t)}var i,a,o,s=t.length%3,u="";for(i=0,o=t.length-s;o>i;i+=3)a=(t[i]<<16)+(t[i+1]<<8)+t[i+2],u+=r(a);switch(s){case 1:a=t[t.length-1],u+=e(a>>2),u+=e(a<<4&63),u+="==";break;case 2:a=(t[t.length-2]<<8)+t[t.length-1],u+=e(a>>10),u+=e(a>>4&63),u+=e(a<<2&63),u+="="}return u}var a="undefined"!=typeof Uint8Array?Uint8Array:Array,o="+".charCodeAt(0),s="/".charCodeAt(0),u="0".charCodeAt(0),f="a".charCodeAt(0),l="A".charCodeAt(0);t.toByteArray=r,t.fromByteArray=i}("undefined"==typeof r?this.base64js={}:r)},{}],191:[function(t,e,r){r.read=function(t,e,r,n,i){var a,o,s=8*i-n-1,u=(1<>1,l=-7,c=r?i-1:0,h=r?-1:1,p=t[e+c];for(c+=h,a=p&(1<<-l)-1,p>>=-l,l+=s;l>0;a=256*a+t[e+c],c+=h,l-=8);for(o=a&(1<<-l)-1,a>>=-l,l+=n;l>0;o=256*o+t[e+c],c+=h,l-=8);if(0===a)a=1-f;else{if(a===u)return o?0/0:1/0*(p?-1:1);o+=Math.pow(2,n),a-=f}return(p?-1:1)*o*Math.pow(2,a-n)},r.write=function(t,e,r,n,i,a){var o,s,u,f=8*a-i-1,l=(1<>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:a-1,d=n?1:-1,g=0>e||0===e&&0>1/e?1:0;for(e=Math.abs(e),isNaN(e)||1/0===e?(s=isNaN(e)?1:0,o=l):(o=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-o))<1&&(o--,u*=2),e+=o+c>=1?h/u:h*Math.pow(2,1-c),e*u>=2&&(o++,u/=2),o+c>=l?(s=0,o=l):o+c>=1?(s=(e*u-1)*Math.pow(2,i),o+=c):(s=e*Math.pow(2,c-1)*Math.pow(2,i),o=0));i>=8;t[r+p]=255&s,p+=d,s/=256,i-=8);for(o=o<0;t[r+p]=255&o,p+=d,o/=256,f-=8);t[r+p-d]|=128*g}},{}],192:[function(t,e){function r(){}var n=e.exports={};n.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var r=[];return window.addEventListener("message",function(t){var e=t.source;if((e===window||null===e)&&"process-tick"===t.data&&(t.stopPropagation(),r.length>0)){var n=r.shift();n()}},!0),function(t){r.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.on=r,n.addListener=r,n.once=r,n.off=r,n.removeListener=r,n.removeAllListeners=r,n.emit=r,n.binding=function(){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"raymarch",link:"https://github.com/mikolalysenko/raymarch/",desc:"",thumb:"http://imgur.com/NpvsXIH.png",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],Tools:[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2}],Math:[{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:2},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:3}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:5}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0}],Internals:[{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:4},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:5}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4}]}},{}],3:[function(require){var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas")),flock=document.getElementById("community").querySelector("canvas");require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid),require("@stackgl/splash-flock")(flock)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;ii;i++)pdata[i]=FBO(gl,[SIZE,SIZE],{"float":!0}),pdata[i].color[0].setPixels(starter);window.addEventListener("resize",debounce(fit(canvas,window))),shaders.logic=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(gl),shaders.render=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(gl)}function switchFrames(data){return data.push(data.shift()),data}function createParticleVAO(gl,size){for(var data=new Float32Array(size*size),n=0,x=0;size>x;x++)for(var y=0;size>y;y++)data[n++]=x/size,data[n++]=y/size;var buffer=createBuffer(gl,data),vao=VAO(gl,[{buffer:buffer,type:gl.FLOAT,size:2}]);return vao.length=data.length/2,vao}function createStartPositions(size){for(var data=new Float32Array(size*size*4),i=0;i=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"}) +},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:189,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;islice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],31:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:37,"ndarray-ops":32,"typedarray-pool":41,webglew:43}],32:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":33}],33:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":35}],34:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:36}],35:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":34}],36:[function(require,module){module.exports=require(13)},{}],37:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":38}],38:[function(require,module){module.exports=require(15)},{}],39:[function(require,module){module.exports=require(16)},{}],40:[function(require,module){module.exports=require(17)},{}],41:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":39,buffer:189,dup:40}],42:[function(require,module,exports){void function(global,undefined_,undefined){function define(object,key,value){return"function"==typeof key&&(value=key,key=nameOf(value).replace(/_$/,"")),defProp(object,key,{configurable:!0,writable:!0,value:value})}function nameOf(func){return"function"!=typeof func?"":"name"in func?func.name:toSource.call(func).match(funcName)[1]}function createStorage(creator){function storage(object,value){return value||2===arguments.length?weakmap.set(object,value):(value=weakmap.get(object),value===undefined&&(value=creator(object),weakmap.set(object,value))),value}var weakmap=new WM;return creator||(creator=defaultCreator),storage}var getProps=Object.getOwnPropertyNames,defProp=Object.defineProperty,toSource=Function.prototype.toString,create=Object.create,hasOwn=Object.prototype.hasOwnProperty,funcName=/^\n?function\s?(\w*)?_?\(/,Data=function(){function Data(){var puid=createUID(),secret={};this.unlock=function(obj){var store=storage(obj);if(hasOwn.call(store,puid))return store[puid](secret);var data=create(null,dataDesc);return defProp(store,puid,{value:new Function("s","l",datalock)(secret,data)}),data}}var dataDesc={value:{writable:!0,value:undefined}},datalock="return function(k){if(k===s)return l}",uids=create(null),createUID=function(){var key=Math.random().toString(36).slice(2);return key in uids?createUID():uids[key]=key},globalID=createUID(),storage=function(obj){if(hasOwn.call(obj,globalID))return obj[globalID];if(!Object.isExtensible(obj))throw new TypeError("Object must be extensible");var store=create(null);return defProp(obj,globalID,{value:store}),store};return define(Object,function(obj){var props=getProps(obj);return hasOwn.call(obj,globalID)&&props.splice(props.indexOf(globalID),1),props}),define(Data.prototype,function(o){return this.unlock(o).value}),define(Data.prototype,function(o,v){this.unlock(o).value=v}),Data}(),WM=function(data){function WeakMap(iterable){return this===global||null==this||this===WeakMap.prototype?new WeakMap(iterable):(wrap(this,new Data),void initialize(this,iterable))}function get(key){validate(key);var value=unwrap(this).get(key);return value===undefined_?undefined:value}function set(key,value){validate(key),unwrap(this).set(key,value===undefined?undefined_:value)}function has(key){return validate(key),unwrap(this).get(key)!==undefined}function delete_(key){validate(key);var data=unwrap(this),had=data.get(key)!==undefined;return data.set(key,undefined),had}function toString(){return unwrap(this),"[object WeakMap]"}var validate=function(key){if(null==key||"object"!=typeof key&&"function"!=typeof key)throw new TypeError("Invalid WeakMap key")},wrap=function(collection,value){var store=data.unlock(collection);if(store.value)throw new TypeError("Object is already a WeakMap");store.value=value},unwrap=function(collection){var storage=data.unlock(collection).value;if(!storage)throw new TypeError("WeakMap is not generic");return storage},initialize=function(weakmap,iterable){null!==iterable&&"object"==typeof iterable&&"function"==typeof iterable.forEach&&iterable.forEach(function(item,i){item instanceof Array&&2===item.length&&set.call(weakmap,iterable[i][0],iterable[i][1])})};try{var src=("return "+delete_).replace("e_","\\u0065"),del=new Function("unwrap","validate",src)(unwrap,validate)}catch(e){var del=delete_}var src=(""+Object).split("Object"),stringifier=function(){return src[0]+nameOf(this)+src[1]};define(stringifier,stringifier);var prep={__proto__:[]}instanceof Array?function(f){f.__proto__=stringifier}:function(f){define(f,stringifier)};return prep(WeakMap),[toString,get,set,has,del].forEach(function(method){define(WeakMap.prototype,method),prep(method)}),WeakMap}(new Data),defaultCreator=Object.create?function(){return Object.create(null)}:function(){return{}};"undefined"!=typeof module?module.exports=WM:"undefined"!=typeof exports?exports.WeakMap=WM:"WeakMap"in global||(global.WeakMap=WM),WM.createStorage=createStorage,global.WeakMap&&(global.WeakMap.createStorage=createStorage)}((0,eval)("this"))},{}],43:[function(require,module){"use strict";function baseName(ext_name){return ext_name.replace(/^[A-Z]+_/,"")}function initWebGLEW(gl){var struct=WebGLEWStruct.get(gl);if(struct)return struct;for(var extensions={},supported=gl.getSupportedExtensions(),i=0;i=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,result.bind(),gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var state=saveFBOState(fbo.gl),gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),width=fbo._shape[0],height=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;ii;++i)this.color[i]=null;this._color_rb=null,this.depth=null,this._depth_rb=null,this._colorType=colorType,this._useDepth=useDepth,this._useStencil=useStencil;var parent=this,shapeVector=[0|width,0|height];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(w){return parent.width=w}},1:{get:function(){return parent._shape[1]},set:function(h){return parent.height=h}}}),this._shapeVector=shapeVector,rebuildFBO(this)}function reshapeFBO(fbo,w,h){if(fbo._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(fbo._shape[0]!==w||fbo._shape[1]!==h){var gl=fbo.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(0>w||w>maxFBOSize||0>h||h>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");fbo._shape[0]=w,fbo._shape[1]=h;for(var state=saveFBOState(gl),i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperties(proto,{shape:{get:function(){return this._destroyed?[0,0]:this._shapeVector},set:function(x){if(Array.isArray(x)||(x=[0|x,0|x]),2!==x.length)throw new Error("gl-fbo: Shape vector must be length 2");var w=0|x[0],h=0|x[1];return reshapeFBO(this,w,h),[w,h]},enumerable:!1},width:{get:function(){return this._destroyed?0:this._shape[0]},set:function(w){return w=0|w,reshapeFBO(this,w,this._shape[1]),w},enumerable:!1},height:{get:function(){return this._destroyed?0:this._shape[1]},set:function(h){return h=0|h,reshapeFBO(this,this._shape[0],h),h},enumerable:!1}}),proto.bind=function(){if(!this._destroyed){var gl=this.gl;gl.bindFramebuffer(gl.FRAMEBUFFER,this.handle),gl.viewport(0,0,this._shape[0],this._shape[1])}},proto.dispose=function(){if(!this._destroyed){this._destroyed=!0;var gl=this.gl;gl.deleteFramebuffer(this.handle),this.handle=null,this.depth&&(this.depth.dispose(),this.depth=null),this._depth_rb&&(gl.deleteRenderbuffer(this._depth_rb),this._depth_rb=null);for(var i=0;iw||w>maxSize||0>h||h>maxSize)throw new Error("gl-texture2d: Invalid texture size");return tex._shape=[w,h],tex.bind(),gl.texImage2D(gl.TEXTURE_2D,0,tex.format,w,h,0,tex.format,tex.type,null),tex._mipLevels=[0],tex}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[width,height],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1;var parent=this,wrapVector=[this._wrapS,this._wrapT];Object.defineProperties(wrapVector,{0:{get:function(){return parent._wrapS},set:function(v){return parent.wrapS=v}},1:{get:function(){return parent._wrapT},set:function(v){return parent.wrapT=v}}}),this._wrapVector=wrapVector;var shapeVector=[this._shape[0],this._shape[1]];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(v){return parent.width=v}},1:{get:function(){return parent._shape[1]},set:function(v){return parent.height=v}}}),this._shapeVector=shapeVector}function isPacked(shape,stride){return 3===shape.length?1===stride[2]&&stride[1]===shape[0]*shape[2]&&stride[0]===shape[2]:1===stride[0]&&stride[1]===shape[0]}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape.slice();if(shape.length<2||shape.length>3)throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d");var type=0,format=0,packed=isPacked(shape,array.stride.slice());"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var channels=1;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}channels=shape[2]}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape,[shape[2],shape[2]*shape[0],1]);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture(); +return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(shape,array.stride.slice()),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type!==gl.FLOAT||webglew(gl).texture_float||(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store,size=array.size;if(packed)buffer=0===array.offset&&array.data.length===size?array.data:array.data.subarray(array.offset,array.offset+size);else{var stride=[shape[2],shape[2]*shape[0],1];buf_store=pool.malloc(size,dtype);var buf_array=ndarray(buf_store,shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,size)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[0],shape[1],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][0],0|arguments[1][1],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew");module.exports=createTexture2D;var linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)},proto=Texture2D.prototype;Object.defineProperties(proto,{minFilter:{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}},magFilter:{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}},mipSamples:{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}},wrapS:{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}},wrapT:{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}},wrap:{get:function(){return this._wrapVector},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapS=v[0],this._wrapT=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),v}},shape:{get:function(){return this._shapeVector},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];return reshapeTexture(this,0|x[0],0|x[1]),[0|x[0],0|x[1]]}},width:{get:function(){return this._shape[0]},set:function(w){return w=0|w,reshapeTexture(this,w,this._shape[1]),w}},height:{get:function(){return this._shape[1]},set:function(h){return h=0|h,reshapeTexture(this,this._shape[0],h),h}}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[1],x_off=0|x_off[0]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}}},{ndarray:54,"ndarray-ops":49,"typedarray-pool":58,webglew:61}],60:[function(require,module){module.exports=require(42)},{}],61:[function(require,module){module.exports=require(43)},{weakmap:60}],62:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":63}],63:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":65}],64:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:66}],65:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":64}],66:[function(require,module){module.exports=require(13)},{}],67:[function(require,module){module.exports=require(16)},{}],68:[function(require,module){module.exports=require(17)},{}],69:[function(require,module){module.exports=require(41)},{"bit-twiddle":67,buffer:189,dup:68}],70:[function(require,module){module.exports=require(42)},{}],71:[function(require,module){module.exports=require(43)},{weakmap:70}],72:[function(require,module,exports){arguments[4][59][0].apply(exports,arguments)},{ndarray:86,"ndarray-ops":62,"typedarray-pool":69,webglew:71}],73:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],74:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":73}],75:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;ii;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],82:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;kheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":89,"a-big-triangle":107,"canvas-fit":108,clone:110,"cube-cube":111,"face-normals":114,"frame-debounce":115,"gl-clear":120,"gl-context":121,"gl-fbo":123,"gl-geometry":126,"gl-matrix":151,"gl-texture2d":164,glslify:166,"glslify/adapter.js":165,"mesh-combine":172,"orbit-camera":179,"right-now":180,"unindex-mesh":181}],91:[function(require,module,exports){arguments[4][8][0].apply(exports,arguments)},{ndarray:97,"ndarray-ops":92,"typedarray-pool":101}],92:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":93}],93:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":95}],94:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:96}],95:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":94}],96:[function(require,module){module.exports=require(13)},{}],97:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":98}],98:[function(require,module){module.exports=require(15)},{}],99:[function(require,module){module.exports=require(16)},{}],100:[function(require,module){module.exports=require(17)},{}],101:[function(require,module){module.exports=require(18)},{"bit-twiddle":99,dup:100}],102:[function(require,module){module.exports=require(19) +},{}],103:[function(require,module){module.exports=require(20)},{"./do-bind.js":102}],104:[function(require,module){module.exports=require(21)},{"./do-bind.js":102}],105:[function(require,module){module.exports=require(22)},{}],106:[function(require,module){module.exports=require(23)},{"./lib/vao-emulated.js":103,"./lib/vao-native.js":104,webglew:105}],107:[function(require,module){module.exports=require(24)},{"gl-buffer":91,"gl-vao":106}],108:[function(require,module,exports){arguments[4][25][0].apply(exports,arguments)},{"element-size":109}],109:[function(require,module){module.exports=require(26)},{}],110:[function(require,module){(function(Buffer){"use strict";function objectToString(o){return Object.prototype.toString.call(o)}function clone(parent,circular,depth,prototype){function _clone(parent,depth){if(null===parent)return null;if(0==depth)return parent;var child;if("object"!=typeof parent)return parent;if(util.isArray(parent))child=[];else if(util.isRegExp(parent))child=new RegExp(parent.source,util.getRegExpFlags(parent)),parent.lastIndex&&(child.lastIndex=parent.lastIndex);else if(util.isDate(parent))child=new Date(parent.getTime());else{if(useBuffer&&Buffer.isBuffer(parent))return child=new Buffer(parent.length),parent.copy(child),child;child=Object.create("undefined"==typeof prototype?Object.getPrototypeOf(parent):prototype)}if(circular){var index=allParents.indexOf(parent);if(-1!=index)return allChildren[index];allParents.push(parent),allChildren.push(child)}for(var i in parent)child[i]=_clone(parent[i],depth-1);return child}var allParents=[],allChildren=[],useBuffer="undefined"!=typeof Buffer;return"undefined"==typeof circular&&(circular=!0),"undefined"==typeof depth&&(depth=1/0),_clone(parent,depth)}var util={isArray:function(ar){return Array.isArray(ar)||"object"==typeof ar&&"[object Array]"===objectToString(ar)},isDate:function(d){return"object"==typeof d&&"[object Date]"===objectToString(d)},isRegExp:function(re){return"object"==typeof re&&"[object RegExp]"===objectToString(re)},getRegExpFlags:function(re){var flags="";return re.global&&(flags+="g"),re.ignoreCase&&(flags+="i"),re.multiline&&(flags+="m"),flags}};"object"==typeof module&&(module.exports=clone),clone.clonePrototype=function(parent){if(null===parent)return null;var c=function(){};return c.prototype=parent,new c}}).call(this,require("buffer").Buffer)},{buffer:189}],111:[function(require,module){function cubecube(w,h,d,filter){filter=filter||truthy;for(var size=[1/w,1/h,1/d],cubes=[],x=0;w>x;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":113}],112:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],113:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],115:[function(require,module,exports){arguments[4][27][0].apply(exports,arguments)},{_process:192,"raf-component":116,sliced:117}],116:[function(require,module){module.exports=require(28)},{}],117:[function(require,module,exports){arguments[4][29][0].apply(exports,arguments)},{"./lib/sliced":118}],118:[function(require,module){module.exports=require(30)},{}],119:[function(require,module){module.exports=require(44)},{}],120:[function(require,module){module.exports=require(45)},{"./defaults":119}],121:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":122}],122:[function(require,module){module.exports=require(28)},{}],123:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:128}],128:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],129:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:135,"ndarray-ops":130,"typedarray-pool":139,webglew:141}],130:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":131}],131:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":133}],132:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:134}],133:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":132}],134:[function(require,module){module.exports=require(13)},{}],135:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":136}],136:[function(require,module){module.exports=require(15)},{}],137:[function(require,module){module.exports=require(16)},{}],138:[function(require,module){module.exports=require(17)},{}],139:[function(require,module){module.exports=require(41)},{"bit-twiddle":137,buffer:189,dup:138}],140:[function(require,module){module.exports=require(42)},{}],141:[function(require,module){module.exports=require(43)},{weakmap:140}],142:[function(require,module){module.exports=require(73)},{}],143:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements){this._elements=elements,this._attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":142}],144:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2]; +return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],152:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":153}],153:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":155}],154:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:156}],155:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":154}],156:[function(require,module){module.exports=require(13)},{}],157:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":158}],158:[function(require,module){module.exports=require(15)},{}],159:[function(require,module){module.exports=require(16)},{}],160:[function(require,module){module.exports=require(17)},{}],161:[function(require,module){module.exports=require(41)},{"bit-twiddle":159,buffer:189,dup:160}],162:[function(require,module){module.exports=require(42)},{}],163:[function(require,module){module.exports=require(43)},{weakmap:162}],164:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function isPacked(array){for(var shape=array.shape,stride=array.stride,s=1,i=shape.length-1;i>=0;--i){if(stride[i]!==s)return!1;s*=shape[i]}return!0}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(array),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type===gl.FLOAT&&webglew(gl).texture_float&&(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store;if(packed){var array_size=array.size;buffer=array.data.subarray(array.offset,array.offset+array_size)}else{for(var sz=1,stride=new Array(shape.length),i=shape.length-1;i>=0;--i)stride[i]=sz,sz*=shape[i];buf_store=pool.malloc(sz,dtype);var buf_array=ndarray(buf_store,array.shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,sz)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[1],shape[0],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE); +if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][1],0|arguments[1][0],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew"),linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)};Object.defineProperty(Texture2D.prototype,"minFilter",{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}});var proto=Texture2D.prototype;Object.defineProperty(proto,"magFilter",{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}}),Object.defineProperty(proto,"wrapS",{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}}),Object.defineProperty(proto,"wrapT",{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}}),Object.defineProperty(proto,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapT=v[0],this._wrapS=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),v}}),Object.defineProperty(proto,"mipSamples",{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(proto,"shape",{get:function(){return this._shape},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];var r=0|x[0],c=0|x[1];if(this.height===r&&this.width===c)return x;var gl=this.gl,maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>c||c>maxSize||0>r||r>maxSize)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[r,c],this.bind(),gl.texImage2D(gl.TEXTURE_2D,0,this.format,c,r,0,this.format,this.type,null),this._mipLevels=[0],x}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[0],x_off=0|x_off[1]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}},module.exports=createTexture2D},{ndarray:157,"ndarray-ops":152,"typedarray-pool":161,webglew:163}],165:[function(require,module,exports){arguments[4][79][0].apply(exports,arguments)},{"gl-shader-core":171}],166:[function(require,module){module.exports=require(80)},{}],167:[function(require,module){module.exports=require(81)},{}],168:[function(require,module,exports){arguments[4][82][0].apply(exports,arguments)},{"./reflect.js":169,dup:170}],169:[function(require,module){module.exports=require(83)},{}],170:[function(require,module){module.exports=require(17)},{}],171:[function(require,module){module.exports=require(85)},{"./lib/create-attributes.js":167,"./lib/create-uniforms.js":168,"./lib/reflect.js":169}],172:[function(require,module){function combine(meshes){for(var pos=[],cel=[],p=0,c=0,k=0,i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out +},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],179:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance}function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":178}],180:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],181:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],182:[function(require,module){function parse(html,doc){if("string"!=typeof html)throw new TypeError("String expected");doc||(doc=document);var m=/<([\w:]+)/.exec(html);if(!m)return doc.createTextNode(html);html=html.replace(/^\s+|\s+$/g,"");var tag=m[1];if("body"==tag){var el=doc.createElement("html");return el.innerHTML=html,el.removeChild(el.lastChild)}var wrap=map[tag]||map._default,depth=wrap[0],prefix=wrap[1],suffix=wrap[2],el=doc.createElement("div");for(el.innerHTML=prefix+html+suffix;depth--;)el=el.lastChild;if(el.firstChild==el.lastChild)return el.removeChild(el.firstChild);for(var fragment=doc.createDocumentFragment();el.firstChild;)fragment.appendChild(el.removeChild(el.firstChild));return fragment}module.exports=parse;var map={legend:[1,"
      ","
      "],tr:[2,"","
      "],col:[2,"","
      "],_default:[0,"",""]};map.td=map.th=[3,"","
      "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
      "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],183:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],184:[function(require,module,exports){arguments[4][27][0].apply(exports,arguments)},{_process:192,"raf-component":185,sliced:187}],185:[function(require,module){module.exports=require(28)},{}],186:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],187:[function(require,module,exports){arguments[4][29][0].apply(exports,arguments)},{"./lib/sliced":188}],188:[function(require,module){module.exports=require(30)},{}],189:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)"base64"===encoding&&(subject=base64clean(subject)),length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new Error("First argument needs to be a number, array or string.");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}var buf;TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;assert(strLen%2===0,"Invalid hex string"),length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);assert(!isNaN(byte),"Invalid hex string"),buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string),buf,offset,length);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function binarySlice(buf,start,end){return asciiSlice(buf,start,end)}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;i=len)){var val;return littleEndian?(val=buf[offset],len>offset+1&&(val|=buf[offset+1]<<8)):(val=buf[offset]<<8,len>offset+1&&(val|=buf[offset+1])),val}}function readUInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val;return littleEndian?(len>offset+2&&(val=buf[offset+2]<<16),len>offset+1&&(val|=buf[offset+1]<<8),val|=buf[offset],len>offset+3&&(val+=buf[offset+3]<<24>>>0)):(len>offset+1&&(val=buf[offset+1]<<16),len>offset+2&&(val|=buf[offset+2]<<8),len>offset+3&&(val|=buf[offset+3]),val+=buf[offset]<<24>>>0),val}}function readInt16(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len)){var val=readUInt16(buf,offset,littleEndian,!0),neg=32768&val;return neg?-1*(65535-val+1):val}}function readInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val=readUInt32(buf,offset,littleEndian,!0),neg=2147483648&val;return neg?-1*(4294967295-val+1):val}}function readFloat(buf,offset,littleEndian,noAssert){return noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i);return offset+2}}function writeUInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255;return offset+4}}function writeInt16(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len))return value>=0?writeUInt16(buf,value,offset,littleEndian,noAssert):writeUInt16(buf,65535+value+1,offset,littleEndian,noAssert),offset+2}function writeInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return value>=0?writeUInt32(buf,value,offset,littleEndian,noAssert):writeUInt32(buf,4294967295+value+1,offset,littleEndian,noAssert),offset+4}function writeFloat(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+7=len))return ieee754.write(buf,value,offset,littleEndian,52,8),offset+8}function base64clean(str){for(str=stringtrim(str).replace(INVALID_BASE64_RE,"");str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArray(subject){return(Array.isArray||function(subject){return"[object Array]"===Object.prototype.toString.call(subject)})(subject)}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(str){for(var byteArray=[],i=0;i=b)byteArray.push(b);else{var start=i;b>=55296&&57343>=b&&i++;for(var h=encodeURIComponent(str.slice(start,i+1)).substr(1).split("%"),j=0;j>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(str)}function blitBuffer(src,dst,offset,length){for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533)}}function verifuint(value,max){assert("number"==typeof value,"cannot write a non-number as a number"),assert(value>=0,"specified a negative value for writing an unsigned value"),assert(max>=value,"value is larger than maximum value for type"),assert(Math.floor(value)===value,"value has a fractional component")}function verifsint(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value"),assert(Math.floor(value)===value,"value has a fractional component")}function verifIEEE754(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value")}function assert(test,message){if(!test)throw new Error(message||"Failed assertion")}var base64=require("base64-js"),ieee754=require("ieee754");exports.Buffer=Buffer,exports.SlowBuffer=Buffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}();Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.byteLength=function(str,encoding){var ret;switch(str=str.toString(),encoding||"utf8"){case"hex":ret=str.length/2;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"ascii":case"binary":case"raw":ret=str.length;break;case"base64":ret=base64ToBytes(str).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=2*str.length;break;default:throw new Error("Unknown encoding")}return ret},Buffer.concat=function(list,totalLength){if(assert(isArray(list),"Usage: Buffer.concat(list[, length])"),0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;ii&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}offset=Number(offset)||0;var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toString=function(encoding,start,end){var self=this;if(encoding=String(encoding||"utf8").toLowerCase(),start=Number(start)||0,end=void 0===end?self.length:Number(end),end===start)return"";var ret;switch(encoding){case"hex":ret=hexSlice(self,start,end);break;case"utf8":case"utf-8":ret=utf8Slice(self,start,end);break;case"ascii":ret=asciiSlice(self,start,end);break;case"binary":ret=binarySlice(self,start,end);break;case"base64":ret=base64Slice(self,start,end);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leSlice(self,start,end);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.equals=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),0===Buffer.compare(this,b)},Buffer.prototype.compare=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),Buffer.compare(this,b)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start||(target_start=0),end!==start&&0!==target.length&&0!==source.length){assert(end>=start,"sourceEnd < sourceStart"),assert(target_start>=0&&target_start=0&&start=0&&end<=source.length,"sourceEnd out of bounds"),end>this.length&&(end=this.length),target.length-target_startlen||!TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start)}},Buffer.prototype.slice=function(start,end){var len=this.length;if(start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start),TYPED_ARRAY_SUPPORT)return Buffer._augment(this.subarray(start,end)); +for(var sliceLen=end-start,newBuf=new Buffer(sliceLen,void 0,!0),i=0;sliceLen>i;i++)newBuf[i]=this[i+start];return newBuf},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return readUInt16(this,offset,!0,noAssert)},Buffer.prototype.readUInt16BE=function(offset,noAssert){return readUInt16(this,offset,!1,noAssert)},Buffer.prototype.readUInt32LE=function(offset,noAssert){return readUInt32(this,offset,!0,noAssert)},Buffer.prototype.readUInt32BE=function(offset,noAssert){return readUInt32(this,offset,!1,noAssert)},Buffer.prototype.readInt8=function(offset,noAssert){if(noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length)){var neg=128&this[offset];return neg?-1*(255-this[offset]+1):this[offset]}},Buffer.prototype.readInt16LE=function(offset,noAssert){return readInt16(this,offset,!0,noAssert)},Buffer.prototype.readInt16BE=function(offset,noAssert){return readInt16(this,offset,!1,noAssert)},Buffer.prototype.readInt32LE=function(offset,noAssert){return readInt32(this,offset,!0,noAssert)},Buffer.prototype.readInt32BE=function(offset,noAssert){return readInt32(this,offset,!1,noAssert)},Buffer.prototype.readFloatLE=function(offset,noAssert){return readFloat(this,offset,!0,noAssert)},Buffer.prototype.readFloatBE=function(offset,noAssert){return readFloat(this,offset,!1,noAssert)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return readDouble(this,offset,!0,noAssert)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return readDouble(this,offset,!1,noAssert)},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(this[offset]=value,offset+1)},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(value>=0?this.writeUInt8(value,offset,noAssert):this.writeUInt8(255+value+1,offset,noAssert),offset+1)},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return writeInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return writeInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return writeInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return writeInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert)},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),assert(end>=start,"end < start"),end!==start&&0!==this.length){assert(start>=0&&start=0&&end<=this.length,"end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.inspect=function(){for(var out=[],len=this.length,i=0;len>i;i++)if(out[i]=toHex(this[i]),i===exports.INSPECT_MAX_BYTES){out[i+1]="...";break}return""},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z]/g},{"base64-js":190,ieee754:191}],190:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS?62:code===SLASH?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],191:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],192:[function(require,module){function noop(){}var process=module.exports={};process.nextTick=function(){var canSetImmediate="undefined"!=typeof window&&window.setImmediate,canPost="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(canSetImmediate)return function(f){return window.setImmediate(f)};if(canPost){var queue=[];return window.addEventListener("message",function(ev){var source=ev.source;if((source===window||null===source)&&"process-tick"===ev.data&&(ev.stopPropagation(),queue.length>0)){var fn=queue.shift();fn()}},!0),function(fn){queue.push(fn),window.postMessage("process-tick","*")}}return function(fn){setTimeout(fn,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file diff --git a/package.json b/package.json index 053aa80..0fd87c3 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "prestart": "npm run links && node data/regenerate", "start": "beefy index.js:bundle.js --open", "postinstall": "npm run links && scoped-bulk stackgl npm install && npm dedupe", - "bundle": "npm run prestart && browserify index.js | uglifyjs -cm > bundle.js", + "bundle": "npm run prestart && browserify index.js | uglifyjs -c > bundle.js", "links": "district stackgl splash-grid splash-flock" }, "repository": { From 09ed0e5a956dedf5bc424bc5d042f7c0307964ec Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 15 Sep 2014 03:35:14 +0200 Subject: [PATCH 13/64] updates! --- bundle.js | 2 +- data/examples.md | 4 ++-- index.css | 13 ++++++++++++- index.html | 23 +++++++++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/bundle.js b/bundle.js index d518659..425b676 100644 --- a/bundle.js +++ b/bundle.js @@ -1,4 +1,4 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"raymarch",link:"https://github.com/mikolalysenko/raymarch/",desc:"",thumb:"http://imgur.com/NpvsXIH.png",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],Tools:[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2}],Math:[{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:2},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:3}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:5}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0}],Internals:[{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:4},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:5}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4}]}},{}],3:[function(require){var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas")),flock=document.getElementById("community").querySelector("canvas");require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid),require("@stackgl/splash-flock")(flock)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;ii;i++)pdata[i]=FBO(gl,[SIZE,SIZE],{"float":!0}),pdata[i].color[0].setPixels(starter);window.addEventListener("resize",debounce(fit(canvas,window))),shaders.logic=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(gl),shaders.render=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(gl)}function switchFrames(data){return data.push(data.shift()),data}function createParticleVAO(gl,size){for(var data=new Float32Array(size*size),n=0,x=0;size>x;x++)for(var y=0;size>y;y++)data[n++]=x/size,data[n++]=y/size;var buffer=createBuffer(gl,data),vao=VAO(gl,[{buffer:buffer,type:gl.FLOAT,size:2}]);return vao.length=data.length/2,vao}function createStartPositions(size){for(var data=new Float32Array(size*size*4),i=0;i=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"}) +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],Tools:[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2}],Math:[{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:2},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:3}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:5}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0}],Internals:[{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:4},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:5}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4}]}},{}],3:[function(require){var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas")),flock=document.getElementById("community").querySelector("canvas");require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid),require("@stackgl/splash-flock")(flock)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;ii;i++)pdata[i]=FBO(gl,[SIZE,SIZE],{"float":!0}),pdata[i].color[0].setPixels(starter);window.addEventListener("resize",debounce(fit(canvas,window))),shaders.logic=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(gl),shaders.render=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(gl)}function switchFrames(data){return data.push(data.shift()),data}function createParticleVAO(gl,size){for(var data=new Float32Array(size*size),n=0,x=0;size>x;x++)for(var y=0;size>y;y++)data[n++]=x/size,data[n++]=y/size;var buffer=createBuffer(gl,data),vao=VAO(gl,[{buffer:buffer,type:gl.FLOAT,size:2}]);return vao.length=data.length/2,vao}function createStartPositions(size){for(var data=new Float32Array(size*size*4),i=0;i=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"}) },{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:189,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;islice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],31:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:37,"ndarray-ops":32,"typedarray-pool":41,webglew:43}],32:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":33}],33:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":35}],34:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:36}],35:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":34}],36:[function(require,module){module.exports=require(13)},{}],37:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":38}],38:[function(require,module){module.exports=require(15)},{}],39:[function(require,module){module.exports=require(16)},{}],40:[function(require,module){module.exports=require(17)},{}],41:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":39,buffer:189,dup:40}],42:[function(require,module,exports){void function(global,undefined_,undefined){function define(object,key,value){return"function"==typeof key&&(value=key,key=nameOf(value).replace(/_$/,"")),defProp(object,key,{configurable:!0,writable:!0,value:value})}function nameOf(func){return"function"!=typeof func?"":"name"in func?func.name:toSource.call(func).match(funcName)[1]}function createStorage(creator){function storage(object,value){return value||2===arguments.length?weakmap.set(object,value):(value=weakmap.get(object),value===undefined&&(value=creator(object),weakmap.set(object,value))),value}var weakmap=new WM;return creator||(creator=defaultCreator),storage}var getProps=Object.getOwnPropertyNames,defProp=Object.defineProperty,toSource=Function.prototype.toString,create=Object.create,hasOwn=Object.prototype.hasOwnProperty,funcName=/^\n?function\s?(\w*)?_?\(/,Data=function(){function Data(){var puid=createUID(),secret={};this.unlock=function(obj){var store=storage(obj);if(hasOwn.call(store,puid))return store[puid](secret);var data=create(null,dataDesc);return defProp(store,puid,{value:new Function("s","l",datalock)(secret,data)}),data}}var dataDesc={value:{writable:!0,value:undefined}},datalock="return function(k){if(k===s)return l}",uids=create(null),createUID=function(){var key=Math.random().toString(36).slice(2);return key in uids?createUID():uids[key]=key},globalID=createUID(),storage=function(obj){if(hasOwn.call(obj,globalID))return obj[globalID];if(!Object.isExtensible(obj))throw new TypeError("Object must be extensible");var store=create(null);return defProp(obj,globalID,{value:store}),store};return define(Object,function(obj){var props=getProps(obj);return hasOwn.call(obj,globalID)&&props.splice(props.indexOf(globalID),1),props}),define(Data.prototype,function(o){return this.unlock(o).value}),define(Data.prototype,function(o,v){this.unlock(o).value=v}),Data}(),WM=function(data){function WeakMap(iterable){return this===global||null==this||this===WeakMap.prototype?new WeakMap(iterable):(wrap(this,new Data),void initialize(this,iterable))}function get(key){validate(key);var value=unwrap(this).get(key);return value===undefined_?undefined:value}function set(key,value){validate(key),unwrap(this).set(key,value===undefined?undefined_:value)}function has(key){return validate(key),unwrap(this).get(key)!==undefined}function delete_(key){validate(key);var data=unwrap(this),had=data.get(key)!==undefined;return data.set(key,undefined),had}function toString(){return unwrap(this),"[object WeakMap]"}var validate=function(key){if(null==key||"object"!=typeof key&&"function"!=typeof key)throw new TypeError("Invalid WeakMap key")},wrap=function(collection,value){var store=data.unlock(collection);if(store.value)throw new TypeError("Object is already a WeakMap");store.value=value},unwrap=function(collection){var storage=data.unlock(collection).value;if(!storage)throw new TypeError("WeakMap is not generic");return storage},initialize=function(weakmap,iterable){null!==iterable&&"object"==typeof iterable&&"function"==typeof iterable.forEach&&iterable.forEach(function(item,i){item instanceof Array&&2===item.length&&set.call(weakmap,iterable[i][0],iterable[i][1])})};try{var src=("return "+delete_).replace("e_","\\u0065"),del=new Function("unwrap","validate",src)(unwrap,validate)}catch(e){var del=delete_}var src=(""+Object).split("Object"),stringifier=function(){return src[0]+nameOf(this)+src[1]};define(stringifier,stringifier);var prep={__proto__:[]}instanceof Array?function(f){f.__proto__=stringifier}:function(f){define(f,stringifier)};return prep(WeakMap),[toString,get,set,has,del].forEach(function(method){define(WeakMap.prototype,method),prep(method)}),WeakMap}(new Data),defaultCreator=Object.create?function(){return Object.create(null)}:function(){return{}};"undefined"!=typeof module?module.exports=WM:"undefined"!=typeof exports?exports.WeakMap=WM:"WeakMap"in global||(global.WeakMap=WM),WM.createStorage=createStorage,global.WeakMap&&(global.WeakMap.createStorage=createStorage)}((0,eval)("this"))},{}],43:[function(require,module){"use strict";function baseName(ext_name){return ext_name.replace(/^[A-Z]+_/,"")}function initWebGLEW(gl){var struct=WebGLEWStruct.get(gl);if(struct)return struct;for(var extensions={},supported=gl.getSupportedExtensions(),i=0;i=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,result.bind(),gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var state=saveFBOState(fbo.gl),gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),width=fbo._shape[0],height=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;ii;++i)this.color[i]=null;this._color_rb=null,this.depth=null,this._depth_rb=null,this._colorType=colorType,this._useDepth=useDepth,this._useStencil=useStencil;var parent=this,shapeVector=[0|width,0|height];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(w){return parent.width=w}},1:{get:function(){return parent._shape[1]},set:function(h){return parent.height=h}}}),this._shapeVector=shapeVector,rebuildFBO(this)}function reshapeFBO(fbo,w,h){if(fbo._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(fbo._shape[0]!==w||fbo._shape[1]!==h){var gl=fbo.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(0>w||w>maxFBOSize||0>h||h>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");fbo._shape[0]=w,fbo._shape[1]=h;for(var state=saveFBOState(gl),i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperties(proto,{shape:{get:function(){return this._destroyed?[0,0]:this._shapeVector},set:function(x){if(Array.isArray(x)||(x=[0|x,0|x]),2!==x.length)throw new Error("gl-fbo: Shape vector must be length 2");var w=0|x[0],h=0|x[1];return reshapeFBO(this,w,h),[w,h]},enumerable:!1},width:{get:function(){return this._destroyed?0:this._shape[0]},set:function(w){return w=0|w,reshapeFBO(this,w,this._shape[1]),w},enumerable:!1},height:{get:function(){return this._destroyed?0:this._shape[1]},set:function(h){return h=0|h,reshapeFBO(this,this._shape[0],h),h},enumerable:!1}}),proto.bind=function(){if(!this._destroyed){var gl=this.gl;gl.bindFramebuffer(gl.FRAMEBUFFER,this.handle),gl.viewport(0,0,this._shape[0],this._shape[1])}},proto.dispose=function(){if(!this._destroyed){this._destroyed=!0;var gl=this.gl;gl.deleteFramebuffer(this.handle),this.handle=null,this.depth&&(this.depth.dispose(),this.depth=null),this._depth_rb&&(gl.deleteRenderbuffer(this._depth_rb),this._depth_rb=null);for(var i=0;iw||w>maxSize||0>h||h>maxSize)throw new Error("gl-texture2d: Invalid texture size");return tex._shape=[w,h],tex.bind(),gl.texImage2D(gl.TEXTURE_2D,0,tex.format,w,h,0,tex.format,tex.type,null),tex._mipLevels=[0],tex}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[width,height],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1;var parent=this,wrapVector=[this._wrapS,this._wrapT];Object.defineProperties(wrapVector,{0:{get:function(){return parent._wrapS},set:function(v){return parent.wrapS=v}},1:{get:function(){return parent._wrapT},set:function(v){return parent.wrapT=v}}}),this._wrapVector=wrapVector;var shapeVector=[this._shape[0],this._shape[1]];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(v){return parent.width=v}},1:{get:function(){return parent._shape[1]},set:function(v){return parent.height=v}}}),this._shapeVector=shapeVector}function isPacked(shape,stride){return 3===shape.length?1===stride[2]&&stride[1]===shape[0]*shape[2]&&stride[0]===shape[2]:1===stride[0]&&stride[1]===shape[0]}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape.slice();if(shape.length<2||shape.length>3)throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d");var type=0,format=0,packed=isPacked(shape,array.stride.slice());"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var channels=1;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}channels=shape[2]}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape,[shape[2],shape[2]*shape[0],1]);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture(); return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(shape,array.stride.slice()),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type!==gl.FLOAT||webglew(gl).texture_float||(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store,size=array.size;if(packed)buffer=0===array.offset&&array.data.length===size?array.data:array.data.subarray(array.offset,array.offset+size);else{var stride=[shape[2],shape[2]*shape[0],1];buf_store=pool.malloc(size,dtype);var buf_array=ndarray(buf_store,shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,size)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[0],shape[1],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][0],0|arguments[1][1],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew");module.exports=createTexture2D;var linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)},proto=Texture2D.prototype;Object.defineProperties(proto,{minFilter:{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}},magFilter:{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}},mipSamples:{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}},wrapS:{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}},wrapT:{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}},wrap:{get:function(){return this._wrapVector},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapS=v[0],this._wrapT=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),v}},shape:{get:function(){return this._shapeVector},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];return reshapeTexture(this,0|x[0],0|x[1]),[0|x[0],0|x[1]]}},width:{get:function(){return this._shape[0]},set:function(w){return w=0|w,reshapeTexture(this,w,this._shape[1]),w}},height:{get:function(){return this._shape[1]},set:function(h){return h=0|h,reshapeTexture(this,this._shape[0],h),h}}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[1],x_off=0|x_off[0]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}}},{ndarray:54,"ndarray-ops":49,"typedarray-pool":58,webglew:61}],60:[function(require,module){module.exports=require(42)},{}],61:[function(require,module){module.exports=require(43)},{weakmap:60}],62:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":63}],63:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":65}],64:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:66}],65:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":64}],66:[function(require,module){module.exports=require(13)},{}],67:[function(require,module){module.exports=require(16)},{}],68:[function(require,module){module.exports=require(17)},{}],69:[function(require,module){module.exports=require(41)},{"bit-twiddle":67,buffer:189,dup:68}],70:[function(require,module){module.exports=require(42)},{}],71:[function(require,module){module.exports=require(43)},{weakmap:70}],72:[function(require,module,exports){arguments[4][59][0].apply(exports,arguments)},{ndarray:86,"ndarray-ops":62,"typedarray-pool":69,webglew:71}],73:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],74:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":73}],75:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;ii;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],82:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;kheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":89,"a-big-triangle":107,"canvas-fit":108,clone:110,"cube-cube":111,"face-normals":114,"frame-debounce":115,"gl-clear":120,"gl-context":121,"gl-fbo":123,"gl-geometry":126,"gl-matrix":151,"gl-texture2d":164,glslify:166,"glslify/adapter.js":165,"mesh-combine":172,"orbit-camera":179,"right-now":180,"unindex-mesh":181}],91:[function(require,module,exports){arguments[4][8][0].apply(exports,arguments)},{ndarray:97,"ndarray-ops":92,"typedarray-pool":101}],92:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":93}],93:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":95}],94:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:96}],95:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":94}],96:[function(require,module){module.exports=require(13)},{}],97:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":98}],98:[function(require,module){module.exports=require(15)},{}],99:[function(require,module){module.exports=require(16)},{}],100:[function(require,module){module.exports=require(17)},{}],101:[function(require,module){module.exports=require(18)},{"bit-twiddle":99,dup:100}],102:[function(require,module){module.exports=require(19) diff --git a/data/examples.md b/data/examples.md index 18c4ecb..392e1a2 100644 --- a/data/examples.md +++ b/data/examples.md @@ -40,9 +40,9 @@ the hood. ![voxel-mipmap-demo](http://imgur.com/9eUBmfB.png) -## [raymarch](https://github.com/mikolalysenko/raymarch/) +## [gif-3d](http://mikolalysenko.github.io/gif-3d/) -![raymarch](http://imgur.com/NpvsXIH.png) +![gif-3d](http://imgur.com/gItopw0.jpg) ## [moire #1](http://hughsk.io/moire-1) diff --git a/index.css b/index.css index ad6d015..4c7f005 100644 --- a/index.css +++ b/index.css @@ -12,6 +12,7 @@ solid #ccc;margin:1em 0;padding:0}input,select{vertical-align:middle} body, html { margin: 0; padding: 0; + overflow-x: hidden; background: #fff; line-height: 1.5em; font-family: 'Ubuntu Mono', 'Helvetica Neue', Helvetica, Arial, sans-serif; @@ -57,7 +58,8 @@ h1 .lighter { margin-bottom: 0.3em; } -#intro aside { +#intro aside, +#community-content aside { max-width: 400px; color: #4A4F5E; font-size: 0.9em; @@ -177,3 +179,12 @@ h1 .lighter { .thumb-filter > li:last-child:after { content: ''; } + +#community-content ul { + margin-left: 1em; +} + +#community-content ul, +#community-content p { + margin-bottom: 1em; +} diff --git a/index.html b/index.html index 3f90e00..7d87060 100644 --- a/index.html +++ b/index.html @@ -53,6 +53,29 @@

      packages

      community

      + +
      From b6074e0879a22d2c27770214236be218585a1a6a Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 15 Sep 2014 03:44:10 +0200 Subject: [PATCH 14/64] Fix Chris' Twitter link --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 7d87060..166b23d 100644 --- a/index.html +++ b/index.html @@ -72,7 +72,7 @@

      community

      From 34c92a477550f81a719328d35ae32c86e7bbaf32 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 15 Sep 2014 03:44:39 +0200 Subject: [PATCH 15/64] fix my own twitter link --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 166b23d..bc87a5f 100644 --- a/index.html +++ b/index.html @@ -71,7 +71,7 @@

      community

      From c95c211062a63a0253f82293a68dfefa884e4ac5 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 15 Sep 2014 05:47:05 +0200 Subject: [PATCH 16/64] google analytics --- bundle.js | 2 +- index.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bundle.js b/bundle.js index 425b676..05191aa 100644 --- a/bundle.js +++ b/bundle.js @@ -1,4 +1,4 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],Tools:[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2}],Math:[{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:2},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:3}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:5}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0}],Internals:[{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:4},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:5}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4}]}},{}],3:[function(require){var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas")),flock=document.getElementById("community").querySelector("canvas");require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid),require("@stackgl/splash-flock")(flock)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;ii;i++)pdata[i]=FBO(gl,[SIZE,SIZE],{"float":!0}),pdata[i].color[0].setPixels(starter);window.addEventListener("resize",debounce(fit(canvas,window))),shaders.logic=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(gl),shaders.render=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(gl)}function switchFrames(data){return data.push(data.shift()),data}function createParticleVAO(gl,size){for(var data=new Float32Array(size*size),n=0,x=0;size>x;x++)for(var y=0;size>y;y++)data[n++]=x/size,data[n++]=y/size;var buffer=createBuffer(gl,data),vao=VAO(gl,[{buffer:buffer,type:gl.FLOAT,size:2}]);return vao.length=data.length/2,vao}function createStartPositions(size){for(var data=new Float32Array(size*size*4),i=0;i=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"}) +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],Tools:[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2}],Math:[{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:2},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:3}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:5}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0}],Internals:[{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:4},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:5}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas")),flock=document.getElementById("community").querySelector("canvas");require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid),require("@stackgl/splash-flock")(flock)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;ii;i++)pdata[i]=FBO(gl,[SIZE,SIZE],{"float":!0}),pdata[i].color[0].setPixels(starter);window.addEventListener("resize",debounce(fit(canvas,window))),shaders.logic=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(gl),shaders.render=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(gl)}function switchFrames(data){return data.push(data.shift()),data}function createParticleVAO(gl,size){for(var data=new Float32Array(size*size),n=0,x=0;size>x;x++)for(var y=0;size>y;y++)data[n++]=x/size,data[n++]=y/size;var buffer=createBuffer(gl,data),vao=VAO(gl,[{buffer:buffer,type:gl.FLOAT,size:2}]);return vao.length=data.length/2,vao}function createStartPositions(size){for(var data=new Float32Array(size*size*4),i=0;i=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"}) },{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:189,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;islice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],31:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:37,"ndarray-ops":32,"typedarray-pool":41,webglew:43}],32:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":33}],33:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":35}],34:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:36}],35:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":34}],36:[function(require,module){module.exports=require(13)},{}],37:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":38}],38:[function(require,module){module.exports=require(15)},{}],39:[function(require,module){module.exports=require(16)},{}],40:[function(require,module){module.exports=require(17)},{}],41:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":39,buffer:189,dup:40}],42:[function(require,module,exports){void function(global,undefined_,undefined){function define(object,key,value){return"function"==typeof key&&(value=key,key=nameOf(value).replace(/_$/,"")),defProp(object,key,{configurable:!0,writable:!0,value:value})}function nameOf(func){return"function"!=typeof func?"":"name"in func?func.name:toSource.call(func).match(funcName)[1]}function createStorage(creator){function storage(object,value){return value||2===arguments.length?weakmap.set(object,value):(value=weakmap.get(object),value===undefined&&(value=creator(object),weakmap.set(object,value))),value}var weakmap=new WM;return creator||(creator=defaultCreator),storage}var getProps=Object.getOwnPropertyNames,defProp=Object.defineProperty,toSource=Function.prototype.toString,create=Object.create,hasOwn=Object.prototype.hasOwnProperty,funcName=/^\n?function\s?(\w*)?_?\(/,Data=function(){function Data(){var puid=createUID(),secret={};this.unlock=function(obj){var store=storage(obj);if(hasOwn.call(store,puid))return store[puid](secret);var data=create(null,dataDesc);return defProp(store,puid,{value:new Function("s","l",datalock)(secret,data)}),data}}var dataDesc={value:{writable:!0,value:undefined}},datalock="return function(k){if(k===s)return l}",uids=create(null),createUID=function(){var key=Math.random().toString(36).slice(2);return key in uids?createUID():uids[key]=key},globalID=createUID(),storage=function(obj){if(hasOwn.call(obj,globalID))return obj[globalID];if(!Object.isExtensible(obj))throw new TypeError("Object must be extensible");var store=create(null);return defProp(obj,globalID,{value:store}),store};return define(Object,function(obj){var props=getProps(obj);return hasOwn.call(obj,globalID)&&props.splice(props.indexOf(globalID),1),props}),define(Data.prototype,function(o){return this.unlock(o).value}),define(Data.prototype,function(o,v){this.unlock(o).value=v}),Data}(),WM=function(data){function WeakMap(iterable){return this===global||null==this||this===WeakMap.prototype?new WeakMap(iterable):(wrap(this,new Data),void initialize(this,iterable))}function get(key){validate(key);var value=unwrap(this).get(key);return value===undefined_?undefined:value}function set(key,value){validate(key),unwrap(this).set(key,value===undefined?undefined_:value)}function has(key){return validate(key),unwrap(this).get(key)!==undefined}function delete_(key){validate(key);var data=unwrap(this),had=data.get(key)!==undefined;return data.set(key,undefined),had}function toString(){return unwrap(this),"[object WeakMap]"}var validate=function(key){if(null==key||"object"!=typeof key&&"function"!=typeof key)throw new TypeError("Invalid WeakMap key")},wrap=function(collection,value){var store=data.unlock(collection);if(store.value)throw new TypeError("Object is already a WeakMap");store.value=value},unwrap=function(collection){var storage=data.unlock(collection).value;if(!storage)throw new TypeError("WeakMap is not generic");return storage},initialize=function(weakmap,iterable){null!==iterable&&"object"==typeof iterable&&"function"==typeof iterable.forEach&&iterable.forEach(function(item,i){item instanceof Array&&2===item.length&&set.call(weakmap,iterable[i][0],iterable[i][1])})};try{var src=("return "+delete_).replace("e_","\\u0065"),del=new Function("unwrap","validate",src)(unwrap,validate)}catch(e){var del=delete_}var src=(""+Object).split("Object"),stringifier=function(){return src[0]+nameOf(this)+src[1]};define(stringifier,stringifier);var prep={__proto__:[]}instanceof Array?function(f){f.__proto__=stringifier}:function(f){define(f,stringifier)};return prep(WeakMap),[toString,get,set,has,del].forEach(function(method){define(WeakMap.prototype,method),prep(method)}),WeakMap}(new Data),defaultCreator=Object.create?function(){return Object.create(null)}:function(){return{}};"undefined"!=typeof module?module.exports=WM:"undefined"!=typeof exports?exports.WeakMap=WM:"WeakMap"in global||(global.WeakMap=WM),WM.createStorage=createStorage,global.WeakMap&&(global.WeakMap.createStorage=createStorage)}((0,eval)("this"))},{}],43:[function(require,module){"use strict";function baseName(ext_name){return ext_name.replace(/^[A-Z]+_/,"")}function initWebGLEW(gl){var struct=WebGLEWStruct.get(gl);if(struct)return struct;for(var extensions={},supported=gl.getSupportedExtensions(),i=0;i=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,result.bind(),gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var state=saveFBOState(fbo.gl),gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),width=fbo._shape[0],height=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;ii;++i)this.color[i]=null;this._color_rb=null,this.depth=null,this._depth_rb=null,this._colorType=colorType,this._useDepth=useDepth,this._useStencil=useStencil;var parent=this,shapeVector=[0|width,0|height];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(w){return parent.width=w}},1:{get:function(){return parent._shape[1]},set:function(h){return parent.height=h}}}),this._shapeVector=shapeVector,rebuildFBO(this)}function reshapeFBO(fbo,w,h){if(fbo._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(fbo._shape[0]!==w||fbo._shape[1]!==h){var gl=fbo.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(0>w||w>maxFBOSize||0>h||h>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");fbo._shape[0]=w,fbo._shape[1]=h;for(var state=saveFBOState(gl),i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperties(proto,{shape:{get:function(){return this._destroyed?[0,0]:this._shapeVector},set:function(x){if(Array.isArray(x)||(x=[0|x,0|x]),2!==x.length)throw new Error("gl-fbo: Shape vector must be length 2");var w=0|x[0],h=0|x[1];return reshapeFBO(this,w,h),[w,h]},enumerable:!1},width:{get:function(){return this._destroyed?0:this._shape[0]},set:function(w){return w=0|w,reshapeFBO(this,w,this._shape[1]),w},enumerable:!1},height:{get:function(){return this._destroyed?0:this._shape[1]},set:function(h){return h=0|h,reshapeFBO(this,this._shape[0],h),h},enumerable:!1}}),proto.bind=function(){if(!this._destroyed){var gl=this.gl;gl.bindFramebuffer(gl.FRAMEBUFFER,this.handle),gl.viewport(0,0,this._shape[0],this._shape[1])}},proto.dispose=function(){if(!this._destroyed){this._destroyed=!0;var gl=this.gl;gl.deleteFramebuffer(this.handle),this.handle=null,this.depth&&(this.depth.dispose(),this.depth=null),this._depth_rb&&(gl.deleteRenderbuffer(this._depth_rb),this._depth_rb=null);for(var i=0;iw||w>maxSize||0>h||h>maxSize)throw new Error("gl-texture2d: Invalid texture size");return tex._shape=[w,h],tex.bind(),gl.texImage2D(gl.TEXTURE_2D,0,tex.format,w,h,0,tex.format,tex.type,null),tex._mipLevels=[0],tex}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[width,height],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1;var parent=this,wrapVector=[this._wrapS,this._wrapT];Object.defineProperties(wrapVector,{0:{get:function(){return parent._wrapS},set:function(v){return parent.wrapS=v}},1:{get:function(){return parent._wrapT},set:function(v){return parent.wrapT=v}}}),this._wrapVector=wrapVector;var shapeVector=[this._shape[0],this._shape[1]];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(v){return parent.width=v}},1:{get:function(){return parent._shape[1]},set:function(v){return parent.height=v}}}),this._shapeVector=shapeVector}function isPacked(shape,stride){return 3===shape.length?1===stride[2]&&stride[1]===shape[0]*shape[2]&&stride[0]===shape[2]:1===stride[0]&&stride[1]===shape[0]}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape.slice();if(shape.length<2||shape.length>3)throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d");var type=0,format=0,packed=isPacked(shape,array.stride.slice());"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var channels=1;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}channels=shape[2]}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape,[shape[2],shape[2]*shape[0],1]);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture(); return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(shape,array.stride.slice()),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type!==gl.FLOAT||webglew(gl).texture_float||(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store,size=array.size;if(packed)buffer=0===array.offset&&array.data.length===size?array.data:array.data.subarray(array.offset,array.offset+size);else{var stride=[shape[2],shape[2]*shape[0],1];buf_store=pool.malloc(size,dtype);var buf_array=ndarray(buf_store,shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,size)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[0],shape[1],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][0],0|arguments[1][1],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew");module.exports=createTexture2D;var linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)},proto=Texture2D.prototype;Object.defineProperties(proto,{minFilter:{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}},magFilter:{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}},mipSamples:{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}},wrapS:{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}},wrapT:{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}},wrap:{get:function(){return this._wrapVector},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapS=v[0],this._wrapT=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),v}},shape:{get:function(){return this._shapeVector},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];return reshapeTexture(this,0|x[0],0|x[1]),[0|x[0],0|x[1]]}},width:{get:function(){return this._shape[0]},set:function(w){return w=0|w,reshapeTexture(this,w,this._shape[1]),w}},height:{get:function(){return this._shape[1]},set:function(h){return h=0|h,reshapeTexture(this,this._shape[0],h),h}}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[1],x_off=0|x_off[0]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}}},{ndarray:54,"ndarray-ops":49,"typedarray-pool":58,webglew:61}],60:[function(require,module){module.exports=require(42)},{}],61:[function(require,module){module.exports=require(43)},{weakmap:60}],62:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":63}],63:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":65}],64:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:66}],65:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":64}],66:[function(require,module){module.exports=require(13)},{}],67:[function(require,module){module.exports=require(16)},{}],68:[function(require,module){module.exports=require(17)},{}],69:[function(require,module){module.exports=require(41)},{"bit-twiddle":67,buffer:189,dup:68}],70:[function(require,module){module.exports=require(42)},{}],71:[function(require,module){module.exports=require(43)},{weakmap:70}],72:[function(require,module,exports){arguments[4][59][0].apply(exports,arguments)},{ndarray:86,"ndarray-ops":62,"typedarray-pool":69,webglew:71}],73:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],74:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":73}],75:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;ii;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],82:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;kheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":89,"a-big-triangle":107,"canvas-fit":108,clone:110,"cube-cube":111,"face-normals":114,"frame-debounce":115,"gl-clear":120,"gl-context":121,"gl-fbo":123,"gl-geometry":126,"gl-matrix":151,"gl-texture2d":164,glslify:166,"glslify/adapter.js":165,"mesh-combine":172,"orbit-camera":179,"right-now":180,"unindex-mesh":181}],91:[function(require,module,exports){arguments[4][8][0].apply(exports,arguments)},{ndarray:97,"ndarray-ops":92,"typedarray-pool":101}],92:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":93}],93:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":95}],94:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:96}],95:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":94}],96:[function(require,module){module.exports=require(13)},{}],97:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":98}],98:[function(require,module){module.exports=require(15)},{}],99:[function(require,module){module.exports=require(16)},{}],100:[function(require,module){module.exports=require(17)},{}],101:[function(require,module){module.exports=require(18)},{"bit-twiddle":99,dup:100}],102:[function(require,module){module.exports=require(19) diff --git a/index.js b/index.js index eb00ee9..c4a24d0 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,11 @@ +(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ +(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), +m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) +})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + +ga('create', 'UA-54792490-1', 'auto'); +ga('send', 'pageview'); + var filter = require('./lib/filter') var minstache = require('minstache') var domify = require('domify') From 6b131d01bcff801e14d7dd28669cb1efaa9cc672 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 15 Sep 2014 14:38:18 +0200 Subject: [PATCH 17/64] Temporarily limit displays to Chrome Until we work out what's going on with gl-texture2d :) /cc @mikolalysenko --- index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index c4a24d0..aa5db46 100644 --- a/index.js +++ b/index.js @@ -17,11 +17,13 @@ var flock = document.getElementById('community').querySelector('canvas') require('./lib/fill')(document.querySelectorAll('[data-fill]')) -try { - require('@stackgl/splash-grid')(grid) - require('@stackgl/splash-flock')(flock) -} catch(e) { - console.error(e.message) +if (window.chrome) { + try { + require('@stackgl/splash-grid')(grid) + require('@stackgl/splash-flock')(flock) + } catch(e) { + console.error(e.message) + } } var thumb = minstache.compile(fs.readFileSync( From c6eace25856cac79d28861d6d659dbbbed8f65d3 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 15 Sep 2014 14:44:14 +0200 Subject: [PATCH 18/64] update bundle.js --- bundle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle.js b/bundle.js index 05191aa..b09b88f 100644 --- a/bundle.js +++ b/bundle.js @@ -1,4 +1,4 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],Tools:[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2}],Math:[{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:2},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:3}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:5}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0}],Internals:[{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:4},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:5}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas")),flock=document.getElementById("community").querySelector("canvas");require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid),require("@stackgl/splash-flock")(flock)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;ii;i++)pdata[i]=FBO(gl,[SIZE,SIZE],{"float":!0}),pdata[i].color[0].setPixels(starter);window.addEventListener("resize",debounce(fit(canvas,window))),shaders.logic=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(gl),shaders.render=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(gl)}function switchFrames(data){return data.push(data.shift()),data}function createParticleVAO(gl,size){for(var data=new Float32Array(size*size),n=0,x=0;size>x;x++)for(var y=0;size>y;y++)data[n++]=x/size,data[n++]=y/size;var buffer=createBuffer(gl,data),vao=VAO(gl,[{buffer:buffer,type:gl.FLOAT,size:2}]);return vao.length=data.length/2,vao}function createStartPositions(size){for(var data=new Float32Array(size*size*4),i=0;i=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"}) +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],Tools:[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2}],Math:[{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:2},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:3}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:5}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0}],Internals:[{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:4},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:5}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas")),flock=document.getElementById("community").querySelector("canvas");if(require("./lib/fill")(document.querySelectorAll("[data-fill]")),window.chrome)try{require("@stackgl/splash-grid")(grid),require("@stackgl/splash-flock")(flock)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;ii;i++)pdata[i]=FBO(gl,[SIZE,SIZE],{"float":!0}),pdata[i].color[0].setPixels(starter);window.addEventListener("resize",debounce(fit(canvas,window))),shaders.logic=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(gl),shaders.render=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(gl)}function switchFrames(data){return data.push(data.shift()),data}function createParticleVAO(gl,size){for(var data=new Float32Array(size*size),n=0,x=0;size>x;x++)for(var y=0;size>y;y++)data[n++]=x/size,data[n++]=y/size;var buffer=createBuffer(gl,data),vao=VAO(gl,[{buffer:buffer,type:gl.FLOAT,size:2}]);return vao.length=data.length/2,vao}function createStartPositions(size){for(var data=new Float32Array(size*size*4),i=0;i=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"}) },{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:189,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;islice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],31:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:37,"ndarray-ops":32,"typedarray-pool":41,webglew:43}],32:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":33}],33:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":35}],34:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:36}],35:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":34}],36:[function(require,module){module.exports=require(13)},{}],37:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":38}],38:[function(require,module){module.exports=require(15)},{}],39:[function(require,module){module.exports=require(16)},{}],40:[function(require,module){module.exports=require(17)},{}],41:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":39,buffer:189,dup:40}],42:[function(require,module,exports){void function(global,undefined_,undefined){function define(object,key,value){return"function"==typeof key&&(value=key,key=nameOf(value).replace(/_$/,"")),defProp(object,key,{configurable:!0,writable:!0,value:value})}function nameOf(func){return"function"!=typeof func?"":"name"in func?func.name:toSource.call(func).match(funcName)[1]}function createStorage(creator){function storage(object,value){return value||2===arguments.length?weakmap.set(object,value):(value=weakmap.get(object),value===undefined&&(value=creator(object),weakmap.set(object,value))),value}var weakmap=new WM;return creator||(creator=defaultCreator),storage}var getProps=Object.getOwnPropertyNames,defProp=Object.defineProperty,toSource=Function.prototype.toString,create=Object.create,hasOwn=Object.prototype.hasOwnProperty,funcName=/^\n?function\s?(\w*)?_?\(/,Data=function(){function Data(){var puid=createUID(),secret={};this.unlock=function(obj){var store=storage(obj);if(hasOwn.call(store,puid))return store[puid](secret);var data=create(null,dataDesc);return defProp(store,puid,{value:new Function("s","l",datalock)(secret,data)}),data}}var dataDesc={value:{writable:!0,value:undefined}},datalock="return function(k){if(k===s)return l}",uids=create(null),createUID=function(){var key=Math.random().toString(36).slice(2);return key in uids?createUID():uids[key]=key},globalID=createUID(),storage=function(obj){if(hasOwn.call(obj,globalID))return obj[globalID];if(!Object.isExtensible(obj))throw new TypeError("Object must be extensible");var store=create(null);return defProp(obj,globalID,{value:store}),store};return define(Object,function(obj){var props=getProps(obj);return hasOwn.call(obj,globalID)&&props.splice(props.indexOf(globalID),1),props}),define(Data.prototype,function(o){return this.unlock(o).value}),define(Data.prototype,function(o,v){this.unlock(o).value=v}),Data}(),WM=function(data){function WeakMap(iterable){return this===global||null==this||this===WeakMap.prototype?new WeakMap(iterable):(wrap(this,new Data),void initialize(this,iterable))}function get(key){validate(key);var value=unwrap(this).get(key);return value===undefined_?undefined:value}function set(key,value){validate(key),unwrap(this).set(key,value===undefined?undefined_:value)}function has(key){return validate(key),unwrap(this).get(key)!==undefined}function delete_(key){validate(key);var data=unwrap(this),had=data.get(key)!==undefined;return data.set(key,undefined),had}function toString(){return unwrap(this),"[object WeakMap]"}var validate=function(key){if(null==key||"object"!=typeof key&&"function"!=typeof key)throw new TypeError("Invalid WeakMap key")},wrap=function(collection,value){var store=data.unlock(collection);if(store.value)throw new TypeError("Object is already a WeakMap");store.value=value},unwrap=function(collection){var storage=data.unlock(collection).value;if(!storage)throw new TypeError("WeakMap is not generic");return storage},initialize=function(weakmap,iterable){null!==iterable&&"object"==typeof iterable&&"function"==typeof iterable.forEach&&iterable.forEach(function(item,i){item instanceof Array&&2===item.length&&set.call(weakmap,iterable[i][0],iterable[i][1])})};try{var src=("return "+delete_).replace("e_","\\u0065"),del=new Function("unwrap","validate",src)(unwrap,validate)}catch(e){var del=delete_}var src=(""+Object).split("Object"),stringifier=function(){return src[0]+nameOf(this)+src[1]};define(stringifier,stringifier);var prep={__proto__:[]}instanceof Array?function(f){f.__proto__=stringifier}:function(f){define(f,stringifier)};return prep(WeakMap),[toString,get,set,has,del].forEach(function(method){define(WeakMap.prototype,method),prep(method)}),WeakMap}(new Data),defaultCreator=Object.create?function(){return Object.create(null)}:function(){return{}};"undefined"!=typeof module?module.exports=WM:"undefined"!=typeof exports?exports.WeakMap=WM:"WeakMap"in global||(global.WeakMap=WM),WM.createStorage=createStorage,global.WeakMap&&(global.WeakMap.createStorage=createStorage)}((0,eval)("this"))},{}],43:[function(require,module){"use strict";function baseName(ext_name){return ext_name.replace(/^[A-Z]+_/,"")}function initWebGLEW(gl){var struct=WebGLEWStruct.get(gl);if(struct)return struct;for(var extensions={},supported=gl.getSupportedExtensions(),i=0;i=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,result.bind(),gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var state=saveFBOState(fbo.gl),gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),width=fbo._shape[0],height=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;ii;++i)this.color[i]=null;this._color_rb=null,this.depth=null,this._depth_rb=null,this._colorType=colorType,this._useDepth=useDepth,this._useStencil=useStencil;var parent=this,shapeVector=[0|width,0|height];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(w){return parent.width=w}},1:{get:function(){return parent._shape[1]},set:function(h){return parent.height=h}}}),this._shapeVector=shapeVector,rebuildFBO(this)}function reshapeFBO(fbo,w,h){if(fbo._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(fbo._shape[0]!==w||fbo._shape[1]!==h){var gl=fbo.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(0>w||w>maxFBOSize||0>h||h>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");fbo._shape[0]=w,fbo._shape[1]=h;for(var state=saveFBOState(gl),i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperties(proto,{shape:{get:function(){return this._destroyed?[0,0]:this._shapeVector},set:function(x){if(Array.isArray(x)||(x=[0|x,0|x]),2!==x.length)throw new Error("gl-fbo: Shape vector must be length 2");var w=0|x[0],h=0|x[1];return reshapeFBO(this,w,h),[w,h]},enumerable:!1},width:{get:function(){return this._destroyed?0:this._shape[0]},set:function(w){return w=0|w,reshapeFBO(this,w,this._shape[1]),w},enumerable:!1},height:{get:function(){return this._destroyed?0:this._shape[1]},set:function(h){return h=0|h,reshapeFBO(this,this._shape[0],h),h},enumerable:!1}}),proto.bind=function(){if(!this._destroyed){var gl=this.gl;gl.bindFramebuffer(gl.FRAMEBUFFER,this.handle),gl.viewport(0,0,this._shape[0],this._shape[1])}},proto.dispose=function(){if(!this._destroyed){this._destroyed=!0;var gl=this.gl;gl.deleteFramebuffer(this.handle),this.handle=null,this.depth&&(this.depth.dispose(),this.depth=null),this._depth_rb&&(gl.deleteRenderbuffer(this._depth_rb),this._depth_rb=null);for(var i=0;iw||w>maxSize||0>h||h>maxSize)throw new Error("gl-texture2d: Invalid texture size");return tex._shape=[w,h],tex.bind(),gl.texImage2D(gl.TEXTURE_2D,0,tex.format,w,h,0,tex.format,tex.type,null),tex._mipLevels=[0],tex}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[width,height],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1;var parent=this,wrapVector=[this._wrapS,this._wrapT];Object.defineProperties(wrapVector,{0:{get:function(){return parent._wrapS},set:function(v){return parent.wrapS=v}},1:{get:function(){return parent._wrapT},set:function(v){return parent.wrapT=v}}}),this._wrapVector=wrapVector;var shapeVector=[this._shape[0],this._shape[1]];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(v){return parent.width=v}},1:{get:function(){return parent._shape[1]},set:function(v){return parent.height=v}}}),this._shapeVector=shapeVector}function isPacked(shape,stride){return 3===shape.length?1===stride[2]&&stride[1]===shape[0]*shape[2]&&stride[0]===shape[2]:1===stride[0]&&stride[1]===shape[0]}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape.slice();if(shape.length<2||shape.length>3)throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d");var type=0,format=0,packed=isPacked(shape,array.stride.slice());"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var channels=1;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}channels=shape[2]}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape,[shape[2],shape[2]*shape[0],1]);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture(); return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(shape,array.stride.slice()),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type!==gl.FLOAT||webglew(gl).texture_float||(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store,size=array.size;if(packed)buffer=0===array.offset&&array.data.length===size?array.data:array.data.subarray(array.offset,array.offset+size);else{var stride=[shape[2],shape[2]*shape[0],1];buf_store=pool.malloc(size,dtype);var buf_array=ndarray(buf_store,shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,size)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[0],shape[1],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][0],0|arguments[1][1],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew");module.exports=createTexture2D;var linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)},proto=Texture2D.prototype;Object.defineProperties(proto,{minFilter:{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}},magFilter:{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}},mipSamples:{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}},wrapS:{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}},wrapT:{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}},wrap:{get:function(){return this._wrapVector},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapS=v[0],this._wrapT=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),v}},shape:{get:function(){return this._shapeVector},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];return reshapeTexture(this,0|x[0],0|x[1]),[0|x[0],0|x[1]]}},width:{get:function(){return this._shape[0]},set:function(w){return w=0|w,reshapeTexture(this,w,this._shape[1]),w}},height:{get:function(){return this._shape[1]},set:function(h){return h=0|h,reshapeTexture(this,this._shape[0],h),h}}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[1],x_off=0|x_off[0]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}}},{ndarray:54,"ndarray-ops":49,"typedarray-pool":58,webglew:61}],60:[function(require,module){module.exports=require(42)},{}],61:[function(require,module){module.exports=require(43)},{weakmap:60}],62:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":63}],63:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":65}],64:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:66}],65:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":64}],66:[function(require,module){module.exports=require(13)},{}],67:[function(require,module){module.exports=require(16)},{}],68:[function(require,module){module.exports=require(17)},{}],69:[function(require,module){module.exports=require(41)},{"bit-twiddle":67,buffer:189,dup:68}],70:[function(require,module){module.exports=require(42)},{}],71:[function(require,module){module.exports=require(43)},{weakmap:70}],72:[function(require,module,exports){arguments[4][59][0].apply(exports,arguments)},{ndarray:86,"ndarray-ops":62,"typedarray-pool":69,webglew:71}],73:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],74:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":73}],75:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;ii;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],82:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;kheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":89,"a-big-triangle":107,"canvas-fit":108,clone:110,"cube-cube":111,"face-normals":114,"frame-debounce":115,"gl-clear":120,"gl-context":121,"gl-fbo":123,"gl-geometry":126,"gl-matrix":151,"gl-texture2d":164,glslify:166,"glslify/adapter.js":165,"mesh-combine":172,"orbit-camera":179,"right-now":180,"unindex-mesh":181}],91:[function(require,module,exports){arguments[4][8][0].apply(exports,arguments)},{ndarray:97,"ndarray-ops":92,"typedarray-pool":101}],92:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":93}],93:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":95}],94:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:96}],95:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":94}],96:[function(require,module){module.exports=require(13)},{}],97:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":98}],98:[function(require,module){module.exports=require(15)},{}],99:[function(require,module){module.exports=require(16)},{}],100:[function(require,module){module.exports=require(17)},{}],101:[function(require,module){module.exports=require(18)},{"bit-twiddle":99,dup:100}],102:[function(require,module){module.exports=require(19) From 24ddcd9861e36045e865b30ad31be49e3df9f025 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 15 Sep 2014 16:31:55 +0200 Subject: [PATCH 19/64] update package list --- data/packages.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/data/packages.md b/data/packages.md index 582a0fc..728fbd0 100644 --- a/data/packages.md +++ b/data/packages.md @@ -18,7 +18,13 @@ To add a new package: ### gl-buffer ![gl-buffer](http://imgur.com/JFZGJBx.png) -## Tools +## WebGL API + +### gl-state +### gl-clear +### gl-fbo-matching + +## Tools/Development ### glslify ![glslify](http://imgur.com/ThMYeUx.png) @@ -26,13 +32,19 @@ To add a new package: ![glslify-live](http://imgur.com/9mmysos.png) ### glslify-optimize ![glslify-optimize](http://imgur.com/pF9tmNg.png) +### glslify-api +### glslify-resolve-remote +### glsl-testify +### glsl-editor ## Math +### ndarray ### gl-mat2 ### gl-mat3 ### gl-mat4 ### gl-matrix +### cubic-hermite ## Camera Controls @@ -49,6 +61,7 @@ To add a new package: ### gl-now ### gl-context +### webgl-context ## Input @@ -57,6 +70,7 @@ To add a new package: ### mouse-speed ### scroll-speed ### canvas-fit +### canvas-autoscale ### vkey ## Shader Components @@ -79,6 +93,15 @@ To add a new package: ### glsl-fog ![glsl-fog](http://imgur.com/8l0otem.png) +### glsl-easings +### glsl-fxaa +### glsl-lut +### glsl-range +### glsl-square-frame +### glsl-hsv2rgb +### glsl-read-float +### matcap + ## Shader Transforms ### glslify-hex @@ -90,13 +113,20 @@ To add a new package: ### gl-compare ![gl-compare](http://imgur.com/z8BkmZl.jpg) +### gl-surface-plot +### canvas-pixels +### gl-line-plot +### gl-scatter-plot +### gl-axes ## Internals +### webglew ### glsl-parser ### glsl-tokenizer ### glsl-deparser ### glsl-extract +### glsl-resolve ### glslify-stream ### gl-shader-core @@ -114,3 +144,37 @@ To add a new package: ### teapot ### stanford-dragon ![stanford-dragon](http://imgur.com/XWYMq6J.png) + +### get-pixels +### save-pixels +### ndpack-image +### font-atlas + +## Interoperability + +### three-glslify + +## Geometry + +### simplicial-complex +### gl-wireframe +### gl-geometry +### normals +### greedy-mesher +### voxelize +### isosurface +### icosphere +### rectangular-prism +### face-normals +### mesh-reindex +### mesh-combine +### unindex-mesh +### vectorize-text +### from-3d-to-2d +### surface-vectors +### orthogami +### plane-to-polygon +### find-basis-3d +### box-frustum +### delaunay-triangulate +### svg-3d-simplicial-complex From 27dcd91b05ce779b41b914000d23c47693597f6c Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 15 Sep 2014 16:44:42 +0200 Subject: [PATCH 20/64] add favicon --- favicon.ico | Bin 0 -> 41566 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 favicon.ico diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..76857299cf1e2f0641a0c2a9b1665bc3835252ed GIT binary patch literal 41566 zcmeHQU5I2y6~6w&A0jaU(S4EyqpUr^Uwl;87sb5z z1HJ?V@kL}o@FA?q?m9Ewvzv93xIrT#1U3;(9te| zrRvtLI_Ep5s!mm%s(ZUAUQ^ss+6t}&*C{|X&{k=u;(a#sfG0;FZQ1s~t3a}aaa}Sp>hr3iB+iNv0@M2sG z+B`As%qL#&$Ob=m?n}41X5%OB(kbU2d%$0eGY!uq5Ar&c(Kti?+}7H9r`7ncyM}VD zMhCoic`?p3d4@bbH}WgbjZ-Ulc1_A%UT4`Img#Jlj+c~Y8lQPO*Br_SPsqI2j683; zX1N#3Y=bYaK#R{1zeyTW24&qZPrS*s%Iog(DWu_f$j>nHH))awd8G`?p8ND0LHAkr z=sIZ%?@BpChw042yi$f`aY0A_((=k*X=o@q04*&qWu{bqBK(u;Z^HVMHZV#132jj5 z?6>_+(0|BRf3|Pd>AzZj8ABR2nA!s7RO~NxumYPq?$4b$^IG?~v6~ma_5t**Kk#yh zD;?%xUcDa`(zdw`ZzGxa#)Z{)z&`#McH>p|IP4=Y#+i0${q0JRWz;TeS{hoqf`4o6 z0oaFsyT5>@*e0=`u$Qn?Oye`=G59SFr7yG$W|a9Ja$98J zGsq)(Q6|!(EPu`}jdKiX3l7>&mIaN-N5_%#$KQ&2 z`vEY$9OT9r1Rax>y-2r9JH}&P(OLPj&;rfKr@7W}fBPnMEVh0}#*^;&1}4#Pid`g73FEb5nSX_oDiePO2kYu5H*hW2f! zeQr+4K69*{(fFb^f?`7Zd8ek)@z=B8pFITs4^ES+2Vxm1`d zbNjKZI`E?ul^c--UUk^43r=bmy?X zUVK@se?SW~$xG@Kyp*q`h4qNUTjdGNYyKm3ENcb79ueN0Pn&tR<=yjK+6T&#hO`&Z z1a0N3^%29?+Q*=;M`a!4*G$o;){m$1PQx@WbjNnOBWpLVlgIyc-SHGyKW7&I<^IQsI0NBOksK|}Zx|0)<|y(*ZaKTqlIHxwPP?noQDB`@WxVW(L> zo1Ez>g0gdpFKECoyeZdoYvndj(ndrkTvlCp#k~{ zxflOcT+vU6GfuPmiT}m;$9FdG|6r%NcD}Q{cHV8AAQbu4-M`mzvkEy!u|7p$Jp$k7 zPcf(5m3?l%FTN{jc&0e4?^4s|9aeDD&(^ikEDIWnQ{>o(Us=l!2`lqH_sHoxfagbOE3fGJ48*JFGlH*5aND^0 zKN56q44R;= zIMce;^l`(~AMLhJ-UDB0OX^;H?&AA~58Jm9>RH>&pf$10!+0p$#uG+=Fxk|{g!sC{4UzcOVUocm!xgHPv2CX6SKzC&_3&}3*X;`2hZvHzVQfN-J3Z^00RhBe=DhKl+&7UVDZ=NA0 z7GP4m7OTbH*=&4-V}9Hx;`rmwEX1~L`Sru3X`{l599ADD?s-FZVc$yTBfw}eTUpTN zTJG=Pg8Z_-gFPP8C(W6!elm>0JLq{zOL&r(%EA7%&HBehY`|#i!QzL!Ta*>y4$24( zq0vZRQ#&{Y2&L)PxY_(iE$|YC;Yib!Jp{AF7HY6YyEp&qWufDdiW>BFll)& z1N$QIqy5y?|D^mUEnmS8{b&6CU6@JrI&S%_|M}`Wt(UC-tpBu4)Va^?C%2zE?Iq2d z+s^{EpMA{VSbu4q&gl^TIlaPo4Ek-}PfyN0a_M>caBy z*wu&N=l?_3kB5ByZv7|fBNV-}4*K~ZOx+Bs|554Gapa+OocK=!%K-lg*TU*UIgI`* zyOxh}^&irAcL@B45x4P;(q}5ZQ~Gb|pP#q?*6#_7?Z1sO^z0`l{&V<4wQs0>kT%?} ze;EHuZ08(L)VIdxX#cc1)9|0G3=Ge5Khf-|aZdqbNK@VmO!hA-{clL0jxuPU_4r5b zUl5DMRwq7c|497xlkOjRU;lN;H?{pEDQFeat&#|4wb9 z#W86--BWWHzj7Dal;1y6Ag+S9sQzHpo3!mIV#PmDaVUPdjA4uzO9r zo2#FNty=i~>r@X`29fEIoFA}qNZ+vI#vwYtQIR8gzciko;eOfzpP#WZ$Mt*oP6F4$KCOI_c~stct$UT z6MoF_T|@8JRJnCug`vN2rVx2qCY;}9z3^_BKGWZ#*BrM-R|v=#qB+lI7{?gOT+4dl1 zpa-GF{SNpwg$H;=Jsf~-sElXl?|-M;YW&(=1-{V7<=ZK`XO;AEm2+6AIuQA#U+|o* zu?^%!p5PtzFo*F{`gnMc1@Ska&d;Dt-t=eUy^mKht9(`#O&d3~Wi<|d{8msq@VqG) zfQ5QU-_20nOd9s|@n+*b*raEqU-F#*+Uzi%MV!H=k1Ol2d?`)x5}xGkzg6@M-aooe z<(!sn=;`Ad<%eOHx5O^vJty`{*lIs^O;O%qy5KX_2YHKa;5%1-oY``~81*oLZK(8d ze0vc6?-#P?iv0}m^=;5#vA9OzpX9m9uKdDz4!_sNy%yL>!J2&YSamWgw0(&6kGa^l zA@2>}-)MsxyItP%uY1*<>VaX5OT7T2j1!F;#7-F~v$b7=bf9@9|K`ch?QJ#wDg8^n z`8?Y`u5#54qwJyoMcY8kuni&uWKo%|jG89$s-F0r!0pEG<$VWyd&rOD-S3Ol#W(N# zQ6KV+Uep<65LqZw`0imp9k6{+4|}cE3+^etD}-?k;|%eWW~4huJ6BhC7GsQatfVZE ziLyyu_nAMd{IDmF_<2mXpV!5)DEW;J{Ckv;ZIt|b&DC@MU7sL-7~d8}raCxi3z#3F zyz@@k>dIe--=gNNCx2O~|3#Il4z8~JM<3;?>;<5-|SO{0#o{mb?*+ke0QuQSdpYTi8lmv#Sp$PAh9!Cb z#p-}@`c(8>=`y|l)T0OcpJz+-{+rc9Y8#g6{l|(P65FsW@4s3dFkX3=WQpE??$Lv_ s4NLU?d#Zi_@% literal 0 HcmV?d00001 From 17c844b19babf9c94e5ba51cc66001484c5e2767 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 15 Sep 2014 16:45:44 +0200 Subject: [PATCH 21/64] update bundle.js --- bundle.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bundle.js b/bundle.js index b09b88f..2cf4d86 100644 --- a/bundle.js +++ b/bundle.js @@ -1,9 +1,9 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],Tools:[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2}],Math:[{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:2},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:3}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:5}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0}],Internals:[{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:4},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:5}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas")),flock=document.getElementById("community").querySelector("canvas");if(require("./lib/fill")(document.querySelectorAll("[data-fill]")),window.chrome)try{require("@stackgl/splash-grid")(grid),require("@stackgl/splash-flock")(flock)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;ii;i++)pdata[i]=FBO(gl,[SIZE,SIZE],{"float":!0}),pdata[i].color[0].setPixels(starter);window.addEventListener("resize",debounce(fit(canvas,window))),shaders.logic=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(gl),shaders.render=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(gl)}function switchFrames(data){return data.push(data.shift()),data}function createParticleVAO(gl,size){for(var data=new Float32Array(size*size),n=0,x=0;size>x;x++)for(var y=0;size>y;y++)data[n++]=x/size,data[n++]=y/size;var buffer=createBuffer(gl,data),vao=VAO(gl,[{buffer:buffer,type:gl.FLOAT,size:2}]);return vao.length=data.length/2,vao}function createStartPositions(size){for(var data=new Float32Array(size*size*4),i=0;i=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"}) -},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:189,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;islice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],31:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:37,"ndarray-ops":32,"typedarray-pool":41,webglew:43}],32:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":33}],33:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":35}],34:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:36}],35:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":34}],36:[function(require,module){module.exports=require(13)},{}],37:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":38}],38:[function(require,module){module.exports=require(15)},{}],39:[function(require,module){module.exports=require(16)},{}],40:[function(require,module){module.exports=require(17)},{}],41:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":39,buffer:189,dup:40}],42:[function(require,module,exports){void function(global,undefined_,undefined){function define(object,key,value){return"function"==typeof key&&(value=key,key=nameOf(value).replace(/_$/,"")),defProp(object,key,{configurable:!0,writable:!0,value:value})}function nameOf(func){return"function"!=typeof func?"":"name"in func?func.name:toSource.call(func).match(funcName)[1]}function createStorage(creator){function storage(object,value){return value||2===arguments.length?weakmap.set(object,value):(value=weakmap.get(object),value===undefined&&(value=creator(object),weakmap.set(object,value))),value}var weakmap=new WM;return creator||(creator=defaultCreator),storage}var getProps=Object.getOwnPropertyNames,defProp=Object.defineProperty,toSource=Function.prototype.toString,create=Object.create,hasOwn=Object.prototype.hasOwnProperty,funcName=/^\n?function\s?(\w*)?_?\(/,Data=function(){function Data(){var puid=createUID(),secret={};this.unlock=function(obj){var store=storage(obj);if(hasOwn.call(store,puid))return store[puid](secret);var data=create(null,dataDesc);return defProp(store,puid,{value:new Function("s","l",datalock)(secret,data)}),data}}var dataDesc={value:{writable:!0,value:undefined}},datalock="return function(k){if(k===s)return l}",uids=create(null),createUID=function(){var key=Math.random().toString(36).slice(2);return key in uids?createUID():uids[key]=key},globalID=createUID(),storage=function(obj){if(hasOwn.call(obj,globalID))return obj[globalID];if(!Object.isExtensible(obj))throw new TypeError("Object must be extensible");var store=create(null);return defProp(obj,globalID,{value:store}),store};return define(Object,function(obj){var props=getProps(obj);return hasOwn.call(obj,globalID)&&props.splice(props.indexOf(globalID),1),props}),define(Data.prototype,function(o){return this.unlock(o).value}),define(Data.prototype,function(o,v){this.unlock(o).value=v}),Data}(),WM=function(data){function WeakMap(iterable){return this===global||null==this||this===WeakMap.prototype?new WeakMap(iterable):(wrap(this,new Data),void initialize(this,iterable))}function get(key){validate(key);var value=unwrap(this).get(key);return value===undefined_?undefined:value}function set(key,value){validate(key),unwrap(this).set(key,value===undefined?undefined_:value)}function has(key){return validate(key),unwrap(this).get(key)!==undefined}function delete_(key){validate(key);var data=unwrap(this),had=data.get(key)!==undefined;return data.set(key,undefined),had}function toString(){return unwrap(this),"[object WeakMap]"}var validate=function(key){if(null==key||"object"!=typeof key&&"function"!=typeof key)throw new TypeError("Invalid WeakMap key")},wrap=function(collection,value){var store=data.unlock(collection);if(store.value)throw new TypeError("Object is already a WeakMap");store.value=value},unwrap=function(collection){var storage=data.unlock(collection).value;if(!storage)throw new TypeError("WeakMap is not generic");return storage},initialize=function(weakmap,iterable){null!==iterable&&"object"==typeof iterable&&"function"==typeof iterable.forEach&&iterable.forEach(function(item,i){item instanceof Array&&2===item.length&&set.call(weakmap,iterable[i][0],iterable[i][1])})};try{var src=("return "+delete_).replace("e_","\\u0065"),del=new Function("unwrap","validate",src)(unwrap,validate)}catch(e){var del=delete_}var src=(""+Object).split("Object"),stringifier=function(){return src[0]+nameOf(this)+src[1]};define(stringifier,stringifier);var prep={__proto__:[]}instanceof Array?function(f){f.__proto__=stringifier}:function(f){define(f,stringifier)};return prep(WeakMap),[toString,get,set,has,del].forEach(function(method){define(WeakMap.prototype,method),prep(method)}),WeakMap}(new Data),defaultCreator=Object.create?function(){return Object.create(null)}:function(){return{}};"undefined"!=typeof module?module.exports=WM:"undefined"!=typeof exports?exports.WeakMap=WM:"WeakMap"in global||(global.WeakMap=WM),WM.createStorage=createStorage,global.WeakMap&&(global.WeakMap.createStorage=createStorage)}((0,eval)("this"))},{}],43:[function(require,module){"use strict";function baseName(ext_name){return ext_name.replace(/^[A-Z]+_/,"")}function initWebGLEW(gl){var struct=WebGLEWStruct.get(gl);if(struct)return struct;for(var extensions={},supported=gl.getSupportedExtensions(),i=0;i=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,result.bind(),gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var state=saveFBOState(fbo.gl),gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),width=fbo._shape[0],height=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;ii;++i)this.color[i]=null;this._color_rb=null,this.depth=null,this._depth_rb=null,this._colorType=colorType,this._useDepth=useDepth,this._useStencil=useStencil;var parent=this,shapeVector=[0|width,0|height];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(w){return parent.width=w}},1:{get:function(){return parent._shape[1]},set:function(h){return parent.height=h}}}),this._shapeVector=shapeVector,rebuildFBO(this)}function reshapeFBO(fbo,w,h){if(fbo._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(fbo._shape[0]!==w||fbo._shape[1]!==h){var gl=fbo.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(0>w||w>maxFBOSize||0>h||h>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");fbo._shape[0]=w,fbo._shape[1]=h;for(var state=saveFBOState(gl),i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperties(proto,{shape:{get:function(){return this._destroyed?[0,0]:this._shapeVector},set:function(x){if(Array.isArray(x)||(x=[0|x,0|x]),2!==x.length)throw new Error("gl-fbo: Shape vector must be length 2");var w=0|x[0],h=0|x[1];return reshapeFBO(this,w,h),[w,h]},enumerable:!1},width:{get:function(){return this._destroyed?0:this._shape[0]},set:function(w){return w=0|w,reshapeFBO(this,w,this._shape[1]),w},enumerable:!1},height:{get:function(){return this._destroyed?0:this._shape[1]},set:function(h){return h=0|h,reshapeFBO(this,this._shape[0],h),h},enumerable:!1}}),proto.bind=function(){if(!this._destroyed){var gl=this.gl;gl.bindFramebuffer(gl.FRAMEBUFFER,this.handle),gl.viewport(0,0,this._shape[0],this._shape[1])}},proto.dispose=function(){if(!this._destroyed){this._destroyed=!0;var gl=this.gl;gl.deleteFramebuffer(this.handle),this.handle=null,this.depth&&(this.depth.dispose(),this.depth=null),this._depth_rb&&(gl.deleteRenderbuffer(this._depth_rb),this._depth_rb=null);for(var i=0;iw||w>maxSize||0>h||h>maxSize)throw new Error("gl-texture2d: Invalid texture size");return tex._shape=[w,h],tex.bind(),gl.texImage2D(gl.TEXTURE_2D,0,tex.format,w,h,0,tex.format,tex.type,null),tex._mipLevels=[0],tex}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[width,height],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1;var parent=this,wrapVector=[this._wrapS,this._wrapT];Object.defineProperties(wrapVector,{0:{get:function(){return parent._wrapS},set:function(v){return parent.wrapS=v}},1:{get:function(){return parent._wrapT},set:function(v){return parent.wrapT=v}}}),this._wrapVector=wrapVector;var shapeVector=[this._shape[0],this._shape[1]];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(v){return parent.width=v}},1:{get:function(){return parent._shape[1]},set:function(v){return parent.height=v}}}),this._shapeVector=shapeVector}function isPacked(shape,stride){return 3===shape.length?1===stride[2]&&stride[1]===shape[0]*shape[2]&&stride[0]===shape[2]:1===stride[0]&&stride[1]===shape[0]}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape.slice();if(shape.length<2||shape.length>3)throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d");var type=0,format=0,packed=isPacked(shape,array.stride.slice());"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var channels=1;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}channels=shape[2]}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape,[shape[2],shape[2]*shape[0],1]);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture(); -return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(shape,array.stride.slice()),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type!==gl.FLOAT||webglew(gl).texture_float||(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store,size=array.size;if(packed)buffer=0===array.offset&&array.data.length===size?array.data:array.data.subarray(array.offset,array.offset+size);else{var stride=[shape[2],shape[2]*shape[0],1];buf_store=pool.malloc(size,dtype);var buf_array=ndarray(buf_store,shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,size)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[0],shape[1],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][0],0|arguments[1][1],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew");module.exports=createTexture2D;var linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)},proto=Texture2D.prototype;Object.defineProperties(proto,{minFilter:{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}},magFilter:{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}},mipSamples:{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}},wrapS:{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}},wrapT:{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}},wrap:{get:function(){return this._wrapVector},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapS=v[0],this._wrapT=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),v}},shape:{get:function(){return this._shapeVector},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];return reshapeTexture(this,0|x[0],0|x[1]),[0|x[0],0|x[1]]}},width:{get:function(){return this._shape[0]},set:function(w){return w=0|w,reshapeTexture(this,w,this._shape[1]),w}},height:{get:function(){return this._shape[1]},set:function(h){return h=0|h,reshapeTexture(this,this._shape[0],h),h}}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[1],x_off=0|x_off[0]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}}},{ndarray:54,"ndarray-ops":49,"typedarray-pool":58,webglew:61}],60:[function(require,module){module.exports=require(42)},{}],61:[function(require,module){module.exports=require(43)},{weakmap:60}],62:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":63}],63:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":65}],64:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:66}],65:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":64}],66:[function(require,module){module.exports=require(13)},{}],67:[function(require,module){module.exports=require(16)},{}],68:[function(require,module){module.exports=require(17)},{}],69:[function(require,module){module.exports=require(41)},{"bit-twiddle":67,buffer:189,dup:68}],70:[function(require,module){module.exports=require(42)},{}],71:[function(require,module){module.exports=require(43)},{weakmap:70}],72:[function(require,module,exports){arguments[4][59][0].apply(exports,arguments)},{ndarray:86,"ndarray-ops":62,"typedarray-pool":69,webglew:71}],73:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],74:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":73}],75:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;ii;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],82:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;kheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":89,"a-big-triangle":107,"canvas-fit":108,clone:110,"cube-cube":111,"face-normals":114,"frame-debounce":115,"gl-clear":120,"gl-context":121,"gl-fbo":123,"gl-geometry":126,"gl-matrix":151,"gl-texture2d":164,glslify:166,"glslify/adapter.js":165,"mesh-combine":172,"orbit-camera":179,"right-now":180,"unindex-mesh":181}],91:[function(require,module,exports){arguments[4][8][0].apply(exports,arguments)},{ndarray:97,"ndarray-ops":92,"typedarray-pool":101}],92:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":93}],93:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":95}],94:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:96}],95:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":94}],96:[function(require,module){module.exports=require(13)},{}],97:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":98}],98:[function(require,module){module.exports=require(15)},{}],99:[function(require,module){module.exports=require(16)},{}],100:[function(require,module){module.exports=require(17)},{}],101:[function(require,module){module.exports=require(18)},{"bit-twiddle":99,dup:100}],102:[function(require,module){module.exports=require(19) -},{}],103:[function(require,module){module.exports=require(20)},{"./do-bind.js":102}],104:[function(require,module){module.exports=require(21)},{"./do-bind.js":102}],105:[function(require,module){module.exports=require(22)},{}],106:[function(require,module){module.exports=require(23)},{"./lib/vao-emulated.js":103,"./lib/vao-native.js":104,webglew:105}],107:[function(require,module){module.exports=require(24)},{"gl-buffer":91,"gl-vao":106}],108:[function(require,module,exports){arguments[4][25][0].apply(exports,arguments)},{"element-size":109}],109:[function(require,module){module.exports=require(26)},{}],110:[function(require,module){(function(Buffer){"use strict";function objectToString(o){return Object.prototype.toString.call(o)}function clone(parent,circular,depth,prototype){function _clone(parent,depth){if(null===parent)return null;if(0==depth)return parent;var child;if("object"!=typeof parent)return parent;if(util.isArray(parent))child=[];else if(util.isRegExp(parent))child=new RegExp(parent.source,util.getRegExpFlags(parent)),parent.lastIndex&&(child.lastIndex=parent.lastIndex);else if(util.isDate(parent))child=new Date(parent.getTime());else{if(useBuffer&&Buffer.isBuffer(parent))return child=new Buffer(parent.length),parent.copy(child),child;child=Object.create("undefined"==typeof prototype?Object.getPrototypeOf(parent):prototype)}if(circular){var index=allParents.indexOf(parent);if(-1!=index)return allChildren[index];allParents.push(parent),allChildren.push(child)}for(var i in parent)child[i]=_clone(parent[i],depth-1);return child}var allParents=[],allChildren=[],useBuffer="undefined"!=typeof Buffer;return"undefined"==typeof circular&&(circular=!0),"undefined"==typeof depth&&(depth=1/0),_clone(parent,depth)}var util={isArray:function(ar){return Array.isArray(ar)||"object"==typeof ar&&"[object Array]"===objectToString(ar)},isDate:function(d){return"object"==typeof d&&"[object Date]"===objectToString(d)},isRegExp:function(re){return"object"==typeof re&&"[object RegExp]"===objectToString(re)},getRegExpFlags:function(re){var flags="";return re.global&&(flags+="g"),re.ignoreCase&&(flags+="i"),re.multiline&&(flags+="m"),flags}};"object"==typeof module&&(module.exports=clone),clone.clonePrototype=function(parent){if(null===parent)return null;var c=function(){};return c.prototype=parent,new c}}).call(this,require("buffer").Buffer)},{buffer:189}],111:[function(require,module){function cubecube(w,h,d,filter){filter=filter||truthy;for(var size=[1/w,1/h,1/d],cubes=[],x=0;w>x;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":113}],112:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],113:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],115:[function(require,module,exports){arguments[4][27][0].apply(exports,arguments)},{_process:192,"raf-component":116,sliced:117}],116:[function(require,module){module.exports=require(28)},{}],117:[function(require,module,exports){arguments[4][29][0].apply(exports,arguments)},{"./lib/sliced":118}],118:[function(require,module){module.exports=require(30)},{}],119:[function(require,module){module.exports=require(44)},{}],120:[function(require,module){module.exports=require(45)},{"./defaults":119}],121:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":122}],122:[function(require,module){module.exports=require(28)},{}],123:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:128}],128:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],129:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:135,"ndarray-ops":130,"typedarray-pool":139,webglew:141}],130:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":131}],131:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":133}],132:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:134}],133:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":132}],134:[function(require,module){module.exports=require(13)},{}],135:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":136}],136:[function(require,module){module.exports=require(15)},{}],137:[function(require,module){module.exports=require(16)},{}],138:[function(require,module){module.exports=require(17)},{}],139:[function(require,module){module.exports=require(41)},{"bit-twiddle":137,buffer:189,dup:138}],140:[function(require,module){module.exports=require(42)},{}],141:[function(require,module){module.exports=require(43)},{weakmap:140}],142:[function(require,module){module.exports=require(73)},{}],143:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements){this._elements=elements,this._attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":142}],144:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2]; -return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],152:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":153}],153:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":155}],154:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:156}],155:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":154}],156:[function(require,module){module.exports=require(13)},{}],157:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":158}],158:[function(require,module){module.exports=require(15)},{}],159:[function(require,module){module.exports=require(16)},{}],160:[function(require,module){module.exports=require(17)},{}],161:[function(require,module){module.exports=require(41)},{"bit-twiddle":159,buffer:189,dup:160}],162:[function(require,module){module.exports=require(42)},{}],163:[function(require,module){module.exports=require(43)},{weakmap:162}],164:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function isPacked(array){for(var shape=array.shape,stride=array.stride,s=1,i=shape.length-1;i>=0;--i){if(stride[i]!==s)return!1;s*=shape[i]}return!0}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(array),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type===gl.FLOAT&&webglew(gl).texture_float&&(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store;if(packed){var array_size=array.size;buffer=array.data.subarray(array.offset,array.offset+array_size)}else{for(var sz=1,stride=new Array(shape.length),i=shape.length-1;i>=0;--i)stride[i]=sz,sz*=shape[i];buf_store=pool.malloc(sz,dtype);var buf_array=ndarray(buf_store,array.shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,sz)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[1],shape[0],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE); -if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][1],0|arguments[1][0],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew"),linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)};Object.defineProperty(Texture2D.prototype,"minFilter",{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}});var proto=Texture2D.prototype;Object.defineProperty(proto,"magFilter",{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}}),Object.defineProperty(proto,"wrapS",{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}}),Object.defineProperty(proto,"wrapT",{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}}),Object.defineProperty(proto,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapT=v[0],this._wrapS=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),v}}),Object.defineProperty(proto,"mipSamples",{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(proto,"shape",{get:function(){return this._shape},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];var r=0|x[0],c=0|x[1];if(this.height===r&&this.width===c)return x;var gl=this.gl,maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>c||c>maxSize||0>r||r>maxSize)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[r,c],this.bind(),gl.texImage2D(gl.TEXTURE_2D,0,this.format,c,r,0,this.format,this.type,null),this._mipLevels=[0],x}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[0],x_off=0|x_off[1]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}},module.exports=createTexture2D},{ndarray:157,"ndarray-ops":152,"typedarray-pool":161,webglew:163}],165:[function(require,module,exports){arguments[4][79][0].apply(exports,arguments)},{"gl-shader-core":171}],166:[function(require,module){module.exports=require(80)},{}],167:[function(require,module){module.exports=require(81)},{}],168:[function(require,module,exports){arguments[4][82][0].apply(exports,arguments)},{"./reflect.js":169,dup:170}],169:[function(require,module){module.exports=require(83)},{}],170:[function(require,module){module.exports=require(17)},{}],171:[function(require,module){module.exports=require(85)},{"./lib/create-attributes.js":167,"./lib/create-uniforms.js":168,"./lib/reflect.js":169}],172:[function(require,module){function combine(meshes){for(var pos=[],cel=[],p=0,c=0,k=0,i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out -},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],179:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance}function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":178}],180:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],181:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],182:[function(require,module){function parse(html,doc){if("string"!=typeof html)throw new TypeError("String expected");doc||(doc=document);var m=/<([\w:]+)/.exec(html);if(!m)return doc.createTextNode(html);html=html.replace(/^\s+|\s+$/g,"");var tag=m[1];if("body"==tag){var el=doc.createElement("html");return el.innerHTML=html,el.removeChild(el.lastChild)}var wrap=map[tag]||map._default,depth=wrap[0],prefix=wrap[1],suffix=wrap[2],el=doc.createElement("div");for(el.innerHTML=prefix+html+suffix;depth--;)el=el.lastChild;if(el.firstChild==el.lastChild)return el.removeChild(el.firstChild);for(var fragment=doc.createDocumentFragment();el.firstChild;)fragment.appendChild(el.removeChild(el.firstChild));return fragment}module.exports=parse;var map={legend:[1,"
      ","
      "],tr:[2,"","
      "],col:[2,"","
      "],_default:[0,"",""]};map.td=map.th=[3,"","
      "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
      "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],183:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],184:[function(require,module,exports){arguments[4][27][0].apply(exports,arguments)},{_process:192,"raf-component":185,sliced:187}],185:[function(require,module){module.exports=require(28)},{}],186:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],187:[function(require,module,exports){arguments[4][29][0].apply(exports,arguments)},{"./lib/sliced":188}],188:[function(require,module){module.exports=require(30)},{}],189:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)"base64"===encoding&&(subject=base64clean(subject)),length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new Error("First argument needs to be a number, array or string.");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}var buf;TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;assert(strLen%2===0,"Invalid hex string"),length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);assert(!isNaN(byte),"Invalid hex string"),buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string),buf,offset,length);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function binarySlice(buf,start,end){return asciiSlice(buf,start,end)}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;i=len)){var val;return littleEndian?(val=buf[offset],len>offset+1&&(val|=buf[offset+1]<<8)):(val=buf[offset]<<8,len>offset+1&&(val|=buf[offset+1])),val}}function readUInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val;return littleEndian?(len>offset+2&&(val=buf[offset+2]<<16),len>offset+1&&(val|=buf[offset+1]<<8),val|=buf[offset],len>offset+3&&(val+=buf[offset+3]<<24>>>0)):(len>offset+1&&(val=buf[offset+1]<<16),len>offset+2&&(val|=buf[offset+2]<<8),len>offset+3&&(val|=buf[offset+3]),val+=buf[offset]<<24>>>0),val}}function readInt16(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len)){var val=readUInt16(buf,offset,littleEndian,!0),neg=32768&val;return neg?-1*(65535-val+1):val}}function readInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val=readUInt32(buf,offset,littleEndian,!0),neg=2147483648&val;return neg?-1*(4294967295-val+1):val}}function readFloat(buf,offset,littleEndian,noAssert){return noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i);return offset+2}}function writeUInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255;return offset+4}}function writeInt16(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len))return value>=0?writeUInt16(buf,value,offset,littleEndian,noAssert):writeUInt16(buf,65535+value+1,offset,littleEndian,noAssert),offset+2}function writeInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return value>=0?writeUInt32(buf,value,offset,littleEndian,noAssert):writeUInt32(buf,4294967295+value+1,offset,littleEndian,noAssert),offset+4}function writeFloat(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+7=len))return ieee754.write(buf,value,offset,littleEndian,52,8),offset+8}function base64clean(str){for(str=stringtrim(str).replace(INVALID_BASE64_RE,"");str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArray(subject){return(Array.isArray||function(subject){return"[object Array]"===Object.prototype.toString.call(subject)})(subject)}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(str){for(var byteArray=[],i=0;i=b)byteArray.push(b);else{var start=i;b>=55296&&57343>=b&&i++;for(var h=encodeURIComponent(str.slice(start,i+1)).substr(1).split("%"),j=0;j>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(str)}function blitBuffer(src,dst,offset,length){for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533)}}function verifuint(value,max){assert("number"==typeof value,"cannot write a non-number as a number"),assert(value>=0,"specified a negative value for writing an unsigned value"),assert(max>=value,"value is larger than maximum value for type"),assert(Math.floor(value)===value,"value has a fractional component")}function verifsint(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value"),assert(Math.floor(value)===value,"value has a fractional component")}function verifIEEE754(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value")}function assert(test,message){if(!test)throw new Error(message||"Failed assertion")}var base64=require("base64-js"),ieee754=require("ieee754");exports.Buffer=Buffer,exports.SlowBuffer=Buffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}();Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.byteLength=function(str,encoding){var ret;switch(str=str.toString(),encoding||"utf8"){case"hex":ret=str.length/2;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"ascii":case"binary":case"raw":ret=str.length;break;case"base64":ret=base64ToBytes(str).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=2*str.length;break;default:throw new Error("Unknown encoding")}return ret},Buffer.concat=function(list,totalLength){if(assert(isArray(list),"Usage: Buffer.concat(list[, length])"),0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;ii&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}offset=Number(offset)||0;var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toString=function(encoding,start,end){var self=this;if(encoding=String(encoding||"utf8").toLowerCase(),start=Number(start)||0,end=void 0===end?self.length:Number(end),end===start)return"";var ret;switch(encoding){case"hex":ret=hexSlice(self,start,end);break;case"utf8":case"utf-8":ret=utf8Slice(self,start,end);break;case"ascii":ret=asciiSlice(self,start,end);break;case"binary":ret=binarySlice(self,start,end);break;case"base64":ret=base64Slice(self,start,end);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leSlice(self,start,end);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.equals=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),0===Buffer.compare(this,b)},Buffer.prototype.compare=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),Buffer.compare(this,b)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start||(target_start=0),end!==start&&0!==target.length&&0!==source.length){assert(end>=start,"sourceEnd < sourceStart"),assert(target_start>=0&&target_start=0&&start=0&&end<=source.length,"sourceEnd out of bounds"),end>this.length&&(end=this.length),target.length-target_startlen||!TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start)}},Buffer.prototype.slice=function(start,end){var len=this.length;if(start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start),TYPED_ARRAY_SUPPORT)return Buffer._augment(this.subarray(start,end)); -for(var sliceLen=end-start,newBuf=new Buffer(sliceLen,void 0,!0),i=0;sliceLen>i;i++)newBuf[i]=this[i+start];return newBuf},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return readUInt16(this,offset,!0,noAssert)},Buffer.prototype.readUInt16BE=function(offset,noAssert){return readUInt16(this,offset,!1,noAssert)},Buffer.prototype.readUInt32LE=function(offset,noAssert){return readUInt32(this,offset,!0,noAssert)},Buffer.prototype.readUInt32BE=function(offset,noAssert){return readUInt32(this,offset,!1,noAssert)},Buffer.prototype.readInt8=function(offset,noAssert){if(noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length)){var neg=128&this[offset];return neg?-1*(255-this[offset]+1):this[offset]}},Buffer.prototype.readInt16LE=function(offset,noAssert){return readInt16(this,offset,!0,noAssert)},Buffer.prototype.readInt16BE=function(offset,noAssert){return readInt16(this,offset,!1,noAssert)},Buffer.prototype.readInt32LE=function(offset,noAssert){return readInt32(this,offset,!0,noAssert)},Buffer.prototype.readInt32BE=function(offset,noAssert){return readInt32(this,offset,!1,noAssert)},Buffer.prototype.readFloatLE=function(offset,noAssert){return readFloat(this,offset,!0,noAssert)},Buffer.prototype.readFloatBE=function(offset,noAssert){return readFloat(this,offset,!1,noAssert)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return readDouble(this,offset,!0,noAssert)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return readDouble(this,offset,!1,noAssert)},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(this[offset]=value,offset+1)},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(value>=0?this.writeUInt8(value,offset,noAssert):this.writeUInt8(255+value+1,offset,noAssert),offset+1)},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return writeInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return writeInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return writeInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return writeInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert)},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),assert(end>=start,"end < start"),end!==start&&0!==this.length){assert(start>=0&&start=0&&end<=this.length,"end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.inspect=function(){for(var out=[],len=this.length,i=0;len>i;i++)if(out[i]=toHex(this[i]),i===exports.INSPECT_MAX_BYTES){out[i+1]="...";break}return""},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z]/g},{"base64-js":190,ieee754:191}],190:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS?62:code===SLASH?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],191:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],192:[function(require,module){function noop(){}var process=module.exports={};process.nextTick=function(){var canSetImmediate="undefined"!=typeof window&&window.setImmediate,canPost="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(canSetImmediate)return function(f){return window.setImmediate(f)};if(canPost){var queue=[];return window.addEventListener("message",function(ev){var source=ev.source;if((source===window||null===source)&&"process-tick"===ev.data&&(ev.stopPropagation(),queue.length>0)){var fn=queue.shift();fn()}},!0),function(fn){queue.push(fn),window.postMessage("process-tick","*")}}return function(fn){setTimeout(fn,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas")),flock=document.getElementById("community").querySelector("canvas");if(require("./lib/fill")(document.querySelectorAll("[data-fill]")),window.chrome)try{require("@stackgl/splash-grid")(grid),require("@stackgl/splash-flock")(flock)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;ii;i++)pdata[i]=FBO(gl,[SIZE,SIZE],{"float":!0}),pdata[i].color[0].setPixels(starter);window.addEventListener("resize",debounce(fit(canvas,window))),shaders.logic=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(gl),shaders.render=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(gl)}function switchFrames(data){return data.push(data.shift()),data}function createParticleVAO(gl,size){for(var data=new Float32Array(size*size),n=0,x=0;size>x;x++)for(var y=0;size>y;y++)data[n++]=x/size,data[n++]=y/size;var buffer=createBuffer(gl,data),vao=VAO(gl,[{buffer:buffer,type:gl.FLOAT,size:2}]);return vao.length=data.length/2,vao}function createStartPositions(size){for(var data=new Float32Array(size*size*4),i=0;i=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:189,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n); +case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;islice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],31:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:37,"ndarray-ops":32,"typedarray-pool":41,webglew:43}],32:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":33}],33:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":35}],34:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:36}],35:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":34}],36:[function(require,module){module.exports=require(13)},{}],37:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":38}],38:[function(require,module){module.exports=require(15)},{}],39:[function(require,module){module.exports=require(16)},{}],40:[function(require,module){module.exports=require(17)},{}],41:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":39,buffer:189,dup:40}],42:[function(require,module,exports){void function(global,undefined_,undefined){function define(object,key,value){return"function"==typeof key&&(value=key,key=nameOf(value).replace(/_$/,"")),defProp(object,key,{configurable:!0,writable:!0,value:value})}function nameOf(func){return"function"!=typeof func?"":"name"in func?func.name:toSource.call(func).match(funcName)[1]}function createStorage(creator){function storage(object,value){return value||2===arguments.length?weakmap.set(object,value):(value=weakmap.get(object),value===undefined&&(value=creator(object),weakmap.set(object,value))),value}var weakmap=new WM;return creator||(creator=defaultCreator),storage}var getProps=Object.getOwnPropertyNames,defProp=Object.defineProperty,toSource=Function.prototype.toString,create=Object.create,hasOwn=Object.prototype.hasOwnProperty,funcName=/^\n?function\s?(\w*)?_?\(/,Data=function(){function Data(){var puid=createUID(),secret={};this.unlock=function(obj){var store=storage(obj);if(hasOwn.call(store,puid))return store[puid](secret);var data=create(null,dataDesc);return defProp(store,puid,{value:new Function("s","l",datalock)(secret,data)}),data}}var dataDesc={value:{writable:!0,value:undefined}},datalock="return function(k){if(k===s)return l}",uids=create(null),createUID=function(){var key=Math.random().toString(36).slice(2);return key in uids?createUID():uids[key]=key},globalID=createUID(),storage=function(obj){if(hasOwn.call(obj,globalID))return obj[globalID];if(!Object.isExtensible(obj))throw new TypeError("Object must be extensible");var store=create(null);return defProp(obj,globalID,{value:store}),store};return define(Object,function(obj){var props=getProps(obj);return hasOwn.call(obj,globalID)&&props.splice(props.indexOf(globalID),1),props}),define(Data.prototype,function(o){return this.unlock(o).value}),define(Data.prototype,function(o,v){this.unlock(o).value=v}),Data}(),WM=function(data){function WeakMap(iterable){return this===global||null==this||this===WeakMap.prototype?new WeakMap(iterable):(wrap(this,new Data),void initialize(this,iterable))}function get(key){validate(key);var value=unwrap(this).get(key);return value===undefined_?undefined:value}function set(key,value){validate(key),unwrap(this).set(key,value===undefined?undefined_:value)}function has(key){return validate(key),unwrap(this).get(key)!==undefined}function delete_(key){validate(key);var data=unwrap(this),had=data.get(key)!==undefined;return data.set(key,undefined),had}function toString(){return unwrap(this),"[object WeakMap]"}var validate=function(key){if(null==key||"object"!=typeof key&&"function"!=typeof key)throw new TypeError("Invalid WeakMap key")},wrap=function(collection,value){var store=data.unlock(collection);if(store.value)throw new TypeError("Object is already a WeakMap");store.value=value},unwrap=function(collection){var storage=data.unlock(collection).value;if(!storage)throw new TypeError("WeakMap is not generic");return storage},initialize=function(weakmap,iterable){null!==iterable&&"object"==typeof iterable&&"function"==typeof iterable.forEach&&iterable.forEach(function(item,i){item instanceof Array&&2===item.length&&set.call(weakmap,iterable[i][0],iterable[i][1])})};try{var src=("return "+delete_).replace("e_","\\u0065"),del=new Function("unwrap","validate",src)(unwrap,validate)}catch(e){var del=delete_}var src=(""+Object).split("Object"),stringifier=function(){return src[0]+nameOf(this)+src[1]};define(stringifier,stringifier);var prep={__proto__:[]}instanceof Array?function(f){f.__proto__=stringifier}:function(f){define(f,stringifier)};return prep(WeakMap),[toString,get,set,has,del].forEach(function(method){define(WeakMap.prototype,method),prep(method)}),WeakMap}(new Data),defaultCreator=Object.create?function(){return Object.create(null)}:function(){return{}};"undefined"!=typeof module?module.exports=WM:"undefined"!=typeof exports?exports.WeakMap=WM:"WeakMap"in global||(global.WeakMap=WM),WM.createStorage=createStorage,global.WeakMap&&(global.WeakMap.createStorage=createStorage)}((0,eval)("this"))},{}],43:[function(require,module){"use strict";function baseName(ext_name){return ext_name.replace(/^[A-Z]+_/,"")}function initWebGLEW(gl){var struct=WebGLEWStruct.get(gl);if(struct)return struct;for(var extensions={},supported=gl.getSupportedExtensions(),i=0;i=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,result.bind(),gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var state=saveFBOState(fbo.gl),gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),width=fbo._shape[0],height=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;ii;++i)this.color[i]=null;this._color_rb=null,this.depth=null,this._depth_rb=null,this._colorType=colorType,this._useDepth=useDepth,this._useStencil=useStencil;var parent=this,shapeVector=[0|width,0|height];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(w){return parent.width=w}},1:{get:function(){return parent._shape[1]},set:function(h){return parent.height=h}}}),this._shapeVector=shapeVector,rebuildFBO(this)}function reshapeFBO(fbo,w,h){if(fbo._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(fbo._shape[0]!==w||fbo._shape[1]!==h){var gl=fbo.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(0>w||w>maxFBOSize||0>h||h>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");fbo._shape[0]=w,fbo._shape[1]=h;for(var state=saveFBOState(gl),i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers") +}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperties(proto,{shape:{get:function(){return this._destroyed?[0,0]:this._shapeVector},set:function(x){if(Array.isArray(x)||(x=[0|x,0|x]),2!==x.length)throw new Error("gl-fbo: Shape vector must be length 2");var w=0|x[0],h=0|x[1];return reshapeFBO(this,w,h),[w,h]},enumerable:!1},width:{get:function(){return this._destroyed?0:this._shape[0]},set:function(w){return w=0|w,reshapeFBO(this,w,this._shape[1]),w},enumerable:!1},height:{get:function(){return this._destroyed?0:this._shape[1]},set:function(h){return h=0|h,reshapeFBO(this,this._shape[0],h),h},enumerable:!1}}),proto.bind=function(){if(!this._destroyed){var gl=this.gl;gl.bindFramebuffer(gl.FRAMEBUFFER,this.handle),gl.viewport(0,0,this._shape[0],this._shape[1])}},proto.dispose=function(){if(!this._destroyed){this._destroyed=!0;var gl=this.gl;gl.deleteFramebuffer(this.handle),this.handle=null,this.depth&&(this.depth.dispose(),this.depth=null),this._depth_rb&&(gl.deleteRenderbuffer(this._depth_rb),this._depth_rb=null);for(var i=0;iw||w>maxSize||0>h||h>maxSize)throw new Error("gl-texture2d: Invalid texture size");return tex._shape=[w,h],tex.bind(),gl.texImage2D(gl.TEXTURE_2D,0,tex.format,w,h,0,tex.format,tex.type,null),tex._mipLevels=[0],tex}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[width,height],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1;var parent=this,wrapVector=[this._wrapS,this._wrapT];Object.defineProperties(wrapVector,{0:{get:function(){return parent._wrapS},set:function(v){return parent.wrapS=v}},1:{get:function(){return parent._wrapT},set:function(v){return parent.wrapT=v}}}),this._wrapVector=wrapVector;var shapeVector=[this._shape[0],this._shape[1]];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(v){return parent.width=v}},1:{get:function(){return parent._shape[1]},set:function(v){return parent.height=v}}}),this._shapeVector=shapeVector}function isPacked(shape,stride){return 3===shape.length?1===stride[2]&&stride[1]===shape[0]*shape[2]&&stride[0]===shape[2]:1===stride[0]&&stride[1]===shape[0]}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape.slice();if(shape.length<2||shape.length>3)throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d");var type=0,format=0,packed=isPacked(shape,array.stride.slice());"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var channels=1;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}channels=shape[2]}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape,[shape[2],shape[2]*shape[0],1]);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(shape,array.stride.slice()),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type!==gl.FLOAT||webglew(gl).texture_float||(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store,size=array.size;if(packed)buffer=0===array.offset&&array.data.length===size?array.data:array.data.subarray(array.offset,array.offset+size);else{var stride=[shape[2],shape[2]*shape[0],1];buf_store=pool.malloc(size,dtype);var buf_array=ndarray(buf_store,shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,size)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[0],shape[1],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][0],0|arguments[1][1],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew");module.exports=createTexture2D;var linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)},proto=Texture2D.prototype;Object.defineProperties(proto,{minFilter:{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}},magFilter:{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}},mipSamples:{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}},wrapS:{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}},wrapT:{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}},wrap:{get:function(){return this._wrapVector},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapS=v[0],this._wrapT=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),v}},shape:{get:function(){return this._shapeVector},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];return reshapeTexture(this,0|x[0],0|x[1]),[0|x[0],0|x[1]]}},width:{get:function(){return this._shape[0]},set:function(w){return w=0|w,reshapeTexture(this,w,this._shape[1]),w}},height:{get:function(){return this._shape[1]},set:function(h){return h=0|h,reshapeTexture(this,this._shape[0],h),h}}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[1],x_off=0|x_off[0]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}}},{ndarray:54,"ndarray-ops":49,"typedarray-pool":58,webglew:61}],60:[function(require,module){module.exports=require(42)},{}],61:[function(require,module){module.exports=require(43)},{weakmap:60}],62:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":63}],63:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":65}],64:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:66}],65:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":64}],66:[function(require,module){module.exports=require(13)},{}],67:[function(require,module){module.exports=require(16)},{}],68:[function(require,module){module.exports=require(17)},{}],69:[function(require,module){module.exports=require(41)},{"bit-twiddle":67,buffer:189,dup:68}],70:[function(require,module){module.exports=require(42)},{}],71:[function(require,module){module.exports=require(43)},{weakmap:70}],72:[function(require,module,exports){arguments[4][59][0].apply(exports,arguments)},{ndarray:86,"ndarray-ops":62,"typedarray-pool":69,webglew:71}],73:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],74:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":73}],75:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;ii;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],82:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;kheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":89,"a-big-triangle":107,"canvas-fit":108,clone:110,"cube-cube":111,"face-normals":114,"frame-debounce":115,"gl-clear":120,"gl-context":121,"gl-fbo":123,"gl-geometry":126,"gl-matrix":151,"gl-texture2d":164,glslify:166,"glslify/adapter.js":165,"mesh-combine":172,"orbit-camera":179,"right-now":180,"unindex-mesh":181}],91:[function(require,module,exports){arguments[4][8][0].apply(exports,arguments)},{ndarray:97,"ndarray-ops":92,"typedarray-pool":101}],92:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":93}],93:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":95}],94:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:96}],95:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":94}],96:[function(require,module){module.exports=require(13)},{}],97:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":98}],98:[function(require,module){module.exports=require(15)},{}],99:[function(require,module){module.exports=require(16)},{}],100:[function(require,module){module.exports=require(17)},{}],101:[function(require,module){module.exports=require(18)},{"bit-twiddle":99,dup:100}],102:[function(require,module){module.exports=require(19)},{}],103:[function(require,module){module.exports=require(20)},{"./do-bind.js":102}],104:[function(require,module){module.exports=require(21)},{"./do-bind.js":102}],105:[function(require,module){module.exports=require(22)},{}],106:[function(require,module){module.exports=require(23)},{"./lib/vao-emulated.js":103,"./lib/vao-native.js":104,webglew:105}],107:[function(require,module){module.exports=require(24)},{"gl-buffer":91,"gl-vao":106}],108:[function(require,module,exports){arguments[4][25][0].apply(exports,arguments)},{"element-size":109}],109:[function(require,module){module.exports=require(26)},{}],110:[function(require,module){(function(Buffer){"use strict";function objectToString(o){return Object.prototype.toString.call(o)}function clone(parent,circular,depth,prototype){function _clone(parent,depth){if(null===parent)return null;if(0==depth)return parent;var child;if("object"!=typeof parent)return parent;if(util.isArray(parent))child=[];else if(util.isRegExp(parent))child=new RegExp(parent.source,util.getRegExpFlags(parent)),parent.lastIndex&&(child.lastIndex=parent.lastIndex);else if(util.isDate(parent))child=new Date(parent.getTime());else{if(useBuffer&&Buffer.isBuffer(parent))return child=new Buffer(parent.length),parent.copy(child),child;child=Object.create("undefined"==typeof prototype?Object.getPrototypeOf(parent):prototype)}if(circular){var index=allParents.indexOf(parent);if(-1!=index)return allChildren[index];allParents.push(parent),allChildren.push(child)}for(var i in parent)child[i]=_clone(parent[i],depth-1);return child}var allParents=[],allChildren=[],useBuffer="undefined"!=typeof Buffer;return"undefined"==typeof circular&&(circular=!0),"undefined"==typeof depth&&(depth=1/0),_clone(parent,depth)}var util={isArray:function(ar){return Array.isArray(ar)||"object"==typeof ar&&"[object Array]"===objectToString(ar)},isDate:function(d){return"object"==typeof d&&"[object Date]"===objectToString(d)},isRegExp:function(re){return"object"==typeof re&&"[object RegExp]"===objectToString(re)},getRegExpFlags:function(re){var flags="";return re.global&&(flags+="g"),re.ignoreCase&&(flags+="i"),re.multiline&&(flags+="m"),flags}};"object"==typeof module&&(module.exports=clone),clone.clonePrototype=function(parent){if(null===parent)return null;var c=function(){};return c.prototype=parent,new c}}).call(this,require("buffer").Buffer)},{buffer:189}],111:[function(require,module){function cubecube(w,h,d,filter){filter=filter||truthy;for(var size=[1/w,1/h,1/d],cubes=[],x=0;w>x;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":113}],112:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],113:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],115:[function(require,module,exports){arguments[4][27][0].apply(exports,arguments)},{_process:192,"raf-component":116,sliced:117}],116:[function(require,module){module.exports=require(28)},{}],117:[function(require,module,exports){arguments[4][29][0].apply(exports,arguments)},{"./lib/sliced":118}],118:[function(require,module){module.exports=require(30)},{}],119:[function(require,module){module.exports=require(44)},{}],120:[function(require,module){module.exports=require(45)},{"./defaults":119}],121:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":122}],122:[function(require,module){module.exports=require(28)},{}],123:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:128}],128:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],129:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:135,"ndarray-ops":130,"typedarray-pool":139,webglew:141}],130:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":131}],131:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":133}],132:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:134}],133:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":132}],134:[function(require,module){module.exports=require(13)},{}],135:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":136}],136:[function(require,module){module.exports=require(15)},{}],137:[function(require,module){module.exports=require(16)},{}],138:[function(require,module){module.exports=require(17)},{}],139:[function(require,module){module.exports=require(41)},{"bit-twiddle":137,buffer:189,dup:138}],140:[function(require,module){module.exports=require(42)},{}],141:[function(require,module){module.exports=require(43)},{weakmap:140}],142:[function(require,module){module.exports=require(73)},{}],143:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements){this._elements=elements,this._attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":142}],144:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot +}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],152:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":153}],153:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":155}],154:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:156}],155:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":154}],156:[function(require,module){module.exports=require(13)},{}],157:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":158}],158:[function(require,module){module.exports=require(15)},{}],159:[function(require,module){module.exports=require(16)},{}],160:[function(require,module){module.exports=require(17)},{}],161:[function(require,module){module.exports=require(41)},{"bit-twiddle":159,buffer:189,dup:160}],162:[function(require,module){module.exports=require(42)},{}],163:[function(require,module){module.exports=require(43)},{weakmap:162}],164:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function isPacked(array){for(var shape=array.shape,stride=array.stride,s=1,i=shape.length-1;i>=0;--i){if(stride[i]!==s)return!1;s*=shape[i]}return!0}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(array),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type===gl.FLOAT&&webglew(gl).texture_float&&(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store;if(packed){var array_size=array.size;buffer=array.data.subarray(array.offset,array.offset+array_size)}else{for(var sz=1,stride=new Array(shape.length),i=shape.length-1;i>=0;--i)stride[i]=sz,sz*=shape[i];buf_store=pool.malloc(sz,dtype);var buf_array=ndarray(buf_store,array.shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,sz)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[1],shape[0],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][1],0|arguments[1][0],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew"),linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)};Object.defineProperty(Texture2D.prototype,"minFilter",{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}});var proto=Texture2D.prototype;Object.defineProperty(proto,"magFilter",{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}}),Object.defineProperty(proto,"wrapS",{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}}),Object.defineProperty(proto,"wrapT",{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}}),Object.defineProperty(proto,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapT=v[0],this._wrapS=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),v}}),Object.defineProperty(proto,"mipSamples",{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(proto,"shape",{get:function(){return this._shape},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];var r=0|x[0],c=0|x[1];if(this.height===r&&this.width===c)return x;var gl=this.gl,maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>c||c>maxSize||0>r||r>maxSize)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[r,c],this.bind(),gl.texImage2D(gl.TEXTURE_2D,0,this.format,c,r,0,this.format,this.type,null),this._mipLevels=[0],x}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[0],x_off=0|x_off[1]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}},module.exports=createTexture2D},{ndarray:157,"ndarray-ops":152,"typedarray-pool":161,webglew:163}],165:[function(require,module,exports){arguments[4][79][0].apply(exports,arguments)},{"gl-shader-core":171}],166:[function(require,module){module.exports=require(80)},{}],167:[function(require,module){module.exports=require(81)},{}],168:[function(require,module,exports){arguments[4][82][0].apply(exports,arguments)},{"./reflect.js":169,dup:170}],169:[function(require,module){module.exports=require(83)},{}],170:[function(require,module){module.exports=require(17)},{}],171:[function(require,module){module.exports=require(85)},{"./lib/create-attributes.js":167,"./lib/create-uniforms.js":168,"./lib/reflect.js":169}],172:[function(require,module){function combine(meshes){for(var pos=[],cel=[],p=0,c=0,k=0,i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out +},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],179:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance}function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":178}],180:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],181:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],182:[function(require,module){function parse(html,doc){if("string"!=typeof html)throw new TypeError("String expected");doc||(doc=document);var m=/<([\w:]+)/.exec(html);if(!m)return doc.createTextNode(html);html=html.replace(/^\s+|\s+$/g,"");var tag=m[1];if("body"==tag){var el=doc.createElement("html");return el.innerHTML=html,el.removeChild(el.lastChild)}var wrap=map[tag]||map._default,depth=wrap[0],prefix=wrap[1],suffix=wrap[2],el=doc.createElement("div");for(el.innerHTML=prefix+html+suffix;depth--;)el=el.lastChild;if(el.firstChild==el.lastChild)return el.removeChild(el.firstChild);for(var fragment=doc.createDocumentFragment();el.firstChild;)fragment.appendChild(el.removeChild(el.firstChild));return fragment}module.exports=parse;var map={legend:[1,"
      ","
      "],tr:[2,"","
      "],col:[2,"","
      "],_default:[0,"",""]};map.td=map.th=[3,"","
      "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
      "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],183:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],184:[function(require,module,exports){arguments[4][27][0].apply(exports,arguments)},{_process:192,"raf-component":185,sliced:187}],185:[function(require,module){module.exports=require(28)},{}],186:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],187:[function(require,module,exports){arguments[4][29][0].apply(exports,arguments)},{"./lib/sliced":188}],188:[function(require,module){module.exports=require(30)},{}],189:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)"base64"===encoding&&(subject=base64clean(subject)),length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new Error("First argument needs to be a number, array or string.");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}var buf;TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;assert(strLen%2===0,"Invalid hex string"),length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);assert(!isNaN(byte),"Invalid hex string"),buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string),buf,offset,length);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function binarySlice(buf,start,end){return asciiSlice(buf,start,end)}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;i=len)){var val;return littleEndian?(val=buf[offset],len>offset+1&&(val|=buf[offset+1]<<8)):(val=buf[offset]<<8,len>offset+1&&(val|=buf[offset+1])),val}}function readUInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val;return littleEndian?(len>offset+2&&(val=buf[offset+2]<<16),len>offset+1&&(val|=buf[offset+1]<<8),val|=buf[offset],len>offset+3&&(val+=buf[offset+3]<<24>>>0)):(len>offset+1&&(val=buf[offset+1]<<16),len>offset+2&&(val|=buf[offset+2]<<8),len>offset+3&&(val|=buf[offset+3]),val+=buf[offset]<<24>>>0),val}}function readInt16(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len)){var val=readUInt16(buf,offset,littleEndian,!0),neg=32768&val;return neg?-1*(65535-val+1):val}}function readInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val=readUInt32(buf,offset,littleEndian,!0),neg=2147483648&val;return neg?-1*(4294967295-val+1):val}}function readFloat(buf,offset,littleEndian,noAssert){return noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i);return offset+2}}function writeUInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255;return offset+4}}function writeInt16(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len))return value>=0?writeUInt16(buf,value,offset,littleEndian,noAssert):writeUInt16(buf,65535+value+1,offset,littleEndian,noAssert),offset+2}function writeInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return value>=0?writeUInt32(buf,value,offset,littleEndian,noAssert):writeUInt32(buf,4294967295+value+1,offset,littleEndian,noAssert),offset+4}function writeFloat(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+7=len))return ieee754.write(buf,value,offset,littleEndian,52,8),offset+8 +}function base64clean(str){for(str=stringtrim(str).replace(INVALID_BASE64_RE,"");str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArray(subject){return(Array.isArray||function(subject){return"[object Array]"===Object.prototype.toString.call(subject)})(subject)}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(str){for(var byteArray=[],i=0;i=b)byteArray.push(b);else{var start=i;b>=55296&&57343>=b&&i++;for(var h=encodeURIComponent(str.slice(start,i+1)).substr(1).split("%"),j=0;j>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(str)}function blitBuffer(src,dst,offset,length){for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533)}}function verifuint(value,max){assert("number"==typeof value,"cannot write a non-number as a number"),assert(value>=0,"specified a negative value for writing an unsigned value"),assert(max>=value,"value is larger than maximum value for type"),assert(Math.floor(value)===value,"value has a fractional component")}function verifsint(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value"),assert(Math.floor(value)===value,"value has a fractional component")}function verifIEEE754(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value")}function assert(test,message){if(!test)throw new Error(message||"Failed assertion")}var base64=require("base64-js"),ieee754=require("ieee754");exports.Buffer=Buffer,exports.SlowBuffer=Buffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}();Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.byteLength=function(str,encoding){var ret;switch(str=str.toString(),encoding||"utf8"){case"hex":ret=str.length/2;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"ascii":case"binary":case"raw":ret=str.length;break;case"base64":ret=base64ToBytes(str).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=2*str.length;break;default:throw new Error("Unknown encoding")}return ret},Buffer.concat=function(list,totalLength){if(assert(isArray(list),"Usage: Buffer.concat(list[, length])"),0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;ii&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}offset=Number(offset)||0;var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toString=function(encoding,start,end){var self=this;if(encoding=String(encoding||"utf8").toLowerCase(),start=Number(start)||0,end=void 0===end?self.length:Number(end),end===start)return"";var ret;switch(encoding){case"hex":ret=hexSlice(self,start,end);break;case"utf8":case"utf-8":ret=utf8Slice(self,start,end);break;case"ascii":ret=asciiSlice(self,start,end);break;case"binary":ret=binarySlice(self,start,end);break;case"base64":ret=base64Slice(self,start,end);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leSlice(self,start,end);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.equals=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),0===Buffer.compare(this,b)},Buffer.prototype.compare=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),Buffer.compare(this,b)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start||(target_start=0),end!==start&&0!==target.length&&0!==source.length){assert(end>=start,"sourceEnd < sourceStart"),assert(target_start>=0&&target_start=0&&start=0&&end<=source.length,"sourceEnd out of bounds"),end>this.length&&(end=this.length),target.length-target_startlen||!TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start)}},Buffer.prototype.slice=function(start,end){var len=this.length;if(start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start),TYPED_ARRAY_SUPPORT)return Buffer._augment(this.subarray(start,end));for(var sliceLen=end-start,newBuf=new Buffer(sliceLen,void 0,!0),i=0;sliceLen>i;i++)newBuf[i]=this[i+start];return newBuf},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return readUInt16(this,offset,!0,noAssert)},Buffer.prototype.readUInt16BE=function(offset,noAssert){return readUInt16(this,offset,!1,noAssert)},Buffer.prototype.readUInt32LE=function(offset,noAssert){return readUInt32(this,offset,!0,noAssert)},Buffer.prototype.readUInt32BE=function(offset,noAssert){return readUInt32(this,offset,!1,noAssert)},Buffer.prototype.readInt8=function(offset,noAssert){if(noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length)){var neg=128&this[offset];return neg?-1*(255-this[offset]+1):this[offset]}},Buffer.prototype.readInt16LE=function(offset,noAssert){return readInt16(this,offset,!0,noAssert)},Buffer.prototype.readInt16BE=function(offset,noAssert){return readInt16(this,offset,!1,noAssert)},Buffer.prototype.readInt32LE=function(offset,noAssert){return readInt32(this,offset,!0,noAssert)},Buffer.prototype.readInt32BE=function(offset,noAssert){return readInt32(this,offset,!1,noAssert)},Buffer.prototype.readFloatLE=function(offset,noAssert){return readFloat(this,offset,!0,noAssert)},Buffer.prototype.readFloatBE=function(offset,noAssert){return readFloat(this,offset,!1,noAssert)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return readDouble(this,offset,!0,noAssert)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return readDouble(this,offset,!1,noAssert)},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(this[offset]=value,offset+1)},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(value>=0?this.writeUInt8(value,offset,noAssert):this.writeUInt8(255+value+1,offset,noAssert),offset+1)},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return writeInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return writeInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return writeInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return writeInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert)},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),assert(end>=start,"end < start"),end!==start&&0!==this.length){assert(start>=0&&start=0&&end<=this.length,"end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.inspect=function(){for(var out=[],len=this.length,i=0;len>i;i++)if(out[i]=toHex(this[i]),i===exports.INSPECT_MAX_BYTES){out[i+1]="...";break}return""},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z]/g},{"base64-js":190,ieee754:191}],190:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS?62:code===SLASH?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],191:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],192:[function(require,module){function noop(){}var process=module.exports={};process.nextTick=function(){var canSetImmediate="undefined"!=typeof window&&window.setImmediate,canPost="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(canSetImmediate)return function(f){return window.setImmediate(f)};if(canPost){var queue=[];return window.addEventListener("message",function(ev){var source=ev.source;if((source===window||null===source)&&"process-tick"===ev.data&&(ev.stopPropagation(),queue.length>0)){var fn=queue.shift();fn()}},!0),function(fn){queue.push(fn),window.postMessage("process-tick","*")}}return function(fn){setTimeout(fn,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file From af8100b30cb87a2db5a67e26f2d1119840b0320d Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Tue, 16 Sep 2014 00:16:10 +0200 Subject: [PATCH 22/64] test: disable flock --- bundle.js | 17 ++++++++--------- index.js | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/bundle.js b/bundle.js index 2cf4d86..64a8ecb 100644 --- a/bundle.js +++ b/bundle.js @@ -1,9 +1,8 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas")),flock=document.getElementById("community").querySelector("canvas");if(require("./lib/fill")(document.querySelectorAll("[data-fill]")),window.chrome)try{require("@stackgl/splash-grid")(grid),require("@stackgl/splash-flock")(flock)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-flock":7,"@stackgl/splash-grid":90,domify:182,minstache:186,sliced:187}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;ii;i++)pdata[i]=FBO(gl,[SIZE,SIZE],{"float":!0}),pdata[i].color[0].setPixels(starter);window.addEventListener("resize",debounce(fit(canvas,window))),shaders.logic=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvarying vec2 vuv;\nvoid main() {\n vuv = (position + 1.0) * 0.5;\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nvarying vec2 vuv;\nuniform sampler2D positions;\nvec3 b_x_mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_mod289(vec4 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 b_x_permute(vec4 x) {\n return b_x_mod289(((x * 34.0) + 1.0) * x);\n}\nvec4 b_x_taylorInvSqrt(vec4 r) {\n return 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat b_x_snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n i = b_x_mod289(i);\n vec4 p = b_x_permute(b_x_permute(b_x_permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = b_x_taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\nvec3 a_x_snoiseVec3(vec3 x) {\n float s = b_x_snoise(vec3(x));\n float s1 = b_x_snoise(vec3(x.y - 19.1, x.z + 33.4, x.x + 47.2));\n float s2 = b_x_snoise(vec3(x.z + 74.2, x.x - 124.5, x.y + 99.4));\n vec3 c = vec3(s, s1, s2);\n return c;\n}\nvec3 a_x_curlNoise(vec3 p) {\n const float e = .1;\n vec3 dx = vec3(e, 0.0, 0.0);\n vec3 dy = vec3(0.0, e, 0.0);\n vec3 dz = vec3(0.0, 0.0, e);\n vec3 p_x0 = a_x_snoiseVec3(p - dx);\n vec3 p_x1 = a_x_snoiseVec3(p + dx);\n vec3 p_y0 = a_x_snoiseVec3(p - dy);\n vec3 p_y1 = a_x_snoiseVec3(p + dy);\n vec3 p_z0 = a_x_snoiseVec3(p - dz);\n vec3 p_z1 = a_x_snoiseVec3(p + dz);\n float x = p_y1.z - p_y0.z - p_z1.y + p_z0.y;\n float y = p_z1.x - p_z0.x - p_x1.z + p_x0.z;\n float z = p_x1.y - p_x0.y - p_y1.x + p_y0.x;\n const float divisor = 1.0 / (2.0 * e);\n return normalize(vec3(x, y, z) * divisor);\n}\n#define CENTER_ATTRACTION 0.0045\n\n#define SPEED_LIMIT 0.065\n\n#define SEPARATION 0.0035\n\n#define ALIGNMENT 0.00125\n\n#define COHESION 0.0007\n\n#define WANDER 0.00035\n\n#define SIZE 32.0\n\nvec2 alignment(vec2 speed) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 speed = texture2D(positions, uv).zw;\n influence += speed;\n }\n return influence;\n}\nvec2 cohesion(vec2 position) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n influence += pos / SIZE / SIZE;\n }\n return influence - position;\n}\nvec2 separation(vec2 position, vec2 maxDistance, vec2 index) {\n vec2 influence = vec2(0.0);\n for(float x = 0.0; x < 1.0; x += 1.0 / SIZE)\n for(float y = 0.0; y < 1.0; y += 1.0 / SIZE) {\n vec2 uv = vec2(x, y);\n vec2 pos = texture2D(positions, uv).xy;\n float self = (x == index.x && y == index.y) ? 0.0 : 1.0;\n float close = all(greaterThanEqual(abs(position - pos), maxDistance)) ? 1.0 : 0.0;\n influence -= self * close * (position - pos);\n }\n return position - influence;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / vec2(SIZE);\n vec2 position = texture2D(positions, uv).xy;\n vec2 speed = texture2D(positions, uv).zw;\n speed += normalize(alignment(speed)) * ALIGNMENT;\n speed += normalize(cohesion(position)) * COHESION;\n speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION;\n speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION;\n speed += a_x_curlNoise(vec3(uv * 10.2920, 1.290393)).xy * WANDER;\n speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT);\n position += speed;\n gl_FragColor.xy = position;\n gl_FragColor.zw = speed;\n}",[{name:"positions",type:"sampler2D"}],[{name:"position",type:"vec2"}])(gl),shaders.render=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 uv;\nuniform sampler2D positions;\nuniform vec2 screenSize;\nvoid main() {\n vec2 position = texture2D(positions, uv).xy;\n position.x += 15.0;\n position *= screenSize.x / screenSize.y / screenSize.xy;\n gl_PointSize = 8.0;\n gl_Position = vec4((position) * 25.0, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tex;\nvoid main() {\n vec4 color = vec4(0.0);\n color += texture2D(tex, gl_PointCoord.xy);\n color *= vec4(1.2, 1.15, 1.21, 1.0);\n color += vec4(0.3, 0.3, 0.3, 0.0);\n color.a = 1.0;\n gl_FragColor = color;\n}",[{name:"positions",type:"sampler2D"},{name:"screenSize",type:"vec2"},{name:"tex",type:"sampler2D"}],[{name:"uv",type:"vec2"}])(gl)}function switchFrames(data){return data.push(data.shift()),data}function createParticleVAO(gl,size){for(var data=new Float32Array(size*size),n=0,x=0;size>x;x++)for(var y=0;size>y;y++)data[n++]=x/size,data[n++]=y/size;var buffer=createBuffer(gl,data),vao=VAO(gl,[{buffer:buffer,type:gl.FLOAT,size:2}]);return vao.length=data.length/2,vao}function createStartPositions(size){for(var data=new Float32Array(size*size*4),i=0;i=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:189,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n); -case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;islice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],31:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:37,"ndarray-ops":32,"typedarray-pool":41,webglew:43}],32:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":33}],33:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":35}],34:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:36}],35:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":34}],36:[function(require,module){module.exports=require(13)},{}],37:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":38}],38:[function(require,module){module.exports=require(15)},{}],39:[function(require,module){module.exports=require(16)},{}],40:[function(require,module){module.exports=require(17)},{}],41:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":39,buffer:189,dup:40}],42:[function(require,module,exports){void function(global,undefined_,undefined){function define(object,key,value){return"function"==typeof key&&(value=key,key=nameOf(value).replace(/_$/,"")),defProp(object,key,{configurable:!0,writable:!0,value:value})}function nameOf(func){return"function"!=typeof func?"":"name"in func?func.name:toSource.call(func).match(funcName)[1]}function createStorage(creator){function storage(object,value){return value||2===arguments.length?weakmap.set(object,value):(value=weakmap.get(object),value===undefined&&(value=creator(object),weakmap.set(object,value))),value}var weakmap=new WM;return creator||(creator=defaultCreator),storage}var getProps=Object.getOwnPropertyNames,defProp=Object.defineProperty,toSource=Function.prototype.toString,create=Object.create,hasOwn=Object.prototype.hasOwnProperty,funcName=/^\n?function\s?(\w*)?_?\(/,Data=function(){function Data(){var puid=createUID(),secret={};this.unlock=function(obj){var store=storage(obj);if(hasOwn.call(store,puid))return store[puid](secret);var data=create(null,dataDesc);return defProp(store,puid,{value:new Function("s","l",datalock)(secret,data)}),data}}var dataDesc={value:{writable:!0,value:undefined}},datalock="return function(k){if(k===s)return l}",uids=create(null),createUID=function(){var key=Math.random().toString(36).slice(2);return key in uids?createUID():uids[key]=key},globalID=createUID(),storage=function(obj){if(hasOwn.call(obj,globalID))return obj[globalID];if(!Object.isExtensible(obj))throw new TypeError("Object must be extensible");var store=create(null);return defProp(obj,globalID,{value:store}),store};return define(Object,function(obj){var props=getProps(obj);return hasOwn.call(obj,globalID)&&props.splice(props.indexOf(globalID),1),props}),define(Data.prototype,function(o){return this.unlock(o).value}),define(Data.prototype,function(o,v){this.unlock(o).value=v}),Data}(),WM=function(data){function WeakMap(iterable){return this===global||null==this||this===WeakMap.prototype?new WeakMap(iterable):(wrap(this,new Data),void initialize(this,iterable))}function get(key){validate(key);var value=unwrap(this).get(key);return value===undefined_?undefined:value}function set(key,value){validate(key),unwrap(this).set(key,value===undefined?undefined_:value)}function has(key){return validate(key),unwrap(this).get(key)!==undefined}function delete_(key){validate(key);var data=unwrap(this),had=data.get(key)!==undefined;return data.set(key,undefined),had}function toString(){return unwrap(this),"[object WeakMap]"}var validate=function(key){if(null==key||"object"!=typeof key&&"function"!=typeof key)throw new TypeError("Invalid WeakMap key")},wrap=function(collection,value){var store=data.unlock(collection);if(store.value)throw new TypeError("Object is already a WeakMap");store.value=value},unwrap=function(collection){var storage=data.unlock(collection).value;if(!storage)throw new TypeError("WeakMap is not generic");return storage},initialize=function(weakmap,iterable){null!==iterable&&"object"==typeof iterable&&"function"==typeof iterable.forEach&&iterable.forEach(function(item,i){item instanceof Array&&2===item.length&&set.call(weakmap,iterable[i][0],iterable[i][1])})};try{var src=("return "+delete_).replace("e_","\\u0065"),del=new Function("unwrap","validate",src)(unwrap,validate)}catch(e){var del=delete_}var src=(""+Object).split("Object"),stringifier=function(){return src[0]+nameOf(this)+src[1]};define(stringifier,stringifier);var prep={__proto__:[]}instanceof Array?function(f){f.__proto__=stringifier}:function(f){define(f,stringifier)};return prep(WeakMap),[toString,get,set,has,del].forEach(function(method){define(WeakMap.prototype,method),prep(method)}),WeakMap}(new Data),defaultCreator=Object.create?function(){return Object.create(null)}:function(){return{}};"undefined"!=typeof module?module.exports=WM:"undefined"!=typeof exports?exports.WeakMap=WM:"WeakMap"in global||(global.WeakMap=WM),WM.createStorage=createStorage,global.WeakMap&&(global.WeakMap.createStorage=createStorage)}((0,eval)("this"))},{}],43:[function(require,module){"use strict";function baseName(ext_name){return ext_name.replace(/^[A-Z]+_/,"")}function initWebGLEW(gl){var struct=WebGLEWStruct.get(gl);if(struct)return struct;for(var extensions={},supported=gl.getSupportedExtensions(),i=0;i=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,result.bind(),gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var state=saveFBOState(fbo.gl),gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),width=fbo._shape[0],height=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;ii;++i)this.color[i]=null;this._color_rb=null,this.depth=null,this._depth_rb=null,this._colorType=colorType,this._useDepth=useDepth,this._useStencil=useStencil;var parent=this,shapeVector=[0|width,0|height];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(w){return parent.width=w}},1:{get:function(){return parent._shape[1]},set:function(h){return parent.height=h}}}),this._shapeVector=shapeVector,rebuildFBO(this)}function reshapeFBO(fbo,w,h){if(fbo._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(fbo._shape[0]!==w||fbo._shape[1]!==h){var gl=fbo.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(0>w||w>maxFBOSize||0>h||h>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");fbo._shape[0]=w,fbo._shape[1]=h;for(var state=saveFBOState(gl),i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers") -}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperties(proto,{shape:{get:function(){return this._destroyed?[0,0]:this._shapeVector},set:function(x){if(Array.isArray(x)||(x=[0|x,0|x]),2!==x.length)throw new Error("gl-fbo: Shape vector must be length 2");var w=0|x[0],h=0|x[1];return reshapeFBO(this,w,h),[w,h]},enumerable:!1},width:{get:function(){return this._destroyed?0:this._shape[0]},set:function(w){return w=0|w,reshapeFBO(this,w,this._shape[1]),w},enumerable:!1},height:{get:function(){return this._destroyed?0:this._shape[1]},set:function(h){return h=0|h,reshapeFBO(this,this._shape[0],h),h},enumerable:!1}}),proto.bind=function(){if(!this._destroyed){var gl=this.gl;gl.bindFramebuffer(gl.FRAMEBUFFER,this.handle),gl.viewport(0,0,this._shape[0],this._shape[1])}},proto.dispose=function(){if(!this._destroyed){this._destroyed=!0;var gl=this.gl;gl.deleteFramebuffer(this.handle),this.handle=null,this.depth&&(this.depth.dispose(),this.depth=null),this._depth_rb&&(gl.deleteRenderbuffer(this._depth_rb),this._depth_rb=null);for(var i=0;iw||w>maxSize||0>h||h>maxSize)throw new Error("gl-texture2d: Invalid texture size");return tex._shape=[w,h],tex.bind(),gl.texImage2D(gl.TEXTURE_2D,0,tex.format,w,h,0,tex.format,tex.type,null),tex._mipLevels=[0],tex}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[width,height],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1;var parent=this,wrapVector=[this._wrapS,this._wrapT];Object.defineProperties(wrapVector,{0:{get:function(){return parent._wrapS},set:function(v){return parent.wrapS=v}},1:{get:function(){return parent._wrapT},set:function(v){return parent.wrapT=v}}}),this._wrapVector=wrapVector;var shapeVector=[this._shape[0],this._shape[1]];Object.defineProperties(shapeVector,{0:{get:function(){return parent._shape[0]},set:function(v){return parent.width=v}},1:{get:function(){return parent._shape[1]},set:function(v){return parent.height=v}}}),this._shapeVector=shapeVector}function isPacked(shape,stride){return 3===shape.length?1===stride[2]&&stride[1]===shape[0]*shape[2]&&stride[0]===shape[2]:1===stride[0]&&stride[1]===shape[0]}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape.slice();if(shape.length<2||shape.length>3)throw new Error("gl-texture2d: Invalid ndarray, must be 2d or 3d");var type=0,format=0,packed=isPacked(shape,array.stride.slice());"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var channels=1;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}channels=shape[2]}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape,[shape[2],shape[2]*shape[0],1]);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[0],shape[1],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[0],shape[1],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(shape,array.stride.slice()),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE,shape=[shape[0],shape[1],1],array=ndarray(array.data,shape,[array.stride[0],array.stride[1],1],array.offset);else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type!==gl.FLOAT||webglew(gl).texture_float||(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store,size=array.size;if(packed)buffer=0===array.offset&&array.data.length===size?array.data:array.data.subarray(array.offset,array.offset+size);else{var stride=[shape[2],shape[2]*shape[0],1];buf_store=pool.malloc(size,dtype);var buf_array=ndarray(buf_store,shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,size)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[0],shape[1],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][0],0|arguments[1][1],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew");module.exports=createTexture2D;var linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)},proto=Texture2D.prototype;Object.defineProperties(proto,{minFilter:{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}},magFilter:{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}},mipSamples:{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}},wrapS:{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}},wrapT:{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}},wrap:{get:function(){return this._wrapVector},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapS=v[0],this._wrapT=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),v}},shape:{get:function(){return this._shapeVector},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];return reshapeTexture(this,0|x[0],0|x[1]),[0|x[0],0|x[1]]}},width:{get:function(){return this._shape[0]},set:function(w){return w=0|w,reshapeTexture(this,w,this._shape[1]),w}},height:{get:function(){return this._shape[1]},set:function(h){return h=0|h,reshapeTexture(this,this._shape[0],h),h}}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[1],x_off=0|x_off[0]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}}},{ndarray:54,"ndarray-ops":49,"typedarray-pool":58,webglew:61}],60:[function(require,module){module.exports=require(42)},{}],61:[function(require,module){module.exports=require(43)},{weakmap:60}],62:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":63}],63:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":65}],64:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:66}],65:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":64}],66:[function(require,module){module.exports=require(13)},{}],67:[function(require,module){module.exports=require(16)},{}],68:[function(require,module){module.exports=require(17)},{}],69:[function(require,module){module.exports=require(41)},{"bit-twiddle":67,buffer:189,dup:68}],70:[function(require,module){module.exports=require(42)},{}],71:[function(require,module){module.exports=require(43)},{weakmap:70}],72:[function(require,module,exports){arguments[4][59][0].apply(exports,arguments)},{ndarray:86,"ndarray-ops":62,"typedarray-pool":69,webglew:71}],73:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],74:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":73}],75:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;ii;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],82:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;kheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":89,"a-big-triangle":107,"canvas-fit":108,clone:110,"cube-cube":111,"face-normals":114,"frame-debounce":115,"gl-clear":120,"gl-context":121,"gl-fbo":123,"gl-geometry":126,"gl-matrix":151,"gl-texture2d":164,glslify:166,"glslify/adapter.js":165,"mesh-combine":172,"orbit-camera":179,"right-now":180,"unindex-mesh":181}],91:[function(require,module,exports){arguments[4][8][0].apply(exports,arguments)},{ndarray:97,"ndarray-ops":92,"typedarray-pool":101}],92:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":93}],93:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":95}],94:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:96}],95:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":94}],96:[function(require,module){module.exports=require(13)},{}],97:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":98}],98:[function(require,module){module.exports=require(15)},{}],99:[function(require,module){module.exports=require(16)},{}],100:[function(require,module){module.exports=require(17)},{}],101:[function(require,module){module.exports=require(18)},{"bit-twiddle":99,dup:100}],102:[function(require,module){module.exports=require(19)},{}],103:[function(require,module){module.exports=require(20)},{"./do-bind.js":102}],104:[function(require,module){module.exports=require(21)},{"./do-bind.js":102}],105:[function(require,module){module.exports=require(22)},{}],106:[function(require,module){module.exports=require(23)},{"./lib/vao-emulated.js":103,"./lib/vao-native.js":104,webglew:105}],107:[function(require,module){module.exports=require(24)},{"gl-buffer":91,"gl-vao":106}],108:[function(require,module,exports){arguments[4][25][0].apply(exports,arguments)},{"element-size":109}],109:[function(require,module){module.exports=require(26)},{}],110:[function(require,module){(function(Buffer){"use strict";function objectToString(o){return Object.prototype.toString.call(o)}function clone(parent,circular,depth,prototype){function _clone(parent,depth){if(null===parent)return null;if(0==depth)return parent;var child;if("object"!=typeof parent)return parent;if(util.isArray(parent))child=[];else if(util.isRegExp(parent))child=new RegExp(parent.source,util.getRegExpFlags(parent)),parent.lastIndex&&(child.lastIndex=parent.lastIndex);else if(util.isDate(parent))child=new Date(parent.getTime());else{if(useBuffer&&Buffer.isBuffer(parent))return child=new Buffer(parent.length),parent.copy(child),child;child=Object.create("undefined"==typeof prototype?Object.getPrototypeOf(parent):prototype)}if(circular){var index=allParents.indexOf(parent);if(-1!=index)return allChildren[index];allParents.push(parent),allChildren.push(child)}for(var i in parent)child[i]=_clone(parent[i],depth-1);return child}var allParents=[],allChildren=[],useBuffer="undefined"!=typeof Buffer;return"undefined"==typeof circular&&(circular=!0),"undefined"==typeof depth&&(depth=1/0),_clone(parent,depth)}var util={isArray:function(ar){return Array.isArray(ar)||"object"==typeof ar&&"[object Array]"===objectToString(ar)},isDate:function(d){return"object"==typeof d&&"[object Date]"===objectToString(d)},isRegExp:function(re){return"object"==typeof re&&"[object RegExp]"===objectToString(re)},getRegExpFlags:function(re){var flags="";return re.global&&(flags+="g"),re.ignoreCase&&(flags+="i"),re.multiline&&(flags+="m"),flags}};"object"==typeof module&&(module.exports=clone),clone.clonePrototype=function(parent){if(null===parent)return null;var c=function(){};return c.prototype=parent,new c}}).call(this,require("buffer").Buffer)},{buffer:189}],111:[function(require,module){function cubecube(w,h,d,filter){filter=filter||truthy;for(var size=[1/w,1/h,1/d],cubes=[],x=0;w>x;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":113}],112:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],113:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],115:[function(require,module,exports){arguments[4][27][0].apply(exports,arguments)},{_process:192,"raf-component":116,sliced:117}],116:[function(require,module){module.exports=require(28)},{}],117:[function(require,module,exports){arguments[4][29][0].apply(exports,arguments)},{"./lib/sliced":118}],118:[function(require,module){module.exports=require(30)},{}],119:[function(require,module){module.exports=require(44)},{}],120:[function(require,module){module.exports=require(45)},{"./defaults":119}],121:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":122}],122:[function(require,module){module.exports=require(28)},{}],123:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:128}],128:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],129:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:135,"ndarray-ops":130,"typedarray-pool":139,webglew:141}],130:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":131}],131:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":133}],132:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:134}],133:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":132}],134:[function(require,module){module.exports=require(13)},{}],135:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":136}],136:[function(require,module){module.exports=require(15)},{}],137:[function(require,module){module.exports=require(16)},{}],138:[function(require,module){module.exports=require(17)},{}],139:[function(require,module){module.exports=require(41)},{"bit-twiddle":137,buffer:189,dup:138}],140:[function(require,module){module.exports=require(42)},{}],141:[function(require,module){module.exports=require(43)},{weakmap:140}],142:[function(require,module){module.exports=require(73)},{}],143:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements){this._elements=elements,this._attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":142}],144:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot -}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],152:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":153}],153:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":155}],154:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:156}],155:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":154}],156:[function(require,module){module.exports=require(13)},{}],157:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:189,"iota-array":158}],158:[function(require,module){module.exports=require(15)},{}],159:[function(require,module){module.exports=require(16)},{}],160:[function(require,module){module.exports=require(17)},{}],161:[function(require,module){module.exports=require(41)},{"bit-twiddle":159,buffer:189,dup:160}],162:[function(require,module){module.exports=require(42)},{}],163:[function(require,module){module.exports=require(43)},{weakmap:162}],164:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function isPacked(array){for(var shape=array.shape,stride=array.stride,s=1,i=shape.length-1;i>=0;--i){if(stride[i]!==s)return!1;s*=shape[i]}return!0}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(array),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type===gl.FLOAT&&webglew(gl).texture_float&&(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store;if(packed){var array_size=array.size;buffer=array.data.subarray(array.offset,array.offset+array_size)}else{for(var sz=1,stride=new Array(shape.length),i=shape.length-1;i>=0;--i)stride[i]=sz,sz*=shape[i];buf_store=pool.malloc(sz,dtype);var buf_array=ndarray(buf_store,array.shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,sz)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[1],shape[0],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][1],0|arguments[1][0],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew"),linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)};Object.defineProperty(Texture2D.prototype,"minFilter",{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}});var proto=Texture2D.prototype;Object.defineProperty(proto,"magFilter",{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}}),Object.defineProperty(proto,"wrapS",{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}}),Object.defineProperty(proto,"wrapT",{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}}),Object.defineProperty(proto,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapT=v[0],this._wrapS=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),v}}),Object.defineProperty(proto,"mipSamples",{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(proto,"shape",{get:function(){return this._shape},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];var r=0|x[0],c=0|x[1];if(this.height===r&&this.width===c)return x;var gl=this.gl,maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>c||c>maxSize||0>r||r>maxSize)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[r,c],this.bind(),gl.texImage2D(gl.TEXTURE_2D,0,this.format,c,r,0,this.format,this.type,null),this._mipLevels=[0],x}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[0],x_off=0|x_off[1]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}},module.exports=createTexture2D},{ndarray:157,"ndarray-ops":152,"typedarray-pool":161,webglew:163}],165:[function(require,module,exports){arguments[4][79][0].apply(exports,arguments)},{"gl-shader-core":171}],166:[function(require,module){module.exports=require(80)},{}],167:[function(require,module){module.exports=require(81)},{}],168:[function(require,module,exports){arguments[4][82][0].apply(exports,arguments)},{"./reflect.js":169,dup:170}],169:[function(require,module){module.exports=require(83)},{}],170:[function(require,module){module.exports=require(17)},{}],171:[function(require,module){module.exports=require(85)},{"./lib/create-attributes.js":167,"./lib/create-uniforms.js":168,"./lib/reflect.js":169}],172:[function(require,module){function combine(meshes){for(var pos=[],cel=[],p=0,c=0,k=0,i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out -},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],179:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance}function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":178}],180:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],181:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],182:[function(require,module){function parse(html,doc){if("string"!=typeof html)throw new TypeError("String expected");doc||(doc=document);var m=/<([\w:]+)/.exec(html);if(!m)return doc.createTextNode(html);html=html.replace(/^\s+|\s+$/g,"");var tag=m[1];if("body"==tag){var el=doc.createElement("html");return el.innerHTML=html,el.removeChild(el.lastChild)}var wrap=map[tag]||map._default,depth=wrap[0],prefix=wrap[1],suffix=wrap[2],el=doc.createElement("div");for(el.innerHTML=prefix+html+suffix;depth--;)el=el.lastChild;if(el.firstChild==el.lastChild)return el.removeChild(el.firstChild);for(var fragment=doc.createDocumentFragment();el.firstChild;)fragment.appendChild(el.removeChild(el.firstChild));return fragment}module.exports=parse;var map={legend:[1,"
      ","
      "],tr:[2,"","
      "],col:[2,"","
      "],_default:[0,"",""]};map.td=map.th=[3,"","
      "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
      "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],183:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],184:[function(require,module,exports){arguments[4][27][0].apply(exports,arguments)},{_process:192,"raf-component":185,sliced:187}],185:[function(require,module){module.exports=require(28)},{}],186:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],187:[function(require,module,exports){arguments[4][29][0].apply(exports,arguments)},{"./lib/sliced":188}],188:[function(require,module){module.exports=require(30)},{}],189:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)"base64"===encoding&&(subject=base64clean(subject)),length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new Error("First argument needs to be a number, array or string.");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}var buf;TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;assert(strLen%2===0,"Invalid hex string"),length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);assert(!isNaN(byte),"Invalid hex string"),buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string),buf,offset,length);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function binarySlice(buf,start,end){return asciiSlice(buf,start,end)}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;i=len)){var val;return littleEndian?(val=buf[offset],len>offset+1&&(val|=buf[offset+1]<<8)):(val=buf[offset]<<8,len>offset+1&&(val|=buf[offset+1])),val}}function readUInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val;return littleEndian?(len>offset+2&&(val=buf[offset+2]<<16),len>offset+1&&(val|=buf[offset+1]<<8),val|=buf[offset],len>offset+3&&(val+=buf[offset+3]<<24>>>0)):(len>offset+1&&(val=buf[offset+1]<<16),len>offset+2&&(val|=buf[offset+2]<<8),len>offset+3&&(val|=buf[offset+3]),val+=buf[offset]<<24>>>0),val}}function readInt16(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len)){var val=readUInt16(buf,offset,littleEndian,!0),neg=32768&val;return neg?-1*(65535-val+1):val}}function readInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val=readUInt32(buf,offset,littleEndian,!0),neg=2147483648&val;return neg?-1*(4294967295-val+1):val}}function readFloat(buf,offset,littleEndian,noAssert){return noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i);return offset+2}}function writeUInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255;return offset+4}}function writeInt16(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len))return value>=0?writeUInt16(buf,value,offset,littleEndian,noAssert):writeUInt16(buf,65535+value+1,offset,littleEndian,noAssert),offset+2}function writeInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return value>=0?writeUInt32(buf,value,offset,littleEndian,noAssert):writeUInt32(buf,4294967295+value+1,offset,littleEndian,noAssert),offset+4}function writeFloat(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+7=len))return ieee754.write(buf,value,offset,littleEndian,52,8),offset+8 -}function base64clean(str){for(str=stringtrim(str).replace(INVALID_BASE64_RE,"");str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArray(subject){return(Array.isArray||function(subject){return"[object Array]"===Object.prototype.toString.call(subject)})(subject)}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(str){for(var byteArray=[],i=0;i=b)byteArray.push(b);else{var start=i;b>=55296&&57343>=b&&i++;for(var h=encodeURIComponent(str.slice(start,i+1)).substr(1).split("%"),j=0;j>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(str)}function blitBuffer(src,dst,offset,length){for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533)}}function verifuint(value,max){assert("number"==typeof value,"cannot write a non-number as a number"),assert(value>=0,"specified a negative value for writing an unsigned value"),assert(max>=value,"value is larger than maximum value for type"),assert(Math.floor(value)===value,"value has a fractional component")}function verifsint(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value"),assert(Math.floor(value)===value,"value has a fractional component")}function verifIEEE754(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value")}function assert(test,message){if(!test)throw new Error(message||"Failed assertion")}var base64=require("base64-js"),ieee754=require("ieee754");exports.Buffer=Buffer,exports.SlowBuffer=Buffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}();Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.byteLength=function(str,encoding){var ret;switch(str=str.toString(),encoding||"utf8"){case"hex":ret=str.length/2;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"ascii":case"binary":case"raw":ret=str.length;break;case"base64":ret=base64ToBytes(str).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=2*str.length;break;default:throw new Error("Unknown encoding")}return ret},Buffer.concat=function(list,totalLength){if(assert(isArray(list),"Usage: Buffer.concat(list[, length])"),0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;ii&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}offset=Number(offset)||0;var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toString=function(encoding,start,end){var self=this;if(encoding=String(encoding||"utf8").toLowerCase(),start=Number(start)||0,end=void 0===end?self.length:Number(end),end===start)return"";var ret;switch(encoding){case"hex":ret=hexSlice(self,start,end);break;case"utf8":case"utf-8":ret=utf8Slice(self,start,end);break;case"ascii":ret=asciiSlice(self,start,end);break;case"binary":ret=binarySlice(self,start,end);break;case"base64":ret=base64Slice(self,start,end);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leSlice(self,start,end);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.equals=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),0===Buffer.compare(this,b)},Buffer.prototype.compare=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),Buffer.compare(this,b)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start||(target_start=0),end!==start&&0!==target.length&&0!==source.length){assert(end>=start,"sourceEnd < sourceStart"),assert(target_start>=0&&target_start=0&&start=0&&end<=source.length,"sourceEnd out of bounds"),end>this.length&&(end=this.length),target.length-target_startlen||!TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start)}},Buffer.prototype.slice=function(start,end){var len=this.length;if(start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start),TYPED_ARRAY_SUPPORT)return Buffer._augment(this.subarray(start,end));for(var sliceLen=end-start,newBuf=new Buffer(sliceLen,void 0,!0),i=0;sliceLen>i;i++)newBuf[i]=this[i+start];return newBuf},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return readUInt16(this,offset,!0,noAssert)},Buffer.prototype.readUInt16BE=function(offset,noAssert){return readUInt16(this,offset,!1,noAssert)},Buffer.prototype.readUInt32LE=function(offset,noAssert){return readUInt32(this,offset,!0,noAssert)},Buffer.prototype.readUInt32BE=function(offset,noAssert){return readUInt32(this,offset,!1,noAssert)},Buffer.prototype.readInt8=function(offset,noAssert){if(noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length)){var neg=128&this[offset];return neg?-1*(255-this[offset]+1):this[offset]}},Buffer.prototype.readInt16LE=function(offset,noAssert){return readInt16(this,offset,!0,noAssert)},Buffer.prototype.readInt16BE=function(offset,noAssert){return readInt16(this,offset,!1,noAssert)},Buffer.prototype.readInt32LE=function(offset,noAssert){return readInt32(this,offset,!0,noAssert)},Buffer.prototype.readInt32BE=function(offset,noAssert){return readInt32(this,offset,!1,noAssert)},Buffer.prototype.readFloatLE=function(offset,noAssert){return readFloat(this,offset,!0,noAssert)},Buffer.prototype.readFloatBE=function(offset,noAssert){return readFloat(this,offset,!1,noAssert)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return readDouble(this,offset,!0,noAssert)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return readDouble(this,offset,!1,noAssert)},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(this[offset]=value,offset+1)},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(value>=0?this.writeUInt8(value,offset,noAssert):this.writeUInt8(255+value+1,offset,noAssert),offset+1)},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return writeInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return writeInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return writeInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return writeInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert)},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),assert(end>=start,"end < start"),end!==start&&0!==this.length){assert(start>=0&&start=0&&end<=this.length,"end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.inspect=function(){for(var out=[],len=this.length,i=0;len>i;i++)if(out[i]=toHex(this[i]),i===exports.INSPECT_MAX_BYTES){out[i+1]="...";break}return""},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z]/g},{"base64-js":190,ieee754:191}],190:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS?62:code===SLASH?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],191:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],192:[function(require,module){function noop(){}var process=module.exports={};process.nextTick=function(){var canSetImmediate="undefined"!=typeof window&&window.setImmediate,canPost="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(canSetImmediate)return function(f){return window.setImmediate(f)};if(canPost){var queue=[];return window.addEventListener("message",function(ev){var source=ev.source;if((source===window||null===source)&&"process-tick"===ev.data&&(ev.stopPropagation(),queue.length>0)){var fn=queue.shift();fn()}},!0),function(fn){queue.push(fn),window.postMessage("process-tick","*")}}return function(fn){setTimeout(fn,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}if(require("./lib/fill")(document.querySelectorAll("[data-fill]")),window.chrome)try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:99,minstache:103,sliced:104}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":96,"right-now":97,"unindex-mesh":98}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:106,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n); +var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":30}],29:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],30:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],32:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:109,"raf-component":33,sliced:34}],33:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],34:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":35}],35:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],36:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],37:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":36}],38:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":39}],39:[function(require,module){module.exports=require(33)},{}],40:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:45}],45:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],46:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:52,"ndarray-ops":47,"typedarray-pool":56,webglew:58}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments) +},{"./lib/thunk.js":50}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:51}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":49}],51:[function(require,module){module.exports=require(13)},{}],52:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:106,"iota-array":53}],53:[function(require,module){module.exports=require(15)},{}],54:[function(require,module){module.exports=require(16)},{}],55:[function(require,module){module.exports=require(17)},{}],56:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":54,buffer:106,dup:55}],57:[function(require,module){module.exports=require(41)},{}],58:[function(require,module){module.exports=require(42)},{weakmap:57}],59:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],60:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements){this._elements=elements,this._attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":59}],61:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null +},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],69:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":70}],70:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":72}],71:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:73}],72:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":71}],73:[function(require,module){module.exports=require(13)},{}],74:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:106,"iota-array":75}],75:[function(require,module){module.exports=require(15)},{}],76:[function(require,module){module.exports=require(16)},{}],77:[function(require,module){module.exports=require(17)},{}],78:[function(require,module){module.exports=require(56)},{"bit-twiddle":76,buffer:106,dup:77}],79:[function(require,module){module.exports=require(41)},{}],80:[function(require,module){module.exports=require(42)},{weakmap:79}],81:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function isPacked(array){for(var shape=array.shape,stride=array.stride,s=1,i=shape.length-1;i>=0;--i){if(stride[i]!==s)return!1;s*=shape[i]}return!0}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(array),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type===gl.FLOAT&&webglew(gl).texture_float&&(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store;if(packed){var array_size=array.size;buffer=array.data.subarray(array.offset,array.offset+array_size)}else{for(var sz=1,stride=new Array(shape.length),i=shape.length-1;i>=0;--i)stride[i]=sz,sz*=shape[i];buf_store=pool.malloc(sz,dtype);var buf_array=ndarray(buf_store,array.shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,sz)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[1],shape[0],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][1],0|arguments[1][0],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew"),linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)};Object.defineProperty(Texture2D.prototype,"minFilter",{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}});var proto=Texture2D.prototype;Object.defineProperty(proto,"magFilter",{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}}),Object.defineProperty(proto,"wrapS",{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}}),Object.defineProperty(proto,"wrapT",{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}}),Object.defineProperty(proto,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapT=v[0],this._wrapS=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),v}}),Object.defineProperty(proto,"mipSamples",{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(proto,"shape",{get:function(){return this._shape},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];var r=0|x[0],c=0|x[1];if(this.height===r&&this.width===c)return x;var gl=this.gl,maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>c||c>maxSize||0>r||r>maxSize)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[r,c],this.bind(),gl.texImage2D(gl.TEXTURE_2D,0,this.format,c,r,0,this.format,this.type,null),this._mipLevels=[0],x}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[0],x_off=0|x_off[1]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}},module.exports=createTexture2D},{ndarray:74,"ndarray-ops":69,"typedarray-pool":78,webglew:80}],82:[function(require,module){function programify(vertex,fragment,uniforms,attributes){return function(gl){return shader(gl,vertex,fragment,uniforms,attributes)}}module.exports=programify;var shader=require("gl-shader-core")},{"gl-shader-core":88}],83:[function(require,module){function noop(){throw new Error("You should bundle your code using `glslify` as a transform.")}module.exports=noop},{}],84:[function(require,module){"use strict";function ShaderAttribute(gl,program,location,dimension,name,constFunc,relink){this._gl=gl,this._program=program,this._location=location,this._dimension=dimension,this._name=name,this._constFunc=constFunc,this._relink=relink}function addVectorAttribute(gl,program,location,dimension,obj,name,doLink){for(var constFuncArgs=["gl","v"],varNames=[],i=0;dimension>i;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],85:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;k0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],96:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance}function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":95}],97:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],98:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],99:[function(require,module){function parse(html,doc){if("string"!=typeof html)throw new TypeError("String expected");doc||(doc=document);var m=/<([\w:]+)/.exec(html);if(!m)return doc.createTextNode(html);html=html.replace(/^\s+|\s+$/g,"");var tag=m[1];if("body"==tag){var el=doc.createElement("html");return el.innerHTML=html,el.removeChild(el.lastChild)}var wrap=map[tag]||map._default,depth=wrap[0],prefix=wrap[1],suffix=wrap[2],el=doc.createElement("div");for(el.innerHTML=prefix+html+suffix;depth--;)el=el.lastChild;if(el.firstChild==el.lastChild)return el.removeChild(el.firstChild);for(var fragment=doc.createDocumentFragment();el.firstChild;)fragment.appendChild(el.removeChild(el.firstChild));return fragment}module.exports=parse;var map={legend:[1,"
      ","
      "],tr:[2,"","
      "],col:[2,"","
      "],_default:[0,"",""]};map.td=map.th=[3,"","
      "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
      "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],100:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],101:[function(require,module,exports){arguments[4][32][0].apply(exports,arguments)},{_process:109,"raf-component":102,sliced:104}],102:[function(require,module){module.exports=require(33)},{}],103:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],104:[function(require,module,exports){arguments[4][34][0].apply(exports,arguments)},{"./lib/sliced":105}],105:[function(require,module){module.exports=require(35)},{}],106:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)"base64"===encoding&&(subject=base64clean(subject)),length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new Error("First argument needs to be a number, array or string.");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}var buf;TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;assert(strLen%2===0,"Invalid hex string"),length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);assert(!isNaN(byte),"Invalid hex string"),buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string),buf,offset,length);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function binarySlice(buf,start,end){return asciiSlice(buf,start,end)}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;i=len)){var val;return littleEndian?(val=buf[offset],len>offset+1&&(val|=buf[offset+1]<<8)):(val=buf[offset]<<8,len>offset+1&&(val|=buf[offset+1])),val}}function readUInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val;return littleEndian?(len>offset+2&&(val=buf[offset+2]<<16),len>offset+1&&(val|=buf[offset+1]<<8),val|=buf[offset],len>offset+3&&(val+=buf[offset+3]<<24>>>0)):(len>offset+1&&(val=buf[offset+1]<<16),len>offset+2&&(val|=buf[offset+2]<<8),len>offset+3&&(val|=buf[offset+3]),val+=buf[offset]<<24>>>0),val}}function readInt16(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len)){var val=readUInt16(buf,offset,littleEndian,!0),neg=32768&val;return neg?-1*(65535-val+1):val}}function readInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val=readUInt32(buf,offset,littleEndian,!0),neg=2147483648&val;return neg?-1*(4294967295-val+1):val}}function readFloat(buf,offset,littleEndian,noAssert){return noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i);return offset+2}}function writeUInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255;return offset+4}}function writeInt16(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len))return value>=0?writeUInt16(buf,value,offset,littleEndian,noAssert):writeUInt16(buf,65535+value+1,offset,littleEndian,noAssert),offset+2}function writeInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return value>=0?writeUInt32(buf,value,offset,littleEndian,noAssert):writeUInt32(buf,4294967295+value+1,offset,littleEndian,noAssert),offset+4}function writeFloat(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+7=len))return ieee754.write(buf,value,offset,littleEndian,52,8),offset+8}function base64clean(str){for(str=stringtrim(str).replace(INVALID_BASE64_RE,"");str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArray(subject){return(Array.isArray||function(subject){return"[object Array]"===Object.prototype.toString.call(subject)})(subject)}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(str){for(var byteArray=[],i=0;i=b)byteArray.push(b);else{var start=i;b>=55296&&57343>=b&&i++;for(var h=encodeURIComponent(str.slice(start,i+1)).substr(1).split("%"),j=0;j>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(str)}function blitBuffer(src,dst,offset,length){for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533)}}function verifuint(value,max){assert("number"==typeof value,"cannot write a non-number as a number"),assert(value>=0,"specified a negative value for writing an unsigned value"),assert(max>=value,"value is larger than maximum value for type"),assert(Math.floor(value)===value,"value has a fractional component")}function verifsint(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value"),assert(Math.floor(value)===value,"value has a fractional component")}function verifIEEE754(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value")}function assert(test,message){if(!test)throw new Error(message||"Failed assertion")}var base64=require("base64-js"),ieee754=require("ieee754");exports.Buffer=Buffer,exports.SlowBuffer=Buffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}();Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.byteLength=function(str,encoding){var ret;switch(str=str.toString(),encoding||"utf8"){case"hex":ret=str.length/2;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"ascii":case"binary":case"raw":ret=str.length;break;case"base64":ret=base64ToBytes(str).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=2*str.length;break;default:throw new Error("Unknown encoding")}return ret},Buffer.concat=function(list,totalLength){if(assert(isArray(list),"Usage: Buffer.concat(list[, length])"),0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;ii&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}offset=Number(offset)||0;var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toString=function(encoding,start,end){var self=this;if(encoding=String(encoding||"utf8").toLowerCase(),start=Number(start)||0,end=void 0===end?self.length:Number(end),end===start)return"";var ret;switch(encoding){case"hex":ret=hexSlice(self,start,end);break;case"utf8":case"utf-8":ret=utf8Slice(self,start,end);break;case"ascii":ret=asciiSlice(self,start,end);break;case"binary":ret=binarySlice(self,start,end);break;case"base64":ret=base64Slice(self,start,end);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leSlice(self,start,end);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.equals=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),0===Buffer.compare(this,b)},Buffer.prototype.compare=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),Buffer.compare(this,b)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start||(target_start=0),end!==start&&0!==target.length&&0!==source.length){assert(end>=start,"sourceEnd < sourceStart"),assert(target_start>=0&&target_start=0&&start=0&&end<=source.length,"sourceEnd out of bounds"),end>this.length&&(end=this.length),target.length-target_startlen||!TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start)}},Buffer.prototype.slice=function(start,end){var len=this.length;if(start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start),TYPED_ARRAY_SUPPORT)return Buffer._augment(this.subarray(start,end));for(var sliceLen=end-start,newBuf=new Buffer(sliceLen,void 0,!0),i=0;sliceLen>i;i++)newBuf[i]=this[i+start];return newBuf},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return readUInt16(this,offset,!0,noAssert)},Buffer.prototype.readUInt16BE=function(offset,noAssert){return readUInt16(this,offset,!1,noAssert)},Buffer.prototype.readUInt32LE=function(offset,noAssert){return readUInt32(this,offset,!0,noAssert)},Buffer.prototype.readUInt32BE=function(offset,noAssert){return readUInt32(this,offset,!1,noAssert)},Buffer.prototype.readInt8=function(offset,noAssert){if(noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length)){var neg=128&this[offset];return neg?-1*(255-this[offset]+1):this[offset]}},Buffer.prototype.readInt16LE=function(offset,noAssert){return readInt16(this,offset,!0,noAssert)},Buffer.prototype.readInt16BE=function(offset,noAssert){return readInt16(this,offset,!1,noAssert)},Buffer.prototype.readInt32LE=function(offset,noAssert){return readInt32(this,offset,!0,noAssert)},Buffer.prototype.readInt32BE=function(offset,noAssert){return readInt32(this,offset,!1,noAssert)},Buffer.prototype.readFloatLE=function(offset,noAssert){return readFloat(this,offset,!0,noAssert)},Buffer.prototype.readFloatBE=function(offset,noAssert){return readFloat(this,offset,!1,noAssert)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return readDouble(this,offset,!0,noAssert)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return readDouble(this,offset,!1,noAssert)},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(this[offset]=value,offset+1)},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(value>=0?this.writeUInt8(value,offset,noAssert):this.writeUInt8(255+value+1,offset,noAssert),offset+1)},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return writeInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return writeInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return writeInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return writeInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert) +},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),assert(end>=start,"end < start"),end!==start&&0!==this.length){assert(start>=0&&start=0&&end<=this.length,"end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.inspect=function(){for(var out=[],len=this.length,i=0;len>i;i++)if(out[i]=toHex(this[i]),i===exports.INSPECT_MAX_BYTES){out[i+1]="...";break}return""},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z]/g},{"base64-js":107,ieee754:108}],107:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS?62:code===SLASH?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],108:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],109:[function(require,module){function noop(){}var process=module.exports={};process.nextTick=function(){var canSetImmediate="undefined"!=typeof window&&window.setImmediate,canPost="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(canSetImmediate)return function(f){return window.setImmediate(f)};if(canPost){var queue=[];return window.addEventListener("message",function(ev){var source=ev.source;if((source===window||null===source)&&"process-tick"===ev.data&&(ev.stopPropagation(),queue.length>0)){var fn=queue.shift();fn()}},!0),function(fn){queue.push(fn),window.postMessage("process-tick","*")}}return function(fn){setTimeout(fn,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file diff --git a/index.js b/index.js index aa5db46..2164fbe 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ require('./lib/fill')(document.querySelectorAll('[data-fill]')) if (window.chrome) { try { require('@stackgl/splash-grid')(grid) - require('@stackgl/splash-flock')(flock) + // require('@stackgl/splash-flock')(flock) } catch(e) { console.error(e.message) } From 09819414cbd0d2b8b1fc3564f4431157dbb26535 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Tue, 16 Sep 2014 00:32:08 +0200 Subject: [PATCH 23/64] update ndpack-image --- bundle.js | 18 ++++++++++-------- index.js | 12 +++++------- splash-grid/package.json | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bundle.js b/bundle.js index 64a8ecb..0b3864c 100644 --- a/bundle.js +++ b/bundle.js @@ -1,8 +1,10 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}if(require("./lib/fill")(document.querySelectorAll("[data-fill]")),window.chrome)try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:99,minstache:103,sliced:104}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":96,"right-now":97,"unindex-mesh":98}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:106,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n); -var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":30}],29:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],30:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],32:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:109,"raf-component":33,sliced:34}],33:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],34:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":35}],35:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],36:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],37:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":36}],38:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":39}],39:[function(require,module){module.exports=require(33)},{}],40:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:45}],45:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],46:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:52,"ndarray-ops":47,"typedarray-pool":56,webglew:58}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments) -},{"./lib/thunk.js":50}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:51}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":49}],51:[function(require,module){module.exports=require(13)},{}],52:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:106,"iota-array":53}],53:[function(require,module){module.exports=require(15)},{}],54:[function(require,module){module.exports=require(16)},{}],55:[function(require,module){module.exports=require(17)},{}],56:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":54,buffer:106,dup:55}],57:[function(require,module){module.exports=require(41)},{}],58:[function(require,module){module.exports=require(42)},{weakmap:57}],59:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],60:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements){this._elements=elements,this._attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":59}],61:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null -},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],69:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":70}],70:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":72}],71:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:73}],72:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":71}],73:[function(require,module){module.exports=require(13)},{}],74:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:106,"iota-array":75}],75:[function(require,module){module.exports=require(15)},{}],76:[function(require,module){module.exports=require(16)},{}],77:[function(require,module){module.exports=require(17)},{}],78:[function(require,module){module.exports=require(56)},{"bit-twiddle":76,buffer:106,dup:77}],79:[function(require,module){module.exports=require(41)},{}],80:[function(require,module){module.exports=require(42)},{weakmap:79}],81:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function isPacked(array){for(var shape=array.shape,stride=array.stride,s=1,i=shape.length-1;i>=0;--i){if(stride[i]!==s)return!1;s*=shape[i]}return!0}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(array),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type===gl.FLOAT&&webglew(gl).texture_float&&(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store;if(packed){var array_size=array.size;buffer=array.data.subarray(array.offset,array.offset+array_size)}else{for(var sz=1,stride=new Array(shape.length),i=shape.length-1;i>=0;--i)stride[i]=sz,sz*=shape[i];buf_store=pool.malloc(sz,dtype);var buf_array=ndarray(buf_store,array.shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,sz)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[1],shape[0],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][1],0|arguments[1][0],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew"),linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)};Object.defineProperty(Texture2D.prototype,"minFilter",{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}});var proto=Texture2D.prototype;Object.defineProperty(proto,"magFilter",{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}}),Object.defineProperty(proto,"wrapS",{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}}),Object.defineProperty(proto,"wrapT",{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}}),Object.defineProperty(proto,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapT=v[0],this._wrapS=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),v}}),Object.defineProperty(proto,"mipSamples",{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(proto,"shape",{get:function(){return this._shape},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];var r=0|x[0],c=0|x[1];if(this.height===r&&this.width===c)return x;var gl=this.gl,maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>c||c>maxSize||0>r||r>maxSize)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[r,c],this.bind(),gl.texImage2D(gl.TEXTURE_2D,0,this.format,c,r,0,this.format,this.type,null),this._mipLevels=[0],x}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[0],x_off=0|x_off[1]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}},module.exports=createTexture2D},{ndarray:74,"ndarray-ops":69,"typedarray-pool":78,webglew:80}],82:[function(require,module){function programify(vertex,fragment,uniforms,attributes){return function(gl){return shader(gl,vertex,fragment,uniforms,attributes)}}module.exports=programify;var shader=require("gl-shader-core")},{"gl-shader-core":88}],83:[function(require,module){function noop(){throw new Error("You should bundle your code using `glslify` as a transform.")}module.exports=noop},{}],84:[function(require,module){"use strict";function ShaderAttribute(gl,program,location,dimension,name,constFunc,relink){this._gl=gl,this._program=program,this._location=location,this._dimension=dimension,this._name=name,this._constFunc=constFunc,this._relink=relink}function addVectorAttribute(gl,program,location,dimension,obj,name,doLink){for(var constFuncArgs=["gl","v"],varNames=[],i=0;dimension>i;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],85:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;k0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],96:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance}function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":95}],97:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],98:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],99:[function(require,module){function parse(html,doc){if("string"!=typeof html)throw new TypeError("String expected");doc||(doc=document);var m=/<([\w:]+)/.exec(html);if(!m)return doc.createTextNode(html);html=html.replace(/^\s+|\s+$/g,"");var tag=m[1];if("body"==tag){var el=doc.createElement("html");return el.innerHTML=html,el.removeChild(el.lastChild)}var wrap=map[tag]||map._default,depth=wrap[0],prefix=wrap[1],suffix=wrap[2],el=doc.createElement("div");for(el.innerHTML=prefix+html+suffix;depth--;)el=el.lastChild;if(el.firstChild==el.lastChild)return el.removeChild(el.firstChild);for(var fragment=doc.createDocumentFragment();el.firstChild;)fragment.appendChild(el.removeChild(el.firstChild));return fragment}module.exports=parse;var map={legend:[1,"
      ","
      "],tr:[2,"","
      "],col:[2,"","
      "],_default:[0,"",""]};map.td=map.th=[3,"","
      "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
      "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],100:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],101:[function(require,module,exports){arguments[4][32][0].apply(exports,arguments)},{_process:109,"raf-component":102,sliced:104}],102:[function(require,module){module.exports=require(33)},{}],103:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],104:[function(require,module,exports){arguments[4][34][0].apply(exports,arguments)},{"./lib/sliced":105}],105:[function(require,module){module.exports=require(35)},{}],106:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)"base64"===encoding&&(subject=base64clean(subject)),length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new Error("First argument needs to be a number, array or string.");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}var buf;TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;assert(strLen%2===0,"Invalid hex string"),length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);assert(!isNaN(byte),"Invalid hex string"),buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string),buf,offset,length);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function binarySlice(buf,start,end){return asciiSlice(buf,start,end)}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;i=len)){var val;return littleEndian?(val=buf[offset],len>offset+1&&(val|=buf[offset+1]<<8)):(val=buf[offset]<<8,len>offset+1&&(val|=buf[offset+1])),val}}function readUInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val;return littleEndian?(len>offset+2&&(val=buf[offset+2]<<16),len>offset+1&&(val|=buf[offset+1]<<8),val|=buf[offset],len>offset+3&&(val+=buf[offset+3]<<24>>>0)):(len>offset+1&&(val=buf[offset+1]<<16),len>offset+2&&(val|=buf[offset+2]<<8),len>offset+3&&(val|=buf[offset+3]),val+=buf[offset]<<24>>>0),val}}function readInt16(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len)){var val=readUInt16(buf,offset,littleEndian,!0),neg=32768&val;return neg?-1*(65535-val+1):val}}function readInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val=readUInt32(buf,offset,littleEndian,!0),neg=2147483648&val;return neg?-1*(4294967295-val+1):val}}function readFloat(buf,offset,littleEndian,noAssert){return noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i);return offset+2}}function writeUInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255;return offset+4}}function writeInt16(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len))return value>=0?writeUInt16(buf,value,offset,littleEndian,noAssert):writeUInt16(buf,65535+value+1,offset,littleEndian,noAssert),offset+2}function writeInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return value>=0?writeUInt32(buf,value,offset,littleEndian,noAssert):writeUInt32(buf,4294967295+value+1,offset,littleEndian,noAssert),offset+4}function writeFloat(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+7=len))return ieee754.write(buf,value,offset,littleEndian,52,8),offset+8}function base64clean(str){for(str=stringtrim(str).replace(INVALID_BASE64_RE,"");str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArray(subject){return(Array.isArray||function(subject){return"[object Array]"===Object.prototype.toString.call(subject)})(subject)}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(str){for(var byteArray=[],i=0;i=b)byteArray.push(b);else{var start=i;b>=55296&&57343>=b&&i++;for(var h=encodeURIComponent(str.slice(start,i+1)).substr(1).split("%"),j=0;j>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(str)}function blitBuffer(src,dst,offset,length){for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533)}}function verifuint(value,max){assert("number"==typeof value,"cannot write a non-number as a number"),assert(value>=0,"specified a negative value for writing an unsigned value"),assert(max>=value,"value is larger than maximum value for type"),assert(Math.floor(value)===value,"value has a fractional component")}function verifsint(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value"),assert(Math.floor(value)===value,"value has a fractional component")}function verifIEEE754(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value")}function assert(test,message){if(!test)throw new Error(message||"Failed assertion")}var base64=require("base64-js"),ieee754=require("ieee754");exports.Buffer=Buffer,exports.SlowBuffer=Buffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}();Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.byteLength=function(str,encoding){var ret;switch(str=str.toString(),encoding||"utf8"){case"hex":ret=str.length/2;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"ascii":case"binary":case"raw":ret=str.length;break;case"base64":ret=base64ToBytes(str).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=2*str.length;break;default:throw new Error("Unknown encoding")}return ret},Buffer.concat=function(list,totalLength){if(assert(isArray(list),"Usage: Buffer.concat(list[, length])"),0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;ii&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}offset=Number(offset)||0;var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toString=function(encoding,start,end){var self=this;if(encoding=String(encoding||"utf8").toLowerCase(),start=Number(start)||0,end=void 0===end?self.length:Number(end),end===start)return"";var ret;switch(encoding){case"hex":ret=hexSlice(self,start,end);break;case"utf8":case"utf-8":ret=utf8Slice(self,start,end);break;case"ascii":ret=asciiSlice(self,start,end);break;case"binary":ret=binarySlice(self,start,end);break;case"base64":ret=base64Slice(self,start,end);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leSlice(self,start,end);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.equals=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),0===Buffer.compare(this,b)},Buffer.prototype.compare=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),Buffer.compare(this,b)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start||(target_start=0),end!==start&&0!==target.length&&0!==source.length){assert(end>=start,"sourceEnd < sourceStart"),assert(target_start>=0&&target_start=0&&start=0&&end<=source.length,"sourceEnd out of bounds"),end>this.length&&(end=this.length),target.length-target_startlen||!TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start)}},Buffer.prototype.slice=function(start,end){var len=this.length;if(start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start),TYPED_ARRAY_SUPPORT)return Buffer._augment(this.subarray(start,end));for(var sliceLen=end-start,newBuf=new Buffer(sliceLen,void 0,!0),i=0;sliceLen>i;i++)newBuf[i]=this[i+start];return newBuf},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return readUInt16(this,offset,!0,noAssert)},Buffer.prototype.readUInt16BE=function(offset,noAssert){return readUInt16(this,offset,!1,noAssert)},Buffer.prototype.readUInt32LE=function(offset,noAssert){return readUInt32(this,offset,!0,noAssert)},Buffer.prototype.readUInt32BE=function(offset,noAssert){return readUInt32(this,offset,!1,noAssert)},Buffer.prototype.readInt8=function(offset,noAssert){if(noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length)){var neg=128&this[offset];return neg?-1*(255-this[offset]+1):this[offset]}},Buffer.prototype.readInt16LE=function(offset,noAssert){return readInt16(this,offset,!0,noAssert)},Buffer.prototype.readInt16BE=function(offset,noAssert){return readInt16(this,offset,!1,noAssert)},Buffer.prototype.readInt32LE=function(offset,noAssert){return readInt32(this,offset,!0,noAssert)},Buffer.prototype.readInt32BE=function(offset,noAssert){return readInt32(this,offset,!1,noAssert)},Buffer.prototype.readFloatLE=function(offset,noAssert){return readFloat(this,offset,!0,noAssert)},Buffer.prototype.readFloatBE=function(offset,noAssert){return readFloat(this,offset,!1,noAssert)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return readDouble(this,offset,!0,noAssert)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return readDouble(this,offset,!1,noAssert)},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(this[offset]=value,offset+1)},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(value>=0?this.writeUInt8(value,offset,noAssert):this.writeUInt8(255+value+1,offset,noAssert),offset+1)},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return writeInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return writeInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return writeInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return writeInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert) -},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),assert(end>=start,"end < start"),end!==start&&0!==this.length){assert(start>=0&&start=0&&end<=this.length,"end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.inspect=function(){for(var out=[],len=this.length,i=0;len>i;i++)if(out[i]=toHex(this[i]),i===exports.INSPECT_MAX_BYTES){out[i+1]="...";break}return""},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z]/g},{"base64-js":107,ieee754:108}],107:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS?62:code===SLASH?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],108:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],109:[function(require,module){function noop(){}var process=module.exports={};process.nextTick=function(){var canSetImmediate="undefined"!=typeof window&&window.setImmediate,canPost="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(canSetImmediate)return function(f){return window.setImmediate(f)};if(canPost){var queue=[];return window.addEventListener("message",function(ev){var source=ev.source;if((source===window||null===source)&&"process-tick"===ev.data&&(ev.stopPropagation(),queue.length>0)){var fn=queue.shift();fn()}},!0),function(fn){queue.push(fn),window.postMessage("process-tick","*")}}return function(fn){setTimeout(fn,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:123,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n); +var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":30}],29:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],30:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],32:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:126,"raf-component":33,sliced:34}],33:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],34:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":35}],35:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],36:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],37:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":36}],38:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":39}],39:[function(require,module){module.exports=require(33)},{}],40:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:45}],45:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],46:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:52,"ndarray-ops":47,"typedarray-pool":56,webglew:58}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments) +},{"./lib/thunk.js":50}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:51}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":49}],51:[function(require,module){module.exports=require(13)},{}],52:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":53}],53:[function(require,module){module.exports=require(15)},{}],54:[function(require,module){module.exports=require(16)},{}],55:[function(require,module){module.exports=require(17)},{}],56:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":54,buffer:123,dup:55}],57:[function(require,module){module.exports=require(41)},{}],58:[function(require,module){module.exports=require(42)},{weakmap:57}],59:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],60:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":59}],61:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06; +return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],69:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":70}],70:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":72}],71:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:73}],72:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":71}],73:[function(require,module){module.exports=require(13)},{}],74:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":75}],75:[function(require,module){module.exports=require(15)},{}],76:[function(require,module){module.exports=require(16)},{}],77:[function(require,module){module.exports=require(17)},{}],78:[function(require,module){module.exports=require(56)},{"bit-twiddle":76,buffer:123,dup:77}],79:[function(require,module){module.exports=require(41)},{}],80:[function(require,module){module.exports=require(42)},{weakmap:79}],81:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function isPacked(array){for(var shape=array.shape,stride=array.stride,s=1,i=shape.length-1;i>=0;--i){if(stride[i]!==s)return!1;s*=shape[i]}return!0}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(array),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type===gl.FLOAT&&webglew(gl).texture_float&&(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store;if(packed){var array_size=array.size;buffer=array.data.subarray(array.offset,array.offset+array_size)}else{for(var sz=1,stride=new Array(shape.length),i=shape.length-1;i>=0;--i)stride[i]=sz,sz*=shape[i];buf_store=pool.malloc(sz,dtype);var buf_array=ndarray(buf_store,array.shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,sz)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[1],shape[0],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][1],0|arguments[1][0],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew"),linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)};Object.defineProperty(Texture2D.prototype,"minFilter",{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}});var proto=Texture2D.prototype;Object.defineProperty(proto,"magFilter",{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}}),Object.defineProperty(proto,"wrapS",{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}}),Object.defineProperty(proto,"wrapT",{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}}),Object.defineProperty(proto,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapT=v[0],this._wrapS=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),v}}),Object.defineProperty(proto,"mipSamples",{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(proto,"shape",{get:function(){return this._shape},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];var r=0|x[0],c=0|x[1];if(this.height===r&&this.width===c)return x;var gl=this.gl,maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>c||c>maxSize||0>r||r>maxSize)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[r,c],this.bind(),gl.texImage2D(gl.TEXTURE_2D,0,this.format,c,r,0,this.format,this.type,null),this._mipLevels=[0],x}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[0],x_off=0|x_off[1]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}},module.exports=createTexture2D},{ndarray:74,"ndarray-ops":69,"typedarray-pool":78,webglew:80}],82:[function(require,module){function programify(vertex,fragment,uniforms,attributes){return function(gl){return shader(gl,vertex,fragment,uniforms,attributes)}}module.exports=programify;var shader=require("gl-shader-core")},{"gl-shader-core":88}],83:[function(require,module){function noop(){throw new Error("You should bundle your code using `glslify` as a transform.")}module.exports=noop},{}],84:[function(require,module){"use strict";function ShaderAttribute(gl,program,location,dimension,name,constFunc,relink){this._gl=gl,this._program=program,this._location=location,this._dimension=dimension,this._name=name,this._constFunc=constFunc,this._relink=relink}function addVectorAttribute(gl,program,location,dimension,obj,name,doLink){for(var constFuncArgs=["gl","v"],varNames=[],i=0;dimension>i;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],85:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;k=pa&&pc>=pa?a:pc>=pb?b:c}function parseData(dataBuffer){function inputData(data){for(var tmp,j,len=data.length,i=0;i!==len;)switch(state){case 0:if(data.readUInt8(i++)!==HEADER[off++])return!1;off===HEADER.length&&(state=1,off=0);break;case 1:if(8-off>len-i)data.copy(buf,off,i),off+=len-i,i=len;else switch(data.copy(buf,off,i,i+8-off),i+=8-off,off=0,chunkLength=buf.readUInt32BE(0),buf.toString("ascii",4,8)){case"IHDR":state=2;break;case"PLTE":if(3!==pngColorType)state=7;else{if(chunkLength%3!==0)return!1;pngPaletteEntries=chunkLength/3,pngPalette=new Buffer(chunkLength),state=3}break;case"tRNS":if(3!==pngColorType)return!1;idChannels++,pngAlphaEntries=chunkLength,pngAlpha=new Buffer(chunkLength),state=4;break;case"IDAT":pngPixels||(pngPixels=new Uint8Array(pngWidth*pngHeight*idChannels)),state=5;break;case"IEND":state=6;break;default:state=7}break;case 2:if(13!==chunkLength)return!1;if(chunkLength-off>len-i)data.copy(buf,off,i),off+=len-i,i=len;else{if(data.copy(buf,off,i,i+chunkLength-off),0!==buf.readUInt8(10))return!1;if(0!==buf.readUInt8(11))return!1;if(0!==buf.readUInt8(12))return!1;switch(i+=chunkLength-off,state=8,off=0,pngWidth=buf.readUInt32BE(0),pngHeight=buf.readUInt32BE(4),pngBitDepth=buf.readUInt8(8),pngDepthMult=255/((1<len-i)data.copy(pngPalette,off,i),off+=len-i,i=len;else for(data.copy(pngPalette,off,i,i+chunkLength-off),i+=chunkLength-off,state=8,off=0,idChannels=1,j=pngPaletteEntries;j--;)if(pngPalette[3*j+0]!==pngPalette[3*j+1]||pngPalette[3*j+0]!==pngPalette[3*j+2]){idChannels=3;break}break;case 4:chunkLength-off>len-i?(data.copy(pngAlpha,off,i),off+=len-i,i=len):(data.copy(pngAlpha,off,i,i+chunkLength-off),i+=chunkLength-off,state=8,off=0);break;case 5:chunkLength-off>len-i?(inflateQueue.push(data.slice(i)),off+=len-i,i=len):(inflateQueue.push(data.slice(i,i+chunkLength-off)),i+=chunkLength-off,state=8,off=0);break;case 6:if(0!==chunkLength)return!1;4-off>len-i?(off+=len-i,i=len):(pngTrailer=new Buffer(0),i+=4-off,state=9,off=0);break;case 7:chunkLength-off>len-i?(off+=len-i,i=len):(i+=chunkLength-off,state=8,off=0);break;case 8:4-off>len-i?(off+=len-i,i=len):(i+=4-off,state=1,off=0);break;case 9:tmp=new Buffer(off+len-i),pngTrailer.copy(tmp),data.copy(tmp,off,i,len),pngTrailer=tmp,off+=len-i,i=len}return!0}function unpackPixels(data){var i,tmp,x,j,k,len=data.length;for(i=0;i!==len;++i){if(-1===b)scanlineFilter=data[i],tmp=currentScanline,currentScanline=priorScanline,priorScanline=tmp;else switch(scanlineFilter){case 0:currentScanline[b]=data[i];break;case 1:currentScanline[b]=pngBytesPerPixel>b?data[i]:data[i]+currentScanline[b-pngBytesPerPixel]&255;break;case 2:currentScanline[b]=data[i]+priorScanline[b]&255;break;case 3:currentScanline[b]=data[i]+((pngBytesPerPixel>b?priorScanline[b]:currentScanline[b-pngBytesPerPixel]+priorScanline[b])>>>1)&255;break;case 4:currentScanline[b]=data[i]+(pngBytesPerPixel>b?priorScanline[b]:paeth(currentScanline[b-pngBytesPerPixel],priorScanline[b],priorScanline[b-pngBytesPerPixel]))&255;break;default:return null}if(++b===pngBytesPerScanline){if(p===pngPixels.length)return null;for(j=0,x=0;x!==pngWidth;++x){for(k=0;k!==pngSamplesPerPixel;++j,++k)switch(pngBitDepth){case 1:pngSamples[k]=currentScanline[j>>>3]>>7-(7&j)&1;break;case 2:pngSamples[k]=currentScanline[j>>>2]>>(3-(3&j)<<1)&3;break;case 4:pngSamples[k]=currentScanline[j>>>1]>>(1-(1&j)<<2)&15;break;case 8:pngSamples[k]=currentScanline[j];break;default:return null}switch(pngColorType){case 0:pngPixels[p++]=pngSamples[0]*pngDepthMult;break;case 2:pngPixels[p++]=pngSamples[0]*pngDepthMult,pngPixels[p++]=pngSamples[1]*pngDepthMult,pngPixels[p++]=pngSamples[2]*pngDepthMult;break;case 3:if(pngSamples[0]>=pngPaletteEntries)return null;switch(idChannels){case 1:pngPixels[p++]=pngPalette[3*pngSamples[0]];break;case 2:pngPixels[p++]=pngPalette[3*pngSamples[0]],pngPixels[p++]=pngSamples[0]0?opt.windowBits=-opt.windowBits:opt.gzip&&opt.windowBits>0&&opt.windowBits<16&&(opt.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;var status=zlib_deflate.deflateInit2(this.strm,opt.level,opt.method,opt.windowBits,opt.memLevel,opt.strategy);if(status!==Z_OK)throw new Error(msg[status]);opt.header&&zlib_deflate.deflateSetHeader(this.strm,opt.header)};Deflate.prototype.push=function(data,mode){var status,_mode,strm=this.strm,chunkSize=this.options.chunkSize;if(this.ended)return!1;_mode=mode===~~mode?mode:mode===!0?Z_FINISH:Z_NO_FLUSH,strm.input="string"==typeof data?strings.string2buf(data):data,strm.next_in=0,strm.avail_in=strm.input.length;do{if(0===strm.avail_out&&(strm.output=new utils.Buf8(chunkSize),strm.next_out=0,strm.avail_out=chunkSize),status=zlib_deflate.deflate(strm,_mode),status!==Z_STREAM_END&&status!==Z_OK)return this.onEnd(status),this.ended=!0,!1;(0===strm.avail_out||0===strm.avail_in&&_mode===Z_FINISH)&&this.onData("string"===this.options.to?strings.buf2binstring(utils.shrinkBuf(strm.output,strm.next_out)):utils.shrinkBuf(strm.output,strm.next_out))}while((strm.avail_in>0||0===strm.avail_out)&&status!==Z_STREAM_END);return _mode===Z_FINISH?(status=zlib_deflate.deflateEnd(this.strm),this.onEnd(status),this.ended=!0,status===Z_OK):!0},Deflate.prototype.onData=function(chunk){this.chunks.push(chunk)},Deflate.prototype.onEnd=function(status){status===Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):utils.flattenChunks(this.chunks)),this.chunks=[],this.err=status,this.msg=this.strm.msg},exports.Deflate=Deflate,exports.deflate=deflate,exports.deflateRaw=deflateRaw,exports.gzip=gzip},{"./utils/common":98,"./utils/strings":99,"./zlib/deflate.js":103,"./zlib/messages":108,"./zlib/zstream":110}],97:[function(require,module,exports){"use strict";function inflate(input,options){var inflator=new Inflate(options);if(inflator.push(input,!0),inflator.err)throw inflator.msg;return inflator.result}function inflateRaw(input,options){return options=options||{},options.raw=!0,inflate(input,options)}var zlib_inflate=require("./zlib/inflate.js"),utils=require("./utils/common"),strings=require("./utils/strings"),c=require("./zlib/constants"),msg=require("./zlib/messages"),zstream=require("./zlib/zstream"),gzheader=require("./zlib/gzheader"),Inflate=function(options){this.options=utils.assign({chunkSize:16384,windowBits:0,to:""},options||{});var opt=this.options;opt.raw&&opt.windowBits>=0&&opt.windowBits<16&&(opt.windowBits=-opt.windowBits,0===opt.windowBits&&(opt.windowBits=-15)),!(opt.windowBits>=0&&opt.windowBits<16)||options&&options.windowBits||(opt.windowBits+=32),opt.windowBits>15&&opt.windowBits<48&&0===(15&opt.windowBits)&&(opt.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;var status=zlib_inflate.inflateInit2(this.strm,opt.windowBits);if(status!==c.Z_OK)throw new Error(msg[status]);this.header=new gzheader,zlib_inflate.inflateGetHeader(this.strm,this.header)};Inflate.prototype.push=function(data,mode){var status,_mode,next_out_utf8,tail,utf8str,strm=this.strm,chunkSize=this.options.chunkSize;if(this.ended)return!1;_mode=mode===~~mode?mode:mode===!0?c.Z_FINISH:c.Z_NO_FLUSH,strm.input="string"==typeof data?strings.binstring2buf(data):data,strm.next_in=0,strm.avail_in=strm.input.length;do{if(0===strm.avail_out&&(strm.output=new utils.Buf8(chunkSize),strm.next_out=0,strm.avail_out=chunkSize),status=zlib_inflate.inflate(strm,c.Z_NO_FLUSH),status!==c.Z_STREAM_END&&status!==c.Z_OK)return this.onEnd(status),this.ended=!0,!1;strm.next_out&&(0===strm.avail_out||status===c.Z_STREAM_END||0===strm.avail_in&&_mode===c.Z_FINISH)&&("string"===this.options.to?(next_out_utf8=strings.utf8border(strm.output,strm.next_out),tail=strm.next_out-next_out_utf8,utf8str=strings.buf2string(strm.output,next_out_utf8),strm.next_out=tail,strm.avail_out=chunkSize-tail,tail&&utils.arraySet(strm.output,strm.output,next_out_utf8,tail,0),this.onData(utf8str)):this.onData(utils.shrinkBuf(strm.output,strm.next_out)))}while(strm.avail_in>0&&status!==c.Z_STREAM_END);return status===c.Z_STREAM_END&&(_mode=c.Z_FINISH),_mode===c.Z_FINISH?(status=zlib_inflate.inflateEnd(this.strm),this.onEnd(status),this.ended=!0,status===c.Z_OK):!0},Inflate.prototype.onData=function(chunk){this.chunks.push(chunk)},Inflate.prototype.onEnd=function(status){status===c.Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):utils.flattenChunks(this.chunks)),this.chunks=[],this.err=status,this.msg=this.strm.msg},exports.Inflate=Inflate,exports.inflate=inflate,exports.inflateRaw=inflateRaw,exports.ungzip=inflate},{"./utils/common":98,"./utils/strings":99,"./zlib/constants":101,"./zlib/gzheader":104,"./zlib/inflate.js":106,"./zlib/messages":108,"./zlib/zstream":110}],98:[function(require,module,exports){"use strict";var TYPED_OK="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;exports.assign=function(obj){for(var sources=Array.prototype.slice.call(arguments,1);sources.length;){var source=sources.shift();if(source){if("object"!=typeof source)throw new TypeError(source+"must be non-object");for(var p in source)source.hasOwnProperty(p)&&(obj[p]=source[p])}}return obj},exports.shrinkBuf=function(buf,size){return buf.length===size?buf:buf.subarray?buf.subarray(0,size):(buf.length=size,buf)};var fnTyped={arraySet:function(dest,src,src_offs,len,dest_offs){if(src.subarray&&dest.subarray)return void dest.set(src.subarray(src_offs,src_offs+len),dest_offs);for(var i=0;len>i;i++)dest[dest_offs+i]=src[src_offs+i]},flattenChunks:function(chunks){var i,l,len,pos,chunk,result;for(len=0,i=0,l=chunks.length;l>i;i++)len+=chunks[i].length;for(result=new Uint8Array(len),pos=0,i=0,l=chunks.length;l>i;i++)chunk=chunks[i],result.set(chunk,pos),pos+=chunk.length;return result}},fnUntyped={arraySet:function(dest,src,src_offs,len,dest_offs){for(var i=0;len>i;i++)dest[dest_offs+i]=src[src_offs+i]},flattenChunks:function(chunks){return[].concat.apply([],chunks)}};exports.setTyped=function(on){on?(exports.Buf8=Uint8Array,exports.Buf16=Uint16Array,exports.Buf32=Int32Array,exports.assign(exports,fnTyped)):(exports.Buf8=Array,exports.Buf16=Array,exports.Buf32=Array,exports.assign(exports,fnUntyped))},exports.setTyped(TYPED_OK)},{}],99:[function(require,module,exports){"use strict";function buf2binstring(buf,len){if(65537>len&&(buf.subarray&&STR_APPLY_UIA_OK||!buf.subarray&&STR_APPLY_OK))return String.fromCharCode.apply(null,utils.shrinkBuf(buf,len));for(var result="",i=0;len>i;i++)result+=String.fromCharCode(buf[i]);return result}var utils=require("./common"),STR_APPLY_OK=!0,STR_APPLY_UIA_OK=!0;try{String.fromCharCode.apply(null,[0])}catch(__){STR_APPLY_OK=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(__){STR_APPLY_UIA_OK=!1}for(var _utf8len=new utils.Buf8(256),i=0;256>i;i++)_utf8len[i]=i>=252?6:i>=248?5:i>=240?4:i>=224?3:i>=192?2:1;_utf8len[254]=_utf8len[254]=1,exports.string2buf=function(str){var buf,c,c2,m_pos,i,str_len=str.length,buf_len=0;for(m_pos=0;str_len>m_pos;m_pos++)c=str.charCodeAt(m_pos),55296===(64512&c)&&str_len>m_pos+1&&(c2=str.charCodeAt(m_pos+1),56320===(64512&c2)&&(c=65536+(c-55296<<10)+(c2-56320),m_pos++)),buf_len+=128>c?1:2048>c?2:65536>c?3:4;for(buf=new utils.Buf8(buf_len),i=0,m_pos=0;buf_len>i;m_pos++)c=str.charCodeAt(m_pos),55296===(64512&c)&&str_len>m_pos+1&&(c2=str.charCodeAt(m_pos+1),56320===(64512&c2)&&(c=65536+(c-55296<<10)+(c2-56320),m_pos++)),128>c?buf[i++]=c:2048>c?(buf[i++]=192|c>>>6,buf[i++]=128|63&c):65536>c?(buf[i++]=224|c>>>12,buf[i++]=128|c>>>6&63,buf[i++]=128|63&c):(buf[i++]=240|c>>>18,buf[i++]=128|c>>>12&63,buf[i++]=128|c>>>6&63,buf[i++]=128|63&c);return buf},exports.buf2binstring=function(buf){return buf2binstring(buf,buf.length)},exports.binstring2buf=function(str){for(var buf=new utils.Buf8(str.length),i=0,len=buf.length;len>i;i++)buf[i]=str.charCodeAt(i);return buf},exports.buf2string=function(buf,max){var i,out,c,c_len,len=max||buf.length,utf16buf=new Array(2*len);for(out=0,i=0;len>i;)if(c=buf[i++],128>c)utf16buf[out++]=c;else if(c_len=_utf8len[c],c_len>4)utf16buf[out++]=65533,i+=c_len-1;else{for(c&=2===c_len?31:3===c_len?15:7;c_len>1&&len>i;)c=c<<6|63&buf[i++],c_len--;c_len>1?utf16buf[out++]=65533:65536>c?utf16buf[out++]=c:(c-=65536,utf16buf[out++]=55296|c>>10&1023,utf16buf[out++]=56320|1023&c)}return buf2binstring(utf16buf,out)},exports.utf8border=function(buf,max){var pos;for(max=max||buf.length,max>buf.length&&(max=buf.length),pos=max-1;pos>=0&&128===(192&buf[pos]);)pos--;return 0>pos?max:0===pos?max:pos+_utf8len[buf[pos]]>max?pos:max}},{"./common":98}],100:[function(require,module){"use strict";function adler32(adler,buf,len,pos){for(var s1=65535&adler|0,s2=adler>>>16&65535|0,n=0;0!==len;){n=len>2e3?2e3:len,len-=n;do s1=s1+buf[pos++]|0,s2=s2+s1|0;while(--n);s1%=65521,s2%=65521}return s1|s2<<16|0}module.exports=adler32},{}],101:[function(require,module){module.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],102:[function(require,module){"use strict";function makeTable(){for(var c,table=[],n=0;256>n;n++){c=n;for(var k=0;8>k;k++)c=1&c?3988292384^c>>>1:c>>>1;table[n]=c}return table}function crc32(crc,buf,len,pos){var t=crcTable,end=pos+len;crc=-1^crc;for(var i=pos;end>i;i++)crc=crc>>>8^t[255&(crc^buf[i])];return-1^crc}var crcTable=makeTable();module.exports=crc32},{}],103:[function(require,module,exports){"use strict";function err(strm,errorCode){return strm.msg=msg[errorCode],errorCode}function rank(f){return(f<<1)-(f>4?9:0)}function zero(buf){for(var len=buf.length;--len>=0;)buf[len]=0}function flush_pending(strm){var s=strm.state,len=s.pending;len>strm.avail_out&&(len=strm.avail_out),0!==len&&(utils.arraySet(strm.output,s.pending_buf,s.pending_out,len,strm.next_out),strm.next_out+=len,s.pending_out+=len,strm.total_out+=len,strm.avail_out-=len,s.pending-=len,0===s.pending&&(s.pending_out=0))}function flush_block_only(s,last){trees._tr_flush_block(s,s.block_start>=0?s.block_start:-1,s.strstart-s.block_start,last),s.block_start=s.strstart,flush_pending(s.strm)}function put_byte(s,b){s.pending_buf[s.pending++]=b}function putShortMSB(s,b){s.pending_buf[s.pending++]=b>>>8&255,s.pending_buf[s.pending++]=255&b}function read_buf(strm,buf,start,size){var len=strm.avail_in;return len>size&&(len=size),0===len?0:(strm.avail_in-=len,utils.arraySet(buf,strm.input,strm.next_in,len,start),1===strm.state.wrap?strm.adler=adler32(strm.adler,buf,len,start):2===strm.state.wrap&&(strm.adler=crc32(strm.adler,buf,len,start)),strm.next_in+=len,strm.total_in+=len,len)}function longest_match(s,cur_match){var match,len,chain_length=s.max_chain_length,scan=s.strstart,best_len=s.prev_length,nice_match=s.nice_match,limit=s.strstart>s.w_size-MIN_LOOKAHEAD?s.strstart-(s.w_size-MIN_LOOKAHEAD):0,_win=s.window,wmask=s.w_mask,prev=s.prev,strend=s.strstart+MAX_MATCH,scan_end1=_win[scan+best_len-1],scan_end=_win[scan+best_len];s.prev_length>=s.good_match&&(chain_length>>=2),nice_match>s.lookahead&&(nice_match=s.lookahead);do if(match=cur_match,_win[match+best_len]===scan_end&&_win[match+best_len-1]===scan_end1&&_win[match]===_win[scan]&&_win[++match]===_win[scan+1]){scan+=2,match++;do;while(_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&strend>scan);if(len=MAX_MATCH-(strend-scan),scan=strend-MAX_MATCH,len>best_len){if(s.match_start=cur_match,best_len=len,len>=nice_match)break;scan_end1=_win[scan+best_len-1],scan_end=_win[scan+best_len]}}while((cur_match=prev[cur_match&wmask])>limit&&0!==--chain_length);return best_len<=s.lookahead?best_len:s.lookahead}function fill_window(s){var p,n,m,more,str,_w_size=s.w_size;do{if(more=s.window_size-s.lookahead-s.strstart,s.strstart>=_w_size+(_w_size-MIN_LOOKAHEAD)){utils.arraySet(s.window,s.window,_w_size,_w_size,0),s.match_start-=_w_size,s.strstart-=_w_size,s.block_start-=_w_size,n=s.hash_size,p=n;do m=s.head[--p],s.head[p]=m>=_w_size?m-_w_size:0;while(--n);n=_w_size,p=n;do m=s.prev[--p],s.prev[p]=m>=_w_size?m-_w_size:0;while(--n);more+=_w_size}if(0===s.strm.avail_in)break;if(n=read_buf(s.strm,s.window,s.strstart+s.lookahead,more),s.lookahead+=n,s.lookahead+s.insert>=MIN_MATCH)for(str=s.strstart-s.insert,s.ins_h=s.window[str],s.ins_h=(s.ins_h<s.pending_buf_size-5&&(max_block_size=s.pending_buf_size-5);;){if(s.lookahead<=1){if(fill_window(s),0===s.lookahead&&flush===Z_NO_FLUSH)return BS_NEED_MORE;if(0===s.lookahead)break}s.strstart+=s.lookahead,s.lookahead=0;var max_start=s.block_start+max_block_size;if((0===s.strstart||s.strstart>=max_start)&&(s.lookahead=s.strstart-max_start,s.strstart=max_start,flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE;if(s.strstart-s.block_start>=s.w_size-MIN_LOOKAHEAD&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.strstart>s.block_start&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_NEED_MORE}function deflate_fast(s,flush){for(var hash_head,bflush;;){if(s.lookahead=MIN_MATCH&&(s.ins_h=(s.ins_h<=MIN_MATCH)if(bflush=trees._tr_tally(s,s.strstart-s.match_start,s.match_length-MIN_MATCH),s.lookahead-=s.match_length,s.match_length<=s.max_lazy_match&&s.lookahead>=MIN_MATCH){s.match_length--;do s.strstart++,s.ins_h=(s.ins_h<=MIN_MATCH&&(s.ins_h=(s.ins_h<4096)&&(s.match_length=MIN_MATCH-1)),s.prev_length>=MIN_MATCH&&s.match_length<=s.prev_length){max_insert=s.strstart+s.lookahead-MIN_MATCH,bflush=trees._tr_tally(s,s.strstart-1-s.prev_match,s.prev_length-MIN_MATCH),s.lookahead-=s.prev_length-1,s.prev_length-=2;do++s.strstart<=max_insert&&(s.ins_h=(s.ins_h<=MIN_MATCH&&s.strstart>0&&(scan=s.strstart-1,prev=_win[scan],prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan])){strend=s.strstart+MAX_MATCH;do;while(prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&strend>scan);s.match_length=MAX_MATCH-(strend-scan),s.match_length>s.lookahead&&(s.match_length=s.lookahead)}if(s.match_length>=MIN_MATCH?(bflush=trees._tr_tally(s,1,s.match_length-MIN_MATCH),s.lookahead-=s.match_length,s.strstart+=s.match_length,s.match_length=0):(bflush=trees._tr_tally(s,0,s.window[s.strstart]),s.lookahead--,s.strstart++),bflush&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.last_lit&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE}function deflate_huff(s,flush){for(var bflush;;){if(0===s.lookahead&&(fill_window(s),0===s.lookahead)){if(flush===Z_NO_FLUSH)return BS_NEED_MORE;break}if(s.match_length=0,bflush=trees._tr_tally(s,0,s.window[s.strstart]),s.lookahead--,s.strstart++,bflush&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.last_lit&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE}function lm_init(s){s.window_size=2*s.w_size,zero(s.head),s.max_lazy_match=configuration_table[s.level].max_lazy,s.good_match=configuration_table[s.level].good_length,s.nice_match=configuration_table[s.level].nice_length,s.max_chain_length=configuration_table[s.level].max_chain,s.strstart=0,s.block_start=0,s.lookahead=0,s.insert=0,s.match_length=s.prev_length=MIN_MATCH-1,s.match_available=0,s.ins_h=0}function DeflateState(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Z_DEFLATED,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new utils.Buf16(2*HEAP_SIZE),this.dyn_dtree=new utils.Buf16(2*(2*D_CODES+1)),this.bl_tree=new utils.Buf16(2*(2*BL_CODES+1)),zero(this.dyn_ltree),zero(this.dyn_dtree),zero(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new utils.Buf16(MAX_BITS+1),this.heap=new utils.Buf16(2*L_CODES+1),zero(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new utils.Buf16(2*L_CODES+1),zero(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function deflateResetKeep(strm){var s;return strm&&strm.state?(strm.total_in=strm.total_out=0,strm.data_type=Z_UNKNOWN,s=strm.state,s.pending=0,s.pending_out=0,s.wrap<0&&(s.wrap=-s.wrap),s.status=s.wrap?INIT_STATE:BUSY_STATE,strm.adler=2===s.wrap?0:1,s.last_flush=Z_NO_FLUSH,trees._tr_init(s),Z_OK):err(strm,Z_STREAM_ERROR)}function deflateReset(strm){var ret=deflateResetKeep(strm);return ret===Z_OK&&lm_init(strm.state),ret}function deflateSetHeader(strm,head){return strm&&strm.state?2!==strm.state.wrap?Z_STREAM_ERROR:(strm.state.gzhead=head,Z_OK):Z_STREAM_ERROR}function deflateInit2(strm,level,method,windowBits,memLevel,strategy){if(!strm)return Z_STREAM_ERROR;var wrap=1;if(level===Z_DEFAULT_COMPRESSION&&(level=6),0>windowBits?(wrap=0,windowBits=-windowBits):windowBits>15&&(wrap=2,windowBits-=16),1>memLevel||memLevel>MAX_MEM_LEVEL||method!==Z_DEFLATED||8>windowBits||windowBits>15||0>level||level>9||0>strategy||strategy>Z_FIXED)return err(strm,Z_STREAM_ERROR);8===windowBits&&(windowBits=9);var s=new DeflateState;return strm.state=s,s.strm=strm,s.wrap=wrap,s.gzhead=null,s.w_bits=windowBits,s.w_size=1<>1,s.l_buf=3*s.lit_bufsize,s.level=level,s.strategy=strategy,s.method=method,deflateReset(strm) +}function deflateInit(strm,level){return deflateInit2(strm,level,Z_DEFLATED,MAX_WBITS,DEF_MEM_LEVEL,Z_DEFAULT_STRATEGY)}function deflate(strm,flush){var old_flush,s,beg,val;if(!strm||!strm.state||flush>Z_BLOCK||0>flush)return strm?err(strm,Z_STREAM_ERROR):Z_STREAM_ERROR;if(s=strm.state,!strm.output||!strm.input&&0!==strm.avail_in||s.status===FINISH_STATE&&flush!==Z_FINISH)return err(strm,0===strm.avail_out?Z_BUF_ERROR:Z_STREAM_ERROR);if(s.strm=strm,old_flush=s.last_flush,s.last_flush=flush,s.status===INIT_STATE)if(2===s.wrap)strm.adler=0,put_byte(s,31),put_byte(s,139),put_byte(s,8),s.gzhead?(put_byte(s,(s.gzhead.text?1:0)+(s.gzhead.hcrc?2:0)+(s.gzhead.extra?4:0)+(s.gzhead.name?8:0)+(s.gzhead.comment?16:0)),put_byte(s,255&s.gzhead.time),put_byte(s,s.gzhead.time>>8&255),put_byte(s,s.gzhead.time>>16&255),put_byte(s,s.gzhead.time>>24&255),put_byte(s,9===s.level?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0),put_byte(s,255&s.gzhead.os),s.gzhead.extra&&s.gzhead.extra.length&&(put_byte(s,255&s.gzhead.extra.length),put_byte(s,s.gzhead.extra.length>>8&255)),s.gzhead.hcrc&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending,0)),s.gzindex=0,s.status=EXTRA_STATE):(put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,9===s.level?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0),put_byte(s,OS_CODE),s.status=BUSY_STATE);else{var header=Z_DEFLATED+(s.w_bits-8<<4)<<8,level_flags=-1;level_flags=s.strategy>=Z_HUFFMAN_ONLY||s.level<2?0:s.level<6?1:6===s.level?2:3,header|=level_flags<<6,0!==s.strstart&&(header|=PRESET_DICT),header+=31-header%31,s.status=BUSY_STATE,putShortMSB(s,header),0!==s.strstart&&(putShortMSB(s,strm.adler>>>16),putShortMSB(s,65535&strm.adler)),strm.adler=1}if(s.status===EXTRA_STATE)if(s.gzhead.extra){for(beg=s.pending;s.gzindex<(65535&s.gzhead.extra.length)&&(s.pending!==s.pending_buf_size||(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending!==s.pending_buf_size));)put_byte(s,255&s.gzhead.extra[s.gzindex]),s.gzindex++;s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),s.gzindex===s.gzhead.extra.length&&(s.gzindex=0,s.status=NAME_STATE)}else s.status=NAME_STATE;if(s.status===NAME_STATE)if(s.gzhead.name){beg=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending===s.pending_buf_size)){val=1;break}val=s.gzindexbeg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),0===val&&(s.gzindex=0,s.status=COMMENT_STATE)}else s.status=COMMENT_STATE;if(s.status===COMMENT_STATE)if(s.gzhead.comment){beg=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending===s.pending_buf_size)){val=1;break}val=s.gzindexbeg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),0===val&&(s.status=HCRC_STATE)}else s.status=HCRC_STATE;if(s.status===HCRC_STATE&&(s.gzhead.hcrc?(s.pending+2>s.pending_buf_size&&flush_pending(strm),s.pending+2<=s.pending_buf_size&&(put_byte(s,255&strm.adler),put_byte(s,strm.adler>>8&255),strm.adler=0,s.status=BUSY_STATE)):s.status=BUSY_STATE),0!==s.pending){if(flush_pending(strm),0===strm.avail_out)return s.last_flush=-1,Z_OK}else if(0===strm.avail_in&&rank(flush)<=rank(old_flush)&&flush!==Z_FINISH)return err(strm,Z_BUF_ERROR);if(s.status===FINISH_STATE&&0!==strm.avail_in)return err(strm,Z_BUF_ERROR);if(0!==strm.avail_in||0!==s.lookahead||flush!==Z_NO_FLUSH&&s.status!==FINISH_STATE){var bstate=s.strategy===Z_HUFFMAN_ONLY?deflate_huff(s,flush):s.strategy===Z_RLE?deflate_rle(s,flush):configuration_table[s.level].func(s,flush);if((bstate===BS_FINISH_STARTED||bstate===BS_FINISH_DONE)&&(s.status=FINISH_STATE),bstate===BS_NEED_MORE||bstate===BS_FINISH_STARTED)return 0===strm.avail_out&&(s.last_flush=-1),Z_OK;if(bstate===BS_BLOCK_DONE&&(flush===Z_PARTIAL_FLUSH?trees._tr_align(s):flush!==Z_BLOCK&&(trees._tr_stored_block(s,0,0,!1),flush===Z_FULL_FLUSH&&(zero(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),flush_pending(strm),0===strm.avail_out))return s.last_flush=-1,Z_OK}return flush!==Z_FINISH?Z_OK:s.wrap<=0?Z_STREAM_END:(2===s.wrap?(put_byte(s,255&strm.adler),put_byte(s,strm.adler>>8&255),put_byte(s,strm.adler>>16&255),put_byte(s,strm.adler>>24&255),put_byte(s,255&strm.total_in),put_byte(s,strm.total_in>>8&255),put_byte(s,strm.total_in>>16&255),put_byte(s,strm.total_in>>24&255)):(putShortMSB(s,strm.adler>>>16),putShortMSB(s,65535&strm.adler)),flush_pending(strm),s.wrap>0&&(s.wrap=-s.wrap),0!==s.pending?Z_OK:Z_STREAM_END)}function deflateEnd(strm){var status;return strm&&strm.state?(status=strm.state.status,status!==INIT_STATE&&status!==EXTRA_STATE&&status!==NAME_STATE&&status!==COMMENT_STATE&&status!==HCRC_STATE&&status!==BUSY_STATE&&status!==FINISH_STATE?err(strm,Z_STREAM_ERROR):(strm.state=null,status===BUSY_STATE?err(strm,Z_DATA_ERROR):Z_OK)):Z_STREAM_ERROR}var configuration_table,utils=require("../utils/common"),trees=require("./trees"),adler32=require("./adler32"),crc32=require("./crc32"),msg=require("./messages"),Z_NO_FLUSH=0,Z_PARTIAL_FLUSH=1,Z_FULL_FLUSH=3,Z_FINISH=4,Z_BLOCK=5,Z_OK=0,Z_STREAM_END=1,Z_STREAM_ERROR=-2,Z_DATA_ERROR=-3,Z_BUF_ERROR=-5,Z_DEFAULT_COMPRESSION=-1,Z_FILTERED=1,Z_HUFFMAN_ONLY=2,Z_RLE=3,Z_FIXED=4,Z_DEFAULT_STRATEGY=0,Z_UNKNOWN=2,Z_DEFLATED=8,MAX_MEM_LEVEL=9,MAX_WBITS=15,DEF_MEM_LEVEL=8,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,MIN_MATCH=3,MAX_MATCH=258,MIN_LOOKAHEAD=MAX_MATCH+MIN_MATCH+1,PRESET_DICT=32,INIT_STATE=42,EXTRA_STATE=69,NAME_STATE=73,COMMENT_STATE=91,HCRC_STATE=103,BUSY_STATE=113,FINISH_STATE=666,BS_NEED_MORE=1,BS_BLOCK_DONE=2,BS_FINISH_STARTED=3,BS_FINISH_DONE=4,OS_CODE=3,Config=function(good_length,max_lazy,nice_length,max_chain,func){this.good_length=good_length,this.max_lazy=max_lazy,this.nice_length=nice_length,this.max_chain=max_chain,this.func=func};configuration_table=[new Config(0,0,0,0,deflate_stored),new Config(4,4,8,4,deflate_fast),new Config(4,5,16,8,deflate_fast),new Config(4,6,32,32,deflate_fast),new Config(4,4,16,16,deflate_slow),new Config(8,16,32,32,deflate_slow),new Config(8,16,128,128,deflate_slow),new Config(8,32,128,256,deflate_slow),new Config(32,128,258,1024,deflate_slow),new Config(32,258,258,4096,deflate_slow)],exports.deflateInit=deflateInit,exports.deflateInit2=deflateInit2,exports.deflateReset=deflateReset,exports.deflateResetKeep=deflateResetKeep,exports.deflateSetHeader=deflateSetHeader,exports.deflate=deflate,exports.deflateEnd=deflateEnd,exports.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":98,"./adler32":100,"./crc32":102,"./messages":108,"./trees":109}],104:[function(require,module){"use strict";function GZheader(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}module.exports=GZheader},{}],105:[function(require,module){"use strict";var BAD=30,TYPE=12;module.exports=function(strm,start){var state,_in,last,_out,beg,end,dmax,wsize,whave,wnext,window,hold,bits,lcode,dcode,lmask,dmask,here,op,len,dist,from,from_source,input,output;state=strm.state,_in=strm.next_in,input=strm.input,last=_in+(strm.avail_in-5),_out=strm.next_out,output=strm.output,beg=_out-(start-strm.avail_out),end=_out+(strm.avail_out-257),dmax=state.dmax,wsize=state.wsize,whave=state.whave,wnext=state.wnext,window=state.window,hold=state.hold,bits=state.bits,lcode=state.lencode,dcode=state.distcode,lmask=(1<bits&&(hold+=input[_in++]<>>24,hold>>>=op,bits-=op,op=here>>>16&255,0===op)output[_out++]=65535&here;else{if(!(16&op)){if(0===(64&op)){here=lcode[(65535&here)+(hold&(1<bits&&(hold+=input[_in++]<>>=op,bits-=op),15>bits&&(hold+=input[_in++]<>>24,hold>>>=op,bits-=op,op=here>>>16&255,!(16&op)){if(0===(64&op)){here=dcode[(65535&here)+(hold&(1<bits&&(hold+=input[_in++]<bits&&(hold+=input[_in++]<dmax){strm.msg="invalid distance too far back",state.mode=BAD;break top}if(hold>>>=op,bits-=op,op=_out-beg,dist>op){if(op=dist-op,op>whave&&state.sane){strm.msg="invalid distance too far back",state.mode=BAD;break top}if(from=0,from_source=window,0===wnext){if(from+=wsize-op,len>op){len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}}else if(op>wnext){if(from+=wsize+wnext-op,op-=wnext,len>op){len-=op;do output[_out++]=window[from++];while(--op);if(from=0,len>wnext){op=wnext,len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}}}else if(from+=wnext-op,len>op){len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}for(;len>2;)output[_out++]=from_source[from++],output[_out++]=from_source[from++],output[_out++]=from_source[from++],len-=3;len&&(output[_out++]=from_source[from++],len>1&&(output[_out++]=from_source[from++]))}else{from=_out-dist;do output[_out++]=output[from++],output[_out++]=output[from++],output[_out++]=output[from++],len-=3;while(len>2);len&&(output[_out++]=output[from++],len>1&&(output[_out++]=output[from++]))}break}}break}}while(last>_in&&end>_out);len=bits>>3,_in-=len,bits-=len<<3,hold&=(1<_in?5+(last-_in):5-(_in-last),strm.avail_out=end>_out?257+(end-_out):257-(_out-end),state.hold=hold,state.bits=bits}},{}],106:[function(require,module,exports){"use strict";function ZSWAP32(q){return(q>>>24&255)+(q>>>8&65280)+((65280&q)<<8)+((255&q)<<24)}function InflateState(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new utils.Buf16(320),this.work=new utils.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function inflateResetKeep(strm){var state;return strm&&strm.state?(state=strm.state,strm.total_in=strm.total_out=state.total=0,strm.msg="",state.wrap&&(strm.adler=1&state.wrap),state.mode=HEAD,state.last=0,state.havedict=0,state.dmax=32768,state.head=null,state.hold=0,state.bits=0,state.lencode=state.lendyn=new utils.Buf32(ENOUGH_LENS),state.distcode=state.distdyn=new utils.Buf32(ENOUGH_DISTS),state.sane=1,state.back=-1,Z_OK):Z_STREAM_ERROR}function inflateReset(strm){var state;return strm&&strm.state?(state=strm.state,state.wsize=0,state.whave=0,state.wnext=0,inflateResetKeep(strm)):Z_STREAM_ERROR}function inflateReset2(strm,windowBits){var wrap,state;return strm&&strm.state?(state=strm.state,0>windowBits?(wrap=0,windowBits=-windowBits):(wrap=(windowBits>>4)+1,48>windowBits&&(windowBits&=15)),windowBits&&(8>windowBits||windowBits>15)?Z_STREAM_ERROR:(null!==state.window&&state.wbits!==windowBits&&(state.window=null),state.wrap=wrap,state.wbits=windowBits,inflateReset(strm))):Z_STREAM_ERROR}function inflateInit2(strm,windowBits){var ret,state;return strm?(state=new InflateState,strm.state=state,state.window=null,ret=inflateReset2(strm,windowBits),ret!==Z_OK&&(strm.state=null),ret):Z_STREAM_ERROR}function inflateInit(strm){return inflateInit2(strm,DEF_WBITS)}function fixedtables(state){if(virgin){var sym;for(lenfix=new utils.Buf32(512),distfix=new utils.Buf32(32),sym=0;144>sym;)state.lens[sym++]=8;for(;256>sym;)state.lens[sym++]=9;for(;280>sym;)state.lens[sym++]=7;for(;288>sym;)state.lens[sym++]=8;for(inflate_table(LENS,state.lens,0,288,lenfix,0,state.work,{bits:9}),sym=0;32>sym;)state.lens[sym++]=5;inflate_table(DISTS,state.lens,0,32,distfix,0,state.work,{bits:5}),virgin=!1}state.lencode=lenfix,state.lenbits=9,state.distcode=distfix,state.distbits=5}function updatewindow(strm,src,end,copy){var dist,state=strm.state;return null===state.window&&(state.wsize=1<=state.wsize?(utils.arraySet(state.window,src,end-state.wsize,state.wsize,0),state.wnext=0,state.whave=state.wsize):(dist=state.wsize-state.wnext,dist>copy&&(dist=copy),utils.arraySet(state.window,src,end-copy,dist,state.wnext),copy-=dist,copy?(utils.arraySet(state.window,src,end-copy,copy,0),state.wnext=copy,state.whave=state.wsize):(state.wnext+=dist,state.wnext===state.wsize&&(state.wnext=0),state.whavebits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,state.check=crc32(state.check,hbuf,2,0),hold=0,bits=0,state.mode=FLAGS;break}if(state.flags=0,state.head&&(state.head.done=!1),!(1&state.wrap)||(((255&hold)<<8)+(hold>>8))%31){strm.msg="incorrect header check",state.mode=BAD;break}if((15&hold)!==Z_DEFLATED){strm.msg="unknown compression method",state.mode=BAD;break}if(hold>>>=4,bits-=4,len=(15&hold)+8,0===state.wbits)state.wbits=len;else if(len>state.wbits){strm.msg="invalid window size",state.mode=BAD;break}state.dmax=1<bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>8&1),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=TIME;case TIME:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,hbuf[2]=hold>>>16&255,hbuf[3]=hold>>>24&255,state.check=crc32(state.check,hbuf,4,0)),hold=0,bits=0,state.mode=OS;case OS:for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>8),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=EXLEN;case EXLEN:if(1024&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0}else state.head&&(state.head.extra=null);state.mode=EXTRA;case EXTRA:if(1024&state.flags&&(copy=state.length,copy>have&&(copy=have),copy&&(state.head&&(len=state.head.extra_len-state.length,state.head.extra||(state.head.extra=new Array(state.head.extra_len)),utils.arraySet(state.head.extra,input,next,copy,len)),512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,state.length-=copy),state.length))break inf_leave;state.length=0,state.mode=NAME;case NAME:if(2048&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.name+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.name=null);state.length=0,state.mode=COMMENT;case COMMENT:if(4096&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.comment+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.comment=null);state.mode=HCRC;case HCRC:if(512&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>9&1,state.head.done=!0),strm.adler=state.check=0,state.mode=TYPE;break;case DICTID:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=7&bits,bits-=7&bits,state.mode=CHECK;break}for(;3>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=1,bits-=1,3&hold){case 0:state.mode=STORED;break;case 1:if(fixedtables(state),state.mode=LEN_,flush===Z_TREES){hold>>>=2,bits-=2;break inf_leave}break;case 2:state.mode=TABLE;break;case 3:strm.msg="invalid block type",state.mode=BAD}hold>>>=2,bits-=2;break;case STORED:for(hold>>>=7&bits,bits-=7&bits;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>16^65535)){strm.msg="invalid stored block lengths",state.mode=BAD;break}if(state.length=65535&hold,hold=0,bits=0,state.mode=COPY_,flush===Z_TREES)break inf_leave;case COPY_:state.mode=COPY;case COPY:if(copy=state.length){if(copy>have&&(copy=have),copy>left&&(copy=left),0===copy)break inf_leave;utils.arraySet(output,input,next,copy,put),have-=copy,next+=copy,left-=copy,put+=copy,state.length-=copy;break}state.mode=TYPE;break;case TABLE:for(;14>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=5,bits-=5,state.ndist=(31&hold)+1,hold>>>=5,bits-=5,state.ncode=(15&hold)+4,hold>>>=4,bits-=4,state.nlen>286||state.ndist>30){strm.msg="too many length or distance symbols",state.mode=BAD;break}state.have=0,state.mode=LENLENS;case LENLENS:for(;state.havebits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=3,bits-=3}for(;state.have<19;)state.lens[order[state.have++]]=0;if(state.lencode=state.lendyn,state.lenbits=7,opts={bits:state.lenbits},ret=inflate_table(CODES,state.lens,0,19,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid code lengths set",state.mode=BAD;break}state.have=0,state.mode=CODELENS;case CODELENS:for(;state.have>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<here_val)hold>>>=here_bits,bits-=here_bits,state.lens[state.have++]=here_val;else{if(16===here_val){for(n=here_bits+2;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,0===state.have){strm.msg="invalid bit length repeat",state.mode=BAD;break}len=state.lens[state.have-1],copy=3+(3&hold),hold>>>=2,bits-=2}else if(17===here_val){for(n=here_bits+3;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=3+(7&hold),hold>>>=3,bits-=3}else{for(n=here_bits+7;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=11+(127&hold),hold>>>=7,bits-=7}if(state.have+copy>state.nlen+state.ndist){strm.msg="invalid bit length repeat",state.mode=BAD;break}for(;copy--;)state.lens[state.have++]=len}}if(state.mode===BAD)break;if(0===state.lens[256]){strm.msg="invalid code -- missing end-of-block",state.mode=BAD;break}if(state.lenbits=9,opts={bits:state.lenbits},ret=inflate_table(LENS,state.lens,0,state.nlen,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid literal/lengths set",state.mode=BAD;break}if(state.distbits=6,state.distcode=state.distdyn,opts={bits:state.distbits},ret=inflate_table(DISTS,state.lens,state.nlen,state.ndist,state.distcode,0,state.work,opts),state.distbits=opts.bits,ret){strm.msg="invalid distances set",state.mode=BAD;break}if(state.mode=LEN_,flush===Z_TREES)break inf_leave;case LEN_:state.mode=LEN;case LEN:if(have>=6&&left>=258){strm.next_out=put,strm.avail_out=left,strm.next_in=next,strm.avail_in=have,state.hold=hold,state.bits=bits,inflate_fast(strm,_out),put=strm.next_out,output=strm.output,left=strm.avail_out,next=strm.next_in,input=strm.input,have=strm.avail_in,hold=state.hold,bits=state.bits,state.mode===TYPE&&(state.back=-1);break}for(state.back=0;here=state.lencode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,state.length=here_val,0===here_op){state.mode=LIT;break}if(32&here_op){state.back=-1,state.mode=TYPE;break}if(64&here_op){strm.msg="invalid literal/length code",state.mode=BAD;break}state.extra=15&here_op,state.mode=LENEXT;case LENEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}state.was=state.length,state.mode=DIST;case DIST:for(;here=state.distcode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,64&here_op){strm.msg="invalid distance code",state.mode=BAD;break}state.offset=here_val,state.extra=15&here_op,state.mode=DISTEXT;case DISTEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}if(state.offset>state.dmax){strm.msg="invalid distance too far back",state.mode=BAD;break}state.mode=MATCH;case MATCH:if(0===left)break inf_leave;if(copy=_out-left,state.offset>copy){if(copy=state.offset-copy,copy>state.whave&&state.sane){strm.msg="invalid distance too far back",state.mode=BAD;break}copy>state.wnext?(copy-=state.wnext,from=state.wsize-copy):from=state.wnext-copy,copy>state.length&&(copy=state.length),from_source=state.window}else from_source=output,from=put-state.offset,copy=state.length;copy>left&&(copy=left),left-=copy,state.length-=copy;do output[put++]=from_source[from++];while(--copy);0===state.length&&(state.mode=LEN);break;case LIT:if(0===left)break inf_leave;output[put++]=state.length,left--,state.mode=LEN;break;case CHECK:if(state.wrap){for(;32>bits;){if(0===have)break inf_leave;have--,hold|=input[next++]<bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<=len;len++)count[len]=0;for(sym=0;codes>sym;sym++)count[lens[lens_index+sym]]++;for(root=bits,max=MAXBITS;max>=1&&0===count[max];max--);if(root>max&&(root=max),0===max)return table[table_index++]=20971520,table[table_index++]=20971520,opts.bits=1,0;for(min=1;max>min&&0===count[min];min++);for(min>root&&(root=min),left=1,len=1;MAXBITS>=len;len++)if(left<<=1,left-=count[len],0>left)return-1;if(left>0&&(type===CODES||1!==max))return-1;for(offs[1]=0,len=1;MAXBITS>len;len++)offs[len+1]=offs[len]+count[len];for(sym=0;codes>sym;sym++)0!==lens[lens_index+sym]&&(work[offs[lens[lens_index+sym]]++]=sym);if(type===CODES?(base=extra=work,end=19):type===LENS?(base=lbase,base_index-=257,extra=lext,extra_index-=257,end=256):(base=dbase,extra=dext,end=-1),huff=0,sym=0,len=min,next=table_index,curr=root,drop=0,low=-1,used=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;for(var i=0;;){i++,here_bits=len-drop,work[sym]end?(here_op=extra[extra_index+work[sym]],here_val=base[base_index+work[sym]]):(here_op=96,here_val=0),incr=1<>drop)+fill]=here_bits<<24|here_op<<16|here_val|0;while(0!==fill);for(incr=1<>=1;if(0!==incr?(huff&=incr-1,huff+=incr):huff=0,sym++,0===--count[len]){if(len===max)break;len=lens[lens_index+work[sym]]}if(len>root&&(huff&mask)!==low){for(0===drop&&(drop=root),next+=min,curr=len-drop,left=1<curr+drop&&(left-=count[curr+drop],!(0>=left));)curr++,left<<=1;if(used+=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;low=huff&mask,table[low]=root<<24|curr<<16|next-table_index|0}}return 0!==huff&&(table[next+huff]=len-drop<<24|64<<16|0),opts.bits=root,0}},{"../utils/common":98}],108:[function(require,module){"use strict";module.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],109:[function(require,module,exports){"use strict";function zero(buf){for(var len=buf.length;--len>=0;)buf[len]=0}function d_code(dist){return 256>dist?_dist_code[dist]:_dist_code[256+(dist>>>7)]}function put_short(s,w){s.pending_buf[s.pending++]=255&w,s.pending_buf[s.pending++]=w>>>8&255}function send_bits(s,value,length){s.bi_valid>Buf_size-length?(s.bi_buf|=value<>Buf_size-s.bi_valid,s.bi_valid+=length-Buf_size):(s.bi_buf|=value<>>=1,res<<=1;while(--len>0);return res>>>1}function bi_flush(s){16===s.bi_valid?(put_short(s,s.bi_buf),s.bi_buf=0,s.bi_valid=0):s.bi_valid>=8&&(s.pending_buf[s.pending++]=255&s.bi_buf,s.bi_buf>>=8,s.bi_valid-=8)}function gen_bitlen(s,desc){var h,n,m,bits,xbits,f,tree=desc.dyn_tree,max_code=desc.max_code,stree=desc.stat_desc.static_tree,has_stree=desc.stat_desc.has_stree,extra=desc.stat_desc.extra_bits,base=desc.stat_desc.extra_base,max_length=desc.stat_desc.max_length,overflow=0; +for(bits=0;MAX_BITS>=bits;bits++)s.bl_count[bits]=0;for(tree[2*s.heap[s.heap_max]+1]=0,h=s.heap_max+1;HEAP_SIZE>h;h++)n=s.heap[h],bits=tree[2*tree[2*n+1]+1]+1,bits>max_length&&(bits=max_length,overflow++),tree[2*n+1]=bits,n>max_code||(s.bl_count[bits]++,xbits=0,n>=base&&(xbits=extra[n-base]),f=tree[2*n],s.opt_len+=f*(bits+xbits),has_stree&&(s.static_len+=f*(stree[2*n+1]+xbits)));if(0!==overflow){do{for(bits=max_length-1;0===s.bl_count[bits];)bits--;s.bl_count[bits]--,s.bl_count[bits+1]+=2,s.bl_count[max_length]--,overflow-=2}while(overflow>0);for(bits=max_length;0!==bits;bits--)for(n=s.bl_count[bits];0!==n;)m=s.heap[--h],m>max_code||(tree[2*m+1]!==bits&&(s.opt_len+=(bits-tree[2*m+1])*tree[2*m],tree[2*m+1]=bits),n--)}}function gen_codes(tree,max_code,bl_count){var bits,n,next_code=new Array(MAX_BITS+1),code=0;for(bits=1;MAX_BITS>=bits;bits++)next_code[bits]=code=code+bl_count[bits-1]<<1;for(n=0;max_code>=n;n++){var len=tree[2*n+1];0!==len&&(tree[2*n]=bi_reverse(next_code[len]++,len))}}function tr_static_init(){var n,bits,length,code,dist,bl_count=new Array(MAX_BITS+1);for(length=0,code=0;LENGTH_CODES-1>code;code++)for(base_length[code]=length,n=0;n<1<code;code++)for(base_dist[code]=dist,n=0;n<1<>=7;D_CODES>code;code++)for(base_dist[code]=dist<<7,n=0;n<1<=bits;bits++)bl_count[bits]=0;for(n=0;143>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(;255>=n;)static_ltree[2*n+1]=9,n++,bl_count[9]++;for(;279>=n;)static_ltree[2*n+1]=7,n++,bl_count[7]++;for(;287>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(gen_codes(static_ltree,L_CODES+1,bl_count),n=0;D_CODES>n;n++)static_dtree[2*n+1]=5,static_dtree[2*n]=bi_reverse(n,5);static_l_desc=new StaticTreeDesc(static_ltree,extra_lbits,LITERALS+1,L_CODES,MAX_BITS),static_d_desc=new StaticTreeDesc(static_dtree,extra_dbits,0,D_CODES,MAX_BITS),static_bl_desc=new StaticTreeDesc(new Array(0),extra_blbits,0,BL_CODES,MAX_BL_BITS)}function init_block(s){var n;for(n=0;L_CODES>n;n++)s.dyn_ltree[2*n]=0;for(n=0;D_CODES>n;n++)s.dyn_dtree[2*n]=0;for(n=0;BL_CODES>n;n++)s.bl_tree[2*n]=0;s.dyn_ltree[2*END_BLOCK]=1,s.opt_len=s.static_len=0,s.last_lit=s.matches=0}function bi_windup(s){s.bi_valid>8?put_short(s,s.bi_buf):s.bi_valid>0&&(s.pending_buf[s.pending++]=s.bi_buf),s.bi_buf=0,s.bi_valid=0}function copy_block(s,buf,len,header){bi_windup(s),header&&(put_short(s,len),put_short(s,~len)),utils.arraySet(s.pending_buf,s.window,buf,len,s.pending),s.pending+=len}function smaller(tree,n,m,depth){var _n2=2*n,_m2=2*m;return tree[_n2]n;n++)0!==tree[2*n]?(s.heap[++s.heap_len]=max_code=n,s.depth[n]=0):tree[2*n+1]=0;for(;s.heap_len<2;)node=s.heap[++s.heap_len]=2>max_code?++max_code:0,tree[2*node]=1,s.depth[node]=0,s.opt_len--,has_stree&&(s.static_len-=stree[2*node+1]);for(desc.max_code=max_code,n=s.heap_len>>1;n>=1;n--)pqdownheap(s,tree,n);node=elems;do n=s.heap[1],s.heap[1]=s.heap[s.heap_len--],pqdownheap(s,tree,1),m=s.heap[1],s.heap[--s.heap_max]=n,s.heap[--s.heap_max]=m,tree[2*node]=tree[2*n]+tree[2*m],s.depth[node]=(s.depth[n]>=s.depth[m]?s.depth[n]:s.depth[m])+1,tree[2*n+1]=tree[2*m+1]=node,s.heap[1]=node++,pqdownheap(s,tree,1);while(s.heap_len>=2);s.heap[--s.heap_max]=s.heap[1],gen_bitlen(s,desc),gen_codes(tree,max_code,s.bl_count)}function scan_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),tree[2*(max_code+1)+1]=65535,n=0;max_code>=n;n++)curlen=nextlen,nextlen=tree[2*(n+1)+1],++countcount?s.bl_tree[2*curlen]+=count:0!==curlen?(curlen!==prevlen&&s.bl_tree[2*curlen]++,s.bl_tree[2*REP_3_6]++):10>=count?s.bl_tree[2*REPZ_3_10]++:s.bl_tree[2*REPZ_11_138]++,count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4))}function send_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),n=0;max_code>=n;n++)if(curlen=nextlen,nextlen=tree[2*(n+1)+1],!(++countcount){do send_code(s,curlen,s.bl_tree);while(0!==--count)}else 0!==curlen?(curlen!==prevlen&&(send_code(s,curlen,s.bl_tree),count--),send_code(s,REP_3_6,s.bl_tree),send_bits(s,count-3,2)):10>=count?(send_code(s,REPZ_3_10,s.bl_tree),send_bits(s,count-3,3)):(send_code(s,REPZ_11_138,s.bl_tree),send_bits(s,count-11,7));count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4)}}function build_bl_tree(s){var max_blindex;for(scan_tree(s,s.dyn_ltree,s.l_desc.max_code),scan_tree(s,s.dyn_dtree,s.d_desc.max_code),build_tree(s,s.bl_desc),max_blindex=BL_CODES-1;max_blindex>=3&&0===s.bl_tree[2*bl_order[max_blindex]+1];max_blindex--);return s.opt_len+=3*(max_blindex+1)+5+5+4,max_blindex}function send_all_trees(s,lcodes,dcodes,blcodes){var rank;for(send_bits(s,lcodes-257,5),send_bits(s,dcodes-1,5),send_bits(s,blcodes-4,4),rank=0;blcodes>rank;rank++)send_bits(s,s.bl_tree[2*bl_order[rank]+1],3);send_tree(s,s.dyn_ltree,lcodes-1),send_tree(s,s.dyn_dtree,dcodes-1)}function detect_data_type(s){var n,black_mask=4093624447;for(n=0;31>=n;n++,black_mask>>>=1)if(1&black_mask&&0!==s.dyn_ltree[2*n])return Z_BINARY;if(0!==s.dyn_ltree[18]||0!==s.dyn_ltree[20]||0!==s.dyn_ltree[26])return Z_TEXT;for(n=32;LITERALS>n;n++)if(0!==s.dyn_ltree[2*n])return Z_TEXT;return Z_BINARY}function _tr_init(s){static_init_done||(tr_static_init(),static_init_done=!0),s.l_desc=new TreeDesc(s.dyn_ltree,static_l_desc),s.d_desc=new TreeDesc(s.dyn_dtree,static_d_desc),s.bl_desc=new TreeDesc(s.bl_tree,static_bl_desc),s.bi_buf=0,s.bi_valid=0,init_block(s)}function _tr_stored_block(s,buf,stored_len,last){send_bits(s,(STORED_BLOCK<<1)+(last?1:0),3),copy_block(s,buf,stored_len,!0)}function _tr_align(s){send_bits(s,STATIC_TREES<<1,3),send_code(s,END_BLOCK,static_ltree),bi_flush(s)}function _tr_flush_block(s,buf,stored_len,last){var opt_lenb,static_lenb,max_blindex=0;s.level>0?(s.strm.data_type===Z_UNKNOWN&&(s.strm.data_type=detect_data_type(s)),build_tree(s,s.l_desc),build_tree(s,s.d_desc),max_blindex=build_bl_tree(s),opt_lenb=s.opt_len+3+7>>>3,static_lenb=s.static_len+3+7>>>3,opt_lenb>=static_lenb&&(opt_lenb=static_lenb)):opt_lenb=static_lenb=stored_len+5,opt_lenb>=stored_len+4&&-1!==buf?_tr_stored_block(s,buf,stored_len,last):s.strategy===Z_FIXED||static_lenb===opt_lenb?(send_bits(s,(STATIC_TREES<<1)+(last?1:0),3),compress_block(s,static_ltree,static_dtree)):(send_bits(s,(DYN_TREES<<1)+(last?1:0),3),send_all_trees(s,s.l_desc.max_code+1,s.d_desc.max_code+1,max_blindex+1),compress_block(s,s.dyn_ltree,s.dyn_dtree)),init_block(s),last&&bi_windup(s)}function _tr_tally(s,dist,lc){return s.pending_buf[s.d_buf+2*s.last_lit]=dist>>>8&255,s.pending_buf[s.d_buf+2*s.last_lit+1]=255&dist,s.pending_buf[s.l_buf+s.last_lit]=255&lc,s.last_lit++,0===dist?s.dyn_ltree[2*lc]++:(s.matches++,dist--,s.dyn_ltree[2*(_length_code[lc]+LITERALS+1)]++,s.dyn_dtree[2*d_code(dist)]++),s.last_lit===s.lit_bufsize-1}var utils=require("../utils/common"),Z_FIXED=4,Z_BINARY=0,Z_TEXT=1,Z_UNKNOWN=2,STORED_BLOCK=0,STATIC_TREES=1,DYN_TREES=2,MIN_MATCH=3,MAX_MATCH=258,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,Buf_size=16,MAX_BL_BITS=7,END_BLOCK=256,REP_3_6=16,REPZ_3_10=17,REPZ_11_138=18,extra_lbits=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],extra_dbits=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],extra_blbits=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],bl_order=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],DIST_CODE_LEN=512,static_ltree=new Array(2*(L_CODES+2));zero(static_ltree);var static_dtree=new Array(2*D_CODES);zero(static_dtree);var _dist_code=new Array(DIST_CODE_LEN);zero(_dist_code);var _length_code=new Array(MAX_MATCH-MIN_MATCH+1);zero(_length_code);var base_length=new Array(LENGTH_CODES);zero(base_length);var base_dist=new Array(D_CODES);zero(base_dist);var static_l_desc,static_d_desc,static_bl_desc,StaticTreeDesc=function(static_tree,extra_bits,extra_base,elems,max_length){this.static_tree=static_tree,this.extra_bits=extra_bits,this.extra_base=extra_base,this.elems=elems,this.max_length=max_length,this.has_stree=static_tree&&static_tree.length},TreeDesc=function(dyn_tree,stat_desc){this.dyn_tree=dyn_tree,this.max_code=0,this.stat_desc=stat_desc},static_init_done=!1;exports._tr_init=_tr_init,exports._tr_stored_block=_tr_stored_block,exports._tr_flush_block=_tr_flush_block,exports._tr_tally=_tr_tally,exports._tr_align=_tr_align},{"../utils/common":98}],110:[function(require,module){"use strict";function ZStream(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}module.exports=ZStream},{}],111:[function(require,module){(function(Buffer){"use strict";function decodeB64(str){return new Buffer(str,"base64")}function unpackPNG(w,h,c,str){var pixels=parse(decodeB64(str));return ndarray(pixels.data,[h,w,pixels.channels],[pixels.channels*w,pixels.channels,1],0)}module.exports=unpackPNG;var ndarray=require("ndarray"),parse=require("pngparse-sync")}).call(this,require("buffer").Buffer)},{buffer:123,ndarray:92,"pngparse-sync":94}],112:[function(require,module,exports){!function(_global){"use strict";var shim={};"undefined"==typeof exports?"function"==typeof define&&"object"==typeof define.amd&&define.amd?(shim.exports={},define(function(){return shim.exports})):shim.exports="undefined"!=typeof window?window:_global:shim.exports=exports,function(exports){if(!GLMAT_EPSILON)var GLMAT_EPSILON=1e-6;if(!GLMAT_ARRAY_TYPE)var GLMAT_ARRAY_TYPE="undefined"!=typeof Float32Array?Float32Array:Array;if(!GLMAT_RANDOM)var GLMAT_RANDOM=Math.random;var glMatrix={};glMatrix.setMatrixArrayType=function(type){GLMAT_ARRAY_TYPE=type},"undefined"!=typeof exports&&(exports.glMatrix=glMatrix);var degree=Math.PI/180;glMatrix.toRadian=function(a){return a*degree};var vec2={};vec2.create=function(){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=0,out[1]=0,out},vec2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=a[0],out[1]=a[1],out},vec2.fromValues=function(x,y){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=x,out[1]=y,out},vec2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out},vec2.set=function(out,x,y){return out[0]=x,out[1]=y,out},vec2.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out},vec2.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out},vec2.sub=vec2.subtract,vec2.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out},vec2.mul=vec2.multiply,vec2.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out},vec2.div=vec2.divide,vec2.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out},vec2.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out},vec2.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out},vec2.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out},vec2.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return Math.sqrt(x*x+y*y)},vec2.dist=vec2.distance,vec2.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return x*x+y*y},vec2.sqrDist=vec2.squaredDistance,vec2.length=function(a){var x=a[0],y=a[1];return Math.sqrt(x*x+y*y)},vec2.len=vec2.length,vec2.squaredLength=function(a){var x=a[0],y=a[1];return x*x+y*y},vec2.sqrLen=vec2.squaredLength,vec2.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out},vec2.normalize=function(out,a){var x=a[0],y=a[1],len=x*x+y*y;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11]; +out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],113:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance}function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":112}],114:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],115:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],116:[function(require,module){function parse(html,doc){if("string"!=typeof html)throw new TypeError("String expected");doc||(doc=document);var m=/<([\w:]+)/.exec(html);if(!m)return doc.createTextNode(html);html=html.replace(/^\s+|\s+$/g,"");var tag=m[1];if("body"==tag){var el=doc.createElement("html");return el.innerHTML=html,el.removeChild(el.lastChild)}var wrap=map[tag]||map._default,depth=wrap[0],prefix=wrap[1],suffix=wrap[2],el=doc.createElement("div");for(el.innerHTML=prefix+html+suffix;depth--;)el=el.lastChild;if(el.firstChild==el.lastChild)return el.removeChild(el.firstChild);for(var fragment=doc.createDocumentFragment();el.firstChild;)fragment.appendChild(el.removeChild(el.firstChild));return fragment}module.exports=parse;var map={legend:[1,"
      ","
      "],tr:[2,"","
      "],col:[2,"","
      "],_default:[0,"",""]};map.td=map.th=[3,"","
      "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
      "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],117:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],118:[function(require,module,exports){arguments[4][32][0].apply(exports,arguments)},{_process:126,"raf-component":119,sliced:121}],119:[function(require,module){module.exports=require(33)},{}],120:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],121:[function(require,module,exports){arguments[4][34][0].apply(exports,arguments)},{"./lib/sliced":122}],122:[function(require,module){module.exports=require(35)},{}],123:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)"base64"===encoding&&(subject=base64clean(subject)),length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new Error("First argument needs to be a number, array or string.");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}var buf;TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;assert(strLen%2===0,"Invalid hex string"),length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);assert(!isNaN(byte),"Invalid hex string"),buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string),buf,offset,length);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function binarySlice(buf,start,end){return asciiSlice(buf,start,end)}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;i=len)){var val;return littleEndian?(val=buf[offset],len>offset+1&&(val|=buf[offset+1]<<8)):(val=buf[offset]<<8,len>offset+1&&(val|=buf[offset+1])),val}}function readUInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val;return littleEndian?(len>offset+2&&(val=buf[offset+2]<<16),len>offset+1&&(val|=buf[offset+1]<<8),val|=buf[offset],len>offset+3&&(val+=buf[offset+3]<<24>>>0)):(len>offset+1&&(val=buf[offset+1]<<16),len>offset+2&&(val|=buf[offset+2]<<8),len>offset+3&&(val|=buf[offset+3]),val+=buf[offset]<<24>>>0),val}}function readInt16(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len)){var val=readUInt16(buf,offset,littleEndian,!0),neg=32768&val;return neg?-1*(65535-val+1):val}}function readInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val=readUInt32(buf,offset,littleEndian,!0),neg=2147483648&val;return neg?-1*(4294967295-val+1):val}}function readFloat(buf,offset,littleEndian,noAssert){return noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i);return offset+2}}function writeUInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255;return offset+4}}function writeInt16(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len))return value>=0?writeUInt16(buf,value,offset,littleEndian,noAssert):writeUInt16(buf,65535+value+1,offset,littleEndian,noAssert),offset+2}function writeInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return value>=0?writeUInt32(buf,value,offset,littleEndian,noAssert):writeUInt32(buf,4294967295+value+1,offset,littleEndian,noAssert),offset+4}function writeFloat(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+7=len))return ieee754.write(buf,value,offset,littleEndian,52,8),offset+8}function base64clean(str){for(str=stringtrim(str).replace(INVALID_BASE64_RE,"");str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArray(subject){return(Array.isArray||function(subject){return"[object Array]"===Object.prototype.toString.call(subject)})(subject)}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(str){for(var byteArray=[],i=0;i=b)byteArray.push(b);else{var start=i;b>=55296&&57343>=b&&i++;for(var h=encodeURIComponent(str.slice(start,i+1)).substr(1).split("%"),j=0;j>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(str)}function blitBuffer(src,dst,offset,length){for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533)}}function verifuint(value,max){assert("number"==typeof value,"cannot write a non-number as a number"),assert(value>=0,"specified a negative value for writing an unsigned value"),assert(max>=value,"value is larger than maximum value for type"),assert(Math.floor(value)===value,"value has a fractional component")}function verifsint(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value"),assert(Math.floor(value)===value,"value has a fractional component")}function verifIEEE754(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value")}function assert(test,message){if(!test)throw new Error(message||"Failed assertion")}var base64=require("base64-js"),ieee754=require("ieee754");exports.Buffer=Buffer,exports.SlowBuffer=Buffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}();Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0; +default:return!1}},Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.byteLength=function(str,encoding){var ret;switch(str=str.toString(),encoding||"utf8"){case"hex":ret=str.length/2;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"ascii":case"binary":case"raw":ret=str.length;break;case"base64":ret=base64ToBytes(str).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=2*str.length;break;default:throw new Error("Unknown encoding")}return ret},Buffer.concat=function(list,totalLength){if(assert(isArray(list),"Usage: Buffer.concat(list[, length])"),0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;ii&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}offset=Number(offset)||0;var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toString=function(encoding,start,end){var self=this;if(encoding=String(encoding||"utf8").toLowerCase(),start=Number(start)||0,end=void 0===end?self.length:Number(end),end===start)return"";var ret;switch(encoding){case"hex":ret=hexSlice(self,start,end);break;case"utf8":case"utf-8":ret=utf8Slice(self,start,end);break;case"ascii":ret=asciiSlice(self,start,end);break;case"binary":ret=binarySlice(self,start,end);break;case"base64":ret=base64Slice(self,start,end);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leSlice(self,start,end);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.equals=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),0===Buffer.compare(this,b)},Buffer.prototype.compare=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),Buffer.compare(this,b)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start||(target_start=0),end!==start&&0!==target.length&&0!==source.length){assert(end>=start,"sourceEnd < sourceStart"),assert(target_start>=0&&target_start=0&&start=0&&end<=source.length,"sourceEnd out of bounds"),end>this.length&&(end=this.length),target.length-target_startlen||!TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start)}},Buffer.prototype.slice=function(start,end){var len=this.length;if(start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start),TYPED_ARRAY_SUPPORT)return Buffer._augment(this.subarray(start,end));for(var sliceLen=end-start,newBuf=new Buffer(sliceLen,void 0,!0),i=0;sliceLen>i;i++)newBuf[i]=this[i+start];return newBuf},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return readUInt16(this,offset,!0,noAssert)},Buffer.prototype.readUInt16BE=function(offset,noAssert){return readUInt16(this,offset,!1,noAssert)},Buffer.prototype.readUInt32LE=function(offset,noAssert){return readUInt32(this,offset,!0,noAssert)},Buffer.prototype.readUInt32BE=function(offset,noAssert){return readUInt32(this,offset,!1,noAssert)},Buffer.prototype.readInt8=function(offset,noAssert){if(noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length)){var neg=128&this[offset];return neg?-1*(255-this[offset]+1):this[offset]}},Buffer.prototype.readInt16LE=function(offset,noAssert){return readInt16(this,offset,!0,noAssert)},Buffer.prototype.readInt16BE=function(offset,noAssert){return readInt16(this,offset,!1,noAssert)},Buffer.prototype.readInt32LE=function(offset,noAssert){return readInt32(this,offset,!0,noAssert)},Buffer.prototype.readInt32BE=function(offset,noAssert){return readInt32(this,offset,!1,noAssert)},Buffer.prototype.readFloatLE=function(offset,noAssert){return readFloat(this,offset,!0,noAssert)},Buffer.prototype.readFloatBE=function(offset,noAssert){return readFloat(this,offset,!1,noAssert)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return readDouble(this,offset,!0,noAssert)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return readDouble(this,offset,!1,noAssert)},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(this[offset]=value,offset+1)},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(value>=0?this.writeUInt8(value,offset,noAssert):this.writeUInt8(255+value+1,offset,noAssert),offset+1)},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return writeInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return writeInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return writeInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return writeInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert)},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),assert(end>=start,"end < start"),end!==start&&0!==this.length){assert(start>=0&&start=0&&end<=this.length,"end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.inspect=function(){for(var out=[],len=this.length,i=0;len>i;i++)if(out[i]=toHex(this[i]),i===exports.INSPECT_MAX_BYTES){out[i+1]="...";break}return""},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z]/g},{"base64-js":124,ieee754:125}],124:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS?62:code===SLASH?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],125:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],126:[function(require,module){function noop(){}var process=module.exports={};process.nextTick=function(){var canSetImmediate="undefined"!=typeof window&&window.setImmediate,canPost="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(canSetImmediate)return function(f){return window.setImmediate(f)};if(canPost){var queue=[];return window.addEventListener("message",function(ev){var source=ev.source;if((source===window||null===source)&&"process-tick"===ev.data&&(ev.stopPropagation(),queue.length>0)){var fn=queue.shift();fn()}},!0),function(fn){queue.push(fn),window.postMessage("process-tick","*")}}return function(fn){setTimeout(fn,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file diff --git a/index.js b/index.js index 2164fbe..59ffe15 100644 --- a/index.js +++ b/index.js @@ -17,13 +17,11 @@ var flock = document.getElementById('community').querySelector('canvas') require('./lib/fill')(document.querySelectorAll('[data-fill]')) -if (window.chrome) { - try { - require('@stackgl/splash-grid')(grid) - // require('@stackgl/splash-flock')(flock) - } catch(e) { - console.error(e.message) - } +try { + require('@stackgl/splash-grid')(grid) + // require('@stackgl/splash-flock')(flock) +} catch(e) { + console.error(e.message) } var thumb = minstache.compile(fs.readFileSync( diff --git a/splash-grid/package.json b/splash-grid/package.json index c31619b..aa7006d 100644 --- a/splash-grid/package.json +++ b/splash-grid/package.json @@ -36,7 +36,7 @@ "gl-texture2d": "^1.2.0", "glslify": "^1.6.0", "mesh-combine": "^1.0.0", - "ndpack-image": "git://github.com/hughsk/ndpack-image#fix-orientation", + "ndpack-image": "^1.0.4", "orbit-camera": "^1.0.0", "right-now": "^1.0.0", "unindex-mesh": "^1.0.1" From 31d91184a634b355f0b77616168e6a330be4a6e4 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Tue, 16 Sep 2014 00:39:54 +0200 Subject: [PATCH 24/64] Fix error in Safari Caused by using .children instead of .childNodes on an HTMLElement --- bundle.js | 2 +- lib/filter.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bundle.js b/bundle.js index 0b3864c..97dcb43 100644 --- a/bundle.js +++ b/bundle.js @@ -1,4 +1,4 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),prev=list.children[0];return prev.setAttribute("class","selected"),slice(list.children).forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;iAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:123,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n); var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":30}],29:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],30:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],32:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:126,"raf-component":33,sliced:34}],33:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],34:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":35}],35:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],36:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],37:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":36}],38:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":39}],39:[function(require,module){module.exports=require(33)},{}],40:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:45}],45:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],46:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:52,"ndarray-ops":47,"typedarray-pool":56,webglew:58}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments) },{"./lib/thunk.js":50}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:51}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":49}],51:[function(require,module){module.exports=require(13)},{}],52:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":53}],53:[function(require,module){module.exports=require(15)},{}],54:[function(require,module){module.exports=require(16)},{}],55:[function(require,module){module.exports=require(17)},{}],56:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":54,buffer:123,dup:55}],57:[function(require,module){module.exports=require(41)},{}],58:[function(require,module){module.exports=require(42)},{weakmap:57}],59:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],60:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":59}],61:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06; diff --git a/lib/filter.js b/lib/filter.js index 84711bc..7fed8e4 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -24,10 +24,14 @@ module.exports = function(thumbs) { }) var list = domify(template({ category: categories })) - var prev = list.children[0] + var children = slice(list.childNodes).filter(function(node) { + return node.nodeType === Node.ELEMENT_NODE + }) + + var prev = children[0] - prev.setAttribute('class', 'selected') - slice(list.children).forEach(function(child) { + children[0].setAttribute('class', 'selected') + children.forEach(function(child) { var name = child.getAttribute('data-name') child.addEventListener('click', function(e) { From 960def5d5597ee433fe573c582f10e5523eef1b9 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Tue, 16 Sep 2014 02:11:43 +0200 Subject: [PATCH 25/64] add gl-texture2d-display --- bundle.js | 2 +- data/packages.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bundle.js b/bundle.js index 97dcb43..35510fa 100644 --- a/bundle.js +++ b/bundle.js @@ -1,4 +1,4 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;iAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2},{name:"gl-texture2d-display",desc:"\n",link:"http://ghub.io/gl-texture2d-display",thumb:"http://imgur.com/z6Cxsfy.png",featured:!1,i:3}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:123,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n); var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":30}],29:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],30:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],32:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:126,"raf-component":33,sliced:34}],33:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],34:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":35}],35:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],36:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],37:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":36}],38:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":39}],39:[function(require,module){module.exports=require(33)},{}],40:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:45}],45:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],46:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:52,"ndarray-ops":47,"typedarray-pool":56,webglew:58}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments) },{"./lib/thunk.js":50}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:51}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":49}],51:[function(require,module){module.exports=require(13)},{}],52:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":53}],53:[function(require,module){module.exports=require(15)},{}],54:[function(require,module){module.exports=require(16)},{}],55:[function(require,module){module.exports=require(17)},{}],56:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":54,buffer:123,dup:55}],57:[function(require,module){module.exports=require(41)},{}],58:[function(require,module){module.exports=require(42)},{weakmap:57}],59:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],60:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":59}],61:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06; diff --git a/data/packages.md b/data/packages.md index 728fbd0..1445905 100644 --- a/data/packages.md +++ b/data/packages.md @@ -23,6 +23,8 @@ To add a new package: ### gl-state ### gl-clear ### gl-fbo-matching +### gl-texture2d-display +![gl-texture2d-display](http://imgur.com/z6Cxsfy.png) ## Tools/Development From fb20a47cdec12b293944a20e4086db5a5485c41e Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Tue, 16 Sep 2014 22:45:38 +0200 Subject: [PATCH 26/64] sync examples/packages from the wiki --- data/examples.md | 2 -- data/packages.md | 2 -- data/sync.js | 24 ++++++++++++++++++++++++ package.json | 5 ++++- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 data/sync.js diff --git a/data/examples.md b/data/examples.md index 392e1a2..4054799 100644 --- a/data/examples.md +++ b/data/examples.md @@ -1,5 +1,3 @@ -# Examples - To add a new example: * Create a new level-two heading (`##`) in this file. diff --git a/data/packages.md b/data/packages.md index 1445905..248dfa8 100644 --- a/data/packages.md +++ b/data/packages.md @@ -1,5 +1,3 @@ -# Packages - To add a new package: * Choose a category to put it in. diff --git a/data/sync.js b/data/sync.js new file mode 100644 index 0000000..a3ecbbb --- /dev/null +++ b/data/sync.js @@ -0,0 +1,24 @@ +var replace = require('replacestream') +var wrap = require('wrap-stream') +var request = require('request') +var path = require('path') +var url = require('url') +var fs = require('fs') + +var wiki = 'https://github.com/stackgl/stackgl.github.io/wiki/' + +;['examples' +, 'packages' +].forEach(function(slug) { + var Slug = slug.slice(0, 1).toUpperCase() + slug.slice(1) + var uri = url.resolve(wiki, Slug) + var dst = path.join(__dirname, slug + '.md') + + request(uri + '.md') + .pipe(replace('\r', '')) + .pipe(wrap('', '\n')) + .pipe(fs.createWriteStream(dst)) + .once('close', function() { + console.log('* updated ' + slug) + }) +}) diff --git a/package.json b/package.json index 0fd87c3..f98bcc5 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,12 @@ "markdown-tree": "0.0.0", "marked": "^0.3.2", "minstache": "^1.2.0", + "replacestream": "^0.2.0", + "request": "^2.42.0", "scoped-bulk": "^1.0.0", "sliced": "0.0.5", - "unhtml": "^0.1.0" + "unhtml": "^0.1.0", + "wrap-stream": "^2.0.0" }, "browserify": { "transform": [ From 17772aa4aaafa8ae5b4856011311b7f128f2adfc Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Tue, 16 Sep 2014 23:04:43 +0200 Subject: [PATCH 27/64] remove markdown files from git --- data/examples.md | 59 ---------------- data/packages.md | 180 ----------------------------------------------- package.json | 5 +- 3 files changed, 3 insertions(+), 241 deletions(-) delete mode 100644 data/examples.md delete mode 100644 data/packages.md diff --git a/data/examples.md b/data/examples.md deleted file mode 100644 index 4054799..0000000 --- a/data/examples.md +++ /dev/null @@ -1,59 +0,0 @@ -To add a new example: - -* Create a new level-two heading (`##`) in this file. -* The heading should be a link pointing to the example. -* Optionally, include a description of the example below the heading. This - will be used if the example is featured. -* Include the example's thumbnail as an image somewhere in the description. -* To mark an example as *featured*, simply make its header italic (`*[like](this)*`). - There should only be only featured example at any one time. - -## *[shader-school](http://github.com/gl-modules/shader-school)* - -![shader-school](http://imgur.com/hegi9dZ.png) - -An introduction to GLSL shaders and graphics programming that runs in your -browser. **shader-school** is a [NodeSchool workshop](http://nodeschool.io/) -originally created for [NodeConf 2014](http://nodeconf.com/). Everything is -powered by browserify, glslify and modules from the stackgl ecosystem under -the hood. - -## [glsl.io](http://glsl.io/) - -![glsl.io](http://imgur.com/56SPiLL.png) - -## [kami](https://github.com/mattdesl/kami) - -![kami](http://imgur.com/j5W3Tuw.png) - -## [run.south.im](http://run.south.im/) - -![run.south.im](http://imgur.com/kZjW5QD.png) - -## [nodesource.com](http://nodesource.com/) - -![nodesource.com](http://imgur.com/tCKuJfx.png) - -## [voxel-mipmap-demo](https://github.com/mikolalysenko/voxel-mipmap-demo/) - -![voxel-mipmap-demo](http://imgur.com/9eUBmfB.png) - -## [gif-3d](http://mikolalysenko.github.io/gif-3d/) - -![gif-3d](http://imgur.com/gItopw0.jpg) - -## [moire #1](http://hughsk.io/moire-1) - -![moire-1](http://imgur.com/9tbJfnF.png) - -## [campjs.com](http://campjs.com/) - -![campjs](http://imgur.com/d47Vesp.png) - -## [particle-excess-demo](https://github.com/hughsk/particle-excess-demo/) - -![particle-excess-demo](http://imgur.com/YyrtLqM.png) - -## [web-audio-analyser](https://github.com/hughsk/web-audio-analyser/) - -![web-audio-analyser](http://imgur.com/xhPfMFP.png) diff --git a/data/packages.md b/data/packages.md deleted file mode 100644 index 248dfa8..0000000 --- a/data/packages.md +++ /dev/null @@ -1,180 +0,0 @@ -To add a new package: - -* Choose a category to put it in. -* Add a level-three heading (`###`) in that group of packages. -* The heading should be the the name of the module on npm. -* Optionally, include a thumbnail image and description below the heading. - -## WebGL Core - -### gl-vao -![gl-vao](http://imgur.com/iv3pOSh.png) -### gl-fbo -![gl-fbo](http://imgur.com/xiXCQGN.png) -### gl-texture2d -![gl-texture2d](http://imgur.com/ZkcCvzx.jpg) -### gl-buffer -![gl-buffer](http://imgur.com/JFZGJBx.png) - -## WebGL API - -### gl-state -### gl-clear -### gl-fbo-matching -### gl-texture2d-display -![gl-texture2d-display](http://imgur.com/z6Cxsfy.png) - -## Tools/Development - -### glslify -![glslify](http://imgur.com/ThMYeUx.png) -### glslify-live -![glslify-live](http://imgur.com/9mmysos.png) -### glslify-optimize -![glslify-optimize](http://imgur.com/pF9tmNg.png) -### glslify-api -### glslify-resolve-remote -### glsl-testify -### glsl-editor - -## Math - -### ndarray -### gl-mat2 -### gl-mat3 -### gl-mat4 -### gl-matrix -### cubic-hermite - -## Camera Controls - -### turntable-camera -![turntable-camera](http://imgur.com/3wiGD3K.png) -### orbit-camera -![orbit-camera](http://imgur.com/BPkl0Yh.png) -### game-shell-orbit-camera -![game-shell-orbit-camera](http://imgur.com/BPkl0Yh.png) -### canvas-orbit-camera -![canvas-orbit-camera](http://imgur.com/BPkl0Yh.png) - -## Initialization - -### gl-now -### gl-context -### webgl-context - -## Input - -### key-pressed -### mouse-pressed -### mouse-speed -### scroll-speed -### canvas-fit -### canvas-autoscale -### vkey - -## Shader Components - -### glsl-luma -![glsl-luma](http://imgur.com/SRxqxj2.png) - -### glsl-dither -![glsl-dither](http://imgur.com/D4ccYiJ.png) - -### glsl-noise -![glsl-noise](http://imgur.com/BFITCvl.jpg) - -### glsl-curl-noise -![glsl-curl-noise](http://imgur.com/ABlBkoE.png) - -### glsl-random -![glsl-random](http://imgur.com/9EOo2or.png) - -### glsl-fog -![glsl-fog](http://imgur.com/8l0otem.png) - -### glsl-easings -### glsl-fxaa -### glsl-lut -### glsl-range -### glsl-square-frame -### glsl-hsv2rgb -### glsl-read-float -### matcap - -## Shader Transforms - -### glslify-hex -![glslify-hex](http://imgur.com/Dh8CPE9.png) -### glslify-import -![glslify-import](http://imgur.com/7trTmBF.png) - -## Visualisation - -### gl-compare -![gl-compare](http://imgur.com/z8BkmZl.jpg) -### gl-surface-plot -### canvas-pixels -### gl-line-plot -### gl-scatter-plot -### gl-axes - -## Internals - -### webglew -### glsl-parser -### glsl-tokenizer -### glsl-deparser -### glsl-extract -### glsl-resolve -### glslify-stream -### gl-shader-core - -## Assets - -### lena -![lena](http://imgur.com/eSx2pBu.png) - -### baboon-image -![baboon-image](http://imgur.com/63yazJ1.png) - -### bunny -![bunny](http://imgur.com/5VIykyD.png) - -### teapot -### stanford-dragon -![stanford-dragon](http://imgur.com/XWYMq6J.png) - -### get-pixels -### save-pixels -### ndpack-image -### font-atlas - -## Interoperability - -### three-glslify - -## Geometry - -### simplicial-complex -### gl-wireframe -### gl-geometry -### normals -### greedy-mesher -### voxelize -### isosurface -### icosphere -### rectangular-prism -### face-normals -### mesh-reindex -### mesh-combine -### unindex-mesh -### vectorize-text -### from-3d-to-2d -### surface-vectors -### orthogami -### plane-to-polygon -### find-basis-3d -### box-frustum -### delaunay-triangulate -### svg-3d-simplicial-complex diff --git a/package.json b/package.json index f98bcc5..29e9291 100644 --- a/package.json +++ b/package.json @@ -32,9 +32,10 @@ "scripts": { "prestart": "npm run links && node data/regenerate", "start": "beefy index.js:bundle.js --open", - "postinstall": "npm run links && scoped-bulk stackgl npm install && npm dedupe", + "postinstall": "npm run links && scoped-bulk stackgl npm install && npm dedupe && npm run sync", "bundle": "npm run prestart && browserify index.js | uglifyjs -c > bundle.js", - "links": "district stackgl splash-grid splash-flock" + "links": "district stackgl splash-grid splash-flock", + "sync": "node data/sync" }, "repository": { "type": "git", From c2f49c40b4893245c54ca1a752d4048fbeb7b717 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Tue, 16 Sep 2014 23:08:26 +0200 Subject: [PATCH 28/64] Fix data/sync.js --- .gitignore | 2 ++ data/sync.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e105467..2a267dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules build/*.json +data/*.md +npm-debug.log diff --git a/data/sync.js b/data/sync.js index a3ecbbb..41f0a1a 100644 --- a/data/sync.js +++ b/data/sync.js @@ -16,7 +16,7 @@ var wiki = 'https://github.com/stackgl/stackgl.github.io/wiki/' request(uri + '.md') .pipe(replace('\r', '')) - .pipe(wrap('', '\n')) + .pipe(wrap('# ' + Slug + '\n\n', '\n')) .pipe(fs.createWriteStream(dst)) .once('close', function() { console.log('* updated ' + slug) From e475eda67bf0172db7b6cd8d2d05b108e27100eb Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Wed, 17 Sep 2014 08:13:49 -0500 Subject: [PATCH 29/64] Word choice --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index bc87a5f..20d4084 100644 --- a/index.html +++ b/index.html @@ -31,7 +31,7 @@

      #stackgl

      bottom up, you can always drill down a layer. Unlike many 3D engines, stackgl emphasizes writing shader code, and provides powerful tools like glslify which bring the - modularity and power of npm to GLSL! + modularity and productivity of npm to GLSL!
      From 4eeb845493c395c6f6506a29ca2bb99a3893a153 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Fri, 3 Oct 2014 20:30:47 +0100 Subject: [PATCH 30/64] update --- bundle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle.js b/bundle.js index 35510fa..814793b 100644 --- a/bundle.js +++ b/bundle.js @@ -1,4 +1,4 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2},{name:"gl-texture2d-display",desc:"\n",link:"http://ghub.io/gl-texture2d-display",thumb:"http://imgur.com/z6Cxsfy.png",featured:!1,i:3}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;iAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2},{name:"gl-texture2d-display",desc:"\n",link:"http://ghub.io/gl-texture2d-display",thumb:"http://imgur.com/z6Cxsfy.png",featured:!1,i:3}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8},{name:"gl-gif",desc:"\n",link:"http://ghub.io/gl-gif",thumb:"http://imgur.com/AiC0Sab.gif",featured:!1,i:9}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:123,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n); var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":30}],29:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],30:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],32:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:126,"raf-component":33,sliced:34}],33:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],34:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":35}],35:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],36:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],37:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":36}],38:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":39}],39:[function(require,module){module.exports=require(33)},{}],40:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:45}],45:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],46:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:52,"ndarray-ops":47,"typedarray-pool":56,webglew:58}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments) },{"./lib/thunk.js":50}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:51}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":49}],51:[function(require,module){module.exports=require(13)},{}],52:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":53}],53:[function(require,module){module.exports=require(15)},{}],54:[function(require,module){module.exports=require(16)},{}],55:[function(require,module){module.exports=require(17)},{}],56:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":54,buffer:123,dup:55}],57:[function(require,module){module.exports=require(41)},{}],58:[function(require,module){module.exports=require(42)},{weakmap:57}],59:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],60:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":59}],61:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06; From 2c149edb6202805dd610eb8bed89186188eb1961 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 2 Nov 2014 01:02:17 +1100 Subject: [PATCH 31/64] update bundle.js --- bundle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle.js b/bundle.js index 814793b..3ed6fa1 100644 --- a/bundle.js +++ b/bundle.js @@ -1,4 +1,4 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to GLSL shaders and graphics programming that runs in your\nbrowser. shader-school is a NodeSchool workshop\noriginally created for NodeConf 2014. Everything is\npowered by browserify, glslify and modules from the stackgl ecosystem under\nthe hood.

      ',thumb:"http://imgur.com/hegi9dZ.png",featured:!0,i:0},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:1},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:2},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:3},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:4},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:5},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:6},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:7},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:8},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:9},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:10}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2},{name:"gl-texture2d-display",desc:"\n",link:"http://ghub.io/gl-texture2d-display",thumb:"http://imgur.com/z6Cxsfy.png",featured:!1,i:3}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8},{name:"gl-gif",desc:"\n",link:"http://ghub.io/gl-gif",thumb:"http://imgur.com/AiC0Sab.gif",featured:!1,i:9}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;iAn introduction to the WebGL API that runs in your browser. webgl-workshop\nis a NodeSchool workshop originally created for\nCampJS IV. Everything is powered by node.js, browserify and\na selection of stackgl packages under the hood.

      ',thumb:"http://i.imgur.com/vBJ7d6o.jpg",featured:!0,i:0},{name:"shader-school",link:"http://github.com/stackgl/shader-school",desc:"",thumb:"http://imgur.com/hegi9dZ.png",featured:!1,i:1},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:2},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:3},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:4},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:5},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:6},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:7},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:8},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:9},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:10},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:11}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2},{name:"gl-texture2d-display",desc:"\n",link:"http://ghub.io/gl-texture2d-display",thumb:"http://imgur.com/z6Cxsfy.png",featured:!1,i:3}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8},{name:"gl-gif",desc:"\n",link:"http://ghub.io/gl-gif",thumb:"http://imgur.com/AiC0Sab.gif",featured:!1,i:9}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:123,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n); var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":30}],29:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],30:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],32:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:126,"raf-component":33,sliced:34}],33:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],34:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":35}],35:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],36:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],37:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":36}],38:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":39}],39:[function(require,module){module.exports=require(33)},{}],40:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:45}],45:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],46:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:52,"ndarray-ops":47,"typedarray-pool":56,webglew:58}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments) },{"./lib/thunk.js":50}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:51}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":49}],51:[function(require,module){module.exports=require(13)},{}],52:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":53}],53:[function(require,module){module.exports=require(15)},{}],54:[function(require,module){module.exports=require(16)},{}],55:[function(require,module){module.exports=require(17)},{}],56:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":54,buffer:123,dup:55}],57:[function(require,module){module.exports=require(41)},{}],58:[function(require,module){module.exports=require(42)},{weakmap:57}],59:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],60:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":59}],61:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06; From 86178fe1e380aca98a375cc3738fa6d7d7ce7ec9 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sun, 2 Nov 2014 01:19:47 +1100 Subject: [PATCH 32/64] update bundle --- bundle.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bundle.js b/bundle.js index 3ed6fa1..83b1c8a 100644 --- a/bundle.js +++ b/bundle.js @@ -1,10 +1,10 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to the WebGL API that runs in your browser. webgl-workshop\nis a NodeSchool workshop originally created for\nCampJS IV. Everything is powered by node.js, browserify and\na selection of stackgl packages under the hood.

      ',thumb:"http://i.imgur.com/vBJ7d6o.jpg",featured:!0,i:0},{name:"shader-school",link:"http://github.com/stackgl/shader-school",desc:"",thumb:"http://imgur.com/hegi9dZ.png",featured:!1,i:1},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:2},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:3},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:4},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:5},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:6},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:7},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:8},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:9},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:10},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:11}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2},{name:"gl-texture2d-display",desc:"\n",link:"http://ghub.io/gl-texture2d-display",thumb:"http://imgur.com/z6Cxsfy.png",featured:!1,i:3}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8},{name:"gl-gif",desc:"\n",link:"http://ghub.io/gl-gif",thumb:"http://imgur.com/AiC0Sab.gif",featured:!1,i:9}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:123,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n); -var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":30}],29:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],30:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],32:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:126,"raf-component":33,sliced:34}],33:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],34:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":35}],35:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],36:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],37:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":36}],38:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":39}],39:[function(require,module){module.exports=require(33)},{}],40:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:45}],45:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],46:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:52,"ndarray-ops":47,"typedarray-pool":56,webglew:58}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments) -},{"./lib/thunk.js":50}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:51}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":49}],51:[function(require,module){module.exports=require(13)},{}],52:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":53}],53:[function(require,module){module.exports=require(15)},{}],54:[function(require,module){module.exports=require(16)},{}],55:[function(require,module){module.exports=require(17)},{}],56:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":54,buffer:123,dup:55}],57:[function(require,module){module.exports=require(41)},{}],58:[function(require,module){module.exports=require(42)},{weakmap:57}],59:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],60:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":59}],61:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06; -return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],69:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":70}],70:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":72}],71:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:73}],72:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":71}],73:[function(require,module){module.exports=require(13)},{}],74:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":75}],75:[function(require,module){module.exports=require(15)},{}],76:[function(require,module){module.exports=require(16)},{}],77:[function(require,module){module.exports=require(17)},{}],78:[function(require,module){module.exports=require(56)},{"bit-twiddle":76,buffer:123,dup:77}],79:[function(require,module){module.exports=require(41)},{}],80:[function(require,module){module.exports=require(42)},{weakmap:79}],81:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function isPacked(array){for(var shape=array.shape,stride=array.stride,s=1,i=shape.length-1;i>=0;--i){if(stride[i]!==s)return!1;s*=shape[i]}return!0}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(array),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type===gl.FLOAT&&webglew(gl).texture_float&&(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store;if(packed){var array_size=array.size;buffer=array.data.subarray(array.offset,array.offset+array_size)}else{for(var sz=1,stride=new Array(shape.length),i=shape.length-1;i>=0;--i)stride[i]=sz,sz*=shape[i];buf_store=pool.malloc(sz,dtype);var buf_array=ndarray(buf_store,array.shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,sz)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[1],shape[0],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][1],0|arguments[1][0],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew"),linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)};Object.defineProperty(Texture2D.prototype,"minFilter",{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}});var proto=Texture2D.prototype;Object.defineProperty(proto,"magFilter",{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}}),Object.defineProperty(proto,"wrapS",{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}}),Object.defineProperty(proto,"wrapT",{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}}),Object.defineProperty(proto,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapT=v[0],this._wrapS=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),v}}),Object.defineProperty(proto,"mipSamples",{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(proto,"shape",{get:function(){return this._shape},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];var r=0|x[0],c=0|x[1];if(this.height===r&&this.width===c)return x;var gl=this.gl,maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>c||c>maxSize||0>r||r>maxSize)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[r,c],this.bind(),gl.texImage2D(gl.TEXTURE_2D,0,this.format,c,r,0,this.format,this.type,null),this._mipLevels=[0],x}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[0],x_off=0|x_off[1]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}},module.exports=createTexture2D},{ndarray:74,"ndarray-ops":69,"typedarray-pool":78,webglew:80}],82:[function(require,module){function programify(vertex,fragment,uniforms,attributes){return function(gl){return shader(gl,vertex,fragment,uniforms,attributes)}}module.exports=programify;var shader=require("gl-shader-core")},{"gl-shader-core":88}],83:[function(require,module){function noop(){throw new Error("You should bundle your code using `glslify` as a transform.")}module.exports=noop},{}],84:[function(require,module){"use strict";function ShaderAttribute(gl,program,location,dimension,name,constFunc,relink){this._gl=gl,this._program=program,this._location=location,this._dimension=dimension,this._name=name,this._constFunc=constFunc,this._relink=relink}function addVectorAttribute(gl,program,location,dimension,obj,name,doLink){for(var constFuncArgs=["gl","v"],varNames=[],i=0;dimension>i;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],85:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;k=pa&&pc>=pa?a:pc>=pb?b:c}function parseData(dataBuffer){function inputData(data){for(var tmp,j,len=data.length,i=0;i!==len;)switch(state){case 0:if(data.readUInt8(i++)!==HEADER[off++])return!1;off===HEADER.length&&(state=1,off=0);break;case 1:if(8-off>len-i)data.copy(buf,off,i),off+=len-i,i=len;else switch(data.copy(buf,off,i,i+8-off),i+=8-off,off=0,chunkLength=buf.readUInt32BE(0),buf.toString("ascii",4,8)){case"IHDR":state=2;break;case"PLTE":if(3!==pngColorType)state=7;else{if(chunkLength%3!==0)return!1;pngPaletteEntries=chunkLength/3,pngPalette=new Buffer(chunkLength),state=3}break;case"tRNS":if(3!==pngColorType)return!1;idChannels++,pngAlphaEntries=chunkLength,pngAlpha=new Buffer(chunkLength),state=4;break;case"IDAT":pngPixels||(pngPixels=new Uint8Array(pngWidth*pngHeight*idChannels)),state=5;break;case"IEND":state=6;break;default:state=7}break;case 2:if(13!==chunkLength)return!1;if(chunkLength-off>len-i)data.copy(buf,off,i),off+=len-i,i=len;else{if(data.copy(buf,off,i,i+chunkLength-off),0!==buf.readUInt8(10))return!1;if(0!==buf.readUInt8(11))return!1;if(0!==buf.readUInt8(12))return!1;switch(i+=chunkLength-off,state=8,off=0,pngWidth=buf.readUInt32BE(0),pngHeight=buf.readUInt32BE(4),pngBitDepth=buf.readUInt8(8),pngDepthMult=255/((1<len-i)data.copy(pngPalette,off,i),off+=len-i,i=len;else for(data.copy(pngPalette,off,i,i+chunkLength-off),i+=chunkLength-off,state=8,off=0,idChannels=1,j=pngPaletteEntries;j--;)if(pngPalette[3*j+0]!==pngPalette[3*j+1]||pngPalette[3*j+0]!==pngPalette[3*j+2]){idChannels=3;break}break;case 4:chunkLength-off>len-i?(data.copy(pngAlpha,off,i),off+=len-i,i=len):(data.copy(pngAlpha,off,i,i+chunkLength-off),i+=chunkLength-off,state=8,off=0);break;case 5:chunkLength-off>len-i?(inflateQueue.push(data.slice(i)),off+=len-i,i=len):(inflateQueue.push(data.slice(i,i+chunkLength-off)),i+=chunkLength-off,state=8,off=0);break;case 6:if(0!==chunkLength)return!1;4-off>len-i?(off+=len-i,i=len):(pngTrailer=new Buffer(0),i+=4-off,state=9,off=0);break;case 7:chunkLength-off>len-i?(off+=len-i,i=len):(i+=chunkLength-off,state=8,off=0);break;case 8:4-off>len-i?(off+=len-i,i=len):(i+=4-off,state=1,off=0);break;case 9:tmp=new Buffer(off+len-i),pngTrailer.copy(tmp),data.copy(tmp,off,i,len),pngTrailer=tmp,off+=len-i,i=len}return!0}function unpackPixels(data){var i,tmp,x,j,k,len=data.length;for(i=0;i!==len;++i){if(-1===b)scanlineFilter=data[i],tmp=currentScanline,currentScanline=priorScanline,priorScanline=tmp;else switch(scanlineFilter){case 0:currentScanline[b]=data[i];break;case 1:currentScanline[b]=pngBytesPerPixel>b?data[i]:data[i]+currentScanline[b-pngBytesPerPixel]&255;break;case 2:currentScanline[b]=data[i]+priorScanline[b]&255;break;case 3:currentScanline[b]=data[i]+((pngBytesPerPixel>b?priorScanline[b]:currentScanline[b-pngBytesPerPixel]+priorScanline[b])>>>1)&255;break;case 4:currentScanline[b]=data[i]+(pngBytesPerPixel>b?priorScanline[b]:paeth(currentScanline[b-pngBytesPerPixel],priorScanline[b],priorScanline[b-pngBytesPerPixel]))&255;break;default:return null}if(++b===pngBytesPerScanline){if(p===pngPixels.length)return null;for(j=0,x=0;x!==pngWidth;++x){for(k=0;k!==pngSamplesPerPixel;++j,++k)switch(pngBitDepth){case 1:pngSamples[k]=currentScanline[j>>>3]>>7-(7&j)&1;break;case 2:pngSamples[k]=currentScanline[j>>>2]>>(3-(3&j)<<1)&3;break;case 4:pngSamples[k]=currentScanline[j>>>1]>>(1-(1&j)<<2)&15;break;case 8:pngSamples[k]=currentScanline[j];break;default:return null}switch(pngColorType){case 0:pngPixels[p++]=pngSamples[0]*pngDepthMult;break;case 2:pngPixels[p++]=pngSamples[0]*pngDepthMult,pngPixels[p++]=pngSamples[1]*pngDepthMult,pngPixels[p++]=pngSamples[2]*pngDepthMult;break;case 3:if(pngSamples[0]>=pngPaletteEntries)return null;switch(idChannels){case 1:pngPixels[p++]=pngPalette[3*pngSamples[0]];break;case 2:pngPixels[p++]=pngPalette[3*pngSamples[0]],pngPixels[p++]=pngSamples[0]0?opt.windowBits=-opt.windowBits:opt.gzip&&opt.windowBits>0&&opt.windowBits<16&&(opt.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;var status=zlib_deflate.deflateInit2(this.strm,opt.level,opt.method,opt.windowBits,opt.memLevel,opt.strategy);if(status!==Z_OK)throw new Error(msg[status]);opt.header&&zlib_deflate.deflateSetHeader(this.strm,opt.header)};Deflate.prototype.push=function(data,mode){var status,_mode,strm=this.strm,chunkSize=this.options.chunkSize;if(this.ended)return!1;_mode=mode===~~mode?mode:mode===!0?Z_FINISH:Z_NO_FLUSH,strm.input="string"==typeof data?strings.string2buf(data):data,strm.next_in=0,strm.avail_in=strm.input.length;do{if(0===strm.avail_out&&(strm.output=new utils.Buf8(chunkSize),strm.next_out=0,strm.avail_out=chunkSize),status=zlib_deflate.deflate(strm,_mode),status!==Z_STREAM_END&&status!==Z_OK)return this.onEnd(status),this.ended=!0,!1;(0===strm.avail_out||0===strm.avail_in&&_mode===Z_FINISH)&&this.onData("string"===this.options.to?strings.buf2binstring(utils.shrinkBuf(strm.output,strm.next_out)):utils.shrinkBuf(strm.output,strm.next_out))}while((strm.avail_in>0||0===strm.avail_out)&&status!==Z_STREAM_END);return _mode===Z_FINISH?(status=zlib_deflate.deflateEnd(this.strm),this.onEnd(status),this.ended=!0,status===Z_OK):!0},Deflate.prototype.onData=function(chunk){this.chunks.push(chunk)},Deflate.prototype.onEnd=function(status){status===Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):utils.flattenChunks(this.chunks)),this.chunks=[],this.err=status,this.msg=this.strm.msg},exports.Deflate=Deflate,exports.deflate=deflate,exports.deflateRaw=deflateRaw,exports.gzip=gzip},{"./utils/common":98,"./utils/strings":99,"./zlib/deflate.js":103,"./zlib/messages":108,"./zlib/zstream":110}],97:[function(require,module,exports){"use strict";function inflate(input,options){var inflator=new Inflate(options);if(inflator.push(input,!0),inflator.err)throw inflator.msg;return inflator.result}function inflateRaw(input,options){return options=options||{},options.raw=!0,inflate(input,options)}var zlib_inflate=require("./zlib/inflate.js"),utils=require("./utils/common"),strings=require("./utils/strings"),c=require("./zlib/constants"),msg=require("./zlib/messages"),zstream=require("./zlib/zstream"),gzheader=require("./zlib/gzheader"),Inflate=function(options){this.options=utils.assign({chunkSize:16384,windowBits:0,to:""},options||{});var opt=this.options;opt.raw&&opt.windowBits>=0&&opt.windowBits<16&&(opt.windowBits=-opt.windowBits,0===opt.windowBits&&(opt.windowBits=-15)),!(opt.windowBits>=0&&opt.windowBits<16)||options&&options.windowBits||(opt.windowBits+=32),opt.windowBits>15&&opt.windowBits<48&&0===(15&opt.windowBits)&&(opt.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;var status=zlib_inflate.inflateInit2(this.strm,opt.windowBits);if(status!==c.Z_OK)throw new Error(msg[status]);this.header=new gzheader,zlib_inflate.inflateGetHeader(this.strm,this.header)};Inflate.prototype.push=function(data,mode){var status,_mode,next_out_utf8,tail,utf8str,strm=this.strm,chunkSize=this.options.chunkSize;if(this.ended)return!1;_mode=mode===~~mode?mode:mode===!0?c.Z_FINISH:c.Z_NO_FLUSH,strm.input="string"==typeof data?strings.binstring2buf(data):data,strm.next_in=0,strm.avail_in=strm.input.length;do{if(0===strm.avail_out&&(strm.output=new utils.Buf8(chunkSize),strm.next_out=0,strm.avail_out=chunkSize),status=zlib_inflate.inflate(strm,c.Z_NO_FLUSH),status!==c.Z_STREAM_END&&status!==c.Z_OK)return this.onEnd(status),this.ended=!0,!1;strm.next_out&&(0===strm.avail_out||status===c.Z_STREAM_END||0===strm.avail_in&&_mode===c.Z_FINISH)&&("string"===this.options.to?(next_out_utf8=strings.utf8border(strm.output,strm.next_out),tail=strm.next_out-next_out_utf8,utf8str=strings.buf2string(strm.output,next_out_utf8),strm.next_out=tail,strm.avail_out=chunkSize-tail,tail&&utils.arraySet(strm.output,strm.output,next_out_utf8,tail,0),this.onData(utf8str)):this.onData(utils.shrinkBuf(strm.output,strm.next_out)))}while(strm.avail_in>0&&status!==c.Z_STREAM_END);return status===c.Z_STREAM_END&&(_mode=c.Z_FINISH),_mode===c.Z_FINISH?(status=zlib_inflate.inflateEnd(this.strm),this.onEnd(status),this.ended=!0,status===c.Z_OK):!0},Inflate.prototype.onData=function(chunk){this.chunks.push(chunk)},Inflate.prototype.onEnd=function(status){status===c.Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):utils.flattenChunks(this.chunks)),this.chunks=[],this.err=status,this.msg=this.strm.msg},exports.Inflate=Inflate,exports.inflate=inflate,exports.inflateRaw=inflateRaw,exports.ungzip=inflate},{"./utils/common":98,"./utils/strings":99,"./zlib/constants":101,"./zlib/gzheader":104,"./zlib/inflate.js":106,"./zlib/messages":108,"./zlib/zstream":110}],98:[function(require,module,exports){"use strict";var TYPED_OK="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;exports.assign=function(obj){for(var sources=Array.prototype.slice.call(arguments,1);sources.length;){var source=sources.shift();if(source){if("object"!=typeof source)throw new TypeError(source+"must be non-object");for(var p in source)source.hasOwnProperty(p)&&(obj[p]=source[p])}}return obj},exports.shrinkBuf=function(buf,size){return buf.length===size?buf:buf.subarray?buf.subarray(0,size):(buf.length=size,buf)};var fnTyped={arraySet:function(dest,src,src_offs,len,dest_offs){if(src.subarray&&dest.subarray)return void dest.set(src.subarray(src_offs,src_offs+len),dest_offs);for(var i=0;len>i;i++)dest[dest_offs+i]=src[src_offs+i]},flattenChunks:function(chunks){var i,l,len,pos,chunk,result;for(len=0,i=0,l=chunks.length;l>i;i++)len+=chunks[i].length;for(result=new Uint8Array(len),pos=0,i=0,l=chunks.length;l>i;i++)chunk=chunks[i],result.set(chunk,pos),pos+=chunk.length;return result}},fnUntyped={arraySet:function(dest,src,src_offs,len,dest_offs){for(var i=0;len>i;i++)dest[dest_offs+i]=src[src_offs+i]},flattenChunks:function(chunks){return[].concat.apply([],chunks)}};exports.setTyped=function(on){on?(exports.Buf8=Uint8Array,exports.Buf16=Uint16Array,exports.Buf32=Int32Array,exports.assign(exports,fnTyped)):(exports.Buf8=Array,exports.Buf16=Array,exports.Buf32=Array,exports.assign(exports,fnUntyped))},exports.setTyped(TYPED_OK)},{}],99:[function(require,module,exports){"use strict";function buf2binstring(buf,len){if(65537>len&&(buf.subarray&&STR_APPLY_UIA_OK||!buf.subarray&&STR_APPLY_OK))return String.fromCharCode.apply(null,utils.shrinkBuf(buf,len));for(var result="",i=0;len>i;i++)result+=String.fromCharCode(buf[i]);return result}var utils=require("./common"),STR_APPLY_OK=!0,STR_APPLY_UIA_OK=!0;try{String.fromCharCode.apply(null,[0])}catch(__){STR_APPLY_OK=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(__){STR_APPLY_UIA_OK=!1}for(var _utf8len=new utils.Buf8(256),i=0;256>i;i++)_utf8len[i]=i>=252?6:i>=248?5:i>=240?4:i>=224?3:i>=192?2:1;_utf8len[254]=_utf8len[254]=1,exports.string2buf=function(str){var buf,c,c2,m_pos,i,str_len=str.length,buf_len=0;for(m_pos=0;str_len>m_pos;m_pos++)c=str.charCodeAt(m_pos),55296===(64512&c)&&str_len>m_pos+1&&(c2=str.charCodeAt(m_pos+1),56320===(64512&c2)&&(c=65536+(c-55296<<10)+(c2-56320),m_pos++)),buf_len+=128>c?1:2048>c?2:65536>c?3:4;for(buf=new utils.Buf8(buf_len),i=0,m_pos=0;buf_len>i;m_pos++)c=str.charCodeAt(m_pos),55296===(64512&c)&&str_len>m_pos+1&&(c2=str.charCodeAt(m_pos+1),56320===(64512&c2)&&(c=65536+(c-55296<<10)+(c2-56320),m_pos++)),128>c?buf[i++]=c:2048>c?(buf[i++]=192|c>>>6,buf[i++]=128|63&c):65536>c?(buf[i++]=224|c>>>12,buf[i++]=128|c>>>6&63,buf[i++]=128|63&c):(buf[i++]=240|c>>>18,buf[i++]=128|c>>>12&63,buf[i++]=128|c>>>6&63,buf[i++]=128|63&c);return buf},exports.buf2binstring=function(buf){return buf2binstring(buf,buf.length)},exports.binstring2buf=function(str){for(var buf=new utils.Buf8(str.length),i=0,len=buf.length;len>i;i++)buf[i]=str.charCodeAt(i);return buf},exports.buf2string=function(buf,max){var i,out,c,c_len,len=max||buf.length,utf16buf=new Array(2*len);for(out=0,i=0;len>i;)if(c=buf[i++],128>c)utf16buf[out++]=c;else if(c_len=_utf8len[c],c_len>4)utf16buf[out++]=65533,i+=c_len-1;else{for(c&=2===c_len?31:3===c_len?15:7;c_len>1&&len>i;)c=c<<6|63&buf[i++],c_len--;c_len>1?utf16buf[out++]=65533:65536>c?utf16buf[out++]=c:(c-=65536,utf16buf[out++]=55296|c>>10&1023,utf16buf[out++]=56320|1023&c)}return buf2binstring(utf16buf,out)},exports.utf8border=function(buf,max){var pos;for(max=max||buf.length,max>buf.length&&(max=buf.length),pos=max-1;pos>=0&&128===(192&buf[pos]);)pos--;return 0>pos?max:0===pos?max:pos+_utf8len[buf[pos]]>max?pos:max}},{"./common":98}],100:[function(require,module){"use strict";function adler32(adler,buf,len,pos){for(var s1=65535&adler|0,s2=adler>>>16&65535|0,n=0;0!==len;){n=len>2e3?2e3:len,len-=n;do s1=s1+buf[pos++]|0,s2=s2+s1|0;while(--n);s1%=65521,s2%=65521}return s1|s2<<16|0}module.exports=adler32},{}],101:[function(require,module){module.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],102:[function(require,module){"use strict";function makeTable(){for(var c,table=[],n=0;256>n;n++){c=n;for(var k=0;8>k;k++)c=1&c?3988292384^c>>>1:c>>>1;table[n]=c}return table}function crc32(crc,buf,len,pos){var t=crcTable,end=pos+len;crc=-1^crc;for(var i=pos;end>i;i++)crc=crc>>>8^t[255&(crc^buf[i])];return-1^crc}var crcTable=makeTable();module.exports=crc32},{}],103:[function(require,module,exports){"use strict";function err(strm,errorCode){return strm.msg=msg[errorCode],errorCode}function rank(f){return(f<<1)-(f>4?9:0)}function zero(buf){for(var len=buf.length;--len>=0;)buf[len]=0}function flush_pending(strm){var s=strm.state,len=s.pending;len>strm.avail_out&&(len=strm.avail_out),0!==len&&(utils.arraySet(strm.output,s.pending_buf,s.pending_out,len,strm.next_out),strm.next_out+=len,s.pending_out+=len,strm.total_out+=len,strm.avail_out-=len,s.pending-=len,0===s.pending&&(s.pending_out=0))}function flush_block_only(s,last){trees._tr_flush_block(s,s.block_start>=0?s.block_start:-1,s.strstart-s.block_start,last),s.block_start=s.strstart,flush_pending(s.strm)}function put_byte(s,b){s.pending_buf[s.pending++]=b}function putShortMSB(s,b){s.pending_buf[s.pending++]=b>>>8&255,s.pending_buf[s.pending++]=255&b}function read_buf(strm,buf,start,size){var len=strm.avail_in;return len>size&&(len=size),0===len?0:(strm.avail_in-=len,utils.arraySet(buf,strm.input,strm.next_in,len,start),1===strm.state.wrap?strm.adler=adler32(strm.adler,buf,len,start):2===strm.state.wrap&&(strm.adler=crc32(strm.adler,buf,len,start)),strm.next_in+=len,strm.total_in+=len,len)}function longest_match(s,cur_match){var match,len,chain_length=s.max_chain_length,scan=s.strstart,best_len=s.prev_length,nice_match=s.nice_match,limit=s.strstart>s.w_size-MIN_LOOKAHEAD?s.strstart-(s.w_size-MIN_LOOKAHEAD):0,_win=s.window,wmask=s.w_mask,prev=s.prev,strend=s.strstart+MAX_MATCH,scan_end1=_win[scan+best_len-1],scan_end=_win[scan+best_len];s.prev_length>=s.good_match&&(chain_length>>=2),nice_match>s.lookahead&&(nice_match=s.lookahead);do if(match=cur_match,_win[match+best_len]===scan_end&&_win[match+best_len-1]===scan_end1&&_win[match]===_win[scan]&&_win[++match]===_win[scan+1]){scan+=2,match++;do;while(_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&strend>scan);if(len=MAX_MATCH-(strend-scan),scan=strend-MAX_MATCH,len>best_len){if(s.match_start=cur_match,best_len=len,len>=nice_match)break;scan_end1=_win[scan+best_len-1],scan_end=_win[scan+best_len]}}while((cur_match=prev[cur_match&wmask])>limit&&0!==--chain_length);return best_len<=s.lookahead?best_len:s.lookahead}function fill_window(s){var p,n,m,more,str,_w_size=s.w_size;do{if(more=s.window_size-s.lookahead-s.strstart,s.strstart>=_w_size+(_w_size-MIN_LOOKAHEAD)){utils.arraySet(s.window,s.window,_w_size,_w_size,0),s.match_start-=_w_size,s.strstart-=_w_size,s.block_start-=_w_size,n=s.hash_size,p=n;do m=s.head[--p],s.head[p]=m>=_w_size?m-_w_size:0;while(--n);n=_w_size,p=n;do m=s.prev[--p],s.prev[p]=m>=_w_size?m-_w_size:0;while(--n);more+=_w_size}if(0===s.strm.avail_in)break;if(n=read_buf(s.strm,s.window,s.strstart+s.lookahead,more),s.lookahead+=n,s.lookahead+s.insert>=MIN_MATCH)for(str=s.strstart-s.insert,s.ins_h=s.window[str],s.ins_h=(s.ins_h<s.pending_buf_size-5&&(max_block_size=s.pending_buf_size-5);;){if(s.lookahead<=1){if(fill_window(s),0===s.lookahead&&flush===Z_NO_FLUSH)return BS_NEED_MORE;if(0===s.lookahead)break}s.strstart+=s.lookahead,s.lookahead=0;var max_start=s.block_start+max_block_size;if((0===s.strstart||s.strstart>=max_start)&&(s.lookahead=s.strstart-max_start,s.strstart=max_start,flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE;if(s.strstart-s.block_start>=s.w_size-MIN_LOOKAHEAD&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.strstart>s.block_start&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_NEED_MORE}function deflate_fast(s,flush){for(var hash_head,bflush;;){if(s.lookahead=MIN_MATCH&&(s.ins_h=(s.ins_h<=MIN_MATCH)if(bflush=trees._tr_tally(s,s.strstart-s.match_start,s.match_length-MIN_MATCH),s.lookahead-=s.match_length,s.match_length<=s.max_lazy_match&&s.lookahead>=MIN_MATCH){s.match_length--;do s.strstart++,s.ins_h=(s.ins_h<=MIN_MATCH&&(s.ins_h=(s.ins_h<4096)&&(s.match_length=MIN_MATCH-1)),s.prev_length>=MIN_MATCH&&s.match_length<=s.prev_length){max_insert=s.strstart+s.lookahead-MIN_MATCH,bflush=trees._tr_tally(s,s.strstart-1-s.prev_match,s.prev_length-MIN_MATCH),s.lookahead-=s.prev_length-1,s.prev_length-=2;do++s.strstart<=max_insert&&(s.ins_h=(s.ins_h<=MIN_MATCH&&s.strstart>0&&(scan=s.strstart-1,prev=_win[scan],prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan])){strend=s.strstart+MAX_MATCH;do;while(prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&strend>scan);s.match_length=MAX_MATCH-(strend-scan),s.match_length>s.lookahead&&(s.match_length=s.lookahead)}if(s.match_length>=MIN_MATCH?(bflush=trees._tr_tally(s,1,s.match_length-MIN_MATCH),s.lookahead-=s.match_length,s.strstart+=s.match_length,s.match_length=0):(bflush=trees._tr_tally(s,0,s.window[s.strstart]),s.lookahead--,s.strstart++),bflush&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.last_lit&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE}function deflate_huff(s,flush){for(var bflush;;){if(0===s.lookahead&&(fill_window(s),0===s.lookahead)){if(flush===Z_NO_FLUSH)return BS_NEED_MORE;break}if(s.match_length=0,bflush=trees._tr_tally(s,0,s.window[s.strstart]),s.lookahead--,s.strstart++,bflush&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.last_lit&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE}function lm_init(s){s.window_size=2*s.w_size,zero(s.head),s.max_lazy_match=configuration_table[s.level].max_lazy,s.good_match=configuration_table[s.level].good_length,s.nice_match=configuration_table[s.level].nice_length,s.max_chain_length=configuration_table[s.level].max_chain,s.strstart=0,s.block_start=0,s.lookahead=0,s.insert=0,s.match_length=s.prev_length=MIN_MATCH-1,s.match_available=0,s.ins_h=0}function DeflateState(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Z_DEFLATED,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new utils.Buf16(2*HEAP_SIZE),this.dyn_dtree=new utils.Buf16(2*(2*D_CODES+1)),this.bl_tree=new utils.Buf16(2*(2*BL_CODES+1)),zero(this.dyn_ltree),zero(this.dyn_dtree),zero(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new utils.Buf16(MAX_BITS+1),this.heap=new utils.Buf16(2*L_CODES+1),zero(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new utils.Buf16(2*L_CODES+1),zero(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function deflateResetKeep(strm){var s;return strm&&strm.state?(strm.total_in=strm.total_out=0,strm.data_type=Z_UNKNOWN,s=strm.state,s.pending=0,s.pending_out=0,s.wrap<0&&(s.wrap=-s.wrap),s.status=s.wrap?INIT_STATE:BUSY_STATE,strm.adler=2===s.wrap?0:1,s.last_flush=Z_NO_FLUSH,trees._tr_init(s),Z_OK):err(strm,Z_STREAM_ERROR)}function deflateReset(strm){var ret=deflateResetKeep(strm);return ret===Z_OK&&lm_init(strm.state),ret}function deflateSetHeader(strm,head){return strm&&strm.state?2!==strm.state.wrap?Z_STREAM_ERROR:(strm.state.gzhead=head,Z_OK):Z_STREAM_ERROR}function deflateInit2(strm,level,method,windowBits,memLevel,strategy){if(!strm)return Z_STREAM_ERROR;var wrap=1;if(level===Z_DEFAULT_COMPRESSION&&(level=6),0>windowBits?(wrap=0,windowBits=-windowBits):windowBits>15&&(wrap=2,windowBits-=16),1>memLevel||memLevel>MAX_MEM_LEVEL||method!==Z_DEFLATED||8>windowBits||windowBits>15||0>level||level>9||0>strategy||strategy>Z_FIXED)return err(strm,Z_STREAM_ERROR);8===windowBits&&(windowBits=9);var s=new DeflateState;return strm.state=s,s.strm=strm,s.wrap=wrap,s.gzhead=null,s.w_bits=windowBits,s.w_size=1<>1,s.l_buf=3*s.lit_bufsize,s.level=level,s.strategy=strategy,s.method=method,deflateReset(strm) -}function deflateInit(strm,level){return deflateInit2(strm,level,Z_DEFLATED,MAX_WBITS,DEF_MEM_LEVEL,Z_DEFAULT_STRATEGY)}function deflate(strm,flush){var old_flush,s,beg,val;if(!strm||!strm.state||flush>Z_BLOCK||0>flush)return strm?err(strm,Z_STREAM_ERROR):Z_STREAM_ERROR;if(s=strm.state,!strm.output||!strm.input&&0!==strm.avail_in||s.status===FINISH_STATE&&flush!==Z_FINISH)return err(strm,0===strm.avail_out?Z_BUF_ERROR:Z_STREAM_ERROR);if(s.strm=strm,old_flush=s.last_flush,s.last_flush=flush,s.status===INIT_STATE)if(2===s.wrap)strm.adler=0,put_byte(s,31),put_byte(s,139),put_byte(s,8),s.gzhead?(put_byte(s,(s.gzhead.text?1:0)+(s.gzhead.hcrc?2:0)+(s.gzhead.extra?4:0)+(s.gzhead.name?8:0)+(s.gzhead.comment?16:0)),put_byte(s,255&s.gzhead.time),put_byte(s,s.gzhead.time>>8&255),put_byte(s,s.gzhead.time>>16&255),put_byte(s,s.gzhead.time>>24&255),put_byte(s,9===s.level?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0),put_byte(s,255&s.gzhead.os),s.gzhead.extra&&s.gzhead.extra.length&&(put_byte(s,255&s.gzhead.extra.length),put_byte(s,s.gzhead.extra.length>>8&255)),s.gzhead.hcrc&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending,0)),s.gzindex=0,s.status=EXTRA_STATE):(put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,9===s.level?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0),put_byte(s,OS_CODE),s.status=BUSY_STATE);else{var header=Z_DEFLATED+(s.w_bits-8<<4)<<8,level_flags=-1;level_flags=s.strategy>=Z_HUFFMAN_ONLY||s.level<2?0:s.level<6?1:6===s.level?2:3,header|=level_flags<<6,0!==s.strstart&&(header|=PRESET_DICT),header+=31-header%31,s.status=BUSY_STATE,putShortMSB(s,header),0!==s.strstart&&(putShortMSB(s,strm.adler>>>16),putShortMSB(s,65535&strm.adler)),strm.adler=1}if(s.status===EXTRA_STATE)if(s.gzhead.extra){for(beg=s.pending;s.gzindex<(65535&s.gzhead.extra.length)&&(s.pending!==s.pending_buf_size||(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending!==s.pending_buf_size));)put_byte(s,255&s.gzhead.extra[s.gzindex]),s.gzindex++;s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),s.gzindex===s.gzhead.extra.length&&(s.gzindex=0,s.status=NAME_STATE)}else s.status=NAME_STATE;if(s.status===NAME_STATE)if(s.gzhead.name){beg=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending===s.pending_buf_size)){val=1;break}val=s.gzindexbeg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),0===val&&(s.gzindex=0,s.status=COMMENT_STATE)}else s.status=COMMENT_STATE;if(s.status===COMMENT_STATE)if(s.gzhead.comment){beg=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending===s.pending_buf_size)){val=1;break}val=s.gzindexbeg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),0===val&&(s.status=HCRC_STATE)}else s.status=HCRC_STATE;if(s.status===HCRC_STATE&&(s.gzhead.hcrc?(s.pending+2>s.pending_buf_size&&flush_pending(strm),s.pending+2<=s.pending_buf_size&&(put_byte(s,255&strm.adler),put_byte(s,strm.adler>>8&255),strm.adler=0,s.status=BUSY_STATE)):s.status=BUSY_STATE),0!==s.pending){if(flush_pending(strm),0===strm.avail_out)return s.last_flush=-1,Z_OK}else if(0===strm.avail_in&&rank(flush)<=rank(old_flush)&&flush!==Z_FINISH)return err(strm,Z_BUF_ERROR);if(s.status===FINISH_STATE&&0!==strm.avail_in)return err(strm,Z_BUF_ERROR);if(0!==strm.avail_in||0!==s.lookahead||flush!==Z_NO_FLUSH&&s.status!==FINISH_STATE){var bstate=s.strategy===Z_HUFFMAN_ONLY?deflate_huff(s,flush):s.strategy===Z_RLE?deflate_rle(s,flush):configuration_table[s.level].func(s,flush);if((bstate===BS_FINISH_STARTED||bstate===BS_FINISH_DONE)&&(s.status=FINISH_STATE),bstate===BS_NEED_MORE||bstate===BS_FINISH_STARTED)return 0===strm.avail_out&&(s.last_flush=-1),Z_OK;if(bstate===BS_BLOCK_DONE&&(flush===Z_PARTIAL_FLUSH?trees._tr_align(s):flush!==Z_BLOCK&&(trees._tr_stored_block(s,0,0,!1),flush===Z_FULL_FLUSH&&(zero(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),flush_pending(strm),0===strm.avail_out))return s.last_flush=-1,Z_OK}return flush!==Z_FINISH?Z_OK:s.wrap<=0?Z_STREAM_END:(2===s.wrap?(put_byte(s,255&strm.adler),put_byte(s,strm.adler>>8&255),put_byte(s,strm.adler>>16&255),put_byte(s,strm.adler>>24&255),put_byte(s,255&strm.total_in),put_byte(s,strm.total_in>>8&255),put_byte(s,strm.total_in>>16&255),put_byte(s,strm.total_in>>24&255)):(putShortMSB(s,strm.adler>>>16),putShortMSB(s,65535&strm.adler)),flush_pending(strm),s.wrap>0&&(s.wrap=-s.wrap),0!==s.pending?Z_OK:Z_STREAM_END)}function deflateEnd(strm){var status;return strm&&strm.state?(status=strm.state.status,status!==INIT_STATE&&status!==EXTRA_STATE&&status!==NAME_STATE&&status!==COMMENT_STATE&&status!==HCRC_STATE&&status!==BUSY_STATE&&status!==FINISH_STATE?err(strm,Z_STREAM_ERROR):(strm.state=null,status===BUSY_STATE?err(strm,Z_DATA_ERROR):Z_OK)):Z_STREAM_ERROR}var configuration_table,utils=require("../utils/common"),trees=require("./trees"),adler32=require("./adler32"),crc32=require("./crc32"),msg=require("./messages"),Z_NO_FLUSH=0,Z_PARTIAL_FLUSH=1,Z_FULL_FLUSH=3,Z_FINISH=4,Z_BLOCK=5,Z_OK=0,Z_STREAM_END=1,Z_STREAM_ERROR=-2,Z_DATA_ERROR=-3,Z_BUF_ERROR=-5,Z_DEFAULT_COMPRESSION=-1,Z_FILTERED=1,Z_HUFFMAN_ONLY=2,Z_RLE=3,Z_FIXED=4,Z_DEFAULT_STRATEGY=0,Z_UNKNOWN=2,Z_DEFLATED=8,MAX_MEM_LEVEL=9,MAX_WBITS=15,DEF_MEM_LEVEL=8,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,MIN_MATCH=3,MAX_MATCH=258,MIN_LOOKAHEAD=MAX_MATCH+MIN_MATCH+1,PRESET_DICT=32,INIT_STATE=42,EXTRA_STATE=69,NAME_STATE=73,COMMENT_STATE=91,HCRC_STATE=103,BUSY_STATE=113,FINISH_STATE=666,BS_NEED_MORE=1,BS_BLOCK_DONE=2,BS_FINISH_STARTED=3,BS_FINISH_DONE=4,OS_CODE=3,Config=function(good_length,max_lazy,nice_length,max_chain,func){this.good_length=good_length,this.max_lazy=max_lazy,this.nice_length=nice_length,this.max_chain=max_chain,this.func=func};configuration_table=[new Config(0,0,0,0,deflate_stored),new Config(4,4,8,4,deflate_fast),new Config(4,5,16,8,deflate_fast),new Config(4,6,32,32,deflate_fast),new Config(4,4,16,16,deflate_slow),new Config(8,16,32,32,deflate_slow),new Config(8,16,128,128,deflate_slow),new Config(8,32,128,256,deflate_slow),new Config(32,128,258,1024,deflate_slow),new Config(32,258,258,4096,deflate_slow)],exports.deflateInit=deflateInit,exports.deflateInit2=deflateInit2,exports.deflateReset=deflateReset,exports.deflateResetKeep=deflateResetKeep,exports.deflateSetHeader=deflateSetHeader,exports.deflate=deflate,exports.deflateEnd=deflateEnd,exports.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":98,"./adler32":100,"./crc32":102,"./messages":108,"./trees":109}],104:[function(require,module){"use strict";function GZheader(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}module.exports=GZheader},{}],105:[function(require,module){"use strict";var BAD=30,TYPE=12;module.exports=function(strm,start){var state,_in,last,_out,beg,end,dmax,wsize,whave,wnext,window,hold,bits,lcode,dcode,lmask,dmask,here,op,len,dist,from,from_source,input,output;state=strm.state,_in=strm.next_in,input=strm.input,last=_in+(strm.avail_in-5),_out=strm.next_out,output=strm.output,beg=_out-(start-strm.avail_out),end=_out+(strm.avail_out-257),dmax=state.dmax,wsize=state.wsize,whave=state.whave,wnext=state.wnext,window=state.window,hold=state.hold,bits=state.bits,lcode=state.lencode,dcode=state.distcode,lmask=(1<bits&&(hold+=input[_in++]<>>24,hold>>>=op,bits-=op,op=here>>>16&255,0===op)output[_out++]=65535&here;else{if(!(16&op)){if(0===(64&op)){here=lcode[(65535&here)+(hold&(1<bits&&(hold+=input[_in++]<>>=op,bits-=op),15>bits&&(hold+=input[_in++]<>>24,hold>>>=op,bits-=op,op=here>>>16&255,!(16&op)){if(0===(64&op)){here=dcode[(65535&here)+(hold&(1<bits&&(hold+=input[_in++]<bits&&(hold+=input[_in++]<dmax){strm.msg="invalid distance too far back",state.mode=BAD;break top}if(hold>>>=op,bits-=op,op=_out-beg,dist>op){if(op=dist-op,op>whave&&state.sane){strm.msg="invalid distance too far back",state.mode=BAD;break top}if(from=0,from_source=window,0===wnext){if(from+=wsize-op,len>op){len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}}else if(op>wnext){if(from+=wsize+wnext-op,op-=wnext,len>op){len-=op;do output[_out++]=window[from++];while(--op);if(from=0,len>wnext){op=wnext,len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}}}else if(from+=wnext-op,len>op){len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}for(;len>2;)output[_out++]=from_source[from++],output[_out++]=from_source[from++],output[_out++]=from_source[from++],len-=3;len&&(output[_out++]=from_source[from++],len>1&&(output[_out++]=from_source[from++]))}else{from=_out-dist;do output[_out++]=output[from++],output[_out++]=output[from++],output[_out++]=output[from++],len-=3;while(len>2);len&&(output[_out++]=output[from++],len>1&&(output[_out++]=output[from++]))}break}}break}}while(last>_in&&end>_out);len=bits>>3,_in-=len,bits-=len<<3,hold&=(1<_in?5+(last-_in):5-(_in-last),strm.avail_out=end>_out?257+(end-_out):257-(_out-end),state.hold=hold,state.bits=bits}},{}],106:[function(require,module,exports){"use strict";function ZSWAP32(q){return(q>>>24&255)+(q>>>8&65280)+((65280&q)<<8)+((255&q)<<24)}function InflateState(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new utils.Buf16(320),this.work=new utils.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function inflateResetKeep(strm){var state;return strm&&strm.state?(state=strm.state,strm.total_in=strm.total_out=state.total=0,strm.msg="",state.wrap&&(strm.adler=1&state.wrap),state.mode=HEAD,state.last=0,state.havedict=0,state.dmax=32768,state.head=null,state.hold=0,state.bits=0,state.lencode=state.lendyn=new utils.Buf32(ENOUGH_LENS),state.distcode=state.distdyn=new utils.Buf32(ENOUGH_DISTS),state.sane=1,state.back=-1,Z_OK):Z_STREAM_ERROR}function inflateReset(strm){var state;return strm&&strm.state?(state=strm.state,state.wsize=0,state.whave=0,state.wnext=0,inflateResetKeep(strm)):Z_STREAM_ERROR}function inflateReset2(strm,windowBits){var wrap,state;return strm&&strm.state?(state=strm.state,0>windowBits?(wrap=0,windowBits=-windowBits):(wrap=(windowBits>>4)+1,48>windowBits&&(windowBits&=15)),windowBits&&(8>windowBits||windowBits>15)?Z_STREAM_ERROR:(null!==state.window&&state.wbits!==windowBits&&(state.window=null),state.wrap=wrap,state.wbits=windowBits,inflateReset(strm))):Z_STREAM_ERROR}function inflateInit2(strm,windowBits){var ret,state;return strm?(state=new InflateState,strm.state=state,state.window=null,ret=inflateReset2(strm,windowBits),ret!==Z_OK&&(strm.state=null),ret):Z_STREAM_ERROR}function inflateInit(strm){return inflateInit2(strm,DEF_WBITS)}function fixedtables(state){if(virgin){var sym;for(lenfix=new utils.Buf32(512),distfix=new utils.Buf32(32),sym=0;144>sym;)state.lens[sym++]=8;for(;256>sym;)state.lens[sym++]=9;for(;280>sym;)state.lens[sym++]=7;for(;288>sym;)state.lens[sym++]=8;for(inflate_table(LENS,state.lens,0,288,lenfix,0,state.work,{bits:9}),sym=0;32>sym;)state.lens[sym++]=5;inflate_table(DISTS,state.lens,0,32,distfix,0,state.work,{bits:5}),virgin=!1}state.lencode=lenfix,state.lenbits=9,state.distcode=distfix,state.distbits=5}function updatewindow(strm,src,end,copy){var dist,state=strm.state;return null===state.window&&(state.wsize=1<=state.wsize?(utils.arraySet(state.window,src,end-state.wsize,state.wsize,0),state.wnext=0,state.whave=state.wsize):(dist=state.wsize-state.wnext,dist>copy&&(dist=copy),utils.arraySet(state.window,src,end-copy,dist,state.wnext),copy-=dist,copy?(utils.arraySet(state.window,src,end-copy,copy,0),state.wnext=copy,state.whave=state.wsize):(state.wnext+=dist,state.wnext===state.wsize&&(state.wnext=0),state.whavebits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,state.check=crc32(state.check,hbuf,2,0),hold=0,bits=0,state.mode=FLAGS;break}if(state.flags=0,state.head&&(state.head.done=!1),!(1&state.wrap)||(((255&hold)<<8)+(hold>>8))%31){strm.msg="incorrect header check",state.mode=BAD;break}if((15&hold)!==Z_DEFLATED){strm.msg="unknown compression method",state.mode=BAD;break}if(hold>>>=4,bits-=4,len=(15&hold)+8,0===state.wbits)state.wbits=len;else if(len>state.wbits){strm.msg="invalid window size",state.mode=BAD;break}state.dmax=1<bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>8&1),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=TIME;case TIME:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,hbuf[2]=hold>>>16&255,hbuf[3]=hold>>>24&255,state.check=crc32(state.check,hbuf,4,0)),hold=0,bits=0,state.mode=OS;case OS:for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>8),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=EXLEN;case EXLEN:if(1024&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0}else state.head&&(state.head.extra=null);state.mode=EXTRA;case EXTRA:if(1024&state.flags&&(copy=state.length,copy>have&&(copy=have),copy&&(state.head&&(len=state.head.extra_len-state.length,state.head.extra||(state.head.extra=new Array(state.head.extra_len)),utils.arraySet(state.head.extra,input,next,copy,len)),512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,state.length-=copy),state.length))break inf_leave;state.length=0,state.mode=NAME;case NAME:if(2048&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.name+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.name=null);state.length=0,state.mode=COMMENT;case COMMENT:if(4096&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.comment+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.comment=null);state.mode=HCRC;case HCRC:if(512&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>9&1,state.head.done=!0),strm.adler=state.check=0,state.mode=TYPE;break;case DICTID:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=7&bits,bits-=7&bits,state.mode=CHECK;break}for(;3>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=1,bits-=1,3&hold){case 0:state.mode=STORED;break;case 1:if(fixedtables(state),state.mode=LEN_,flush===Z_TREES){hold>>>=2,bits-=2;break inf_leave}break;case 2:state.mode=TABLE;break;case 3:strm.msg="invalid block type",state.mode=BAD}hold>>>=2,bits-=2;break;case STORED:for(hold>>>=7&bits,bits-=7&bits;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>16^65535)){strm.msg="invalid stored block lengths",state.mode=BAD;break}if(state.length=65535&hold,hold=0,bits=0,state.mode=COPY_,flush===Z_TREES)break inf_leave;case COPY_:state.mode=COPY;case COPY:if(copy=state.length){if(copy>have&&(copy=have),copy>left&&(copy=left),0===copy)break inf_leave;utils.arraySet(output,input,next,copy,put),have-=copy,next+=copy,left-=copy,put+=copy,state.length-=copy;break}state.mode=TYPE;break;case TABLE:for(;14>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=5,bits-=5,state.ndist=(31&hold)+1,hold>>>=5,bits-=5,state.ncode=(15&hold)+4,hold>>>=4,bits-=4,state.nlen>286||state.ndist>30){strm.msg="too many length or distance symbols",state.mode=BAD;break}state.have=0,state.mode=LENLENS;case LENLENS:for(;state.havebits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=3,bits-=3}for(;state.have<19;)state.lens[order[state.have++]]=0;if(state.lencode=state.lendyn,state.lenbits=7,opts={bits:state.lenbits},ret=inflate_table(CODES,state.lens,0,19,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid code lengths set",state.mode=BAD;break}state.have=0,state.mode=CODELENS;case CODELENS:for(;state.have>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<here_val)hold>>>=here_bits,bits-=here_bits,state.lens[state.have++]=here_val;else{if(16===here_val){for(n=here_bits+2;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,0===state.have){strm.msg="invalid bit length repeat",state.mode=BAD;break}len=state.lens[state.have-1],copy=3+(3&hold),hold>>>=2,bits-=2}else if(17===here_val){for(n=here_bits+3;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=3+(7&hold),hold>>>=3,bits-=3}else{for(n=here_bits+7;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=11+(127&hold),hold>>>=7,bits-=7}if(state.have+copy>state.nlen+state.ndist){strm.msg="invalid bit length repeat",state.mode=BAD;break}for(;copy--;)state.lens[state.have++]=len}}if(state.mode===BAD)break;if(0===state.lens[256]){strm.msg="invalid code -- missing end-of-block",state.mode=BAD;break}if(state.lenbits=9,opts={bits:state.lenbits},ret=inflate_table(LENS,state.lens,0,state.nlen,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid literal/lengths set",state.mode=BAD;break}if(state.distbits=6,state.distcode=state.distdyn,opts={bits:state.distbits},ret=inflate_table(DISTS,state.lens,state.nlen,state.ndist,state.distcode,0,state.work,opts),state.distbits=opts.bits,ret){strm.msg="invalid distances set",state.mode=BAD;break}if(state.mode=LEN_,flush===Z_TREES)break inf_leave;case LEN_:state.mode=LEN;case LEN:if(have>=6&&left>=258){strm.next_out=put,strm.avail_out=left,strm.next_in=next,strm.avail_in=have,state.hold=hold,state.bits=bits,inflate_fast(strm,_out),put=strm.next_out,output=strm.output,left=strm.avail_out,next=strm.next_in,input=strm.input,have=strm.avail_in,hold=state.hold,bits=state.bits,state.mode===TYPE&&(state.back=-1);break}for(state.back=0;here=state.lencode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,state.length=here_val,0===here_op){state.mode=LIT;break}if(32&here_op){state.back=-1,state.mode=TYPE;break}if(64&here_op){strm.msg="invalid literal/length code",state.mode=BAD;break}state.extra=15&here_op,state.mode=LENEXT;case LENEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}state.was=state.length,state.mode=DIST;case DIST:for(;here=state.distcode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,64&here_op){strm.msg="invalid distance code",state.mode=BAD;break}state.offset=here_val,state.extra=15&here_op,state.mode=DISTEXT;case DISTEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}if(state.offset>state.dmax){strm.msg="invalid distance too far back",state.mode=BAD;break}state.mode=MATCH;case MATCH:if(0===left)break inf_leave;if(copy=_out-left,state.offset>copy){if(copy=state.offset-copy,copy>state.whave&&state.sane){strm.msg="invalid distance too far back",state.mode=BAD;break}copy>state.wnext?(copy-=state.wnext,from=state.wsize-copy):from=state.wnext-copy,copy>state.length&&(copy=state.length),from_source=state.window}else from_source=output,from=put-state.offset,copy=state.length;copy>left&&(copy=left),left-=copy,state.length-=copy;do output[put++]=from_source[from++];while(--copy);0===state.length&&(state.mode=LEN);break;case LIT:if(0===left)break inf_leave;output[put++]=state.length,left--,state.mode=LEN;break;case CHECK:if(state.wrap){for(;32>bits;){if(0===have)break inf_leave;have--,hold|=input[next++]<bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<=len;len++)count[len]=0;for(sym=0;codes>sym;sym++)count[lens[lens_index+sym]]++;for(root=bits,max=MAXBITS;max>=1&&0===count[max];max--);if(root>max&&(root=max),0===max)return table[table_index++]=20971520,table[table_index++]=20971520,opts.bits=1,0;for(min=1;max>min&&0===count[min];min++);for(min>root&&(root=min),left=1,len=1;MAXBITS>=len;len++)if(left<<=1,left-=count[len],0>left)return-1;if(left>0&&(type===CODES||1!==max))return-1;for(offs[1]=0,len=1;MAXBITS>len;len++)offs[len+1]=offs[len]+count[len];for(sym=0;codes>sym;sym++)0!==lens[lens_index+sym]&&(work[offs[lens[lens_index+sym]]++]=sym);if(type===CODES?(base=extra=work,end=19):type===LENS?(base=lbase,base_index-=257,extra=lext,extra_index-=257,end=256):(base=dbase,extra=dext,end=-1),huff=0,sym=0,len=min,next=table_index,curr=root,drop=0,low=-1,used=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;for(var i=0;;){i++,here_bits=len-drop,work[sym]end?(here_op=extra[extra_index+work[sym]],here_val=base[base_index+work[sym]]):(here_op=96,here_val=0),incr=1<>drop)+fill]=here_bits<<24|here_op<<16|here_val|0;while(0!==fill);for(incr=1<>=1;if(0!==incr?(huff&=incr-1,huff+=incr):huff=0,sym++,0===--count[len]){if(len===max)break;len=lens[lens_index+work[sym]]}if(len>root&&(huff&mask)!==low){for(0===drop&&(drop=root),next+=min,curr=len-drop,left=1<curr+drop&&(left-=count[curr+drop],!(0>=left));)curr++,left<<=1;if(used+=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;low=huff&mask,table[low]=root<<24|curr<<16|next-table_index|0}}return 0!==huff&&(table[next+huff]=len-drop<<24|64<<16|0),opts.bits=root,0}},{"../utils/common":98}],108:[function(require,module){"use strict";module.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],109:[function(require,module,exports){"use strict";function zero(buf){for(var len=buf.length;--len>=0;)buf[len]=0}function d_code(dist){return 256>dist?_dist_code[dist]:_dist_code[256+(dist>>>7)]}function put_short(s,w){s.pending_buf[s.pending++]=255&w,s.pending_buf[s.pending++]=w>>>8&255}function send_bits(s,value,length){s.bi_valid>Buf_size-length?(s.bi_buf|=value<>Buf_size-s.bi_valid,s.bi_valid+=length-Buf_size):(s.bi_buf|=value<>>=1,res<<=1;while(--len>0);return res>>>1}function bi_flush(s){16===s.bi_valid?(put_short(s,s.bi_buf),s.bi_buf=0,s.bi_valid=0):s.bi_valid>=8&&(s.pending_buf[s.pending++]=255&s.bi_buf,s.bi_buf>>=8,s.bi_valid-=8)}function gen_bitlen(s,desc){var h,n,m,bits,xbits,f,tree=desc.dyn_tree,max_code=desc.max_code,stree=desc.stat_desc.static_tree,has_stree=desc.stat_desc.has_stree,extra=desc.stat_desc.extra_bits,base=desc.stat_desc.extra_base,max_length=desc.stat_desc.max_length,overflow=0; -for(bits=0;MAX_BITS>=bits;bits++)s.bl_count[bits]=0;for(tree[2*s.heap[s.heap_max]+1]=0,h=s.heap_max+1;HEAP_SIZE>h;h++)n=s.heap[h],bits=tree[2*tree[2*n+1]+1]+1,bits>max_length&&(bits=max_length,overflow++),tree[2*n+1]=bits,n>max_code||(s.bl_count[bits]++,xbits=0,n>=base&&(xbits=extra[n-base]),f=tree[2*n],s.opt_len+=f*(bits+xbits),has_stree&&(s.static_len+=f*(stree[2*n+1]+xbits)));if(0!==overflow){do{for(bits=max_length-1;0===s.bl_count[bits];)bits--;s.bl_count[bits]--,s.bl_count[bits+1]+=2,s.bl_count[max_length]--,overflow-=2}while(overflow>0);for(bits=max_length;0!==bits;bits--)for(n=s.bl_count[bits];0!==n;)m=s.heap[--h],m>max_code||(tree[2*m+1]!==bits&&(s.opt_len+=(bits-tree[2*m+1])*tree[2*m],tree[2*m+1]=bits),n--)}}function gen_codes(tree,max_code,bl_count){var bits,n,next_code=new Array(MAX_BITS+1),code=0;for(bits=1;MAX_BITS>=bits;bits++)next_code[bits]=code=code+bl_count[bits-1]<<1;for(n=0;max_code>=n;n++){var len=tree[2*n+1];0!==len&&(tree[2*n]=bi_reverse(next_code[len]++,len))}}function tr_static_init(){var n,bits,length,code,dist,bl_count=new Array(MAX_BITS+1);for(length=0,code=0;LENGTH_CODES-1>code;code++)for(base_length[code]=length,n=0;n<1<code;code++)for(base_dist[code]=dist,n=0;n<1<>=7;D_CODES>code;code++)for(base_dist[code]=dist<<7,n=0;n<1<=bits;bits++)bl_count[bits]=0;for(n=0;143>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(;255>=n;)static_ltree[2*n+1]=9,n++,bl_count[9]++;for(;279>=n;)static_ltree[2*n+1]=7,n++,bl_count[7]++;for(;287>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(gen_codes(static_ltree,L_CODES+1,bl_count),n=0;D_CODES>n;n++)static_dtree[2*n+1]=5,static_dtree[2*n]=bi_reverse(n,5);static_l_desc=new StaticTreeDesc(static_ltree,extra_lbits,LITERALS+1,L_CODES,MAX_BITS),static_d_desc=new StaticTreeDesc(static_dtree,extra_dbits,0,D_CODES,MAX_BITS),static_bl_desc=new StaticTreeDesc(new Array(0),extra_blbits,0,BL_CODES,MAX_BL_BITS)}function init_block(s){var n;for(n=0;L_CODES>n;n++)s.dyn_ltree[2*n]=0;for(n=0;D_CODES>n;n++)s.dyn_dtree[2*n]=0;for(n=0;BL_CODES>n;n++)s.bl_tree[2*n]=0;s.dyn_ltree[2*END_BLOCK]=1,s.opt_len=s.static_len=0,s.last_lit=s.matches=0}function bi_windup(s){s.bi_valid>8?put_short(s,s.bi_buf):s.bi_valid>0&&(s.pending_buf[s.pending++]=s.bi_buf),s.bi_buf=0,s.bi_valid=0}function copy_block(s,buf,len,header){bi_windup(s),header&&(put_short(s,len),put_short(s,~len)),utils.arraySet(s.pending_buf,s.window,buf,len,s.pending),s.pending+=len}function smaller(tree,n,m,depth){var _n2=2*n,_m2=2*m;return tree[_n2]n;n++)0!==tree[2*n]?(s.heap[++s.heap_len]=max_code=n,s.depth[n]=0):tree[2*n+1]=0;for(;s.heap_len<2;)node=s.heap[++s.heap_len]=2>max_code?++max_code:0,tree[2*node]=1,s.depth[node]=0,s.opt_len--,has_stree&&(s.static_len-=stree[2*node+1]);for(desc.max_code=max_code,n=s.heap_len>>1;n>=1;n--)pqdownheap(s,tree,n);node=elems;do n=s.heap[1],s.heap[1]=s.heap[s.heap_len--],pqdownheap(s,tree,1),m=s.heap[1],s.heap[--s.heap_max]=n,s.heap[--s.heap_max]=m,tree[2*node]=tree[2*n]+tree[2*m],s.depth[node]=(s.depth[n]>=s.depth[m]?s.depth[n]:s.depth[m])+1,tree[2*n+1]=tree[2*m+1]=node,s.heap[1]=node++,pqdownheap(s,tree,1);while(s.heap_len>=2);s.heap[--s.heap_max]=s.heap[1],gen_bitlen(s,desc),gen_codes(tree,max_code,s.bl_count)}function scan_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),tree[2*(max_code+1)+1]=65535,n=0;max_code>=n;n++)curlen=nextlen,nextlen=tree[2*(n+1)+1],++countcount?s.bl_tree[2*curlen]+=count:0!==curlen?(curlen!==prevlen&&s.bl_tree[2*curlen]++,s.bl_tree[2*REP_3_6]++):10>=count?s.bl_tree[2*REPZ_3_10]++:s.bl_tree[2*REPZ_11_138]++,count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4))}function send_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),n=0;max_code>=n;n++)if(curlen=nextlen,nextlen=tree[2*(n+1)+1],!(++countcount){do send_code(s,curlen,s.bl_tree);while(0!==--count)}else 0!==curlen?(curlen!==prevlen&&(send_code(s,curlen,s.bl_tree),count--),send_code(s,REP_3_6,s.bl_tree),send_bits(s,count-3,2)):10>=count?(send_code(s,REPZ_3_10,s.bl_tree),send_bits(s,count-3,3)):(send_code(s,REPZ_11_138,s.bl_tree),send_bits(s,count-11,7));count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4)}}function build_bl_tree(s){var max_blindex;for(scan_tree(s,s.dyn_ltree,s.l_desc.max_code),scan_tree(s,s.dyn_dtree,s.d_desc.max_code),build_tree(s,s.bl_desc),max_blindex=BL_CODES-1;max_blindex>=3&&0===s.bl_tree[2*bl_order[max_blindex]+1];max_blindex--);return s.opt_len+=3*(max_blindex+1)+5+5+4,max_blindex}function send_all_trees(s,lcodes,dcodes,blcodes){var rank;for(send_bits(s,lcodes-257,5),send_bits(s,dcodes-1,5),send_bits(s,blcodes-4,4),rank=0;blcodes>rank;rank++)send_bits(s,s.bl_tree[2*bl_order[rank]+1],3);send_tree(s,s.dyn_ltree,lcodes-1),send_tree(s,s.dyn_dtree,dcodes-1)}function detect_data_type(s){var n,black_mask=4093624447;for(n=0;31>=n;n++,black_mask>>>=1)if(1&black_mask&&0!==s.dyn_ltree[2*n])return Z_BINARY;if(0!==s.dyn_ltree[18]||0!==s.dyn_ltree[20]||0!==s.dyn_ltree[26])return Z_TEXT;for(n=32;LITERALS>n;n++)if(0!==s.dyn_ltree[2*n])return Z_TEXT;return Z_BINARY}function _tr_init(s){static_init_done||(tr_static_init(),static_init_done=!0),s.l_desc=new TreeDesc(s.dyn_ltree,static_l_desc),s.d_desc=new TreeDesc(s.dyn_dtree,static_d_desc),s.bl_desc=new TreeDesc(s.bl_tree,static_bl_desc),s.bi_buf=0,s.bi_valid=0,init_block(s)}function _tr_stored_block(s,buf,stored_len,last){send_bits(s,(STORED_BLOCK<<1)+(last?1:0),3),copy_block(s,buf,stored_len,!0)}function _tr_align(s){send_bits(s,STATIC_TREES<<1,3),send_code(s,END_BLOCK,static_ltree),bi_flush(s)}function _tr_flush_block(s,buf,stored_len,last){var opt_lenb,static_lenb,max_blindex=0;s.level>0?(s.strm.data_type===Z_UNKNOWN&&(s.strm.data_type=detect_data_type(s)),build_tree(s,s.l_desc),build_tree(s,s.d_desc),max_blindex=build_bl_tree(s),opt_lenb=s.opt_len+3+7>>>3,static_lenb=s.static_len+3+7>>>3,opt_lenb>=static_lenb&&(opt_lenb=static_lenb)):opt_lenb=static_lenb=stored_len+5,opt_lenb>=stored_len+4&&-1!==buf?_tr_stored_block(s,buf,stored_len,last):s.strategy===Z_FIXED||static_lenb===opt_lenb?(send_bits(s,(STATIC_TREES<<1)+(last?1:0),3),compress_block(s,static_ltree,static_dtree)):(send_bits(s,(DYN_TREES<<1)+(last?1:0),3),send_all_trees(s,s.l_desc.max_code+1,s.d_desc.max_code+1,max_blindex+1),compress_block(s,s.dyn_ltree,s.dyn_dtree)),init_block(s),last&&bi_windup(s)}function _tr_tally(s,dist,lc){return s.pending_buf[s.d_buf+2*s.last_lit]=dist>>>8&255,s.pending_buf[s.d_buf+2*s.last_lit+1]=255&dist,s.pending_buf[s.l_buf+s.last_lit]=255&lc,s.last_lit++,0===dist?s.dyn_ltree[2*lc]++:(s.matches++,dist--,s.dyn_ltree[2*(_length_code[lc]+LITERALS+1)]++,s.dyn_dtree[2*d_code(dist)]++),s.last_lit===s.lit_bufsize-1}var utils=require("../utils/common"),Z_FIXED=4,Z_BINARY=0,Z_TEXT=1,Z_UNKNOWN=2,STORED_BLOCK=0,STATIC_TREES=1,DYN_TREES=2,MIN_MATCH=3,MAX_MATCH=258,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,Buf_size=16,MAX_BL_BITS=7,END_BLOCK=256,REP_3_6=16,REPZ_3_10=17,REPZ_11_138=18,extra_lbits=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],extra_dbits=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],extra_blbits=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],bl_order=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],DIST_CODE_LEN=512,static_ltree=new Array(2*(L_CODES+2));zero(static_ltree);var static_dtree=new Array(2*D_CODES);zero(static_dtree);var _dist_code=new Array(DIST_CODE_LEN);zero(_dist_code);var _length_code=new Array(MAX_MATCH-MIN_MATCH+1);zero(_length_code);var base_length=new Array(LENGTH_CODES);zero(base_length);var base_dist=new Array(D_CODES);zero(base_dist);var static_l_desc,static_d_desc,static_bl_desc,StaticTreeDesc=function(static_tree,extra_bits,extra_base,elems,max_length){this.static_tree=static_tree,this.extra_bits=extra_bits,this.extra_base=extra_base,this.elems=elems,this.max_length=max_length,this.has_stree=static_tree&&static_tree.length},TreeDesc=function(dyn_tree,stat_desc){this.dyn_tree=dyn_tree,this.max_code=0,this.stat_desc=stat_desc},static_init_done=!1;exports._tr_init=_tr_init,exports._tr_stored_block=_tr_stored_block,exports._tr_flush_block=_tr_flush_block,exports._tr_tally=_tr_tally,exports._tr_align=_tr_align},{"../utils/common":98}],110:[function(require,module){"use strict";function ZStream(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}module.exports=ZStream},{}],111:[function(require,module){(function(Buffer){"use strict";function decodeB64(str){return new Buffer(str,"base64")}function unpackPNG(w,h,c,str){var pixels=parse(decodeB64(str));return ndarray(pixels.data,[h,w,pixels.channels],[pixels.channels*w,pixels.channels,1],0)}module.exports=unpackPNG;var ndarray=require("ndarray"),parse=require("pngparse-sync")}).call(this,require("buffer").Buffer)},{buffer:123,ndarray:92,"pngparse-sync":94}],112:[function(require,module,exports){!function(_global){"use strict";var shim={};"undefined"==typeof exports?"function"==typeof define&&"object"==typeof define.amd&&define.amd?(shim.exports={},define(function(){return shim.exports})):shim.exports="undefined"!=typeof window?window:_global:shim.exports=exports,function(exports){if(!GLMAT_EPSILON)var GLMAT_EPSILON=1e-6;if(!GLMAT_ARRAY_TYPE)var GLMAT_ARRAY_TYPE="undefined"!=typeof Float32Array?Float32Array:Array;if(!GLMAT_RANDOM)var GLMAT_RANDOM=Math.random;var glMatrix={};glMatrix.setMatrixArrayType=function(type){GLMAT_ARRAY_TYPE=type},"undefined"!=typeof exports&&(exports.glMatrix=glMatrix);var degree=Math.PI/180;glMatrix.toRadian=function(a){return a*degree};var vec2={};vec2.create=function(){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=0,out[1]=0,out},vec2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=a[0],out[1]=a[1],out},vec2.fromValues=function(x,y){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=x,out[1]=y,out},vec2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out},vec2.set=function(out,x,y){return out[0]=x,out[1]=y,out},vec2.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out},vec2.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out},vec2.sub=vec2.subtract,vec2.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out},vec2.mul=vec2.multiply,vec2.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out},vec2.div=vec2.divide,vec2.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out},vec2.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out},vec2.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out},vec2.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out},vec2.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return Math.sqrt(x*x+y*y)},vec2.dist=vec2.distance,vec2.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return x*x+y*y},vec2.sqrDist=vec2.squaredDistance,vec2.length=function(a){var x=a[0],y=a[1];return Math.sqrt(x*x+y*y)},vec2.len=vec2.length,vec2.squaredLength=function(a){var x=a[0],y=a[1];return x*x+y*y},vec2.sqrLen=vec2.squaredLength,vec2.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out},vec2.normalize=function(out,a){var x=a[0],y=a[1],len=x*x+y*y;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11]; -out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],113:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance}function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":112}],114:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],115:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],116:[function(require,module){function parse(html,doc){if("string"!=typeof html)throw new TypeError("String expected");doc||(doc=document);var m=/<([\w:]+)/.exec(html);if(!m)return doc.createTextNode(html);html=html.replace(/^\s+|\s+$/g,"");var tag=m[1];if("body"==tag){var el=doc.createElement("html");return el.innerHTML=html,el.removeChild(el.lastChild)}var wrap=map[tag]||map._default,depth=wrap[0],prefix=wrap[1],suffix=wrap[2],el=doc.createElement("div");for(el.innerHTML=prefix+html+suffix;depth--;)el=el.lastChild;if(el.firstChild==el.lastChild)return el.removeChild(el.firstChild);for(var fragment=doc.createDocumentFragment();el.firstChild;)fragment.appendChild(el.removeChild(el.firstChild));return fragment}module.exports=parse;var map={legend:[1,"
      ","
      "],tr:[2,"","
      "],col:[2,"","
      "],_default:[0,"",""]};map.td=map.th=[3,"","
      "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
      "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],117:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],118:[function(require,module,exports){arguments[4][32][0].apply(exports,arguments)},{_process:126,"raf-component":119,sliced:121}],119:[function(require,module){module.exports=require(33)},{}],120:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],121:[function(require,module,exports){arguments[4][34][0].apply(exports,arguments)},{"./lib/sliced":122}],122:[function(require,module){module.exports=require(35)},{}],123:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)"base64"===encoding&&(subject=base64clean(subject)),length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new Error("First argument needs to be a number, array or string.");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}var buf;TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;assert(strLen%2===0,"Invalid hex string"),length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);assert(!isNaN(byte),"Invalid hex string"),buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string),buf,offset,length);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function binarySlice(buf,start,end){return asciiSlice(buf,start,end)}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;i=len)){var val;return littleEndian?(val=buf[offset],len>offset+1&&(val|=buf[offset+1]<<8)):(val=buf[offset]<<8,len>offset+1&&(val|=buf[offset+1])),val}}function readUInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val;return littleEndian?(len>offset+2&&(val=buf[offset+2]<<16),len>offset+1&&(val|=buf[offset+1]<<8),val|=buf[offset],len>offset+3&&(val+=buf[offset+3]<<24>>>0)):(len>offset+1&&(val=buf[offset+1]<<16),len>offset+2&&(val|=buf[offset+2]<<8),len>offset+3&&(val|=buf[offset+3]),val+=buf[offset]<<24>>>0),val}}function readInt16(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len)){var val=readUInt16(buf,offset,littleEndian,!0),neg=32768&val;return neg?-1*(65535-val+1):val}}function readInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val=readUInt32(buf,offset,littleEndian,!0),neg=2147483648&val;return neg?-1*(4294967295-val+1):val}}function readFloat(buf,offset,littleEndian,noAssert){return noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i);return offset+2}}function writeUInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255;return offset+4}}function writeInt16(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len))return value>=0?writeUInt16(buf,value,offset,littleEndian,noAssert):writeUInt16(buf,65535+value+1,offset,littleEndian,noAssert),offset+2}function writeInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return value>=0?writeUInt32(buf,value,offset,littleEndian,noAssert):writeUInt32(buf,4294967295+value+1,offset,littleEndian,noAssert),offset+4}function writeFloat(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+7=len))return ieee754.write(buf,value,offset,littleEndian,52,8),offset+8}function base64clean(str){for(str=stringtrim(str).replace(INVALID_BASE64_RE,"");str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArray(subject){return(Array.isArray||function(subject){return"[object Array]"===Object.prototype.toString.call(subject)})(subject)}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(str){for(var byteArray=[],i=0;i=b)byteArray.push(b);else{var start=i;b>=55296&&57343>=b&&i++;for(var h=encodeURIComponent(str.slice(start,i+1)).substr(1).split("%"),j=0;j>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(str)}function blitBuffer(src,dst,offset,length){for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533)}}function verifuint(value,max){assert("number"==typeof value,"cannot write a non-number as a number"),assert(value>=0,"specified a negative value for writing an unsigned value"),assert(max>=value,"value is larger than maximum value for type"),assert(Math.floor(value)===value,"value has a fractional component")}function verifsint(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value"),assert(Math.floor(value)===value,"value has a fractional component")}function verifIEEE754(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value")}function assert(test,message){if(!test)throw new Error(message||"Failed assertion")}var base64=require("base64-js"),ieee754=require("ieee754");exports.Buffer=Buffer,exports.SlowBuffer=Buffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}();Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0; -default:return!1}},Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.byteLength=function(str,encoding){var ret;switch(str=str.toString(),encoding||"utf8"){case"hex":ret=str.length/2;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"ascii":case"binary":case"raw":ret=str.length;break;case"base64":ret=base64ToBytes(str).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=2*str.length;break;default:throw new Error("Unknown encoding")}return ret},Buffer.concat=function(list,totalLength){if(assert(isArray(list),"Usage: Buffer.concat(list[, length])"),0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;ii&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}offset=Number(offset)||0;var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toString=function(encoding,start,end){var self=this;if(encoding=String(encoding||"utf8").toLowerCase(),start=Number(start)||0,end=void 0===end?self.length:Number(end),end===start)return"";var ret;switch(encoding){case"hex":ret=hexSlice(self,start,end);break;case"utf8":case"utf-8":ret=utf8Slice(self,start,end);break;case"ascii":ret=asciiSlice(self,start,end);break;case"binary":ret=binarySlice(self,start,end);break;case"base64":ret=base64Slice(self,start,end);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leSlice(self,start,end);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.equals=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),0===Buffer.compare(this,b)},Buffer.prototype.compare=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),Buffer.compare(this,b)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start||(target_start=0),end!==start&&0!==target.length&&0!==source.length){assert(end>=start,"sourceEnd < sourceStart"),assert(target_start>=0&&target_start=0&&start=0&&end<=source.length,"sourceEnd out of bounds"),end>this.length&&(end=this.length),target.length-target_startlen||!TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start)}},Buffer.prototype.slice=function(start,end){var len=this.length;if(start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start),TYPED_ARRAY_SUPPORT)return Buffer._augment(this.subarray(start,end));for(var sliceLen=end-start,newBuf=new Buffer(sliceLen,void 0,!0),i=0;sliceLen>i;i++)newBuf[i]=this[i+start];return newBuf},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return readUInt16(this,offset,!0,noAssert)},Buffer.prototype.readUInt16BE=function(offset,noAssert){return readUInt16(this,offset,!1,noAssert)},Buffer.prototype.readUInt32LE=function(offset,noAssert){return readUInt32(this,offset,!0,noAssert)},Buffer.prototype.readUInt32BE=function(offset,noAssert){return readUInt32(this,offset,!1,noAssert)},Buffer.prototype.readInt8=function(offset,noAssert){if(noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length)){var neg=128&this[offset];return neg?-1*(255-this[offset]+1):this[offset]}},Buffer.prototype.readInt16LE=function(offset,noAssert){return readInt16(this,offset,!0,noAssert)},Buffer.prototype.readInt16BE=function(offset,noAssert){return readInt16(this,offset,!1,noAssert)},Buffer.prototype.readInt32LE=function(offset,noAssert){return readInt32(this,offset,!0,noAssert)},Buffer.prototype.readInt32BE=function(offset,noAssert){return readInt32(this,offset,!1,noAssert)},Buffer.prototype.readFloatLE=function(offset,noAssert){return readFloat(this,offset,!0,noAssert)},Buffer.prototype.readFloatBE=function(offset,noAssert){return readFloat(this,offset,!1,noAssert)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return readDouble(this,offset,!0,noAssert)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return readDouble(this,offset,!1,noAssert)},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(this[offset]=value,offset+1)},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(value>=0?this.writeUInt8(value,offset,noAssert):this.writeUInt8(255+value+1,offset,noAssert),offset+1)},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return writeInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return writeInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return writeInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return writeInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert)},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),assert(end>=start,"end < start"),end!==start&&0!==this.length){assert(start>=0&&start=0&&end<=this.length,"end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.inspect=function(){for(var out=[],len=this.length,i=0;len>i;i++)if(out[i]=toHex(this[i]),i===exports.INSPECT_MAX_BYTES){out[i+1]="...";break}return""},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z]/g},{"base64-js":124,ieee754:125}],124:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS?62:code===SLASH?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],125:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],126:[function(require,module){function noop(){}var process=module.exports={};process.nextTick=function(){var canSetImmediate="undefined"!=typeof window&&window.setImmediate,canPost="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(canSetImmediate)return function(f){return window.setImmediate(f)};if(canPost){var queue=[];return window.addEventListener("message",function(ev){var source=ev.source;if((source===window||null===source)&&"process-tick"===ev.data&&(ev.stopPropagation(),queue.length>0)){var fn=queue.shift();fn()}},!0),function(fn){queue.push(fn),window.postMessage("process-tick","*")}}return function(fn){setTimeout(fn,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to the WebGL API that runs in your browser. webgl-workshop\nis a NodeSchool workshop originally created for\nCampJS IV. Everything is powered by node.js, browserify and\na selection of stackgl packages under the hood.

      ',thumb:"http://i.imgur.com/vBJ7d6o.jpg",featured:!0,i:0},{name:"shader-school",link:"http://github.com/stackgl/shader-school",desc:"",thumb:"http://imgur.com/hegi9dZ.png",featured:!1,i:1},{name:"gl-surface-plot",link:"https://github.com/mikolalysenko/gl-surface-plot",desc:"",thumb:"http://i.imgur.com/z4xjpgu.jpg",featured:!1,i:2},{name:"bunny-walkthrough",link:"https://github.com/stackgl/bunny-walkthrough",desc:"",thumb:"http://i.imgur.com/OefbPjB.jpg",featured:!1,i:3},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:4},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:5},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:6},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:7},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:8},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:9},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:10},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:11},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:12},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:13}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2},{name:"gl-texture2d-display",desc:"\n",link:"http://ghub.io/gl-texture2d-display",thumb:"http://imgur.com/z6Cxsfy.png",featured:!1,i:3}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8},{name:"gl-gif",desc:"\n",link:"http://ghub.io/gl-gif",thumb:"http://imgur.com/AiC0Sab.gif",featured:!1,i:9}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
    • \n
      \n \n
      \n
      \n
      \n \n

      {{name}}

      \n
      \n
      \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
      \n
      \n
      \n
    • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:123,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n); +case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":30}],29:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],30:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],32:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:126,"raf-component":33,sliced:34}],33:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],34:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":35}],35:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],36:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],37:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":36}],38:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":39}],39:[function(require,module){module.exports=require(33)},{}],40:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:45}],45:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],46:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t) +}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:52,"ndarray-ops":47,"typedarray-pool":56,webglew:58}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":50}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:51}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":49}],51:[function(require,module){module.exports=require(13)},{}],52:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":53}],53:[function(require,module){module.exports=require(15)},{}],54:[function(require,module){module.exports=require(16)},{}],55:[function(require,module){module.exports=require(17)},{}],56:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":54,buffer:123,dup:55}],57:[function(require,module){module.exports=require(41)},{}],58:[function(require,module){module.exports=require(42)},{weakmap:57}],59:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],60:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":59}],61:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out +},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],69:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":70}],70:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":72}],71:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:73}],72:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":71}],73:[function(require,module){module.exports=require(13)},{}],74:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":75}],75:[function(require,module){module.exports=require(15)},{}],76:[function(require,module){module.exports=require(16)},{}],77:[function(require,module){module.exports=require(17)},{}],78:[function(require,module){module.exports=require(56)},{"bit-twiddle":76,buffer:123,dup:77}],79:[function(require,module){module.exports=require(41)},{}],80:[function(require,module){module.exports=require(42)},{weakmap:79}],81:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function isPacked(array){for(var shape=array.shape,stride=array.stride,s=1,i=shape.length-1;i>=0;--i){if(stride[i]!==s)return!1;s*=shape[i]}return!0}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(array),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type===gl.FLOAT&&webglew(gl).texture_float&&(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store;if(packed){var array_size=array.size;buffer=array.data.subarray(array.offset,array.offset+array_size)}else{for(var sz=1,stride=new Array(shape.length),i=shape.length-1;i>=0;--i)stride[i]=sz,sz*=shape[i];buf_store=pool.malloc(sz,dtype);var buf_array=ndarray(buf_store,array.shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,sz)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[1],shape[0],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][1],0|arguments[1][0],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew"),linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)};Object.defineProperty(Texture2D.prototype,"minFilter",{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}});var proto=Texture2D.prototype;Object.defineProperty(proto,"magFilter",{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}}),Object.defineProperty(proto,"wrapS",{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}}),Object.defineProperty(proto,"wrapT",{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}}),Object.defineProperty(proto,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapT=v[0],this._wrapS=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),v}}),Object.defineProperty(proto,"mipSamples",{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(proto,"shape",{get:function(){return this._shape},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];var r=0|x[0],c=0|x[1];if(this.height===r&&this.width===c)return x;var gl=this.gl,maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>c||c>maxSize||0>r||r>maxSize)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[r,c],this.bind(),gl.texImage2D(gl.TEXTURE_2D,0,this.format,c,r,0,this.format,this.type,null),this._mipLevels=[0],x}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[0],x_off=0|x_off[1]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}},module.exports=createTexture2D},{ndarray:74,"ndarray-ops":69,"typedarray-pool":78,webglew:80}],82:[function(require,module){function programify(vertex,fragment,uniforms,attributes){return function(gl){return shader(gl,vertex,fragment,uniforms,attributes)}}module.exports=programify;var shader=require("gl-shader-core")},{"gl-shader-core":88}],83:[function(require,module){function noop(){throw new Error("You should bundle your code using `glslify` as a transform.")}module.exports=noop},{}],84:[function(require,module){"use strict";function ShaderAttribute(gl,program,location,dimension,name,constFunc,relink){this._gl=gl,this._program=program,this._location=location,this._dimension=dimension,this._name=name,this._constFunc=constFunc,this._relink=relink}function addVectorAttribute(gl,program,location,dimension,obj,name,doLink){for(var constFuncArgs=["gl","v"],varNames=[],i=0;dimension>i;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],85:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;k=pa&&pc>=pa?a:pc>=pb?b:c}function parseData(dataBuffer){function inputData(data){for(var tmp,j,len=data.length,i=0;i!==len;)switch(state){case 0:if(data.readUInt8(i++)!==HEADER[off++])return!1;off===HEADER.length&&(state=1,off=0);break;case 1:if(8-off>len-i)data.copy(buf,off,i),off+=len-i,i=len;else switch(data.copy(buf,off,i,i+8-off),i+=8-off,off=0,chunkLength=buf.readUInt32BE(0),buf.toString("ascii",4,8)){case"IHDR":state=2;break;case"PLTE":if(3!==pngColorType)state=7;else{if(chunkLength%3!==0)return!1;pngPaletteEntries=chunkLength/3,pngPalette=new Buffer(chunkLength),state=3}break;case"tRNS":if(3!==pngColorType)return!1;idChannels++,pngAlphaEntries=chunkLength,pngAlpha=new Buffer(chunkLength),state=4;break;case"IDAT":pngPixels||(pngPixels=new Uint8Array(pngWidth*pngHeight*idChannels)),state=5;break;case"IEND":state=6;break;default:state=7}break;case 2:if(13!==chunkLength)return!1;if(chunkLength-off>len-i)data.copy(buf,off,i),off+=len-i,i=len;else{if(data.copy(buf,off,i,i+chunkLength-off),0!==buf.readUInt8(10))return!1;if(0!==buf.readUInt8(11))return!1;if(0!==buf.readUInt8(12))return!1;switch(i+=chunkLength-off,state=8,off=0,pngWidth=buf.readUInt32BE(0),pngHeight=buf.readUInt32BE(4),pngBitDepth=buf.readUInt8(8),pngDepthMult=255/((1<len-i)data.copy(pngPalette,off,i),off+=len-i,i=len;else for(data.copy(pngPalette,off,i,i+chunkLength-off),i+=chunkLength-off,state=8,off=0,idChannels=1,j=pngPaletteEntries;j--;)if(pngPalette[3*j+0]!==pngPalette[3*j+1]||pngPalette[3*j+0]!==pngPalette[3*j+2]){idChannels=3;break}break;case 4:chunkLength-off>len-i?(data.copy(pngAlpha,off,i),off+=len-i,i=len):(data.copy(pngAlpha,off,i,i+chunkLength-off),i+=chunkLength-off,state=8,off=0);break;case 5:chunkLength-off>len-i?(inflateQueue.push(data.slice(i)),off+=len-i,i=len):(inflateQueue.push(data.slice(i,i+chunkLength-off)),i+=chunkLength-off,state=8,off=0);break;case 6:if(0!==chunkLength)return!1;4-off>len-i?(off+=len-i,i=len):(pngTrailer=new Buffer(0),i+=4-off,state=9,off=0);break;case 7:chunkLength-off>len-i?(off+=len-i,i=len):(i+=chunkLength-off,state=8,off=0);break;case 8:4-off>len-i?(off+=len-i,i=len):(i+=4-off,state=1,off=0);break;case 9:tmp=new Buffer(off+len-i),pngTrailer.copy(tmp),data.copy(tmp,off,i,len),pngTrailer=tmp,off+=len-i,i=len}return!0}function unpackPixels(data){var i,tmp,x,j,k,len=data.length;for(i=0;i!==len;++i){if(-1===b)scanlineFilter=data[i],tmp=currentScanline,currentScanline=priorScanline,priorScanline=tmp;else switch(scanlineFilter){case 0:currentScanline[b]=data[i];break;case 1:currentScanline[b]=pngBytesPerPixel>b?data[i]:data[i]+currentScanline[b-pngBytesPerPixel]&255;break;case 2:currentScanline[b]=data[i]+priorScanline[b]&255;break;case 3:currentScanline[b]=data[i]+((pngBytesPerPixel>b?priorScanline[b]:currentScanline[b-pngBytesPerPixel]+priorScanline[b])>>>1)&255;break;case 4:currentScanline[b]=data[i]+(pngBytesPerPixel>b?priorScanline[b]:paeth(currentScanline[b-pngBytesPerPixel],priorScanline[b],priorScanline[b-pngBytesPerPixel]))&255;break;default:return null}if(++b===pngBytesPerScanline){if(p===pngPixels.length)return null;for(j=0,x=0;x!==pngWidth;++x){for(k=0;k!==pngSamplesPerPixel;++j,++k)switch(pngBitDepth){case 1:pngSamples[k]=currentScanline[j>>>3]>>7-(7&j)&1;break;case 2:pngSamples[k]=currentScanline[j>>>2]>>(3-(3&j)<<1)&3;break;case 4:pngSamples[k]=currentScanline[j>>>1]>>(1-(1&j)<<2)&15;break;case 8:pngSamples[k]=currentScanline[j];break;default:return null}switch(pngColorType){case 0:pngPixels[p++]=pngSamples[0]*pngDepthMult;break;case 2:pngPixels[p++]=pngSamples[0]*pngDepthMult,pngPixels[p++]=pngSamples[1]*pngDepthMult,pngPixels[p++]=pngSamples[2]*pngDepthMult;break;case 3:if(pngSamples[0]>=pngPaletteEntries)return null;switch(idChannels){case 1:pngPixels[p++]=pngPalette[3*pngSamples[0]];break;case 2:pngPixels[p++]=pngPalette[3*pngSamples[0]],pngPixels[p++]=pngSamples[0]0?opt.windowBits=-opt.windowBits:opt.gzip&&opt.windowBits>0&&opt.windowBits<16&&(opt.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;var status=zlib_deflate.deflateInit2(this.strm,opt.level,opt.method,opt.windowBits,opt.memLevel,opt.strategy);if(status!==Z_OK)throw new Error(msg[status]);opt.header&&zlib_deflate.deflateSetHeader(this.strm,opt.header)};Deflate.prototype.push=function(data,mode){var status,_mode,strm=this.strm,chunkSize=this.options.chunkSize;if(this.ended)return!1;_mode=mode===~~mode?mode:mode===!0?Z_FINISH:Z_NO_FLUSH,strm.input="string"==typeof data?strings.string2buf(data):data,strm.next_in=0,strm.avail_in=strm.input.length;do{if(0===strm.avail_out&&(strm.output=new utils.Buf8(chunkSize),strm.next_out=0,strm.avail_out=chunkSize),status=zlib_deflate.deflate(strm,_mode),status!==Z_STREAM_END&&status!==Z_OK)return this.onEnd(status),this.ended=!0,!1;(0===strm.avail_out||0===strm.avail_in&&_mode===Z_FINISH)&&this.onData("string"===this.options.to?strings.buf2binstring(utils.shrinkBuf(strm.output,strm.next_out)):utils.shrinkBuf(strm.output,strm.next_out))}while((strm.avail_in>0||0===strm.avail_out)&&status!==Z_STREAM_END);return _mode===Z_FINISH?(status=zlib_deflate.deflateEnd(this.strm),this.onEnd(status),this.ended=!0,status===Z_OK):!0},Deflate.prototype.onData=function(chunk){this.chunks.push(chunk)},Deflate.prototype.onEnd=function(status){status===Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):utils.flattenChunks(this.chunks)),this.chunks=[],this.err=status,this.msg=this.strm.msg},exports.Deflate=Deflate,exports.deflate=deflate,exports.deflateRaw=deflateRaw,exports.gzip=gzip},{"./utils/common":98,"./utils/strings":99,"./zlib/deflate.js":103,"./zlib/messages":108,"./zlib/zstream":110}],97:[function(require,module,exports){"use strict";function inflate(input,options){var inflator=new Inflate(options);if(inflator.push(input,!0),inflator.err)throw inflator.msg;return inflator.result}function inflateRaw(input,options){return options=options||{},options.raw=!0,inflate(input,options)}var zlib_inflate=require("./zlib/inflate.js"),utils=require("./utils/common"),strings=require("./utils/strings"),c=require("./zlib/constants"),msg=require("./zlib/messages"),zstream=require("./zlib/zstream"),gzheader=require("./zlib/gzheader"),Inflate=function(options){this.options=utils.assign({chunkSize:16384,windowBits:0,to:""},options||{});var opt=this.options;opt.raw&&opt.windowBits>=0&&opt.windowBits<16&&(opt.windowBits=-opt.windowBits,0===opt.windowBits&&(opt.windowBits=-15)),!(opt.windowBits>=0&&opt.windowBits<16)||options&&options.windowBits||(opt.windowBits+=32),opt.windowBits>15&&opt.windowBits<48&&0===(15&opt.windowBits)&&(opt.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;var status=zlib_inflate.inflateInit2(this.strm,opt.windowBits);if(status!==c.Z_OK)throw new Error(msg[status]);this.header=new gzheader,zlib_inflate.inflateGetHeader(this.strm,this.header)};Inflate.prototype.push=function(data,mode){var status,_mode,next_out_utf8,tail,utf8str,strm=this.strm,chunkSize=this.options.chunkSize;if(this.ended)return!1;_mode=mode===~~mode?mode:mode===!0?c.Z_FINISH:c.Z_NO_FLUSH,strm.input="string"==typeof data?strings.binstring2buf(data):data,strm.next_in=0,strm.avail_in=strm.input.length;do{if(0===strm.avail_out&&(strm.output=new utils.Buf8(chunkSize),strm.next_out=0,strm.avail_out=chunkSize),status=zlib_inflate.inflate(strm,c.Z_NO_FLUSH),status!==c.Z_STREAM_END&&status!==c.Z_OK)return this.onEnd(status),this.ended=!0,!1;strm.next_out&&(0===strm.avail_out||status===c.Z_STREAM_END||0===strm.avail_in&&_mode===c.Z_FINISH)&&("string"===this.options.to?(next_out_utf8=strings.utf8border(strm.output,strm.next_out),tail=strm.next_out-next_out_utf8,utf8str=strings.buf2string(strm.output,next_out_utf8),strm.next_out=tail,strm.avail_out=chunkSize-tail,tail&&utils.arraySet(strm.output,strm.output,next_out_utf8,tail,0),this.onData(utf8str)):this.onData(utils.shrinkBuf(strm.output,strm.next_out)))}while(strm.avail_in>0&&status!==c.Z_STREAM_END);return status===c.Z_STREAM_END&&(_mode=c.Z_FINISH),_mode===c.Z_FINISH?(status=zlib_inflate.inflateEnd(this.strm),this.onEnd(status),this.ended=!0,status===c.Z_OK):!0},Inflate.prototype.onData=function(chunk){this.chunks.push(chunk)},Inflate.prototype.onEnd=function(status){status===c.Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):utils.flattenChunks(this.chunks)),this.chunks=[],this.err=status,this.msg=this.strm.msg},exports.Inflate=Inflate,exports.inflate=inflate,exports.inflateRaw=inflateRaw,exports.ungzip=inflate},{"./utils/common":98,"./utils/strings":99,"./zlib/constants":101,"./zlib/gzheader":104,"./zlib/inflate.js":106,"./zlib/messages":108,"./zlib/zstream":110}],98:[function(require,module,exports){"use strict";var TYPED_OK="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;exports.assign=function(obj){for(var sources=Array.prototype.slice.call(arguments,1);sources.length;){var source=sources.shift();if(source){if("object"!=typeof source)throw new TypeError(source+"must be non-object");for(var p in source)source.hasOwnProperty(p)&&(obj[p]=source[p])}}return obj},exports.shrinkBuf=function(buf,size){return buf.length===size?buf:buf.subarray?buf.subarray(0,size):(buf.length=size,buf)};var fnTyped={arraySet:function(dest,src,src_offs,len,dest_offs){if(src.subarray&&dest.subarray)return void dest.set(src.subarray(src_offs,src_offs+len),dest_offs);for(var i=0;len>i;i++)dest[dest_offs+i]=src[src_offs+i]},flattenChunks:function(chunks){var i,l,len,pos,chunk,result;for(len=0,i=0,l=chunks.length;l>i;i++)len+=chunks[i].length;for(result=new Uint8Array(len),pos=0,i=0,l=chunks.length;l>i;i++)chunk=chunks[i],result.set(chunk,pos),pos+=chunk.length;return result}},fnUntyped={arraySet:function(dest,src,src_offs,len,dest_offs){for(var i=0;len>i;i++)dest[dest_offs+i]=src[src_offs+i]},flattenChunks:function(chunks){return[].concat.apply([],chunks)}};exports.setTyped=function(on){on?(exports.Buf8=Uint8Array,exports.Buf16=Uint16Array,exports.Buf32=Int32Array,exports.assign(exports,fnTyped)):(exports.Buf8=Array,exports.Buf16=Array,exports.Buf32=Array,exports.assign(exports,fnUntyped))},exports.setTyped(TYPED_OK)},{}],99:[function(require,module,exports){"use strict";function buf2binstring(buf,len){if(65537>len&&(buf.subarray&&STR_APPLY_UIA_OK||!buf.subarray&&STR_APPLY_OK))return String.fromCharCode.apply(null,utils.shrinkBuf(buf,len));for(var result="",i=0;len>i;i++)result+=String.fromCharCode(buf[i]);return result}var utils=require("./common"),STR_APPLY_OK=!0,STR_APPLY_UIA_OK=!0;try{String.fromCharCode.apply(null,[0])}catch(__){STR_APPLY_OK=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(__){STR_APPLY_UIA_OK=!1}for(var _utf8len=new utils.Buf8(256),i=0;256>i;i++)_utf8len[i]=i>=252?6:i>=248?5:i>=240?4:i>=224?3:i>=192?2:1;_utf8len[254]=_utf8len[254]=1,exports.string2buf=function(str){var buf,c,c2,m_pos,i,str_len=str.length,buf_len=0;for(m_pos=0;str_len>m_pos;m_pos++)c=str.charCodeAt(m_pos),55296===(64512&c)&&str_len>m_pos+1&&(c2=str.charCodeAt(m_pos+1),56320===(64512&c2)&&(c=65536+(c-55296<<10)+(c2-56320),m_pos++)),buf_len+=128>c?1:2048>c?2:65536>c?3:4;for(buf=new utils.Buf8(buf_len),i=0,m_pos=0;buf_len>i;m_pos++)c=str.charCodeAt(m_pos),55296===(64512&c)&&str_len>m_pos+1&&(c2=str.charCodeAt(m_pos+1),56320===(64512&c2)&&(c=65536+(c-55296<<10)+(c2-56320),m_pos++)),128>c?buf[i++]=c:2048>c?(buf[i++]=192|c>>>6,buf[i++]=128|63&c):65536>c?(buf[i++]=224|c>>>12,buf[i++]=128|c>>>6&63,buf[i++]=128|63&c):(buf[i++]=240|c>>>18,buf[i++]=128|c>>>12&63,buf[i++]=128|c>>>6&63,buf[i++]=128|63&c);return buf},exports.buf2binstring=function(buf){return buf2binstring(buf,buf.length)},exports.binstring2buf=function(str){for(var buf=new utils.Buf8(str.length),i=0,len=buf.length;len>i;i++)buf[i]=str.charCodeAt(i);return buf},exports.buf2string=function(buf,max){var i,out,c,c_len,len=max||buf.length,utf16buf=new Array(2*len);for(out=0,i=0;len>i;)if(c=buf[i++],128>c)utf16buf[out++]=c;else if(c_len=_utf8len[c],c_len>4)utf16buf[out++]=65533,i+=c_len-1;else{for(c&=2===c_len?31:3===c_len?15:7;c_len>1&&len>i;)c=c<<6|63&buf[i++],c_len--;c_len>1?utf16buf[out++]=65533:65536>c?utf16buf[out++]=c:(c-=65536,utf16buf[out++]=55296|c>>10&1023,utf16buf[out++]=56320|1023&c)}return buf2binstring(utf16buf,out)},exports.utf8border=function(buf,max){var pos;for(max=max||buf.length,max>buf.length&&(max=buf.length),pos=max-1;pos>=0&&128===(192&buf[pos]);)pos--;return 0>pos?max:0===pos?max:pos+_utf8len[buf[pos]]>max?pos:max}},{"./common":98}],100:[function(require,module){"use strict";function adler32(adler,buf,len,pos){for(var s1=65535&adler|0,s2=adler>>>16&65535|0,n=0;0!==len;){n=len>2e3?2e3:len,len-=n;do s1=s1+buf[pos++]|0,s2=s2+s1|0;while(--n);s1%=65521,s2%=65521}return s1|s2<<16|0}module.exports=adler32},{}],101:[function(require,module){module.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],102:[function(require,module){"use strict";function makeTable(){for(var c,table=[],n=0;256>n;n++){c=n;for(var k=0;8>k;k++)c=1&c?3988292384^c>>>1:c>>>1;table[n]=c}return table}function crc32(crc,buf,len,pos){var t=crcTable,end=pos+len;crc=-1^crc;for(var i=pos;end>i;i++)crc=crc>>>8^t[255&(crc^buf[i])];return-1^crc}var crcTable=makeTable();module.exports=crc32},{}],103:[function(require,module,exports){"use strict";function err(strm,errorCode){return strm.msg=msg[errorCode],errorCode}function rank(f){return(f<<1)-(f>4?9:0)}function zero(buf){for(var len=buf.length;--len>=0;)buf[len]=0}function flush_pending(strm){var s=strm.state,len=s.pending;len>strm.avail_out&&(len=strm.avail_out),0!==len&&(utils.arraySet(strm.output,s.pending_buf,s.pending_out,len,strm.next_out),strm.next_out+=len,s.pending_out+=len,strm.total_out+=len,strm.avail_out-=len,s.pending-=len,0===s.pending&&(s.pending_out=0))}function flush_block_only(s,last){trees._tr_flush_block(s,s.block_start>=0?s.block_start:-1,s.strstart-s.block_start,last),s.block_start=s.strstart,flush_pending(s.strm)}function put_byte(s,b){s.pending_buf[s.pending++]=b}function putShortMSB(s,b){s.pending_buf[s.pending++]=b>>>8&255,s.pending_buf[s.pending++]=255&b}function read_buf(strm,buf,start,size){var len=strm.avail_in;return len>size&&(len=size),0===len?0:(strm.avail_in-=len,utils.arraySet(buf,strm.input,strm.next_in,len,start),1===strm.state.wrap?strm.adler=adler32(strm.adler,buf,len,start):2===strm.state.wrap&&(strm.adler=crc32(strm.adler,buf,len,start)),strm.next_in+=len,strm.total_in+=len,len)}function longest_match(s,cur_match){var match,len,chain_length=s.max_chain_length,scan=s.strstart,best_len=s.prev_length,nice_match=s.nice_match,limit=s.strstart>s.w_size-MIN_LOOKAHEAD?s.strstart-(s.w_size-MIN_LOOKAHEAD):0,_win=s.window,wmask=s.w_mask,prev=s.prev,strend=s.strstart+MAX_MATCH,scan_end1=_win[scan+best_len-1],scan_end=_win[scan+best_len];s.prev_length>=s.good_match&&(chain_length>>=2),nice_match>s.lookahead&&(nice_match=s.lookahead);do if(match=cur_match,_win[match+best_len]===scan_end&&_win[match+best_len-1]===scan_end1&&_win[match]===_win[scan]&&_win[++match]===_win[scan+1]){scan+=2,match++;do;while(_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&strend>scan);if(len=MAX_MATCH-(strend-scan),scan=strend-MAX_MATCH,len>best_len){if(s.match_start=cur_match,best_len=len,len>=nice_match)break;scan_end1=_win[scan+best_len-1],scan_end=_win[scan+best_len]}}while((cur_match=prev[cur_match&wmask])>limit&&0!==--chain_length);return best_len<=s.lookahead?best_len:s.lookahead}function fill_window(s){var p,n,m,more,str,_w_size=s.w_size;do{if(more=s.window_size-s.lookahead-s.strstart,s.strstart>=_w_size+(_w_size-MIN_LOOKAHEAD)){utils.arraySet(s.window,s.window,_w_size,_w_size,0),s.match_start-=_w_size,s.strstart-=_w_size,s.block_start-=_w_size,n=s.hash_size,p=n;do m=s.head[--p],s.head[p]=m>=_w_size?m-_w_size:0;while(--n);n=_w_size,p=n;do m=s.prev[--p],s.prev[p]=m>=_w_size?m-_w_size:0;while(--n);more+=_w_size}if(0===s.strm.avail_in)break;if(n=read_buf(s.strm,s.window,s.strstart+s.lookahead,more),s.lookahead+=n,s.lookahead+s.insert>=MIN_MATCH)for(str=s.strstart-s.insert,s.ins_h=s.window[str],s.ins_h=(s.ins_h<s.pending_buf_size-5&&(max_block_size=s.pending_buf_size-5);;){if(s.lookahead<=1){if(fill_window(s),0===s.lookahead&&flush===Z_NO_FLUSH)return BS_NEED_MORE;if(0===s.lookahead)break}s.strstart+=s.lookahead,s.lookahead=0;var max_start=s.block_start+max_block_size;if((0===s.strstart||s.strstart>=max_start)&&(s.lookahead=s.strstart-max_start,s.strstart=max_start,flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE;if(s.strstart-s.block_start>=s.w_size-MIN_LOOKAHEAD&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.strstart>s.block_start&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_NEED_MORE}function deflate_fast(s,flush){for(var hash_head,bflush;;){if(s.lookahead=MIN_MATCH&&(s.ins_h=(s.ins_h<=MIN_MATCH)if(bflush=trees._tr_tally(s,s.strstart-s.match_start,s.match_length-MIN_MATCH),s.lookahead-=s.match_length,s.match_length<=s.max_lazy_match&&s.lookahead>=MIN_MATCH){s.match_length--;do s.strstart++,s.ins_h=(s.ins_h<=MIN_MATCH&&(s.ins_h=(s.ins_h<4096)&&(s.match_length=MIN_MATCH-1)),s.prev_length>=MIN_MATCH&&s.match_length<=s.prev_length){max_insert=s.strstart+s.lookahead-MIN_MATCH,bflush=trees._tr_tally(s,s.strstart-1-s.prev_match,s.prev_length-MIN_MATCH),s.lookahead-=s.prev_length-1,s.prev_length-=2;do++s.strstart<=max_insert&&(s.ins_h=(s.ins_h<=MIN_MATCH&&s.strstart>0&&(scan=s.strstart-1,prev=_win[scan],prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan])){strend=s.strstart+MAX_MATCH;do;while(prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&strend>scan);s.match_length=MAX_MATCH-(strend-scan),s.match_length>s.lookahead&&(s.match_length=s.lookahead)}if(s.match_length>=MIN_MATCH?(bflush=trees._tr_tally(s,1,s.match_length-MIN_MATCH),s.lookahead-=s.match_length,s.strstart+=s.match_length,s.match_length=0):(bflush=trees._tr_tally(s,0,s.window[s.strstart]),s.lookahead--,s.strstart++),bflush&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.last_lit&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE}function deflate_huff(s,flush){for(var bflush;;){if(0===s.lookahead&&(fill_window(s),0===s.lookahead)){if(flush===Z_NO_FLUSH)return BS_NEED_MORE;break}if(s.match_length=0,bflush=trees._tr_tally(s,0,s.window[s.strstart]),s.lookahead--,s.strstart++,bflush&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.last_lit&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE}function lm_init(s){s.window_size=2*s.w_size,zero(s.head),s.max_lazy_match=configuration_table[s.level].max_lazy,s.good_match=configuration_table[s.level].good_length,s.nice_match=configuration_table[s.level].nice_length,s.max_chain_length=configuration_table[s.level].max_chain,s.strstart=0,s.block_start=0,s.lookahead=0,s.insert=0,s.match_length=s.prev_length=MIN_MATCH-1,s.match_available=0,s.ins_h=0}function DeflateState(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Z_DEFLATED,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new utils.Buf16(2*HEAP_SIZE),this.dyn_dtree=new utils.Buf16(2*(2*D_CODES+1)),this.bl_tree=new utils.Buf16(2*(2*BL_CODES+1)),zero(this.dyn_ltree),zero(this.dyn_dtree),zero(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new utils.Buf16(MAX_BITS+1),this.heap=new utils.Buf16(2*L_CODES+1),zero(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new utils.Buf16(2*L_CODES+1),zero(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function deflateResetKeep(strm){var s;return strm&&strm.state?(strm.total_in=strm.total_out=0,strm.data_type=Z_UNKNOWN,s=strm.state,s.pending=0,s.pending_out=0,s.wrap<0&&(s.wrap=-s.wrap),s.status=s.wrap?INIT_STATE:BUSY_STATE,strm.adler=2===s.wrap?0:1,s.last_flush=Z_NO_FLUSH,trees._tr_init(s),Z_OK):err(strm,Z_STREAM_ERROR) +}function deflateReset(strm){var ret=deflateResetKeep(strm);return ret===Z_OK&&lm_init(strm.state),ret}function deflateSetHeader(strm,head){return strm&&strm.state?2!==strm.state.wrap?Z_STREAM_ERROR:(strm.state.gzhead=head,Z_OK):Z_STREAM_ERROR}function deflateInit2(strm,level,method,windowBits,memLevel,strategy){if(!strm)return Z_STREAM_ERROR;var wrap=1;if(level===Z_DEFAULT_COMPRESSION&&(level=6),0>windowBits?(wrap=0,windowBits=-windowBits):windowBits>15&&(wrap=2,windowBits-=16),1>memLevel||memLevel>MAX_MEM_LEVEL||method!==Z_DEFLATED||8>windowBits||windowBits>15||0>level||level>9||0>strategy||strategy>Z_FIXED)return err(strm,Z_STREAM_ERROR);8===windowBits&&(windowBits=9);var s=new DeflateState;return strm.state=s,s.strm=strm,s.wrap=wrap,s.gzhead=null,s.w_bits=windowBits,s.w_size=1<>1,s.l_buf=3*s.lit_bufsize,s.level=level,s.strategy=strategy,s.method=method,deflateReset(strm)}function deflateInit(strm,level){return deflateInit2(strm,level,Z_DEFLATED,MAX_WBITS,DEF_MEM_LEVEL,Z_DEFAULT_STRATEGY)}function deflate(strm,flush){var old_flush,s,beg,val;if(!strm||!strm.state||flush>Z_BLOCK||0>flush)return strm?err(strm,Z_STREAM_ERROR):Z_STREAM_ERROR;if(s=strm.state,!strm.output||!strm.input&&0!==strm.avail_in||s.status===FINISH_STATE&&flush!==Z_FINISH)return err(strm,0===strm.avail_out?Z_BUF_ERROR:Z_STREAM_ERROR);if(s.strm=strm,old_flush=s.last_flush,s.last_flush=flush,s.status===INIT_STATE)if(2===s.wrap)strm.adler=0,put_byte(s,31),put_byte(s,139),put_byte(s,8),s.gzhead?(put_byte(s,(s.gzhead.text?1:0)+(s.gzhead.hcrc?2:0)+(s.gzhead.extra?4:0)+(s.gzhead.name?8:0)+(s.gzhead.comment?16:0)),put_byte(s,255&s.gzhead.time),put_byte(s,s.gzhead.time>>8&255),put_byte(s,s.gzhead.time>>16&255),put_byte(s,s.gzhead.time>>24&255),put_byte(s,9===s.level?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0),put_byte(s,255&s.gzhead.os),s.gzhead.extra&&s.gzhead.extra.length&&(put_byte(s,255&s.gzhead.extra.length),put_byte(s,s.gzhead.extra.length>>8&255)),s.gzhead.hcrc&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending,0)),s.gzindex=0,s.status=EXTRA_STATE):(put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,9===s.level?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0),put_byte(s,OS_CODE),s.status=BUSY_STATE);else{var header=Z_DEFLATED+(s.w_bits-8<<4)<<8,level_flags=-1;level_flags=s.strategy>=Z_HUFFMAN_ONLY||s.level<2?0:s.level<6?1:6===s.level?2:3,header|=level_flags<<6,0!==s.strstart&&(header|=PRESET_DICT),header+=31-header%31,s.status=BUSY_STATE,putShortMSB(s,header),0!==s.strstart&&(putShortMSB(s,strm.adler>>>16),putShortMSB(s,65535&strm.adler)),strm.adler=1}if(s.status===EXTRA_STATE)if(s.gzhead.extra){for(beg=s.pending;s.gzindex<(65535&s.gzhead.extra.length)&&(s.pending!==s.pending_buf_size||(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending!==s.pending_buf_size));)put_byte(s,255&s.gzhead.extra[s.gzindex]),s.gzindex++;s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),s.gzindex===s.gzhead.extra.length&&(s.gzindex=0,s.status=NAME_STATE)}else s.status=NAME_STATE;if(s.status===NAME_STATE)if(s.gzhead.name){beg=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending===s.pending_buf_size)){val=1;break}val=s.gzindexbeg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),0===val&&(s.gzindex=0,s.status=COMMENT_STATE)}else s.status=COMMENT_STATE;if(s.status===COMMENT_STATE)if(s.gzhead.comment){beg=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending===s.pending_buf_size)){val=1;break}val=s.gzindexbeg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),0===val&&(s.status=HCRC_STATE)}else s.status=HCRC_STATE;if(s.status===HCRC_STATE&&(s.gzhead.hcrc?(s.pending+2>s.pending_buf_size&&flush_pending(strm),s.pending+2<=s.pending_buf_size&&(put_byte(s,255&strm.adler),put_byte(s,strm.adler>>8&255),strm.adler=0,s.status=BUSY_STATE)):s.status=BUSY_STATE),0!==s.pending){if(flush_pending(strm),0===strm.avail_out)return s.last_flush=-1,Z_OK}else if(0===strm.avail_in&&rank(flush)<=rank(old_flush)&&flush!==Z_FINISH)return err(strm,Z_BUF_ERROR);if(s.status===FINISH_STATE&&0!==strm.avail_in)return err(strm,Z_BUF_ERROR);if(0!==strm.avail_in||0!==s.lookahead||flush!==Z_NO_FLUSH&&s.status!==FINISH_STATE){var bstate=s.strategy===Z_HUFFMAN_ONLY?deflate_huff(s,flush):s.strategy===Z_RLE?deflate_rle(s,flush):configuration_table[s.level].func(s,flush);if((bstate===BS_FINISH_STARTED||bstate===BS_FINISH_DONE)&&(s.status=FINISH_STATE),bstate===BS_NEED_MORE||bstate===BS_FINISH_STARTED)return 0===strm.avail_out&&(s.last_flush=-1),Z_OK;if(bstate===BS_BLOCK_DONE&&(flush===Z_PARTIAL_FLUSH?trees._tr_align(s):flush!==Z_BLOCK&&(trees._tr_stored_block(s,0,0,!1),flush===Z_FULL_FLUSH&&(zero(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),flush_pending(strm),0===strm.avail_out))return s.last_flush=-1,Z_OK}return flush!==Z_FINISH?Z_OK:s.wrap<=0?Z_STREAM_END:(2===s.wrap?(put_byte(s,255&strm.adler),put_byte(s,strm.adler>>8&255),put_byte(s,strm.adler>>16&255),put_byte(s,strm.adler>>24&255),put_byte(s,255&strm.total_in),put_byte(s,strm.total_in>>8&255),put_byte(s,strm.total_in>>16&255),put_byte(s,strm.total_in>>24&255)):(putShortMSB(s,strm.adler>>>16),putShortMSB(s,65535&strm.adler)),flush_pending(strm),s.wrap>0&&(s.wrap=-s.wrap),0!==s.pending?Z_OK:Z_STREAM_END)}function deflateEnd(strm){var status;return strm&&strm.state?(status=strm.state.status,status!==INIT_STATE&&status!==EXTRA_STATE&&status!==NAME_STATE&&status!==COMMENT_STATE&&status!==HCRC_STATE&&status!==BUSY_STATE&&status!==FINISH_STATE?err(strm,Z_STREAM_ERROR):(strm.state=null,status===BUSY_STATE?err(strm,Z_DATA_ERROR):Z_OK)):Z_STREAM_ERROR}var configuration_table,utils=require("../utils/common"),trees=require("./trees"),adler32=require("./adler32"),crc32=require("./crc32"),msg=require("./messages"),Z_NO_FLUSH=0,Z_PARTIAL_FLUSH=1,Z_FULL_FLUSH=3,Z_FINISH=4,Z_BLOCK=5,Z_OK=0,Z_STREAM_END=1,Z_STREAM_ERROR=-2,Z_DATA_ERROR=-3,Z_BUF_ERROR=-5,Z_DEFAULT_COMPRESSION=-1,Z_FILTERED=1,Z_HUFFMAN_ONLY=2,Z_RLE=3,Z_FIXED=4,Z_DEFAULT_STRATEGY=0,Z_UNKNOWN=2,Z_DEFLATED=8,MAX_MEM_LEVEL=9,MAX_WBITS=15,DEF_MEM_LEVEL=8,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,MIN_MATCH=3,MAX_MATCH=258,MIN_LOOKAHEAD=MAX_MATCH+MIN_MATCH+1,PRESET_DICT=32,INIT_STATE=42,EXTRA_STATE=69,NAME_STATE=73,COMMENT_STATE=91,HCRC_STATE=103,BUSY_STATE=113,FINISH_STATE=666,BS_NEED_MORE=1,BS_BLOCK_DONE=2,BS_FINISH_STARTED=3,BS_FINISH_DONE=4,OS_CODE=3,Config=function(good_length,max_lazy,nice_length,max_chain,func){this.good_length=good_length,this.max_lazy=max_lazy,this.nice_length=nice_length,this.max_chain=max_chain,this.func=func};configuration_table=[new Config(0,0,0,0,deflate_stored),new Config(4,4,8,4,deflate_fast),new Config(4,5,16,8,deflate_fast),new Config(4,6,32,32,deflate_fast),new Config(4,4,16,16,deflate_slow),new Config(8,16,32,32,deflate_slow),new Config(8,16,128,128,deflate_slow),new Config(8,32,128,256,deflate_slow),new Config(32,128,258,1024,deflate_slow),new Config(32,258,258,4096,deflate_slow)],exports.deflateInit=deflateInit,exports.deflateInit2=deflateInit2,exports.deflateReset=deflateReset,exports.deflateResetKeep=deflateResetKeep,exports.deflateSetHeader=deflateSetHeader,exports.deflate=deflate,exports.deflateEnd=deflateEnd,exports.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":98,"./adler32":100,"./crc32":102,"./messages":108,"./trees":109}],104:[function(require,module){"use strict";function GZheader(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}module.exports=GZheader},{}],105:[function(require,module){"use strict";var BAD=30,TYPE=12;module.exports=function(strm,start){var state,_in,last,_out,beg,end,dmax,wsize,whave,wnext,window,hold,bits,lcode,dcode,lmask,dmask,here,op,len,dist,from,from_source,input,output;state=strm.state,_in=strm.next_in,input=strm.input,last=_in+(strm.avail_in-5),_out=strm.next_out,output=strm.output,beg=_out-(start-strm.avail_out),end=_out+(strm.avail_out-257),dmax=state.dmax,wsize=state.wsize,whave=state.whave,wnext=state.wnext,window=state.window,hold=state.hold,bits=state.bits,lcode=state.lencode,dcode=state.distcode,lmask=(1<bits&&(hold+=input[_in++]<>>24,hold>>>=op,bits-=op,op=here>>>16&255,0===op)output[_out++]=65535&here;else{if(!(16&op)){if(0===(64&op)){here=lcode[(65535&here)+(hold&(1<bits&&(hold+=input[_in++]<>>=op,bits-=op),15>bits&&(hold+=input[_in++]<>>24,hold>>>=op,bits-=op,op=here>>>16&255,!(16&op)){if(0===(64&op)){here=dcode[(65535&here)+(hold&(1<bits&&(hold+=input[_in++]<bits&&(hold+=input[_in++]<dmax){strm.msg="invalid distance too far back",state.mode=BAD;break top}if(hold>>>=op,bits-=op,op=_out-beg,dist>op){if(op=dist-op,op>whave&&state.sane){strm.msg="invalid distance too far back",state.mode=BAD;break top}if(from=0,from_source=window,0===wnext){if(from+=wsize-op,len>op){len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}}else if(op>wnext){if(from+=wsize+wnext-op,op-=wnext,len>op){len-=op;do output[_out++]=window[from++];while(--op);if(from=0,len>wnext){op=wnext,len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}}}else if(from+=wnext-op,len>op){len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}for(;len>2;)output[_out++]=from_source[from++],output[_out++]=from_source[from++],output[_out++]=from_source[from++],len-=3;len&&(output[_out++]=from_source[from++],len>1&&(output[_out++]=from_source[from++]))}else{from=_out-dist;do output[_out++]=output[from++],output[_out++]=output[from++],output[_out++]=output[from++],len-=3;while(len>2);len&&(output[_out++]=output[from++],len>1&&(output[_out++]=output[from++]))}break}}break}}while(last>_in&&end>_out);len=bits>>3,_in-=len,bits-=len<<3,hold&=(1<_in?5+(last-_in):5-(_in-last),strm.avail_out=end>_out?257+(end-_out):257-(_out-end),state.hold=hold,state.bits=bits}},{}],106:[function(require,module,exports){"use strict";function ZSWAP32(q){return(q>>>24&255)+(q>>>8&65280)+((65280&q)<<8)+((255&q)<<24)}function InflateState(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new utils.Buf16(320),this.work=new utils.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function inflateResetKeep(strm){var state;return strm&&strm.state?(state=strm.state,strm.total_in=strm.total_out=state.total=0,strm.msg="",state.wrap&&(strm.adler=1&state.wrap),state.mode=HEAD,state.last=0,state.havedict=0,state.dmax=32768,state.head=null,state.hold=0,state.bits=0,state.lencode=state.lendyn=new utils.Buf32(ENOUGH_LENS),state.distcode=state.distdyn=new utils.Buf32(ENOUGH_DISTS),state.sane=1,state.back=-1,Z_OK):Z_STREAM_ERROR}function inflateReset(strm){var state;return strm&&strm.state?(state=strm.state,state.wsize=0,state.whave=0,state.wnext=0,inflateResetKeep(strm)):Z_STREAM_ERROR}function inflateReset2(strm,windowBits){var wrap,state;return strm&&strm.state?(state=strm.state,0>windowBits?(wrap=0,windowBits=-windowBits):(wrap=(windowBits>>4)+1,48>windowBits&&(windowBits&=15)),windowBits&&(8>windowBits||windowBits>15)?Z_STREAM_ERROR:(null!==state.window&&state.wbits!==windowBits&&(state.window=null),state.wrap=wrap,state.wbits=windowBits,inflateReset(strm))):Z_STREAM_ERROR}function inflateInit2(strm,windowBits){var ret,state;return strm?(state=new InflateState,strm.state=state,state.window=null,ret=inflateReset2(strm,windowBits),ret!==Z_OK&&(strm.state=null),ret):Z_STREAM_ERROR}function inflateInit(strm){return inflateInit2(strm,DEF_WBITS)}function fixedtables(state){if(virgin){var sym;for(lenfix=new utils.Buf32(512),distfix=new utils.Buf32(32),sym=0;144>sym;)state.lens[sym++]=8;for(;256>sym;)state.lens[sym++]=9;for(;280>sym;)state.lens[sym++]=7;for(;288>sym;)state.lens[sym++]=8;for(inflate_table(LENS,state.lens,0,288,lenfix,0,state.work,{bits:9}),sym=0;32>sym;)state.lens[sym++]=5;inflate_table(DISTS,state.lens,0,32,distfix,0,state.work,{bits:5}),virgin=!1}state.lencode=lenfix,state.lenbits=9,state.distcode=distfix,state.distbits=5}function updatewindow(strm,src,end,copy){var dist,state=strm.state;return null===state.window&&(state.wsize=1<=state.wsize?(utils.arraySet(state.window,src,end-state.wsize,state.wsize,0),state.wnext=0,state.whave=state.wsize):(dist=state.wsize-state.wnext,dist>copy&&(dist=copy),utils.arraySet(state.window,src,end-copy,dist,state.wnext),copy-=dist,copy?(utils.arraySet(state.window,src,end-copy,copy,0),state.wnext=copy,state.whave=state.wsize):(state.wnext+=dist,state.wnext===state.wsize&&(state.wnext=0),state.whavebits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,state.check=crc32(state.check,hbuf,2,0),hold=0,bits=0,state.mode=FLAGS;break}if(state.flags=0,state.head&&(state.head.done=!1),!(1&state.wrap)||(((255&hold)<<8)+(hold>>8))%31){strm.msg="incorrect header check",state.mode=BAD;break}if((15&hold)!==Z_DEFLATED){strm.msg="unknown compression method",state.mode=BAD;break}if(hold>>>=4,bits-=4,len=(15&hold)+8,0===state.wbits)state.wbits=len;else if(len>state.wbits){strm.msg="invalid window size",state.mode=BAD;break}state.dmax=1<bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>8&1),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=TIME;case TIME:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,hbuf[2]=hold>>>16&255,hbuf[3]=hold>>>24&255,state.check=crc32(state.check,hbuf,4,0)),hold=0,bits=0,state.mode=OS;case OS:for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>8),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=EXLEN;case EXLEN:if(1024&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0}else state.head&&(state.head.extra=null);state.mode=EXTRA;case EXTRA:if(1024&state.flags&&(copy=state.length,copy>have&&(copy=have),copy&&(state.head&&(len=state.head.extra_len-state.length,state.head.extra||(state.head.extra=new Array(state.head.extra_len)),utils.arraySet(state.head.extra,input,next,copy,len)),512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,state.length-=copy),state.length))break inf_leave;state.length=0,state.mode=NAME;case NAME:if(2048&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.name+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.name=null);state.length=0,state.mode=COMMENT;case COMMENT:if(4096&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.comment+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.comment=null);state.mode=HCRC;case HCRC:if(512&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>9&1,state.head.done=!0),strm.adler=state.check=0,state.mode=TYPE;break;case DICTID:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=7&bits,bits-=7&bits,state.mode=CHECK;break}for(;3>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=1,bits-=1,3&hold){case 0:state.mode=STORED;break;case 1:if(fixedtables(state),state.mode=LEN_,flush===Z_TREES){hold>>>=2,bits-=2;break inf_leave}break;case 2:state.mode=TABLE;break;case 3:strm.msg="invalid block type",state.mode=BAD}hold>>>=2,bits-=2;break;case STORED:for(hold>>>=7&bits,bits-=7&bits;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>16^65535)){strm.msg="invalid stored block lengths",state.mode=BAD;break}if(state.length=65535&hold,hold=0,bits=0,state.mode=COPY_,flush===Z_TREES)break inf_leave;case COPY_:state.mode=COPY;case COPY:if(copy=state.length){if(copy>have&&(copy=have),copy>left&&(copy=left),0===copy)break inf_leave;utils.arraySet(output,input,next,copy,put),have-=copy,next+=copy,left-=copy,put+=copy,state.length-=copy;break}state.mode=TYPE;break;case TABLE:for(;14>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=5,bits-=5,state.ndist=(31&hold)+1,hold>>>=5,bits-=5,state.ncode=(15&hold)+4,hold>>>=4,bits-=4,state.nlen>286||state.ndist>30){strm.msg="too many length or distance symbols",state.mode=BAD;break}state.have=0,state.mode=LENLENS;case LENLENS:for(;state.havebits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=3,bits-=3}for(;state.have<19;)state.lens[order[state.have++]]=0;if(state.lencode=state.lendyn,state.lenbits=7,opts={bits:state.lenbits},ret=inflate_table(CODES,state.lens,0,19,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid code lengths set",state.mode=BAD;break}state.have=0,state.mode=CODELENS;case CODELENS:for(;state.have>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<here_val)hold>>>=here_bits,bits-=here_bits,state.lens[state.have++]=here_val;else{if(16===here_val){for(n=here_bits+2;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,0===state.have){strm.msg="invalid bit length repeat",state.mode=BAD;break}len=state.lens[state.have-1],copy=3+(3&hold),hold>>>=2,bits-=2}else if(17===here_val){for(n=here_bits+3;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=3+(7&hold),hold>>>=3,bits-=3}else{for(n=here_bits+7;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=11+(127&hold),hold>>>=7,bits-=7}if(state.have+copy>state.nlen+state.ndist){strm.msg="invalid bit length repeat",state.mode=BAD;break}for(;copy--;)state.lens[state.have++]=len}}if(state.mode===BAD)break;if(0===state.lens[256]){strm.msg="invalid code -- missing end-of-block",state.mode=BAD;break}if(state.lenbits=9,opts={bits:state.lenbits},ret=inflate_table(LENS,state.lens,0,state.nlen,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid literal/lengths set",state.mode=BAD;break}if(state.distbits=6,state.distcode=state.distdyn,opts={bits:state.distbits},ret=inflate_table(DISTS,state.lens,state.nlen,state.ndist,state.distcode,0,state.work,opts),state.distbits=opts.bits,ret){strm.msg="invalid distances set",state.mode=BAD;break}if(state.mode=LEN_,flush===Z_TREES)break inf_leave;case LEN_:state.mode=LEN;case LEN:if(have>=6&&left>=258){strm.next_out=put,strm.avail_out=left,strm.next_in=next,strm.avail_in=have,state.hold=hold,state.bits=bits,inflate_fast(strm,_out),put=strm.next_out,output=strm.output,left=strm.avail_out,next=strm.next_in,input=strm.input,have=strm.avail_in,hold=state.hold,bits=state.bits,state.mode===TYPE&&(state.back=-1);break}for(state.back=0;here=state.lencode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,state.length=here_val,0===here_op){state.mode=LIT;break}if(32&here_op){state.back=-1,state.mode=TYPE;break}if(64&here_op){strm.msg="invalid literal/length code",state.mode=BAD;break}state.extra=15&here_op,state.mode=LENEXT;case LENEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}state.was=state.length,state.mode=DIST;case DIST:for(;here=state.distcode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,64&here_op){strm.msg="invalid distance code",state.mode=BAD;break}state.offset=here_val,state.extra=15&here_op,state.mode=DISTEXT;case DISTEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}if(state.offset>state.dmax){strm.msg="invalid distance too far back",state.mode=BAD;break}state.mode=MATCH;case MATCH:if(0===left)break inf_leave;if(copy=_out-left,state.offset>copy){if(copy=state.offset-copy,copy>state.whave&&state.sane){strm.msg="invalid distance too far back",state.mode=BAD;break}copy>state.wnext?(copy-=state.wnext,from=state.wsize-copy):from=state.wnext-copy,copy>state.length&&(copy=state.length),from_source=state.window}else from_source=output,from=put-state.offset,copy=state.length;copy>left&&(copy=left),left-=copy,state.length-=copy;do output[put++]=from_source[from++];while(--copy);0===state.length&&(state.mode=LEN);break;case LIT:if(0===left)break inf_leave;output[put++]=state.length,left--,state.mode=LEN;break;case CHECK:if(state.wrap){for(;32>bits;){if(0===have)break inf_leave;have--,hold|=input[next++]<bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<=len;len++)count[len]=0;for(sym=0;codes>sym;sym++)count[lens[lens_index+sym]]++;for(root=bits,max=MAXBITS;max>=1&&0===count[max];max--);if(root>max&&(root=max),0===max)return table[table_index++]=20971520,table[table_index++]=20971520,opts.bits=1,0;for(min=1;max>min&&0===count[min];min++);for(min>root&&(root=min),left=1,len=1;MAXBITS>=len;len++)if(left<<=1,left-=count[len],0>left)return-1;if(left>0&&(type===CODES||1!==max))return-1;for(offs[1]=0,len=1;MAXBITS>len;len++)offs[len+1]=offs[len]+count[len];for(sym=0;codes>sym;sym++)0!==lens[lens_index+sym]&&(work[offs[lens[lens_index+sym]]++]=sym);if(type===CODES?(base=extra=work,end=19):type===LENS?(base=lbase,base_index-=257,extra=lext,extra_index-=257,end=256):(base=dbase,extra=dext,end=-1),huff=0,sym=0,len=min,next=table_index,curr=root,drop=0,low=-1,used=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;for(var i=0;;){i++,here_bits=len-drop,work[sym]end?(here_op=extra[extra_index+work[sym]],here_val=base[base_index+work[sym]]):(here_op=96,here_val=0),incr=1<>drop)+fill]=here_bits<<24|here_op<<16|here_val|0;while(0!==fill);for(incr=1<>=1;if(0!==incr?(huff&=incr-1,huff+=incr):huff=0,sym++,0===--count[len]){if(len===max)break;len=lens[lens_index+work[sym]]}if(len>root&&(huff&mask)!==low){for(0===drop&&(drop=root),next+=min,curr=len-drop,left=1<curr+drop&&(left-=count[curr+drop],!(0>=left));)curr++,left<<=1;if(used+=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;low=huff&mask,table[low]=root<<24|curr<<16|next-table_index|0 +}}return 0!==huff&&(table[next+huff]=len-drop<<24|64<<16|0),opts.bits=root,0}},{"../utils/common":98}],108:[function(require,module){"use strict";module.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],109:[function(require,module,exports){"use strict";function zero(buf){for(var len=buf.length;--len>=0;)buf[len]=0}function d_code(dist){return 256>dist?_dist_code[dist]:_dist_code[256+(dist>>>7)]}function put_short(s,w){s.pending_buf[s.pending++]=255&w,s.pending_buf[s.pending++]=w>>>8&255}function send_bits(s,value,length){s.bi_valid>Buf_size-length?(s.bi_buf|=value<>Buf_size-s.bi_valid,s.bi_valid+=length-Buf_size):(s.bi_buf|=value<>>=1,res<<=1;while(--len>0);return res>>>1}function bi_flush(s){16===s.bi_valid?(put_short(s,s.bi_buf),s.bi_buf=0,s.bi_valid=0):s.bi_valid>=8&&(s.pending_buf[s.pending++]=255&s.bi_buf,s.bi_buf>>=8,s.bi_valid-=8)}function gen_bitlen(s,desc){var h,n,m,bits,xbits,f,tree=desc.dyn_tree,max_code=desc.max_code,stree=desc.stat_desc.static_tree,has_stree=desc.stat_desc.has_stree,extra=desc.stat_desc.extra_bits,base=desc.stat_desc.extra_base,max_length=desc.stat_desc.max_length,overflow=0;for(bits=0;MAX_BITS>=bits;bits++)s.bl_count[bits]=0;for(tree[2*s.heap[s.heap_max]+1]=0,h=s.heap_max+1;HEAP_SIZE>h;h++)n=s.heap[h],bits=tree[2*tree[2*n+1]+1]+1,bits>max_length&&(bits=max_length,overflow++),tree[2*n+1]=bits,n>max_code||(s.bl_count[bits]++,xbits=0,n>=base&&(xbits=extra[n-base]),f=tree[2*n],s.opt_len+=f*(bits+xbits),has_stree&&(s.static_len+=f*(stree[2*n+1]+xbits)));if(0!==overflow){do{for(bits=max_length-1;0===s.bl_count[bits];)bits--;s.bl_count[bits]--,s.bl_count[bits+1]+=2,s.bl_count[max_length]--,overflow-=2}while(overflow>0);for(bits=max_length;0!==bits;bits--)for(n=s.bl_count[bits];0!==n;)m=s.heap[--h],m>max_code||(tree[2*m+1]!==bits&&(s.opt_len+=(bits-tree[2*m+1])*tree[2*m],tree[2*m+1]=bits),n--)}}function gen_codes(tree,max_code,bl_count){var bits,n,next_code=new Array(MAX_BITS+1),code=0;for(bits=1;MAX_BITS>=bits;bits++)next_code[bits]=code=code+bl_count[bits-1]<<1;for(n=0;max_code>=n;n++){var len=tree[2*n+1];0!==len&&(tree[2*n]=bi_reverse(next_code[len]++,len))}}function tr_static_init(){var n,bits,length,code,dist,bl_count=new Array(MAX_BITS+1);for(length=0,code=0;LENGTH_CODES-1>code;code++)for(base_length[code]=length,n=0;n<1<code;code++)for(base_dist[code]=dist,n=0;n<1<>=7;D_CODES>code;code++)for(base_dist[code]=dist<<7,n=0;n<1<=bits;bits++)bl_count[bits]=0;for(n=0;143>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(;255>=n;)static_ltree[2*n+1]=9,n++,bl_count[9]++;for(;279>=n;)static_ltree[2*n+1]=7,n++,bl_count[7]++;for(;287>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(gen_codes(static_ltree,L_CODES+1,bl_count),n=0;D_CODES>n;n++)static_dtree[2*n+1]=5,static_dtree[2*n]=bi_reverse(n,5);static_l_desc=new StaticTreeDesc(static_ltree,extra_lbits,LITERALS+1,L_CODES,MAX_BITS),static_d_desc=new StaticTreeDesc(static_dtree,extra_dbits,0,D_CODES,MAX_BITS),static_bl_desc=new StaticTreeDesc(new Array(0),extra_blbits,0,BL_CODES,MAX_BL_BITS)}function init_block(s){var n;for(n=0;L_CODES>n;n++)s.dyn_ltree[2*n]=0;for(n=0;D_CODES>n;n++)s.dyn_dtree[2*n]=0;for(n=0;BL_CODES>n;n++)s.bl_tree[2*n]=0;s.dyn_ltree[2*END_BLOCK]=1,s.opt_len=s.static_len=0,s.last_lit=s.matches=0}function bi_windup(s){s.bi_valid>8?put_short(s,s.bi_buf):s.bi_valid>0&&(s.pending_buf[s.pending++]=s.bi_buf),s.bi_buf=0,s.bi_valid=0}function copy_block(s,buf,len,header){bi_windup(s),header&&(put_short(s,len),put_short(s,~len)),utils.arraySet(s.pending_buf,s.window,buf,len,s.pending),s.pending+=len}function smaller(tree,n,m,depth){var _n2=2*n,_m2=2*m;return tree[_n2]n;n++)0!==tree[2*n]?(s.heap[++s.heap_len]=max_code=n,s.depth[n]=0):tree[2*n+1]=0;for(;s.heap_len<2;)node=s.heap[++s.heap_len]=2>max_code?++max_code:0,tree[2*node]=1,s.depth[node]=0,s.opt_len--,has_stree&&(s.static_len-=stree[2*node+1]);for(desc.max_code=max_code,n=s.heap_len>>1;n>=1;n--)pqdownheap(s,tree,n);node=elems;do n=s.heap[1],s.heap[1]=s.heap[s.heap_len--],pqdownheap(s,tree,1),m=s.heap[1],s.heap[--s.heap_max]=n,s.heap[--s.heap_max]=m,tree[2*node]=tree[2*n]+tree[2*m],s.depth[node]=(s.depth[n]>=s.depth[m]?s.depth[n]:s.depth[m])+1,tree[2*n+1]=tree[2*m+1]=node,s.heap[1]=node++,pqdownheap(s,tree,1);while(s.heap_len>=2);s.heap[--s.heap_max]=s.heap[1],gen_bitlen(s,desc),gen_codes(tree,max_code,s.bl_count)}function scan_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),tree[2*(max_code+1)+1]=65535,n=0;max_code>=n;n++)curlen=nextlen,nextlen=tree[2*(n+1)+1],++countcount?s.bl_tree[2*curlen]+=count:0!==curlen?(curlen!==prevlen&&s.bl_tree[2*curlen]++,s.bl_tree[2*REP_3_6]++):10>=count?s.bl_tree[2*REPZ_3_10]++:s.bl_tree[2*REPZ_11_138]++,count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4))}function send_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),n=0;max_code>=n;n++)if(curlen=nextlen,nextlen=tree[2*(n+1)+1],!(++countcount){do send_code(s,curlen,s.bl_tree);while(0!==--count)}else 0!==curlen?(curlen!==prevlen&&(send_code(s,curlen,s.bl_tree),count--),send_code(s,REP_3_6,s.bl_tree),send_bits(s,count-3,2)):10>=count?(send_code(s,REPZ_3_10,s.bl_tree),send_bits(s,count-3,3)):(send_code(s,REPZ_11_138,s.bl_tree),send_bits(s,count-11,7));count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4)}}function build_bl_tree(s){var max_blindex;for(scan_tree(s,s.dyn_ltree,s.l_desc.max_code),scan_tree(s,s.dyn_dtree,s.d_desc.max_code),build_tree(s,s.bl_desc),max_blindex=BL_CODES-1;max_blindex>=3&&0===s.bl_tree[2*bl_order[max_blindex]+1];max_blindex--);return s.opt_len+=3*(max_blindex+1)+5+5+4,max_blindex}function send_all_trees(s,lcodes,dcodes,blcodes){var rank;for(send_bits(s,lcodes-257,5),send_bits(s,dcodes-1,5),send_bits(s,blcodes-4,4),rank=0;blcodes>rank;rank++)send_bits(s,s.bl_tree[2*bl_order[rank]+1],3);send_tree(s,s.dyn_ltree,lcodes-1),send_tree(s,s.dyn_dtree,dcodes-1)}function detect_data_type(s){var n,black_mask=4093624447;for(n=0;31>=n;n++,black_mask>>>=1)if(1&black_mask&&0!==s.dyn_ltree[2*n])return Z_BINARY;if(0!==s.dyn_ltree[18]||0!==s.dyn_ltree[20]||0!==s.dyn_ltree[26])return Z_TEXT;for(n=32;LITERALS>n;n++)if(0!==s.dyn_ltree[2*n])return Z_TEXT;return Z_BINARY}function _tr_init(s){static_init_done||(tr_static_init(),static_init_done=!0),s.l_desc=new TreeDesc(s.dyn_ltree,static_l_desc),s.d_desc=new TreeDesc(s.dyn_dtree,static_d_desc),s.bl_desc=new TreeDesc(s.bl_tree,static_bl_desc),s.bi_buf=0,s.bi_valid=0,init_block(s)}function _tr_stored_block(s,buf,stored_len,last){send_bits(s,(STORED_BLOCK<<1)+(last?1:0),3),copy_block(s,buf,stored_len,!0)}function _tr_align(s){send_bits(s,STATIC_TREES<<1,3),send_code(s,END_BLOCK,static_ltree),bi_flush(s)}function _tr_flush_block(s,buf,stored_len,last){var opt_lenb,static_lenb,max_blindex=0;s.level>0?(s.strm.data_type===Z_UNKNOWN&&(s.strm.data_type=detect_data_type(s)),build_tree(s,s.l_desc),build_tree(s,s.d_desc),max_blindex=build_bl_tree(s),opt_lenb=s.opt_len+3+7>>>3,static_lenb=s.static_len+3+7>>>3,opt_lenb>=static_lenb&&(opt_lenb=static_lenb)):opt_lenb=static_lenb=stored_len+5,opt_lenb>=stored_len+4&&-1!==buf?_tr_stored_block(s,buf,stored_len,last):s.strategy===Z_FIXED||static_lenb===opt_lenb?(send_bits(s,(STATIC_TREES<<1)+(last?1:0),3),compress_block(s,static_ltree,static_dtree)):(send_bits(s,(DYN_TREES<<1)+(last?1:0),3),send_all_trees(s,s.l_desc.max_code+1,s.d_desc.max_code+1,max_blindex+1),compress_block(s,s.dyn_ltree,s.dyn_dtree)),init_block(s),last&&bi_windup(s)}function _tr_tally(s,dist,lc){return s.pending_buf[s.d_buf+2*s.last_lit]=dist>>>8&255,s.pending_buf[s.d_buf+2*s.last_lit+1]=255&dist,s.pending_buf[s.l_buf+s.last_lit]=255&lc,s.last_lit++,0===dist?s.dyn_ltree[2*lc]++:(s.matches++,dist--,s.dyn_ltree[2*(_length_code[lc]+LITERALS+1)]++,s.dyn_dtree[2*d_code(dist)]++),s.last_lit===s.lit_bufsize-1}var utils=require("../utils/common"),Z_FIXED=4,Z_BINARY=0,Z_TEXT=1,Z_UNKNOWN=2,STORED_BLOCK=0,STATIC_TREES=1,DYN_TREES=2,MIN_MATCH=3,MAX_MATCH=258,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,Buf_size=16,MAX_BL_BITS=7,END_BLOCK=256,REP_3_6=16,REPZ_3_10=17,REPZ_11_138=18,extra_lbits=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],extra_dbits=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],extra_blbits=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],bl_order=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],DIST_CODE_LEN=512,static_ltree=new Array(2*(L_CODES+2));zero(static_ltree);var static_dtree=new Array(2*D_CODES);zero(static_dtree);var _dist_code=new Array(DIST_CODE_LEN);zero(_dist_code);var _length_code=new Array(MAX_MATCH-MIN_MATCH+1);zero(_length_code);var base_length=new Array(LENGTH_CODES);zero(base_length);var base_dist=new Array(D_CODES);zero(base_dist);var static_l_desc,static_d_desc,static_bl_desc,StaticTreeDesc=function(static_tree,extra_bits,extra_base,elems,max_length){this.static_tree=static_tree,this.extra_bits=extra_bits,this.extra_base=extra_base,this.elems=elems,this.max_length=max_length,this.has_stree=static_tree&&static_tree.length},TreeDesc=function(dyn_tree,stat_desc){this.dyn_tree=dyn_tree,this.max_code=0,this.stat_desc=stat_desc},static_init_done=!1;exports._tr_init=_tr_init,exports._tr_stored_block=_tr_stored_block,exports._tr_flush_block=_tr_flush_block,exports._tr_tally=_tr_tally,exports._tr_align=_tr_align},{"../utils/common":98}],110:[function(require,module){"use strict";function ZStream(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}module.exports=ZStream},{}],111:[function(require,module){(function(Buffer){"use strict";function decodeB64(str){return new Buffer(str,"base64")}function unpackPNG(w,h,c,str){var pixels=parse(decodeB64(str));return ndarray(pixels.data,[h,w,pixels.channels],[pixels.channels*w,pixels.channels,1],0)}module.exports=unpackPNG;var ndarray=require("ndarray"),parse=require("pngparse-sync")}).call(this,require("buffer").Buffer)},{buffer:123,ndarray:92,"pngparse-sync":94}],112:[function(require,module,exports){!function(_global){"use strict";var shim={};"undefined"==typeof exports?"function"==typeof define&&"object"==typeof define.amd&&define.amd?(shim.exports={},define(function(){return shim.exports})):shim.exports="undefined"!=typeof window?window:_global:shim.exports=exports,function(exports){if(!GLMAT_EPSILON)var GLMAT_EPSILON=1e-6;if(!GLMAT_ARRAY_TYPE)var GLMAT_ARRAY_TYPE="undefined"!=typeof Float32Array?Float32Array:Array;if(!GLMAT_RANDOM)var GLMAT_RANDOM=Math.random;var glMatrix={};glMatrix.setMatrixArrayType=function(type){GLMAT_ARRAY_TYPE=type},"undefined"!=typeof exports&&(exports.glMatrix=glMatrix);var degree=Math.PI/180;glMatrix.toRadian=function(a){return a*degree};var vec2={};vec2.create=function(){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=0,out[1]=0,out},vec2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=a[0],out[1]=a[1],out},vec2.fromValues=function(x,y){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=x,out[1]=y,out},vec2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out},vec2.set=function(out,x,y){return out[0]=x,out[1]=y,out},vec2.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out},vec2.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out},vec2.sub=vec2.subtract,vec2.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out},vec2.mul=vec2.multiply,vec2.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out},vec2.div=vec2.divide,vec2.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out},vec2.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out},vec2.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out},vec2.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out},vec2.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return Math.sqrt(x*x+y*y)},vec2.dist=vec2.distance,vec2.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return x*x+y*y},vec2.sqrDist=vec2.squaredDistance,vec2.length=function(a){var x=a[0],y=a[1];return Math.sqrt(x*x+y*y)},vec2.len=vec2.length,vec2.squaredLength=function(a){var x=a[0],y=a[1];return x*x+y*y},vec2.sqrLen=vec2.squaredLength,vec2.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out},vec2.normalize=function(out,a){var x=a[0],y=a[1],len=x*x+y*y;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null +},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],113:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance}function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":112}],114:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],115:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],116:[function(require,module){function parse(html,doc){if("string"!=typeof html)throw new TypeError("String expected");doc||(doc=document);var m=/<([\w:]+)/.exec(html);if(!m)return doc.createTextNode(html);html=html.replace(/^\s+|\s+$/g,"");var tag=m[1];if("body"==tag){var el=doc.createElement("html");return el.innerHTML=html,el.removeChild(el.lastChild)}var wrap=map[tag]||map._default,depth=wrap[0],prefix=wrap[1],suffix=wrap[2],el=doc.createElement("div");for(el.innerHTML=prefix+html+suffix;depth--;)el=el.lastChild;if(el.firstChild==el.lastChild)return el.removeChild(el.firstChild);for(var fragment=doc.createDocumentFragment();el.firstChild;)fragment.appendChild(el.removeChild(el.firstChild));return fragment}module.exports=parse;var map={legend:[1,"
      ","
      "],tr:[2,"","
      "],col:[2,"","
      "],_default:[0,"",""]};map.td=map.th=[3,"","
      "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
      "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],117:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],118:[function(require,module,exports){arguments[4][32][0].apply(exports,arguments)},{_process:126,"raf-component":119,sliced:121}],119:[function(require,module){module.exports=require(33)},{}],120:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],121:[function(require,module,exports){arguments[4][34][0].apply(exports,arguments)},{"./lib/sliced":122}],122:[function(require,module){module.exports=require(35)},{}],123:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)"base64"===encoding&&(subject=base64clean(subject)),length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new Error("First argument needs to be a number, array or string.");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}var buf;TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;assert(strLen%2===0,"Invalid hex string"),length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);assert(!isNaN(byte),"Invalid hex string"),buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string),buf,offset,length);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function binarySlice(buf,start,end){return asciiSlice(buf,start,end)}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;i=len)){var val;return littleEndian?(val=buf[offset],len>offset+1&&(val|=buf[offset+1]<<8)):(val=buf[offset]<<8,len>offset+1&&(val|=buf[offset+1])),val}}function readUInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val;return littleEndian?(len>offset+2&&(val=buf[offset+2]<<16),len>offset+1&&(val|=buf[offset+1]<<8),val|=buf[offset],len>offset+3&&(val+=buf[offset+3]<<24>>>0)):(len>offset+1&&(val=buf[offset+1]<<16),len>offset+2&&(val|=buf[offset+2]<<8),len>offset+3&&(val|=buf[offset+3]),val+=buf[offset]<<24>>>0),val}}function readInt16(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len)){var val=readUInt16(buf,offset,littleEndian,!0),neg=32768&val;return neg?-1*(65535-val+1):val}}function readInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val=readUInt32(buf,offset,littleEndian,!0),neg=2147483648&val;return neg?-1*(4294967295-val+1):val}}function readFloat(buf,offset,littleEndian,noAssert){return noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i);return offset+2}}function writeUInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255;return offset+4}}function writeInt16(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len))return value>=0?writeUInt16(buf,value,offset,littleEndian,noAssert):writeUInt16(buf,65535+value+1,offset,littleEndian,noAssert),offset+2}function writeInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return value>=0?writeUInt32(buf,value,offset,littleEndian,noAssert):writeUInt32(buf,4294967295+value+1,offset,littleEndian,noAssert),offset+4}function writeFloat(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+7=len))return ieee754.write(buf,value,offset,littleEndian,52,8),offset+8}function base64clean(str){for(str=stringtrim(str).replace(INVALID_BASE64_RE,"");str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArray(subject){return(Array.isArray||function(subject){return"[object Array]"===Object.prototype.toString.call(subject)})(subject)}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(str){for(var byteArray=[],i=0;i=b)byteArray.push(b);else{var start=i;b>=55296&&57343>=b&&i++;for(var h=encodeURIComponent(str.slice(start,i+1)).substr(1).split("%"),j=0;j>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(str)}function blitBuffer(src,dst,offset,length){for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533) +}}function verifuint(value,max){assert("number"==typeof value,"cannot write a non-number as a number"),assert(value>=0,"specified a negative value for writing an unsigned value"),assert(max>=value,"value is larger than maximum value for type"),assert(Math.floor(value)===value,"value has a fractional component")}function verifsint(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value"),assert(Math.floor(value)===value,"value has a fractional component")}function verifIEEE754(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value")}function assert(test,message){if(!test)throw new Error(message||"Failed assertion")}var base64=require("base64-js"),ieee754=require("ieee754");exports.Buffer=Buffer,exports.SlowBuffer=Buffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}();Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.byteLength=function(str,encoding){var ret;switch(str=str.toString(),encoding||"utf8"){case"hex":ret=str.length/2;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"ascii":case"binary":case"raw":ret=str.length;break;case"base64":ret=base64ToBytes(str).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=2*str.length;break;default:throw new Error("Unknown encoding")}return ret},Buffer.concat=function(list,totalLength){if(assert(isArray(list),"Usage: Buffer.concat(list[, length])"),0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;ii&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}offset=Number(offset)||0;var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toString=function(encoding,start,end){var self=this;if(encoding=String(encoding||"utf8").toLowerCase(),start=Number(start)||0,end=void 0===end?self.length:Number(end),end===start)return"";var ret;switch(encoding){case"hex":ret=hexSlice(self,start,end);break;case"utf8":case"utf-8":ret=utf8Slice(self,start,end);break;case"ascii":ret=asciiSlice(self,start,end);break;case"binary":ret=binarySlice(self,start,end);break;case"base64":ret=base64Slice(self,start,end);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leSlice(self,start,end);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.equals=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),0===Buffer.compare(this,b)},Buffer.prototype.compare=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),Buffer.compare(this,b)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start||(target_start=0),end!==start&&0!==target.length&&0!==source.length){assert(end>=start,"sourceEnd < sourceStart"),assert(target_start>=0&&target_start=0&&start=0&&end<=source.length,"sourceEnd out of bounds"),end>this.length&&(end=this.length),target.length-target_startlen||!TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start)}},Buffer.prototype.slice=function(start,end){var len=this.length;if(start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start),TYPED_ARRAY_SUPPORT)return Buffer._augment(this.subarray(start,end));for(var sliceLen=end-start,newBuf=new Buffer(sliceLen,void 0,!0),i=0;sliceLen>i;i++)newBuf[i]=this[i+start];return newBuf},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return readUInt16(this,offset,!0,noAssert)},Buffer.prototype.readUInt16BE=function(offset,noAssert){return readUInt16(this,offset,!1,noAssert)},Buffer.prototype.readUInt32LE=function(offset,noAssert){return readUInt32(this,offset,!0,noAssert)},Buffer.prototype.readUInt32BE=function(offset,noAssert){return readUInt32(this,offset,!1,noAssert)},Buffer.prototype.readInt8=function(offset,noAssert){if(noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length)){var neg=128&this[offset];return neg?-1*(255-this[offset]+1):this[offset]}},Buffer.prototype.readInt16LE=function(offset,noAssert){return readInt16(this,offset,!0,noAssert)},Buffer.prototype.readInt16BE=function(offset,noAssert){return readInt16(this,offset,!1,noAssert)},Buffer.prototype.readInt32LE=function(offset,noAssert){return readInt32(this,offset,!0,noAssert)},Buffer.prototype.readInt32BE=function(offset,noAssert){return readInt32(this,offset,!1,noAssert)},Buffer.prototype.readFloatLE=function(offset,noAssert){return readFloat(this,offset,!0,noAssert)},Buffer.prototype.readFloatBE=function(offset,noAssert){return readFloat(this,offset,!1,noAssert)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return readDouble(this,offset,!0,noAssert)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return readDouble(this,offset,!1,noAssert)},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(this[offset]=value,offset+1)},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(value>=0?this.writeUInt8(value,offset,noAssert):this.writeUInt8(255+value+1,offset,noAssert),offset+1)},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return writeInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return writeInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return writeInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return writeInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert)},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),assert(end>=start,"end < start"),end!==start&&0!==this.length){assert(start>=0&&start=0&&end<=this.length,"end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.inspect=function(){for(var out=[],len=this.length,i=0;len>i;i++)if(out[i]=toHex(this[i]),i===exports.INSPECT_MAX_BYTES){out[i+1]="...";break}return""},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z]/g},{"base64-js":124,ieee754:125}],124:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS?62:code===SLASH?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],125:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],126:[function(require,module){function noop(){}var process=module.exports={};process.nextTick=function(){var canSetImmediate="undefined"!=typeof window&&window.setImmediate,canPost="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(canSetImmediate)return function(f){return window.setImmediate(f)};if(canPost){var queue=[];return window.addEventListener("message",function(ev){var source=ev.source;if((source===window||null===source)&&"process-tick"===ev.data&&(ev.stopPropagation(),queue.length>0)){var fn=queue.shift();fn()}},!0),function(fn){queue.push(fn),window.postMessage("process-tick","*")}}return function(fn){setTimeout(fn,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file From 0ac3e6f0f9527923b619937615561bd3f0e5128d Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Mon, 5 Jan 2015 01:34:22 +0100 Subject: [PATCH 33/64] fix #2 :) --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index 29e9291..3b301bc 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,6 @@ "brfs" ] }, - "bundledDependencies": [ - "splash-grid" - ], "scripts": { "prestart": "npm run links && node data/regenerate", "start": "beefy index.js:bundle.js --open", From ec01a4fce7945233246996f52d9381026a99af4f Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Fri, 16 Jan 2015 20:54:28 +0800 Subject: [PATCH 34/64] Add tracker for http://webglstats.com/ --- index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/index.html b/index.html index 20d4084..7474694 100644 --- a/index.html +++ b/index.html @@ -82,5 +82,6 @@

      community

      + From 474b79c5e3ca5624ce296dcf3e1da28b0e43a198 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sat, 17 Jan 2015 16:41:19 +0800 Subject: [PATCH 35/64] remove packages display --- data/regenerate.js | 46 ---------------------------------------------- data/sync.js | 4 +--- index.html | 6 ------ 3 files changed, 1 insertion(+), 55 deletions(-) diff --git a/data/regenerate.js b/data/regenerate.js index 48ab09a..ea6f0a7 100644 --- a/data/regenerate.js +++ b/data/regenerate.js @@ -53,49 +53,3 @@ var examples = tree( fs.writeFileSync(__dirname + '/../build/examples.json' , JSON.stringify(examples, null, 2) ) - -console.error() -console.error('extracting packages') - -var packages = tree( - fs.readFileSync(path.join(__dirname, 'packages.md'), 'utf8') -).children[0] - .children - .reduce(function(list, category) { - category.text = unhtml(category.text) - - list[category.text] = category.children.map(function(pkg, i) { - pkg.tokens.links = {} - - var name = unhtml(pkg.text) - var html = marked.Parser.parse(pkg.tokens) - var thumb = 'default.jpg' - - var $ = cheerio.load(html) - - $('img').each(function(i, img) { - var $img = $(img) - thumb = $img.attr('src') - $img.parent().remove() - }) - - var desc = $.html() - - console.error('*', category.text, '/', name) - - return { - name: name - , desc: desc - , link: 'http://ghub.io/' + name - , thumb: thumb || '' - , featured: false - , i: i - } - }) - - return list - }, {}) - -fs.writeFileSync(__dirname + '/../build/packages.json' - , JSON.stringify(packages, null, 2) -) diff --git a/data/sync.js b/data/sync.js index 41f0a1a..96ca59c 100644 --- a/data/sync.js +++ b/data/sync.js @@ -7,9 +7,7 @@ var fs = require('fs') var wiki = 'https://github.com/stackgl/stackgl.github.io/wiki/' -;['examples' -, 'packages' -].forEach(function(slug) { +;['examples'].forEach(function(slug) { var Slug = slug.slice(0, 1).toUpperCase() + slug.slice(1) var uri = url.resolve(wiki, Slug) var dst = path.join(__dirname, slug + '.md') diff --git a/index.html b/index.html index 7474694..cf395b2 100644 --- a/index.html +++ b/index.html @@ -44,12 +44,6 @@

      examples & demos

        -
        -

        packages

        -
          -
            -
            -

            community

            From dd852e98bedc8a93d0b579d3b53e1222b74b9d12 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sat, 17 Jan 2015 16:41:34 +0800 Subject: [PATCH 36/64] move GA into index --- index.html | 11 ++++++++++- index.js | 8 -------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index cf395b2..11d1f21 100644 --- a/index.html +++ b/index.html @@ -75,7 +75,16 @@

            community

            - + + diff --git a/index.js b/index.js index 59ffe15..6b58cbc 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,3 @@ -(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ -(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), -m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) -})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); - -ga('create', 'UA-54792490-1', 'auto'); -ga('send', 'pageview'); - var filter = require('./lib/filter') var minstache = require('minstache') var domify = require('domify') From 9a963a9a12e94ca56abc3615114ba39f06c24d7d Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sat, 17 Jan 2015 16:48:38 +0800 Subject: [PATCH 37/64] only load background image if required --- index.css | 2 +- index.js | 3 ++- package.json | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/index.css b/index.css index 4c7f005..62532df 100644 --- a/index.css +++ b/index.css @@ -93,7 +93,7 @@ h1 .lighter { z-index: 1; } -#grid { +.no-webgl #grid { background-image: url(bg.jpg); background-size: cover; } diff --git a/index.js b/index.js index 6b58cbc..cd3bfc3 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ var filter = require('./lib/filter') +var cl = require('class-list') var minstache = require('minstache') var domify = require('domify') var slice = require('sliced') @@ -11,9 +12,9 @@ require('./lib/fill')(document.querySelectorAll('[data-fill]')) try { require('@stackgl/splash-grid')(grid) - // require('@stackgl/splash-flock')(flock) } catch(e) { console.error(e.message) + cl(document.body).add('no-webgl') } var thumb = minstache.compile(fs.readFileSync( diff --git a/package.json b/package.json index 3b301bc..7840472 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "dependencies": { "brfs": "^1.1.2", "cheerio": "^0.17.0", + "class-list": "^0.1.1", "district": "^1.0.1", "domify": "^1.3.0", "findup-element": "0.0.0", From 3f221512accc71cf752b9b4bf288a036c5e8c864 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sat, 17 Jan 2015 16:49:17 +0800 Subject: [PATCH 38/64] Default to 100% viewport height for [data-fill] elements Stops the page from looking as crap while it is loading --- index.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.css b/index.css index 62532df..7fcfe22 100644 --- a/index.css +++ b/index.css @@ -188,3 +188,7 @@ h1 .lighter { #community-content p { margin-bottom: 1em; } + +[data-fill] { + height: 100vh; +} From 6552e5d87c2b1122743fec1fd95e9e5300ce7ce9 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sat, 17 Jan 2015 16:51:24 +0800 Subject: [PATCH 39/64] update getting started links --- index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 11d1f21..8eabdeb 100644 --- a/index.html +++ b/index.html @@ -57,8 +57,9 @@

            community

            stack.gl contributors: From f047178d2b8c233f2be502cbaccca9eac42f077a Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sat, 17 Jan 2015 16:58:18 +0800 Subject: [PATCH 40/64] add disc for file size checking --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7840472..42a4bbb 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "brfs": "^1.1.2", "cheerio": "^0.17.0", "class-list": "^0.1.1", + "disc": "^1.3.1", "district": "^1.0.1", "domify": "^1.3.0", "findup-element": "0.0.0", @@ -33,7 +34,8 @@ "postinstall": "npm run links && scoped-bulk stackgl npm install && npm dedupe && npm run sync", "bundle": "npm run prestart && browserify index.js | uglifyjs -c > bundle.js", "links": "district stackgl splash-grid splash-flock", - "sync": "node data/sync" + "sync": "node data/sync", + "disc": "browserify index.js --full-paths | uglifyjs -c | discify --open" }, "repository": { "type": "git", From d1a2369a70a41c67bb936e3f7871b5637554fecb Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sat, 17 Jan 2015 17:00:35 +0800 Subject: [PATCH 41/64] more junk trimming --- index.js | 12 ------------ package.json | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/index.js b/index.js index cd3bfc3..d8386e9 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,6 @@ var slice = require('sliced') var fs = require('fs') var grid = document.getElementById('grid').querySelector('canvas') -var flock = document.getElementById('community').querySelector('canvas') require('./lib/fill')(document.querySelectorAll('[data-fill]')) @@ -25,17 +24,6 @@ var examples = require('./build/examples.json').map(function(meta) { return thumb(meta) }).join('\n') -var packages = require('./build/packages.json') - -packages = Object.keys(packages).reduce(function(pkgs, group) { - return pkgs.concat(packages[group].map(function(pkg) { - pkg.group = group - return pkg - })) -}, []).map(function(meta) { - return thumb(meta) -}).join('\n') - document .getElementById('examples') .querySelector('ul.thumb-list') diff --git a/package.json b/package.json index 42a4bbb..70605c3 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "start": "beefy index.js:bundle.js --open", "postinstall": "npm run links && scoped-bulk stackgl npm install && npm dedupe && npm run sync", "bundle": "npm run prestart && browserify index.js | uglifyjs -c > bundle.js", - "links": "district stackgl splash-grid splash-flock", + "links": "district stackgl splash-grid", "sync": "node data/sync", "disc": "browserify index.js --full-paths | uglifyjs -c | discify --open" }, From b7dd0b031c0d130dcd5dfd2f74725ea3ac0e6572 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sat, 17 Jan 2015 17:34:31 +0800 Subject: [PATCH 42/64] remove splash-flock, update package.json --- package.json | 10 +-- splash-flock/boid.js | 1 - splash-flock/boid.png | Bin 1309 -> 0 bytes splash-flock/demo.js | 7 -- splash-flock/index.js | 111 ------------------------------- splash-flock/package.json | 31 --------- splash-flock/shaders/logic.frag | 78 ---------------------- splash-flock/shaders/logic.vert | 9 --- splash-flock/shaders/render.frag | 14 ---- splash-flock/shaders/render.vert | 16 ----- 10 files changed, 6 insertions(+), 271 deletions(-) delete mode 100644 splash-flock/boid.js delete mode 100644 splash-flock/boid.png delete mode 100644 splash-flock/demo.js delete mode 100644 splash-flock/index.js delete mode 100644 splash-flock/package.json delete mode 100644 splash-flock/shaders/logic.frag delete mode 100644 splash-flock/shaders/logic.vert delete mode 100644 splash-flock/shaders/render.frag delete mode 100644 splash-flock/shaders/render.vert diff --git a/package.json b/package.json index 70605c3..372f5cf 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ }, "scripts": { "prestart": "npm run links && node data/regenerate", - "start": "beefy index.js:bundle.js --open", + "start": "wzrd index.js:bundle.js", "postinstall": "npm run links && scoped-bulk stackgl npm install && npm dedupe && npm run sync", "bundle": "npm run prestart && browserify index.js | uglifyjs -c > bundle.js", "links": "district stackgl splash-grid", @@ -44,7 +44,8 @@ "contributors": [ "Hugh Kennedy ", "Mikola Lysenko ", - "Chris Dickinson " + "Chris Dickinson ", + "Matt DesLauriers " ], "license": "MIT", "bugs": { @@ -52,7 +53,8 @@ }, "homepage": "https://github.com/gl-modules/gl-modules.github.io", "devDependencies": { - "beefy": "^2.0.3", - "uglify-js": "^2.4.15" + "browserify": "^8.1.1", + "uglify-js": "^2.4.16", + "wzrd": "^1.2.1" } } diff --git a/splash-flock/boid.js b/splash-flock/boid.js deleted file mode 100644 index c57ab5d..0000000 --- a/splash-flock/boid.js +++ /dev/null @@ -1 +0,0 @@ -module.exports=require('ndpack-image')(16,16,4,"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAklEQVR4AewaftIAAAHfSURBVKXBcW+aQBjA4R94vsBR72Cl1Jr1+3+qJjYuuDo3hQnIiXYjoYlpmvSPPo/3+h9f4PNFig8452ialq7ruFx6fH9CEIRoHSEiXFO887eq+LPbsS/3NHXNqT+jlCKONYlN+JamzIzhjeJKVVW8bF5YFz/ZbF4oyz3OnRARrLXk+T3OOV7xMGbGQDFyzrHb7VkXa5bLJavVit/bLceuIwgDsts7mqbB4xURIQwDRATFqGlbynLPZrNh9WPF09MTRVHQNi2RjlgsSgZaa4y1WGsRERSj7njkcDhQliXbX1uKomD5/ExVlhhjwANrLfP5PXVd4zrHQDG6XC705x7nHF3X0bYtVVmyXq8Bj7Zp6I4dzp3o+zPny5mBYjTxfdREMZUpQRAQRRHWGPDAmhlaxwRRgMgUpSZMfJ+BYiRhyM1NTGITsixjsViAB23donXEw8MDd7cZ1lriOEbCgIFipKMIaxPyPKdpGjw8rLV03ZEgCMmyjO+Pj+T5PWmSoiPNQDESEdI0xbkT4KG1Jp/nnNyJqUxJbEKe5ywWc5I0RUQYKK4YYxiITEms4VDX9H2PUlPiWJMkCWmaYsyMN4p3jDGEYUhiLUfnuJzP+L5PGIZEUYSIcE3xARFBRLB87h/fHcFMratoHAAAAABJRU5ErkJggg==") diff --git a/splash-flock/boid.png b/splash-flock/boid.png deleted file mode 100644 index 9e2b9e65d8b69985160bacb8b6f79696891079c6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1309 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+n3Xd_B1$5BeXNr6bM+EIYV;~{3xK*A7;Nk-3KEmEQ%e+* zQqwc@Y?a>c-mj#PnPRIHZt82`Ti~3Uk?B!Ylp0*+7m{3+ootz+WN)WnQ(*-(AUCxn zQK2F?C$HG5!d3}vt`(3C64qBz04piUwpD^SD#ABF!8yMuRl!uxR5#hc$WX!DQqR!T z#M01EN5ROz&{*HlK;Otx*U-?)#N5izOaTg%fVLH-q*(>IxIyg#@@$ndN=gc>^!3Zj z%k|2Q_413-^$jg8E%gnI^o@*kfhu&1EAvVcD|GXUm0>2hq!uR^WfqiV=I1GZOiWD5 zFD$Tv3bSNU;+l1ennz|zM-B0$V)JVzP|XC=H|jx7ncO3BHWAB;NpiyW)Z+ZoqGVvir744~DzI`cN=+=uFAB-e&w+(vKt_H^esM;Afr7KMf`)Hma%LWg zuL;)R>ucqiS6q^qmz?V9Vygr+LN7Bj#md#m$i>aY&CS@z$;Hsn)x^Tw!obzc+{o3% z!ob+T*aD{4B|o_|H#M&WrZ)wq*VVuPr(RH6$SnZc?2=lPS(cjOR+OKs0QR$0CKk82 zxEebd8<|)b8<|>QcMC*s3NE*}xVhqVi$2gX`kGQ&7W-`!E@wbg46-srJPa!|F7?w(#0t@i}y@ZuWVeI z@2!oVYqw;bXRqJz{@iox=*uR$cE;EK3-uTVX|4Tg@on4QC0A0<6w5rXJ#>EA&%n^F zD^hRI``sw;=(i5n;^=eN9Se?5xc_2VCg0PAC-zT$>ez8>hH=Yb1D{FkG1j_k6e7;E ze(KHdk2hYPwaaAR?&(2M-JB`cmqx^M25GLCmO8WcY}xMEdC$GH`YSWF z3QkFIADTXsbJuIX<&y;-{itE7`v2t$hv0$jTN&~;S7zM4mSG$%C3xz>VTn(HUW~CK ztV)4Fulyd{*4pztHV~e+&39VL(={4P=RI!?f17Z2hQDn@yx=C5G_?n==H_-nJ&!GX zgBOIZzHp#y_ul>84^MrsJ-*bq(b2SLlFH7MB*ulM?bi^m)-yA?Xk=_ qO@{6Ew%F^gZ1Vq>*3XP*;$hf1^?q9HrK=^N0?X6Y&t;ucLK6V9J>ob3 diff --git a/splash-flock/demo.js b/splash-flock/demo.js deleted file mode 100644 index 30d3f61..0000000 --- a/splash-flock/demo.js +++ /dev/null @@ -1,7 +0,0 @@ -document.body.style.margin = 0 -document.body.style.padding = 0 -document.body.style.overflow = 'hidden' - -require('./')(document.body.appendChild( - document.createElement('canvas') -)) diff --git a/splash-flock/index.js b/splash-flock/index.js deleted file mode 100644 index 70677ef..0000000 --- a/splash-flock/index.js +++ /dev/null @@ -1,111 +0,0 @@ -var clear = require('gl-clear')({ color: [1, 1, 1, 1] }) -var triangle = require('a-big-triangle') -var debounce = require('frame-debounce') -var fit = require('canvas-fit') -var createBuffer = require('gl-buffer') -var ndarray = require('ndarray') -var Shader = require('glslify') -var FBO = require('gl-fbo') -var VAO = require('gl-vao') -var SIZE = 32 -var STEPS = 2 - -module.exports = init - -function init(canvas) { - var gl = require('gl-context')(canvas, render) - var boid = require('gl-texture2d')(gl, require('./boid')) - var vao = createParticleVAO(gl, SIZE) - var shaders = {} - var pdata = [] - - var starter = createStartPositions(SIZE) - for (var i = 0; i < STEPS; i++) { - pdata[i] = FBO(gl, [SIZE, SIZE], { float: true }) - pdata[i].color[0].setPixels(starter) - } - - window.addEventListener('resize' - , debounce(fit(canvas, window)) - ) - - shaders.logic = Shader({ - vert: './shaders/logic.vert' - , frag: './shaders/logic.frag' - })(gl) - - shaders.render = Shader({ - vert: './shaders/render.vert' - , frag: './shaders/render.frag' - })(gl) - - function render() { - var width = canvas.width - var height = canvas.height - - gl.disable(gl.DEPTH_TEST) - gl.disable(gl.CULL_FACE) - gl.disable(gl.BLEND) - pdata[0].bind() - - gl.viewport(0, 0, width, height) - shaders.logic.bind() - shaders.logic.uniforms.positions = pdata[1].color[0].bind(0) - triangle(gl) - - gl.bindFramebuffer(gl.FRAMEBUFFER, null) - gl.viewport(0, 0, width, height) - clear(gl) - gl.enable(gl.BLEND) - gl.blendFunc(gl.DST_COLOR, gl.ZERO) - - shaders.render.bind() - shaders.render.uniforms.positions = pdata[0].color[0].bind(0) - shaders.render.uniforms.tex = boid.bind(1) - shaders.render.uniforms.screenSize = [width, height] - vao.bind() - vao.draw(gl.POINTS, vao.length) - - switchFrames(pdata) - } -} - -function switchFrames(data) { - data.push(data.shift()) - return data -} - -function createParticleVAO(gl, size) { - var data = new Float32Array(size * size) - var n = 0 - for (var x = 0; x < size; x++) - for (var y = 0; y < size; y++) { - data[n++] = x / size - data[n++] = y / size - } - - var buffer = createBuffer(gl, data) - var vao = VAO(gl, [{ - buffer: buffer - , type: gl.FLOAT - , size: 2 - }]) - - vao.length = data.length / 2 - - return vao -} - -function createStartPositions(size) { - var data = new Float32Array(size * size * 4) - for (var i = 0; i < data.length;) { - // positions - data[i++] = Math.random() - 0.5 - data[i++] = Math.random() - 0.5 - // speeds - data[i++] = Math.random() * 0.1 - 0.05 - data[i++] = Math.random() * 0.1 - 0.05 - } - - return ndarray(data, [size, size, 4]) -} diff --git a/splash-flock/package.json b/splash-flock/package.json deleted file mode 100644 index 0690b9c..0000000 --- a/splash-flock/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "scripts": { - "start": "npm start glslify-live & npm run serve", - "serve": "beefy demo.js:bundle.js --open", - "image": "ndpack-image boid.png > boid.js" - }, - "browserify": { - "transform": ["glslify"] - }, - "dependencies": { - "a-big-triangle": "0.0.0", - "canvas-fit": "^1.2.0", - "frame-debounce": "0.0.0", - "gl-buffer": "^2.0.9", - "gl-clear": "0.0.1", - "gl-context": "^0.1.0", - "gl-fbo": "^2.0.3", - "gl-texture2d": "^2.0.3", - "gl-vao": "^1.2.0", - "glsl-curl-noise": "0.0.4", - "glsl-square-frame": "^1.0.0", - "glslify": "^1.6.0", - "ndarray": "^1.0.15" - }, - "devDependencies": { - "beefy": "^2.1.1", - "browserify": "^5.11.2", - "glslify-live": "^2.0.4", - "ndpack-image": "^1.0.3" - } -} diff --git a/splash-flock/shaders/logic.frag b/splash-flock/shaders/logic.frag deleted file mode 100644 index 2685526..0000000 --- a/splash-flock/shaders/logic.frag +++ /dev/null @@ -1,78 +0,0 @@ -precision mediump float; - -varying vec2 vuv; -uniform sampler2D positions; - -#pragma glslify: noise = require(glsl-curl-noise) - -#define CENTER_ATTRACTION 0.0045 -#define SPEED_LIMIT 0.065 -#define SEPARATION 0.0035 -#define ALIGNMENT 0.00125 -#define COHESION 0.0007 -#define WANDER 0.00035 -#define SIZE 32.0 - -vec2 alignment(vec2 speed) { - vec2 influence = vec2(0.0); - - for (float x = 0.0; x < 1.0; x += 1.0 / SIZE) - for (float y = 0.0; y < 1.0; y += 1.0 / SIZE) { - vec2 uv = vec2(x, y); - vec2 speed = texture2D(positions, uv).zw; - - influence += speed; - } - - return influence; -} -vec2 cohesion(vec2 position) { - vec2 influence = vec2(0.0); - - for (float x = 0.0; x < 1.0; x += 1.0 / SIZE) - for (float y = 0.0; y < 1.0; y += 1.0 / SIZE) { - vec2 uv = vec2(x, y); - vec2 pos = texture2D(positions, uv).xy; - - influence += pos / SIZE / SIZE; - } - - return influence - position; -} -vec2 separation(vec2 position, vec2 maxDistance, vec2 index) { - vec2 influence = vec2(0.0); - for (float x = 0.0; x < 1.0; x += 1.0 / SIZE) - for (float y = 0.0; y < 1.0; y += 1.0 / SIZE) { - vec2 uv = vec2(x, y); - vec2 pos = texture2D(positions, uv).xy; - float self = ( - x == index.x && - y == index.y - ) ? 0.0 : 1.0; - - float close = all( - greaterThanEqual(abs(position - pos), maxDistance) - ) ? 1.0 : 0.0; - - influence -= self * close * (position - pos); - } - return position - influence; -} - -void main() { - vec2 uv = gl_FragCoord.xy / vec2(SIZE); - vec2 position = texture2D(positions, uv).xy; - vec2 speed = texture2D(positions, uv).zw; - - speed += normalize(alignment(speed)) * ALIGNMENT; - speed += normalize(cohesion(position)) * COHESION; - speed += normalize(separation(position, vec2(0.5), uv)) * SEPARATION; - speed += normalize(vec2(0.5) - position) * CENTER_ATTRACTION; - speed += noise(vec3(uv * 10.2920, 1.290393)).xy * WANDER; - speed = clamp(speed, -SPEED_LIMIT, +SPEED_LIMIT); - - position += speed; - - gl_FragColor.xy = position; - gl_FragColor.zw = speed; -} diff --git a/splash-flock/shaders/logic.vert b/splash-flock/shaders/logic.vert deleted file mode 100644 index a35398a..0000000 --- a/splash-flock/shaders/logic.vert +++ /dev/null @@ -1,9 +0,0 @@ -precision mediump float; - -attribute vec2 position; -varying vec2 vuv; - -void main() { - vuv = (position + 1.0) * 0.5; - gl_Position = vec4(position.xy, 1.0, 1.0); -} diff --git a/splash-flock/shaders/render.frag b/splash-flock/shaders/render.frag deleted file mode 100644 index 107f8db..0000000 --- a/splash-flock/shaders/render.frag +++ /dev/null @@ -1,14 +0,0 @@ -precision mediump float; - -uniform sampler2D tex; - -void main() { - vec4 color = vec4(0.0); - - color += texture2D(tex, gl_PointCoord.xy); - color *= vec4(1.2, 1.15, 1.21, 1.0); - color += vec4(0.3, 0.3, 0.3, 0.0); - color.a = 1.0; - - gl_FragColor = color; -} diff --git a/splash-flock/shaders/render.vert b/splash-flock/shaders/render.vert deleted file mode 100644 index bb644e1..0000000 --- a/splash-flock/shaders/render.vert +++ /dev/null @@ -1,16 +0,0 @@ -precision mediump float; - -attribute vec2 uv; - -uniform sampler2D positions; -uniform vec2 screenSize; - -void main() { - vec2 position = texture2D(positions, uv).xy; - - position.x += 15.0; - position *= screenSize.x / screenSize.y / screenSize.xy; - - gl_PointSize = 8.0; - gl_Position = vec4((position) * 25.0, 1.0, 1.0); -} From 7207de0f0675c7f997cb7647337a995f1bdcd0a7 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sat, 17 Jan 2015 18:18:53 +0800 Subject: [PATCH 43/64] Shuffle things around a bit Should improve page load of site and upkeep of the build --- Makefile | 37 +++++++++++++++++++++++++++++++++++++ build/bundle.min.js | 1 + build/splash.min.js | 10 ++++++++++ bundle.js | 10 ---------- index.html | 5 +++-- index.js | 40 ---------------------------------------- package.json | 11 ++++------- src/index.js | 21 +++++++++++++++++++++ src/splash.js | 9 +++++++++ 9 files changed, 85 insertions(+), 59 deletions(-) create mode 100644 Makefile create mode 100644 build/bundle.min.js create mode 100644 build/splash.min.js delete mode 100644 bundle.js delete mode 100644 index.js create mode 100644 src/index.js create mode 100644 src/splash.js diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f532ed8 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +PATH := $(PWD)/node_modules/.bin:$(PATH) + +.PHONY: bundle clean relink disc + +bundle: build/bundle.min.js build/splash.min.js + +clean: + rm -rf build/*.js build/*.json data/*.md + +disc: + browserify src/index.js src/splash.js --full-paths | uglifyjs -c | discify --open + +start: relink build/examples.json + wzrd src/index.js:build/bundle.min.js \ + src/splash.js:build/splash.min.js + +relink: + district stackgl splash-grid + +postinstall: relink + scoped-bulk stackgl npm install + npm dedupe + +build/: + mkdir build + +build/bundle.min.js: build/ build/examples.json + browserify src/index.js | uglifyjs -c > build/bundle.min.js + +build/splash.min.js: build/ build/examples.json + browserify src/splash.js | uglifyjs -c > build/splash.min.js + +build/examples.json: build/ data/examples.md + node data/regenerate + +data/examples.md: build/ + node data/sync diff --git a/build/bundle.min.js b/build/bundle.min.js new file mode 100644 index 0000000..179d47f --- /dev/null +++ b/build/bundle.min.js @@ -0,0 +1 @@ +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to the WebGL API that runs in your browser. webgl-workshop\nis a NodeSchool workshop originally created for\nCampJS IV. Everything is powered by node.js, browserify and\na selection of stackgl packages under the hood.

            ',thumb:"http://i.imgur.com/vBJ7d6o.jpg",featured:!0,i:0},{name:"shader-school",link:"http://github.com/stackgl/shader-school",desc:"",thumb:"http://imgur.com/hegi9dZ.png",featured:!1,i:1},{name:"gl-surface-plot",link:"https://github.com/mikolalysenko/gl-surface-plot",desc:"",thumb:"http://i.imgur.com/z4xjpgu.jpg",featured:!1,i:2},{name:"bunny-walkthrough",link:"https://github.com/stackgl/bunny-walkthrough",desc:"",thumb:"http://i.imgur.com/OefbPjB.jpg",featured:!1,i:3},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:4},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:5},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:6},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:7},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:8},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:9},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:10},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:11},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:12},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:13}]},{}],2:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;i-1||(list.push(token),setTokens(list))}function remove(token){var list=getTokens(),index=indexof(list,token);-1!==index&&(list.splice(index,1),setTokens(list))}function contains(token){return indexof(getTokens(),token)>-1}function toggle(token){return contains(token)?(remove(token),!1):(add(token),!0)}function $toString(){return elem.className}function item(index){var tokens=getTokens();return tokens[index]||null}function getTokens(){var className=elem.className;return filter(className.split(" "),isTruthy)}function setTokens(list){var length=list.length;elem.className=list.join(" "),classList.length=length;for(var i=0;i
            a';var innerHTMLBug=!div.getElementsByTagName("link").length;div=void 0;var map={legend:[1,"
            ","
            "],tr:[2,"","
            "],col:[2,"","
            "],_default:innerHTMLBug?[1,"X
            ","
            "]:[0,"",""]};map.td=map.th=[3,"","
            "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
            "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],8:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],9:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:4,"raf-component":10,sliced:12}],10:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],11:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],12:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":13}],13:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],14:[function(require){{var minstache=(require("../lib/filter"),require("class-list"),require("minstache")),domify=require("domify");require("sliced")}require("../lib/fill")(document.querySelectorAll("[data-fill]"));var thumb=minstache.compile('
          • \n
            \n \n
            \n
            \n
            \n \n

            {{name}}

            \n
            \n
            \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
            \n
            \n
            \n
          • \n'),examples=require("../build/examples.json").map(function(meta){return thumb(meta)}).join("\n");document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples))},{"../build/examples.json":1,"../lib/fill":2,"../lib/filter":3,"class-list":5,domify:7,minstache:11,sliced:12}]},{},[14]); \ No newline at end of file diff --git a/build/splash.min.js b/build/splash.min.js new file mode 100644 index 0000000..f1df359 --- /dev/null +++ b/build/splash.min.js @@ -0,0 +1,10 @@ +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":1,"a-big-triangle":19,"canvas-fit":20,clone:22,"cube-cube":23,"face-normals":26,"frame-debounce":27,"gl-clear":32,"gl-context":33,"gl-fbo":35,"gl-geometry":38,"gl-matrix":63,"gl-texture2d":76,glslify:78,"glslify/adapter.js":77,"mesh-combine":84,"orbit-camera":108,"right-now":109,"unindex-mesh":110}],3:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:9,"ndarray-ops":4,"typedarray-pool":13}],4:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":5}],5:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":7}],6:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:8}],7:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],9:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:111,"iota-array":10}],10:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],11:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],12:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],13:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":11,dup:12}],14:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],15:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":14}],16:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":14}],17:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":25}],24:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],25:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],27:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:115,"raf-component":28,sliced:29}],28:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],29:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":30}],30:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],31:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],32:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":31}],33:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":34}],34:[function(require,module,exports){arguments[4][28][0].apply(exports,arguments)},{dup:28}],35:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT)); +var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options["float"]&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:40}],40:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],41:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:47,"ndarray-ops":42,"typedarray-pool":51,webglew:53}],42:[function(require,module,exports){arguments[4][4][0].apply(exports,arguments)},{"cwise-compiler":43,dup:4}],43:[function(require,module,exports){arguments[4][5][0].apply(exports,arguments)},{"./lib/thunk.js":45,dup:5}],44:[function(require,module,exports){arguments[4][6][0].apply(exports,arguments)},{dup:6,uniq:46}],45:[function(require,module,exports){arguments[4][7][0].apply(exports,arguments)},{"./compile.js":44,dup:7}],46:[function(require,module,exports){arguments[4][8][0].apply(exports,arguments)},{dup:8}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{buffer:111,dup:9,"iota-array":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{dup:10}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{dup:11}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{dup:12}],51:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":49,buffer:111,dup:50}],52:[function(require,module,exports){arguments[4][36][0].apply(exports,arguments)},{dup:36}],53:[function(require,module,exports){arguments[4][37][0].apply(exports,arguments)},{dup:37,weakmap:52}],54:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],55:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":54}],56:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1]; +return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],64:[function(require,module,exports){arguments[4][4][0].apply(exports,arguments)},{"cwise-compiler":65,dup:4}],65:[function(require,module,exports){arguments[4][5][0].apply(exports,arguments)},{"./lib/thunk.js":67,dup:5}],66:[function(require,module,exports){arguments[4][6][0].apply(exports,arguments)},{dup:6,uniq:68}],67:[function(require,module,exports){arguments[4][7][0].apply(exports,arguments)},{"./compile.js":66,dup:7}],68:[function(require,module,exports){arguments[4][8][0].apply(exports,arguments)},{dup:8}],69:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{buffer:111,dup:9,"iota-array":70}],70:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{dup:10}],71:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{dup:11}],72:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{dup:12}],73:[function(require,module,exports){arguments[4][51][0].apply(exports,arguments)},{"bit-twiddle":71,buffer:111,dup:51}],74:[function(require,module,exports){arguments[4][36][0].apply(exports,arguments)},{dup:36}],75:[function(require,module,exports){arguments[4][37][0].apply(exports,arguments)},{dup:37,weakmap:74}],76:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0; +if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function isPacked(array){for(var shape=array.shape,stride=array.stride,s=1,i=shape.length-1;i>=0;--i){if(stride[i]!==s)return!1;s*=shape[i]}return!0}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(array),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type===gl.FLOAT&&webglew(gl).texture_float&&(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store;if(packed){var array_size=array.size;buffer=array.data.subarray(array.offset,array.offset+array_size)}else{for(var sz=1,stride=new Array(shape.length),i=shape.length-1;i>=0;--i)stride[i]=sz,sz*=shape[i];buf_store=pool.malloc(sz,dtype);var buf_array=ndarray(buf_store,array.shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,sz)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[1],shape[0],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][1],0|arguments[1][0],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew"),linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)};Object.defineProperty(Texture2D.prototype,"minFilter",{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}});var proto=Texture2D.prototype;Object.defineProperty(proto,"magFilter",{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}}),Object.defineProperty(proto,"wrapS",{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}}),Object.defineProperty(proto,"wrapT",{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}}),Object.defineProperty(proto,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapT=v[0],this._wrapS=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),v}}),Object.defineProperty(proto,"mipSamples",{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(proto,"shape",{get:function(){return this._shape},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];var r=0|x[0],c=0|x[1];if(this.height===r&&this.width===c)return x;var gl=this.gl,maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>c||c>maxSize||0>r||r>maxSize)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[r,c],this.bind(),gl.texImage2D(gl.TEXTURE_2D,0,this.format,c,r,0,this.format,this.type,null),this._mipLevels=[0],x}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[0],x_off=0|x_off[1]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}},module.exports=createTexture2D},{ndarray:69,"ndarray-ops":64,"typedarray-pool":73,webglew:75}],77:[function(require,module){function programify(vertex,fragment,uniforms,attributes){return function(gl){return shader(gl,vertex,fragment,uniforms,attributes)}}module.exports=programify;var shader=require("gl-shader-core")},{"gl-shader-core":83}],78:[function(require,module){function noop(){throw new Error("You should bundle your code using `glslify` as a transform.")}module.exports=noop},{}],79:[function(require,module){"use strict";function ShaderAttribute(gl,program,location,dimension,name,constFunc,relink){this._gl=gl,this._program=program,this._location=location,this._dimension=dimension,this._name=name,this._constFunc=constFunc,this._relink=relink}function addVectorAttribute(gl,program,location,dimension,obj,name,doLink){for(var constFuncArgs=["gl","v"],varNames=[],i=0;dimension>i;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],80:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;k=pa&&pc>=pa?a:pc>=pb?b:c}function parseData(dataBuffer){function inputData(data){for(var tmp,j,len=data.length,i=0;i!==len;)switch(state){case 0:if(data.readUInt8(i++)!==HEADER[off++])return!1;off===HEADER.length&&(state=1,off=0);break;case 1:if(8-off>len-i)data.copy(buf,off,i),off+=len-i,i=len;else switch(data.copy(buf,off,i,i+8-off),i+=8-off,off=0,chunkLength=buf.readUInt32BE(0),buf.toString("ascii",4,8)){case"IHDR":state=2;break;case"PLTE":if(3!==pngColorType)state=7;else{if(chunkLength%3!==0)return!1;pngPaletteEntries=chunkLength/3,pngPalette=new Buffer(chunkLength),state=3}break;case"tRNS":if(3!==pngColorType)return!1;idChannels++,pngAlphaEntries=chunkLength,pngAlpha=new Buffer(chunkLength),state=4;break;case"IDAT":pngPixels||(pngPixels=new Uint8Array(pngWidth*pngHeight*idChannels)),state=5;break;case"IEND":state=6;break;default:state=7}break;case 2:if(13!==chunkLength)return!1;if(chunkLength-off>len-i)data.copy(buf,off,i),off+=len-i,i=len;else{if(data.copy(buf,off,i,i+chunkLength-off),0!==buf.readUInt8(10))return!1;if(0!==buf.readUInt8(11))return!1;if(0!==buf.readUInt8(12))return!1;switch(i+=chunkLength-off,state=8,off=0,pngWidth=buf.readUInt32BE(0),pngHeight=buf.readUInt32BE(4),pngBitDepth=buf.readUInt8(8),pngDepthMult=255/((1<len-i)data.copy(pngPalette,off,i),off+=len-i,i=len;else for(data.copy(pngPalette,off,i,i+chunkLength-off),i+=chunkLength-off,state=8,off=0,idChannels=1,j=pngPaletteEntries;j--;)if(pngPalette[3*j+0]!==pngPalette[3*j+1]||pngPalette[3*j+0]!==pngPalette[3*j+2]){idChannels=3;break}break;case 4:chunkLength-off>len-i?(data.copy(pngAlpha,off,i),off+=len-i,i=len):(data.copy(pngAlpha,off,i,i+chunkLength-off),i+=chunkLength-off,state=8,off=0);break;case 5:chunkLength-off>len-i?(inflateQueue.push(data.slice(i)),off+=len-i,i=len):(inflateQueue.push(data.slice(i,i+chunkLength-off)),i+=chunkLength-off,state=8,off=0);break;case 6:if(0!==chunkLength)return!1;4-off>len-i?(off+=len-i,i=len):(pngTrailer=new Buffer(0),i+=4-off,state=9,off=0);break;case 7:chunkLength-off>len-i?(off+=len-i,i=len):(i+=chunkLength-off,state=8,off=0);break;case 8:4-off>len-i?(off+=len-i,i=len):(i+=4-off,state=1,off=0);break;case 9:tmp=new Buffer(off+len-i),pngTrailer.copy(tmp),data.copy(tmp,off,i,len),pngTrailer=tmp,off+=len-i,i=len}return!0}function unpackPixels(data){var i,tmp,x,j,k,len=data.length;for(i=0;i!==len;++i){if(-1===b)scanlineFilter=data[i],tmp=currentScanline,currentScanline=priorScanline,priorScanline=tmp;else switch(scanlineFilter){case 0:currentScanline[b]=data[i];break;case 1:currentScanline[b]=pngBytesPerPixel>b?data[i]:data[i]+currentScanline[b-pngBytesPerPixel]&255;break;case 2:currentScanline[b]=data[i]+priorScanline[b]&255;break;case 3:currentScanline[b]=data[i]+((pngBytesPerPixel>b?priorScanline[b]:currentScanline[b-pngBytesPerPixel]+priorScanline[b])>>>1)&255;break;case 4:currentScanline[b]=data[i]+(pngBytesPerPixel>b?priorScanline[b]:paeth(currentScanline[b-pngBytesPerPixel],priorScanline[b],priorScanline[b-pngBytesPerPixel]))&255;break;default:return null}if(++b===pngBytesPerScanline){if(p===pngPixels.length)return null;for(j=0,x=0;x!==pngWidth;++x){for(k=0;k!==pngSamplesPerPixel;++j,++k)switch(pngBitDepth){case 1:pngSamples[k]=currentScanline[j>>>3]>>7-(7&j)&1;break;case 2:pngSamples[k]=currentScanline[j>>>2]>>(3-(3&j)<<1)&3;break;case 4:pngSamples[k]=currentScanline[j>>>1]>>(1-(1&j)<<2)&15;break;case 8:pngSamples[k]=currentScanline[j];break;default:return null}switch(pngColorType){case 0:pngPixels[p++]=pngSamples[0]*pngDepthMult;break;case 2:pngPixels[p++]=pngSamples[0]*pngDepthMult,pngPixels[p++]=pngSamples[1]*pngDepthMult,pngPixels[p++]=pngSamples[2]*pngDepthMult;break;case 3:if(pngSamples[0]>=pngPaletteEntries)return null;switch(idChannels){case 1:pngPixels[p++]=pngPalette[3*pngSamples[0]];break;case 2:pngPixels[p++]=pngPalette[3*pngSamples[0]],pngPixels[p++]=pngSamples[0]0?opt.windowBits=-opt.windowBits:opt.gzip&&opt.windowBits>0&&opt.windowBits<16&&(opt.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;var status=zlib_deflate.deflateInit2(this.strm,opt.level,opt.method,opt.windowBits,opt.memLevel,opt.strategy);if(status!==Z_OK)throw new Error(msg[status]);opt.header&&zlib_deflate.deflateSetHeader(this.strm,opt.header)};Deflate.prototype.push=function(data,mode){var status,_mode,strm=this.strm,chunkSize=this.options.chunkSize;if(this.ended)return!1;_mode=mode===~~mode?mode:mode===!0?Z_FINISH:Z_NO_FLUSH,strm.input="string"==typeof data?strings.string2buf(data):data,strm.next_in=0,strm.avail_in=strm.input.length;do{if(0===strm.avail_out&&(strm.output=new utils.Buf8(chunkSize),strm.next_out=0,strm.avail_out=chunkSize),status=zlib_deflate.deflate(strm,_mode),status!==Z_STREAM_END&&status!==Z_OK)return this.onEnd(status),this.ended=!0,!1;(0===strm.avail_out||0===strm.avail_in&&_mode===Z_FINISH)&&this.onData("string"===this.options.to?strings.buf2binstring(utils.shrinkBuf(strm.output,strm.next_out)):utils.shrinkBuf(strm.output,strm.next_out))}while((strm.avail_in>0||0===strm.avail_out)&&status!==Z_STREAM_END);return _mode===Z_FINISH?(status=zlib_deflate.deflateEnd(this.strm),this.onEnd(status),this.ended=!0,status===Z_OK):!0},Deflate.prototype.onData=function(chunk){this.chunks.push(chunk)},Deflate.prototype.onEnd=function(status){status===Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):utils.flattenChunks(this.chunks)),this.chunks=[],this.err=status,this.msg=this.strm.msg},exports.Deflate=Deflate,exports.deflate=deflate,exports.deflateRaw=deflateRaw,exports.gzip=gzip},{"./utils/common":93,"./utils/strings":94,"./zlib/deflate.js":98,"./zlib/messages":103,"./zlib/zstream":105}],92:[function(require,module,exports){"use strict";function inflate(input,options){var inflator=new Inflate(options);if(inflator.push(input,!0),inflator.err)throw inflator.msg;return inflator.result}function inflateRaw(input,options){return options=options||{},options.raw=!0,inflate(input,options)}var zlib_inflate=require("./zlib/inflate.js"),utils=require("./utils/common"),strings=require("./utils/strings"),c=require("./zlib/constants"),msg=require("./zlib/messages"),zstream=require("./zlib/zstream"),gzheader=require("./zlib/gzheader"),Inflate=function(options){this.options=utils.assign({chunkSize:16384,windowBits:0,to:""},options||{});var opt=this.options;opt.raw&&opt.windowBits>=0&&opt.windowBits<16&&(opt.windowBits=-opt.windowBits,0===opt.windowBits&&(opt.windowBits=-15)),!(opt.windowBits>=0&&opt.windowBits<16)||options&&options.windowBits||(opt.windowBits+=32),opt.windowBits>15&&opt.windowBits<48&&0===(15&opt.windowBits)&&(opt.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;var status=zlib_inflate.inflateInit2(this.strm,opt.windowBits);if(status!==c.Z_OK)throw new Error(msg[status]);this.header=new gzheader,zlib_inflate.inflateGetHeader(this.strm,this.header)};Inflate.prototype.push=function(data,mode){var status,_mode,next_out_utf8,tail,utf8str,strm=this.strm,chunkSize=this.options.chunkSize;if(this.ended)return!1;_mode=mode===~~mode?mode:mode===!0?c.Z_FINISH:c.Z_NO_FLUSH,strm.input="string"==typeof data?strings.binstring2buf(data):data,strm.next_in=0,strm.avail_in=strm.input.length;do{if(0===strm.avail_out&&(strm.output=new utils.Buf8(chunkSize),strm.next_out=0,strm.avail_out=chunkSize),status=zlib_inflate.inflate(strm,c.Z_NO_FLUSH),status!==c.Z_STREAM_END&&status!==c.Z_OK)return this.onEnd(status),this.ended=!0,!1;strm.next_out&&(0===strm.avail_out||status===c.Z_STREAM_END||0===strm.avail_in&&_mode===c.Z_FINISH)&&("string"===this.options.to?(next_out_utf8=strings.utf8border(strm.output,strm.next_out),tail=strm.next_out-next_out_utf8,utf8str=strings.buf2string(strm.output,next_out_utf8),strm.next_out=tail,strm.avail_out=chunkSize-tail,tail&&utils.arraySet(strm.output,strm.output,next_out_utf8,tail,0),this.onData(utf8str)):this.onData(utils.shrinkBuf(strm.output,strm.next_out)))}while(strm.avail_in>0&&status!==c.Z_STREAM_END);return status===c.Z_STREAM_END&&(_mode=c.Z_FINISH),_mode===c.Z_FINISH?(status=zlib_inflate.inflateEnd(this.strm),this.onEnd(status),this.ended=!0,status===c.Z_OK):!0},Inflate.prototype.onData=function(chunk){this.chunks.push(chunk)},Inflate.prototype.onEnd=function(status){status===c.Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):utils.flattenChunks(this.chunks)),this.chunks=[],this.err=status,this.msg=this.strm.msg},exports.Inflate=Inflate,exports.inflate=inflate,exports.inflateRaw=inflateRaw,exports.ungzip=inflate},{"./utils/common":93,"./utils/strings":94,"./zlib/constants":96,"./zlib/gzheader":99,"./zlib/inflate.js":101,"./zlib/messages":103,"./zlib/zstream":105}],93:[function(require,module,exports){"use strict";var TYPED_OK="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;exports.assign=function(obj){for(var sources=Array.prototype.slice.call(arguments,1);sources.length;){var source=sources.shift(); +if(source){if("object"!=typeof source)throw new TypeError(source+"must be non-object");for(var p in source)source.hasOwnProperty(p)&&(obj[p]=source[p])}}return obj},exports.shrinkBuf=function(buf,size){return buf.length===size?buf:buf.subarray?buf.subarray(0,size):(buf.length=size,buf)};var fnTyped={arraySet:function(dest,src,src_offs,len,dest_offs){if(src.subarray&&dest.subarray)return void dest.set(src.subarray(src_offs,src_offs+len),dest_offs);for(var i=0;len>i;i++)dest[dest_offs+i]=src[src_offs+i]},flattenChunks:function(chunks){var i,l,len,pos,chunk,result;for(len=0,i=0,l=chunks.length;l>i;i++)len+=chunks[i].length;for(result=new Uint8Array(len),pos=0,i=0,l=chunks.length;l>i;i++)chunk=chunks[i],result.set(chunk,pos),pos+=chunk.length;return result}},fnUntyped={arraySet:function(dest,src,src_offs,len,dest_offs){for(var i=0;len>i;i++)dest[dest_offs+i]=src[src_offs+i]},flattenChunks:function(chunks){return[].concat.apply([],chunks)}};exports.setTyped=function(on){on?(exports.Buf8=Uint8Array,exports.Buf16=Uint16Array,exports.Buf32=Int32Array,exports.assign(exports,fnTyped)):(exports.Buf8=Array,exports.Buf16=Array,exports.Buf32=Array,exports.assign(exports,fnUntyped))},exports.setTyped(TYPED_OK)},{}],94:[function(require,module,exports){"use strict";function buf2binstring(buf,len){if(65537>len&&(buf.subarray&&STR_APPLY_UIA_OK||!buf.subarray&&STR_APPLY_OK))return String.fromCharCode.apply(null,utils.shrinkBuf(buf,len));for(var result="",i=0;len>i;i++)result+=String.fromCharCode(buf[i]);return result}var utils=require("./common"),STR_APPLY_OK=!0,STR_APPLY_UIA_OK=!0;try{String.fromCharCode.apply(null,[0])}catch(__){STR_APPLY_OK=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(__){STR_APPLY_UIA_OK=!1}for(var _utf8len=new utils.Buf8(256),i=0;256>i;i++)_utf8len[i]=i>=252?6:i>=248?5:i>=240?4:i>=224?3:i>=192?2:1;_utf8len[254]=_utf8len[254]=1,exports.string2buf=function(str){var buf,c,c2,m_pos,i,str_len=str.length,buf_len=0;for(m_pos=0;str_len>m_pos;m_pos++)c=str.charCodeAt(m_pos),55296===(64512&c)&&str_len>m_pos+1&&(c2=str.charCodeAt(m_pos+1),56320===(64512&c2)&&(c=65536+(c-55296<<10)+(c2-56320),m_pos++)),buf_len+=128>c?1:2048>c?2:65536>c?3:4;for(buf=new utils.Buf8(buf_len),i=0,m_pos=0;buf_len>i;m_pos++)c=str.charCodeAt(m_pos),55296===(64512&c)&&str_len>m_pos+1&&(c2=str.charCodeAt(m_pos+1),56320===(64512&c2)&&(c=65536+(c-55296<<10)+(c2-56320),m_pos++)),128>c?buf[i++]=c:2048>c?(buf[i++]=192|c>>>6,buf[i++]=128|63&c):65536>c?(buf[i++]=224|c>>>12,buf[i++]=128|c>>>6&63,buf[i++]=128|63&c):(buf[i++]=240|c>>>18,buf[i++]=128|c>>>12&63,buf[i++]=128|c>>>6&63,buf[i++]=128|63&c);return buf},exports.buf2binstring=function(buf){return buf2binstring(buf,buf.length)},exports.binstring2buf=function(str){for(var buf=new utils.Buf8(str.length),i=0,len=buf.length;len>i;i++)buf[i]=str.charCodeAt(i);return buf},exports.buf2string=function(buf,max){var i,out,c,c_len,len=max||buf.length,utf16buf=new Array(2*len);for(out=0,i=0;len>i;)if(c=buf[i++],128>c)utf16buf[out++]=c;else if(c_len=_utf8len[c],c_len>4)utf16buf[out++]=65533,i+=c_len-1;else{for(c&=2===c_len?31:3===c_len?15:7;c_len>1&&len>i;)c=c<<6|63&buf[i++],c_len--;c_len>1?utf16buf[out++]=65533:65536>c?utf16buf[out++]=c:(c-=65536,utf16buf[out++]=55296|c>>10&1023,utf16buf[out++]=56320|1023&c)}return buf2binstring(utf16buf,out)},exports.utf8border=function(buf,max){var pos;for(max=max||buf.length,max>buf.length&&(max=buf.length),pos=max-1;pos>=0&&128===(192&buf[pos]);)pos--;return 0>pos?max:0===pos?max:pos+_utf8len[buf[pos]]>max?pos:max}},{"./common":93}],95:[function(require,module){"use strict";function adler32(adler,buf,len,pos){for(var s1=65535&adler|0,s2=adler>>>16&65535|0,n=0;0!==len;){n=len>2e3?2e3:len,len-=n;do s1=s1+buf[pos++]|0,s2=s2+s1|0;while(--n);s1%=65521,s2%=65521}return s1|s2<<16|0}module.exports=adler32},{}],96:[function(require,module){module.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],97:[function(require,module){"use strict";function makeTable(){for(var c,table=[],n=0;256>n;n++){c=n;for(var k=0;8>k;k++)c=1&c?3988292384^c>>>1:c>>>1;table[n]=c}return table}function crc32(crc,buf,len,pos){var t=crcTable,end=pos+len;crc=-1^crc;for(var i=pos;end>i;i++)crc=crc>>>8^t[255&(crc^buf[i])];return-1^crc}var crcTable=makeTable();module.exports=crc32},{}],98:[function(require,module,exports){"use strict";function err(strm,errorCode){return strm.msg=msg[errorCode],errorCode}function rank(f){return(f<<1)-(f>4?9:0)}function zero(buf){for(var len=buf.length;--len>=0;)buf[len]=0}function flush_pending(strm){var s=strm.state,len=s.pending;len>strm.avail_out&&(len=strm.avail_out),0!==len&&(utils.arraySet(strm.output,s.pending_buf,s.pending_out,len,strm.next_out),strm.next_out+=len,s.pending_out+=len,strm.total_out+=len,strm.avail_out-=len,s.pending-=len,0===s.pending&&(s.pending_out=0))}function flush_block_only(s,last){trees._tr_flush_block(s,s.block_start>=0?s.block_start:-1,s.strstart-s.block_start,last),s.block_start=s.strstart,flush_pending(s.strm)}function put_byte(s,b){s.pending_buf[s.pending++]=b}function putShortMSB(s,b){s.pending_buf[s.pending++]=b>>>8&255,s.pending_buf[s.pending++]=255&b}function read_buf(strm,buf,start,size){var len=strm.avail_in;return len>size&&(len=size),0===len?0:(strm.avail_in-=len,utils.arraySet(buf,strm.input,strm.next_in,len,start),1===strm.state.wrap?strm.adler=adler32(strm.adler,buf,len,start):2===strm.state.wrap&&(strm.adler=crc32(strm.adler,buf,len,start)),strm.next_in+=len,strm.total_in+=len,len)}function longest_match(s,cur_match){var match,len,chain_length=s.max_chain_length,scan=s.strstart,best_len=s.prev_length,nice_match=s.nice_match,limit=s.strstart>s.w_size-MIN_LOOKAHEAD?s.strstart-(s.w_size-MIN_LOOKAHEAD):0,_win=s.window,wmask=s.w_mask,prev=s.prev,strend=s.strstart+MAX_MATCH,scan_end1=_win[scan+best_len-1],scan_end=_win[scan+best_len];s.prev_length>=s.good_match&&(chain_length>>=2),nice_match>s.lookahead&&(nice_match=s.lookahead);do if(match=cur_match,_win[match+best_len]===scan_end&&_win[match+best_len-1]===scan_end1&&_win[match]===_win[scan]&&_win[++match]===_win[scan+1]){scan+=2,match++;do;while(_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&strend>scan);if(len=MAX_MATCH-(strend-scan),scan=strend-MAX_MATCH,len>best_len){if(s.match_start=cur_match,best_len=len,len>=nice_match)break;scan_end1=_win[scan+best_len-1],scan_end=_win[scan+best_len]}}while((cur_match=prev[cur_match&wmask])>limit&&0!==--chain_length);return best_len<=s.lookahead?best_len:s.lookahead}function fill_window(s){var p,n,m,more,str,_w_size=s.w_size;do{if(more=s.window_size-s.lookahead-s.strstart,s.strstart>=_w_size+(_w_size-MIN_LOOKAHEAD)){utils.arraySet(s.window,s.window,_w_size,_w_size,0),s.match_start-=_w_size,s.strstart-=_w_size,s.block_start-=_w_size,n=s.hash_size,p=n;do m=s.head[--p],s.head[p]=m>=_w_size?m-_w_size:0;while(--n);n=_w_size,p=n;do m=s.prev[--p],s.prev[p]=m>=_w_size?m-_w_size:0;while(--n);more+=_w_size}if(0===s.strm.avail_in)break;if(n=read_buf(s.strm,s.window,s.strstart+s.lookahead,more),s.lookahead+=n,s.lookahead+s.insert>=MIN_MATCH)for(str=s.strstart-s.insert,s.ins_h=s.window[str],s.ins_h=(s.ins_h<s.pending_buf_size-5&&(max_block_size=s.pending_buf_size-5);;){if(s.lookahead<=1){if(fill_window(s),0===s.lookahead&&flush===Z_NO_FLUSH)return BS_NEED_MORE;if(0===s.lookahead)break}s.strstart+=s.lookahead,s.lookahead=0;var max_start=s.block_start+max_block_size;if((0===s.strstart||s.strstart>=max_start)&&(s.lookahead=s.strstart-max_start,s.strstart=max_start,flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE;if(s.strstart-s.block_start>=s.w_size-MIN_LOOKAHEAD&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.strstart>s.block_start&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_NEED_MORE}function deflate_fast(s,flush){for(var hash_head,bflush;;){if(s.lookahead=MIN_MATCH&&(s.ins_h=(s.ins_h<=MIN_MATCH)if(bflush=trees._tr_tally(s,s.strstart-s.match_start,s.match_length-MIN_MATCH),s.lookahead-=s.match_length,s.match_length<=s.max_lazy_match&&s.lookahead>=MIN_MATCH){s.match_length--;do s.strstart++,s.ins_h=(s.ins_h<=MIN_MATCH&&(s.ins_h=(s.ins_h<4096)&&(s.match_length=MIN_MATCH-1)),s.prev_length>=MIN_MATCH&&s.match_length<=s.prev_length){max_insert=s.strstart+s.lookahead-MIN_MATCH,bflush=trees._tr_tally(s,s.strstart-1-s.prev_match,s.prev_length-MIN_MATCH),s.lookahead-=s.prev_length-1,s.prev_length-=2;do++s.strstart<=max_insert&&(s.ins_h=(s.ins_h<=MIN_MATCH&&s.strstart>0&&(scan=s.strstart-1,prev=_win[scan],prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan])){strend=s.strstart+MAX_MATCH;do;while(prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&strend>scan);s.match_length=MAX_MATCH-(strend-scan),s.match_length>s.lookahead&&(s.match_length=s.lookahead)}if(s.match_length>=MIN_MATCH?(bflush=trees._tr_tally(s,1,s.match_length-MIN_MATCH),s.lookahead-=s.match_length,s.strstart+=s.match_length,s.match_length=0):(bflush=trees._tr_tally(s,0,s.window[s.strstart]),s.lookahead--,s.strstart++),bflush&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.last_lit&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE}function deflate_huff(s,flush){for(var bflush;;){if(0===s.lookahead&&(fill_window(s),0===s.lookahead)){if(flush===Z_NO_FLUSH)return BS_NEED_MORE;break}if(s.match_length=0,bflush=trees._tr_tally(s,0,s.window[s.strstart]),s.lookahead--,s.strstart++,bflush&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.last_lit&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE}function lm_init(s){s.window_size=2*s.w_size,zero(s.head),s.max_lazy_match=configuration_table[s.level].max_lazy,s.good_match=configuration_table[s.level].good_length,s.nice_match=configuration_table[s.level].nice_length,s.max_chain_length=configuration_table[s.level].max_chain,s.strstart=0,s.block_start=0,s.lookahead=0,s.insert=0,s.match_length=s.prev_length=MIN_MATCH-1,s.match_available=0,s.ins_h=0}function DeflateState(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Z_DEFLATED,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new utils.Buf16(2*HEAP_SIZE),this.dyn_dtree=new utils.Buf16(2*(2*D_CODES+1)),this.bl_tree=new utils.Buf16(2*(2*BL_CODES+1)),zero(this.dyn_ltree),zero(this.dyn_dtree),zero(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new utils.Buf16(MAX_BITS+1),this.heap=new utils.Buf16(2*L_CODES+1),zero(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new utils.Buf16(2*L_CODES+1),zero(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function deflateResetKeep(strm){var s;return strm&&strm.state?(strm.total_in=strm.total_out=0,strm.data_type=Z_UNKNOWN,s=strm.state,s.pending=0,s.pending_out=0,s.wrap<0&&(s.wrap=-s.wrap),s.status=s.wrap?INIT_STATE:BUSY_STATE,strm.adler=2===s.wrap?0:1,s.last_flush=Z_NO_FLUSH,trees._tr_init(s),Z_OK):err(strm,Z_STREAM_ERROR)}function deflateReset(strm){var ret=deflateResetKeep(strm);return ret===Z_OK&&lm_init(strm.state),ret}function deflateSetHeader(strm,head){return strm&&strm.state?2!==strm.state.wrap?Z_STREAM_ERROR:(strm.state.gzhead=head,Z_OK):Z_STREAM_ERROR}function deflateInit2(strm,level,method,windowBits,memLevel,strategy){if(!strm)return Z_STREAM_ERROR;var wrap=1;if(level===Z_DEFAULT_COMPRESSION&&(level=6),0>windowBits?(wrap=0,windowBits=-windowBits):windowBits>15&&(wrap=2,windowBits-=16),1>memLevel||memLevel>MAX_MEM_LEVEL||method!==Z_DEFLATED||8>windowBits||windowBits>15||0>level||level>9||0>strategy||strategy>Z_FIXED)return err(strm,Z_STREAM_ERROR);8===windowBits&&(windowBits=9);var s=new DeflateState;return strm.state=s,s.strm=strm,s.wrap=wrap,s.gzhead=null,s.w_bits=windowBits,s.w_size=1<>1,s.l_buf=3*s.lit_bufsize,s.level=level,s.strategy=strategy,s.method=method,deflateReset(strm)}function deflateInit(strm,level){return deflateInit2(strm,level,Z_DEFLATED,MAX_WBITS,DEF_MEM_LEVEL,Z_DEFAULT_STRATEGY)}function deflate(strm,flush){var old_flush,s,beg,val;if(!strm||!strm.state||flush>Z_BLOCK||0>flush)return strm?err(strm,Z_STREAM_ERROR):Z_STREAM_ERROR;if(s=strm.state,!strm.output||!strm.input&&0!==strm.avail_in||s.status===FINISH_STATE&&flush!==Z_FINISH)return err(strm,0===strm.avail_out?Z_BUF_ERROR:Z_STREAM_ERROR);if(s.strm=strm,old_flush=s.last_flush,s.last_flush=flush,s.status===INIT_STATE)if(2===s.wrap)strm.adler=0,put_byte(s,31),put_byte(s,139),put_byte(s,8),s.gzhead?(put_byte(s,(s.gzhead.text?1:0)+(s.gzhead.hcrc?2:0)+(s.gzhead.extra?4:0)+(s.gzhead.name?8:0)+(s.gzhead.comment?16:0)),put_byte(s,255&s.gzhead.time),put_byte(s,s.gzhead.time>>8&255),put_byte(s,s.gzhead.time>>16&255),put_byte(s,s.gzhead.time>>24&255),put_byte(s,9===s.level?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0),put_byte(s,255&s.gzhead.os),s.gzhead.extra&&s.gzhead.extra.length&&(put_byte(s,255&s.gzhead.extra.length),put_byte(s,s.gzhead.extra.length>>8&255)),s.gzhead.hcrc&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending,0)),s.gzindex=0,s.status=EXTRA_STATE):(put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,9===s.level?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0),put_byte(s,OS_CODE),s.status=BUSY_STATE);else{var header=Z_DEFLATED+(s.w_bits-8<<4)<<8,level_flags=-1;level_flags=s.strategy>=Z_HUFFMAN_ONLY||s.level<2?0:s.level<6?1:6===s.level?2:3,header|=level_flags<<6,0!==s.strstart&&(header|=PRESET_DICT),header+=31-header%31,s.status=BUSY_STATE,putShortMSB(s,header),0!==s.strstart&&(putShortMSB(s,strm.adler>>>16),putShortMSB(s,65535&strm.adler)),strm.adler=1}if(s.status===EXTRA_STATE)if(s.gzhead.extra){for(beg=s.pending;s.gzindex<(65535&s.gzhead.extra.length)&&(s.pending!==s.pending_buf_size||(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending!==s.pending_buf_size));)put_byte(s,255&s.gzhead.extra[s.gzindex]),s.gzindex++;s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),s.gzindex===s.gzhead.extra.length&&(s.gzindex=0,s.status=NAME_STATE)}else s.status=NAME_STATE;if(s.status===NAME_STATE)if(s.gzhead.name){beg=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending===s.pending_buf_size)){val=1;break}val=s.gzindexbeg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),0===val&&(s.gzindex=0,s.status=COMMENT_STATE)}else s.status=COMMENT_STATE;if(s.status===COMMENT_STATE)if(s.gzhead.comment){beg=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending===s.pending_buf_size)){val=1;break}val=s.gzindexbeg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),0===val&&(s.status=HCRC_STATE)}else s.status=HCRC_STATE;if(s.status===HCRC_STATE&&(s.gzhead.hcrc?(s.pending+2>s.pending_buf_size&&flush_pending(strm),s.pending+2<=s.pending_buf_size&&(put_byte(s,255&strm.adler),put_byte(s,strm.adler>>8&255),strm.adler=0,s.status=BUSY_STATE)):s.status=BUSY_STATE),0!==s.pending){if(flush_pending(strm),0===strm.avail_out)return s.last_flush=-1,Z_OK}else if(0===strm.avail_in&&rank(flush)<=rank(old_flush)&&flush!==Z_FINISH)return err(strm,Z_BUF_ERROR);if(s.status===FINISH_STATE&&0!==strm.avail_in)return err(strm,Z_BUF_ERROR);if(0!==strm.avail_in||0!==s.lookahead||flush!==Z_NO_FLUSH&&s.status!==FINISH_STATE){var bstate=s.strategy===Z_HUFFMAN_ONLY?deflate_huff(s,flush):s.strategy===Z_RLE?deflate_rle(s,flush):configuration_table[s.level].func(s,flush);if((bstate===BS_FINISH_STARTED||bstate===BS_FINISH_DONE)&&(s.status=FINISH_STATE),bstate===BS_NEED_MORE||bstate===BS_FINISH_STARTED)return 0===strm.avail_out&&(s.last_flush=-1),Z_OK;if(bstate===BS_BLOCK_DONE&&(flush===Z_PARTIAL_FLUSH?trees._tr_align(s):flush!==Z_BLOCK&&(trees._tr_stored_block(s,0,0,!1),flush===Z_FULL_FLUSH&&(zero(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),flush_pending(strm),0===strm.avail_out))return s.last_flush=-1,Z_OK}return flush!==Z_FINISH?Z_OK:s.wrap<=0?Z_STREAM_END:(2===s.wrap?(put_byte(s,255&strm.adler),put_byte(s,strm.adler>>8&255),put_byte(s,strm.adler>>16&255),put_byte(s,strm.adler>>24&255),put_byte(s,255&strm.total_in),put_byte(s,strm.total_in>>8&255),put_byte(s,strm.total_in>>16&255),put_byte(s,strm.total_in>>24&255)):(putShortMSB(s,strm.adler>>>16),putShortMSB(s,65535&strm.adler)),flush_pending(strm),s.wrap>0&&(s.wrap=-s.wrap),0!==s.pending?Z_OK:Z_STREAM_END)}function deflateEnd(strm){var status;return strm&&strm.state?(status=strm.state.status,status!==INIT_STATE&&status!==EXTRA_STATE&&status!==NAME_STATE&&status!==COMMENT_STATE&&status!==HCRC_STATE&&status!==BUSY_STATE&&status!==FINISH_STATE?err(strm,Z_STREAM_ERROR):(strm.state=null,status===BUSY_STATE?err(strm,Z_DATA_ERROR):Z_OK)):Z_STREAM_ERROR}var configuration_table,utils=require("../utils/common"),trees=require("./trees"),adler32=require("./adler32"),crc32=require("./crc32"),msg=require("./messages"),Z_NO_FLUSH=0,Z_PARTIAL_FLUSH=1,Z_FULL_FLUSH=3,Z_FINISH=4,Z_BLOCK=5,Z_OK=0,Z_STREAM_END=1,Z_STREAM_ERROR=-2,Z_DATA_ERROR=-3,Z_BUF_ERROR=-5,Z_DEFAULT_COMPRESSION=-1,Z_FILTERED=1,Z_HUFFMAN_ONLY=2,Z_RLE=3,Z_FIXED=4,Z_DEFAULT_STRATEGY=0,Z_UNKNOWN=2,Z_DEFLATED=8,MAX_MEM_LEVEL=9,MAX_WBITS=15,DEF_MEM_LEVEL=8,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,MIN_MATCH=3,MAX_MATCH=258,MIN_LOOKAHEAD=MAX_MATCH+MIN_MATCH+1,PRESET_DICT=32,INIT_STATE=42,EXTRA_STATE=69,NAME_STATE=73,COMMENT_STATE=91,HCRC_STATE=103,BUSY_STATE=113,FINISH_STATE=666,BS_NEED_MORE=1,BS_BLOCK_DONE=2,BS_FINISH_STARTED=3,BS_FINISH_DONE=4,OS_CODE=3,Config=function(good_length,max_lazy,nice_length,max_chain,func){this.good_length=good_length,this.max_lazy=max_lazy,this.nice_length=nice_length,this.max_chain=max_chain,this.func=func};configuration_table=[new Config(0,0,0,0,deflate_stored),new Config(4,4,8,4,deflate_fast),new Config(4,5,16,8,deflate_fast),new Config(4,6,32,32,deflate_fast),new Config(4,4,16,16,deflate_slow),new Config(8,16,32,32,deflate_slow),new Config(8,16,128,128,deflate_slow),new Config(8,32,128,256,deflate_slow),new Config(32,128,258,1024,deflate_slow),new Config(32,258,258,4096,deflate_slow)],exports.deflateInit=deflateInit,exports.deflateInit2=deflateInit2,exports.deflateReset=deflateReset,exports.deflateResetKeep=deflateResetKeep,exports.deflateSetHeader=deflateSetHeader,exports.deflate=deflate,exports.deflateEnd=deflateEnd,exports.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":93,"./adler32":95,"./crc32":97,"./messages":103,"./trees":104}],99:[function(require,module){"use strict";function GZheader(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}module.exports=GZheader},{}],100:[function(require,module){"use strict";var BAD=30,TYPE=12;module.exports=function(strm,start){var state,_in,last,_out,beg,end,dmax,wsize,whave,wnext,window,hold,bits,lcode,dcode,lmask,dmask,here,op,len,dist,from,from_source,input,output;state=strm.state,_in=strm.next_in,input=strm.input,last=_in+(strm.avail_in-5),_out=strm.next_out,output=strm.output,beg=_out-(start-strm.avail_out),end=_out+(strm.avail_out-257),dmax=state.dmax,wsize=state.wsize,whave=state.whave,wnext=state.wnext,window=state.window,hold=state.hold,bits=state.bits,lcode=state.lencode,dcode=state.distcode,lmask=(1<bits&&(hold+=input[_in++]<>>24,hold>>>=op,bits-=op,op=here>>>16&255,0===op)output[_out++]=65535&here;else{if(!(16&op)){if(0===(64&op)){here=lcode[(65535&here)+(hold&(1<bits&&(hold+=input[_in++]<>>=op,bits-=op),15>bits&&(hold+=input[_in++]<>>24,hold>>>=op,bits-=op,op=here>>>16&255,!(16&op)){if(0===(64&op)){here=dcode[(65535&here)+(hold&(1<bits&&(hold+=input[_in++]<bits&&(hold+=input[_in++]<dmax){strm.msg="invalid distance too far back",state.mode=BAD;break top}if(hold>>>=op,bits-=op,op=_out-beg,dist>op){if(op=dist-op,op>whave&&state.sane){strm.msg="invalid distance too far back",state.mode=BAD;break top}if(from=0,from_source=window,0===wnext){if(from+=wsize-op,len>op){len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}}else if(op>wnext){if(from+=wsize+wnext-op,op-=wnext,len>op){len-=op;do output[_out++]=window[from++];while(--op);if(from=0,len>wnext){op=wnext,len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}}}else if(from+=wnext-op,len>op){len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}for(;len>2;)output[_out++]=from_source[from++],output[_out++]=from_source[from++],output[_out++]=from_source[from++],len-=3;len&&(output[_out++]=from_source[from++],len>1&&(output[_out++]=from_source[from++]))}else{from=_out-dist;do output[_out++]=output[from++],output[_out++]=output[from++],output[_out++]=output[from++],len-=3;while(len>2);len&&(output[_out++]=output[from++],len>1&&(output[_out++]=output[from++]))}break}}break}}while(last>_in&&end>_out);len=bits>>3,_in-=len,bits-=len<<3,hold&=(1<_in?5+(last-_in):5-(_in-last),strm.avail_out=end>_out?257+(end-_out):257-(_out-end),state.hold=hold,state.bits=bits}},{}],101:[function(require,module,exports){"use strict";function ZSWAP32(q){return(q>>>24&255)+(q>>>8&65280)+((65280&q)<<8)+((255&q)<<24)}function InflateState(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new utils.Buf16(320),this.work=new utils.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function inflateResetKeep(strm){var state;return strm&&strm.state?(state=strm.state,strm.total_in=strm.total_out=state.total=0,strm.msg="",state.wrap&&(strm.adler=1&state.wrap),state.mode=HEAD,state.last=0,state.havedict=0,state.dmax=32768,state.head=null,state.hold=0,state.bits=0,state.lencode=state.lendyn=new utils.Buf32(ENOUGH_LENS),state.distcode=state.distdyn=new utils.Buf32(ENOUGH_DISTS),state.sane=1,state.back=-1,Z_OK):Z_STREAM_ERROR}function inflateReset(strm){var state;return strm&&strm.state?(state=strm.state,state.wsize=0,state.whave=0,state.wnext=0,inflateResetKeep(strm)):Z_STREAM_ERROR}function inflateReset2(strm,windowBits){var wrap,state;return strm&&strm.state?(state=strm.state,0>windowBits?(wrap=0,windowBits=-windowBits):(wrap=(windowBits>>4)+1,48>windowBits&&(windowBits&=15)),windowBits&&(8>windowBits||windowBits>15)?Z_STREAM_ERROR:(null!==state.window&&state.wbits!==windowBits&&(state.window=null),state.wrap=wrap,state.wbits=windowBits,inflateReset(strm))):Z_STREAM_ERROR}function inflateInit2(strm,windowBits){var ret,state;return strm?(state=new InflateState,strm.state=state,state.window=null,ret=inflateReset2(strm,windowBits),ret!==Z_OK&&(strm.state=null),ret):Z_STREAM_ERROR}function inflateInit(strm){return inflateInit2(strm,DEF_WBITS)}function fixedtables(state){if(virgin){var sym;for(lenfix=new utils.Buf32(512),distfix=new utils.Buf32(32),sym=0;144>sym;)state.lens[sym++]=8;for(;256>sym;)state.lens[sym++]=9;for(;280>sym;)state.lens[sym++]=7;for(;288>sym;)state.lens[sym++]=8;for(inflate_table(LENS,state.lens,0,288,lenfix,0,state.work,{bits:9}),sym=0;32>sym;)state.lens[sym++]=5;inflate_table(DISTS,state.lens,0,32,distfix,0,state.work,{bits:5}),virgin=!1}state.lencode=lenfix,state.lenbits=9,state.distcode=distfix,state.distbits=5}function updatewindow(strm,src,end,copy){var dist,state=strm.state;return null===state.window&&(state.wsize=1<=state.wsize?(utils.arraySet(state.window,src,end-state.wsize,state.wsize,0),state.wnext=0,state.whave=state.wsize):(dist=state.wsize-state.wnext,dist>copy&&(dist=copy),utils.arraySet(state.window,src,end-copy,dist,state.wnext),copy-=dist,copy?(utils.arraySet(state.window,src,end-copy,copy,0),state.wnext=copy,state.whave=state.wsize):(state.wnext+=dist,state.wnext===state.wsize&&(state.wnext=0),state.whavebits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,state.check=crc32(state.check,hbuf,2,0),hold=0,bits=0,state.mode=FLAGS;break}if(state.flags=0,state.head&&(state.head.done=!1),!(1&state.wrap)||(((255&hold)<<8)+(hold>>8))%31){strm.msg="incorrect header check",state.mode=BAD;break}if((15&hold)!==Z_DEFLATED){strm.msg="unknown compression method",state.mode=BAD;break}if(hold>>>=4,bits-=4,len=(15&hold)+8,0===state.wbits)state.wbits=len;else if(len>state.wbits){strm.msg="invalid window size",state.mode=BAD;break}state.dmax=1<bits;){if(0===have)break inf_leave; +have--,hold+=input[next++]<>8&1),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=TIME;case TIME:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,hbuf[2]=hold>>>16&255,hbuf[3]=hold>>>24&255,state.check=crc32(state.check,hbuf,4,0)),hold=0,bits=0,state.mode=OS;case OS:for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>8),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=EXLEN;case EXLEN:if(1024&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0}else state.head&&(state.head.extra=null);state.mode=EXTRA;case EXTRA:if(1024&state.flags&&(copy=state.length,copy>have&&(copy=have),copy&&(state.head&&(len=state.head.extra_len-state.length,state.head.extra||(state.head.extra=new Array(state.head.extra_len)),utils.arraySet(state.head.extra,input,next,copy,len)),512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,state.length-=copy),state.length))break inf_leave;state.length=0,state.mode=NAME;case NAME:if(2048&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.name+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.name=null);state.length=0,state.mode=COMMENT;case COMMENT:if(4096&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.comment+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.comment=null);state.mode=HCRC;case HCRC:if(512&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>9&1,state.head.done=!0),strm.adler=state.check=0,state.mode=TYPE;break;case DICTID:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=7&bits,bits-=7&bits,state.mode=CHECK;break}for(;3>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=1,bits-=1,3&hold){case 0:state.mode=STORED;break;case 1:if(fixedtables(state),state.mode=LEN_,flush===Z_TREES){hold>>>=2,bits-=2;break inf_leave}break;case 2:state.mode=TABLE;break;case 3:strm.msg="invalid block type",state.mode=BAD}hold>>>=2,bits-=2;break;case STORED:for(hold>>>=7&bits,bits-=7&bits;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>16^65535)){strm.msg="invalid stored block lengths",state.mode=BAD;break}if(state.length=65535&hold,hold=0,bits=0,state.mode=COPY_,flush===Z_TREES)break inf_leave;case COPY_:state.mode=COPY;case COPY:if(copy=state.length){if(copy>have&&(copy=have),copy>left&&(copy=left),0===copy)break inf_leave;utils.arraySet(output,input,next,copy,put),have-=copy,next+=copy,left-=copy,put+=copy,state.length-=copy;break}state.mode=TYPE;break;case TABLE:for(;14>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=5,bits-=5,state.ndist=(31&hold)+1,hold>>>=5,bits-=5,state.ncode=(15&hold)+4,hold>>>=4,bits-=4,state.nlen>286||state.ndist>30){strm.msg="too many length or distance symbols",state.mode=BAD;break}state.have=0,state.mode=LENLENS;case LENLENS:for(;state.havebits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=3,bits-=3}for(;state.have<19;)state.lens[order[state.have++]]=0;if(state.lencode=state.lendyn,state.lenbits=7,opts={bits:state.lenbits},ret=inflate_table(CODES,state.lens,0,19,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid code lengths set",state.mode=BAD;break}state.have=0,state.mode=CODELENS;case CODELENS:for(;state.have>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<here_val)hold>>>=here_bits,bits-=here_bits,state.lens[state.have++]=here_val;else{if(16===here_val){for(n=here_bits+2;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,0===state.have){strm.msg="invalid bit length repeat",state.mode=BAD;break}len=state.lens[state.have-1],copy=3+(3&hold),hold>>>=2,bits-=2}else if(17===here_val){for(n=here_bits+3;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=3+(7&hold),hold>>>=3,bits-=3}else{for(n=here_bits+7;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=11+(127&hold),hold>>>=7,bits-=7}if(state.have+copy>state.nlen+state.ndist){strm.msg="invalid bit length repeat",state.mode=BAD;break}for(;copy--;)state.lens[state.have++]=len}}if(state.mode===BAD)break;if(0===state.lens[256]){strm.msg="invalid code -- missing end-of-block",state.mode=BAD;break}if(state.lenbits=9,opts={bits:state.lenbits},ret=inflate_table(LENS,state.lens,0,state.nlen,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid literal/lengths set",state.mode=BAD;break}if(state.distbits=6,state.distcode=state.distdyn,opts={bits:state.distbits},ret=inflate_table(DISTS,state.lens,state.nlen,state.ndist,state.distcode,0,state.work,opts),state.distbits=opts.bits,ret){strm.msg="invalid distances set",state.mode=BAD;break}if(state.mode=LEN_,flush===Z_TREES)break inf_leave;case LEN_:state.mode=LEN;case LEN:if(have>=6&&left>=258){strm.next_out=put,strm.avail_out=left,strm.next_in=next,strm.avail_in=have,state.hold=hold,state.bits=bits,inflate_fast(strm,_out),put=strm.next_out,output=strm.output,left=strm.avail_out,next=strm.next_in,input=strm.input,have=strm.avail_in,hold=state.hold,bits=state.bits,state.mode===TYPE&&(state.back=-1);break}for(state.back=0;here=state.lencode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,state.length=here_val,0===here_op){state.mode=LIT;break}if(32&here_op){state.back=-1,state.mode=TYPE;break}if(64&here_op){strm.msg="invalid literal/length code",state.mode=BAD;break}state.extra=15&here_op,state.mode=LENEXT;case LENEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}state.was=state.length,state.mode=DIST;case DIST:for(;here=state.distcode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,64&here_op){strm.msg="invalid distance code",state.mode=BAD;break}state.offset=here_val,state.extra=15&here_op,state.mode=DISTEXT;case DISTEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}if(state.offset>state.dmax){strm.msg="invalid distance too far back",state.mode=BAD;break}state.mode=MATCH;case MATCH:if(0===left)break inf_leave;if(copy=_out-left,state.offset>copy){if(copy=state.offset-copy,copy>state.whave&&state.sane){strm.msg="invalid distance too far back",state.mode=BAD;break}copy>state.wnext?(copy-=state.wnext,from=state.wsize-copy):from=state.wnext-copy,copy>state.length&&(copy=state.length),from_source=state.window}else from_source=output,from=put-state.offset,copy=state.length;copy>left&&(copy=left),left-=copy,state.length-=copy;do output[put++]=from_source[from++];while(--copy);0===state.length&&(state.mode=LEN);break;case LIT:if(0===left)break inf_leave;output[put++]=state.length,left--,state.mode=LEN;break;case CHECK:if(state.wrap){for(;32>bits;){if(0===have)break inf_leave;have--,hold|=input[next++]<bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<=len;len++)count[len]=0;for(sym=0;codes>sym;sym++)count[lens[lens_index+sym]]++;for(root=bits,max=MAXBITS;max>=1&&0===count[max];max--);if(root>max&&(root=max),0===max)return table[table_index++]=20971520,table[table_index++]=20971520,opts.bits=1,0;for(min=1;max>min&&0===count[min];min++);for(min>root&&(root=min),left=1,len=1;MAXBITS>=len;len++)if(left<<=1,left-=count[len],0>left)return-1;if(left>0&&(type===CODES||1!==max))return-1;for(offs[1]=0,len=1;MAXBITS>len;len++)offs[len+1]=offs[len]+count[len];for(sym=0;codes>sym;sym++)0!==lens[lens_index+sym]&&(work[offs[lens[lens_index+sym]]++]=sym);if(type===CODES?(base=extra=work,end=19):type===LENS?(base=lbase,base_index-=257,extra=lext,extra_index-=257,end=256):(base=dbase,extra=dext,end=-1),huff=0,sym=0,len=min,next=table_index,curr=root,drop=0,low=-1,used=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;for(var i=0;;){i++,here_bits=len-drop,work[sym]end?(here_op=extra[extra_index+work[sym]],here_val=base[base_index+work[sym]]):(here_op=96,here_val=0),incr=1<>drop)+fill]=here_bits<<24|here_op<<16|here_val|0;while(0!==fill);for(incr=1<>=1;if(0!==incr?(huff&=incr-1,huff+=incr):huff=0,sym++,0===--count[len]){if(len===max)break;len=lens[lens_index+work[sym]]}if(len>root&&(huff&mask)!==low){for(0===drop&&(drop=root),next+=min,curr=len-drop,left=1<curr+drop&&(left-=count[curr+drop],!(0>=left));)curr++,left<<=1;if(used+=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;low=huff&mask,table[low]=root<<24|curr<<16|next-table_index|0}}return 0!==huff&&(table[next+huff]=len-drop<<24|64<<16|0),opts.bits=root,0}},{"../utils/common":93}],103:[function(require,module){"use strict";module.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],104:[function(require,module,exports){"use strict";function zero(buf){for(var len=buf.length;--len>=0;)buf[len]=0}function d_code(dist){return 256>dist?_dist_code[dist]:_dist_code[256+(dist>>>7)]}function put_short(s,w){s.pending_buf[s.pending++]=255&w,s.pending_buf[s.pending++]=w>>>8&255}function send_bits(s,value,length){s.bi_valid>Buf_size-length?(s.bi_buf|=value<>Buf_size-s.bi_valid,s.bi_valid+=length-Buf_size):(s.bi_buf|=value<>>=1,res<<=1;while(--len>0);return res>>>1}function bi_flush(s){16===s.bi_valid?(put_short(s,s.bi_buf),s.bi_buf=0,s.bi_valid=0):s.bi_valid>=8&&(s.pending_buf[s.pending++]=255&s.bi_buf,s.bi_buf>>=8,s.bi_valid-=8)}function gen_bitlen(s,desc){var h,n,m,bits,xbits,f,tree=desc.dyn_tree,max_code=desc.max_code,stree=desc.stat_desc.static_tree,has_stree=desc.stat_desc.has_stree,extra=desc.stat_desc.extra_bits,base=desc.stat_desc.extra_base,max_length=desc.stat_desc.max_length,overflow=0;for(bits=0;MAX_BITS>=bits;bits++)s.bl_count[bits]=0;for(tree[2*s.heap[s.heap_max]+1]=0,h=s.heap_max+1;HEAP_SIZE>h;h++)n=s.heap[h],bits=tree[2*tree[2*n+1]+1]+1,bits>max_length&&(bits=max_length,overflow++),tree[2*n+1]=bits,n>max_code||(s.bl_count[bits]++,xbits=0,n>=base&&(xbits=extra[n-base]),f=tree[2*n],s.opt_len+=f*(bits+xbits),has_stree&&(s.static_len+=f*(stree[2*n+1]+xbits)));if(0!==overflow){do{for(bits=max_length-1;0===s.bl_count[bits];)bits--;s.bl_count[bits]--,s.bl_count[bits+1]+=2,s.bl_count[max_length]--,overflow-=2}while(overflow>0);for(bits=max_length;0!==bits;bits--)for(n=s.bl_count[bits];0!==n;)m=s.heap[--h],m>max_code||(tree[2*m+1]!==bits&&(s.opt_len+=(bits-tree[2*m+1])*tree[2*m],tree[2*m+1]=bits),n--)}}function gen_codes(tree,max_code,bl_count){var bits,n,next_code=new Array(MAX_BITS+1),code=0;for(bits=1;MAX_BITS>=bits;bits++)next_code[bits]=code=code+bl_count[bits-1]<<1;for(n=0;max_code>=n;n++){var len=tree[2*n+1];0!==len&&(tree[2*n]=bi_reverse(next_code[len]++,len))}}function tr_static_init(){var n,bits,length,code,dist,bl_count=new Array(MAX_BITS+1);for(length=0,code=0;LENGTH_CODES-1>code;code++)for(base_length[code]=length,n=0;n<1<code;code++)for(base_dist[code]=dist,n=0;n<1<>=7;D_CODES>code;code++)for(base_dist[code]=dist<<7,n=0;n<1<=bits;bits++)bl_count[bits]=0;for(n=0;143>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(;255>=n;)static_ltree[2*n+1]=9,n++,bl_count[9]++;for(;279>=n;)static_ltree[2*n+1]=7,n++,bl_count[7]++;for(;287>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(gen_codes(static_ltree,L_CODES+1,bl_count),n=0;D_CODES>n;n++)static_dtree[2*n+1]=5,static_dtree[2*n]=bi_reverse(n,5);static_l_desc=new StaticTreeDesc(static_ltree,extra_lbits,LITERALS+1,L_CODES,MAX_BITS),static_d_desc=new StaticTreeDesc(static_dtree,extra_dbits,0,D_CODES,MAX_BITS),static_bl_desc=new StaticTreeDesc(new Array(0),extra_blbits,0,BL_CODES,MAX_BL_BITS)}function init_block(s){var n;for(n=0;L_CODES>n;n++)s.dyn_ltree[2*n]=0;for(n=0;D_CODES>n;n++)s.dyn_dtree[2*n]=0;for(n=0;BL_CODES>n;n++)s.bl_tree[2*n]=0;s.dyn_ltree[2*END_BLOCK]=1,s.opt_len=s.static_len=0,s.last_lit=s.matches=0}function bi_windup(s){s.bi_valid>8?put_short(s,s.bi_buf):s.bi_valid>0&&(s.pending_buf[s.pending++]=s.bi_buf),s.bi_buf=0,s.bi_valid=0}function copy_block(s,buf,len,header){bi_windup(s),header&&(put_short(s,len),put_short(s,~len)),utils.arraySet(s.pending_buf,s.window,buf,len,s.pending),s.pending+=len}function smaller(tree,n,m,depth){var _n2=2*n,_m2=2*m;return tree[_n2]n;n++)0!==tree[2*n]?(s.heap[++s.heap_len]=max_code=n,s.depth[n]=0):tree[2*n+1]=0;for(;s.heap_len<2;)node=s.heap[++s.heap_len]=2>max_code?++max_code:0,tree[2*node]=1,s.depth[node]=0,s.opt_len--,has_stree&&(s.static_len-=stree[2*node+1]);for(desc.max_code=max_code,n=s.heap_len>>1;n>=1;n--)pqdownheap(s,tree,n);node=elems;do n=s.heap[1],s.heap[1]=s.heap[s.heap_len--],pqdownheap(s,tree,1),m=s.heap[1],s.heap[--s.heap_max]=n,s.heap[--s.heap_max]=m,tree[2*node]=tree[2*n]+tree[2*m],s.depth[node]=(s.depth[n]>=s.depth[m]?s.depth[n]:s.depth[m])+1,tree[2*n+1]=tree[2*m+1]=node,s.heap[1]=node++,pqdownheap(s,tree,1);while(s.heap_len>=2);s.heap[--s.heap_max]=s.heap[1],gen_bitlen(s,desc),gen_codes(tree,max_code,s.bl_count)}function scan_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),tree[2*(max_code+1)+1]=65535,n=0;max_code>=n;n++)curlen=nextlen,nextlen=tree[2*(n+1)+1],++countcount?s.bl_tree[2*curlen]+=count:0!==curlen?(curlen!==prevlen&&s.bl_tree[2*curlen]++,s.bl_tree[2*REP_3_6]++):10>=count?s.bl_tree[2*REPZ_3_10]++:s.bl_tree[2*REPZ_11_138]++,count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4))}function send_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),n=0;max_code>=n;n++)if(curlen=nextlen,nextlen=tree[2*(n+1)+1],!(++countcount){do send_code(s,curlen,s.bl_tree);while(0!==--count)}else 0!==curlen?(curlen!==prevlen&&(send_code(s,curlen,s.bl_tree),count--),send_code(s,REP_3_6,s.bl_tree),send_bits(s,count-3,2)):10>=count?(send_code(s,REPZ_3_10,s.bl_tree),send_bits(s,count-3,3)):(send_code(s,REPZ_11_138,s.bl_tree),send_bits(s,count-11,7));count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4)}}function build_bl_tree(s){var max_blindex;for(scan_tree(s,s.dyn_ltree,s.l_desc.max_code),scan_tree(s,s.dyn_dtree,s.d_desc.max_code),build_tree(s,s.bl_desc),max_blindex=BL_CODES-1;max_blindex>=3&&0===s.bl_tree[2*bl_order[max_blindex]+1];max_blindex--);return s.opt_len+=3*(max_blindex+1)+5+5+4,max_blindex}function send_all_trees(s,lcodes,dcodes,blcodes){var rank;for(send_bits(s,lcodes-257,5),send_bits(s,dcodes-1,5),send_bits(s,blcodes-4,4),rank=0;blcodes>rank;rank++)send_bits(s,s.bl_tree[2*bl_order[rank]+1],3);send_tree(s,s.dyn_ltree,lcodes-1),send_tree(s,s.dyn_dtree,dcodes-1)}function detect_data_type(s){var n,black_mask=4093624447;for(n=0;31>=n;n++,black_mask>>>=1)if(1&black_mask&&0!==s.dyn_ltree[2*n])return Z_BINARY;if(0!==s.dyn_ltree[18]||0!==s.dyn_ltree[20]||0!==s.dyn_ltree[26])return Z_TEXT;for(n=32;LITERALS>n;n++)if(0!==s.dyn_ltree[2*n])return Z_TEXT;return Z_BINARY}function _tr_init(s){static_init_done||(tr_static_init(),static_init_done=!0),s.l_desc=new TreeDesc(s.dyn_ltree,static_l_desc),s.d_desc=new TreeDesc(s.dyn_dtree,static_d_desc),s.bl_desc=new TreeDesc(s.bl_tree,static_bl_desc),s.bi_buf=0,s.bi_valid=0,init_block(s)}function _tr_stored_block(s,buf,stored_len,last){send_bits(s,(STORED_BLOCK<<1)+(last?1:0),3),copy_block(s,buf,stored_len,!0)}function _tr_align(s){send_bits(s,STATIC_TREES<<1,3),send_code(s,END_BLOCK,static_ltree),bi_flush(s)}function _tr_flush_block(s,buf,stored_len,last){var opt_lenb,static_lenb,max_blindex=0;s.level>0?(s.strm.data_type===Z_UNKNOWN&&(s.strm.data_type=detect_data_type(s)),build_tree(s,s.l_desc),build_tree(s,s.d_desc),max_blindex=build_bl_tree(s),opt_lenb=s.opt_len+3+7>>>3,static_lenb=s.static_len+3+7>>>3,opt_lenb>=static_lenb&&(opt_lenb=static_lenb)):opt_lenb=static_lenb=stored_len+5,opt_lenb>=stored_len+4&&-1!==buf?_tr_stored_block(s,buf,stored_len,last):s.strategy===Z_FIXED||static_lenb===opt_lenb?(send_bits(s,(STATIC_TREES<<1)+(last?1:0),3),compress_block(s,static_ltree,static_dtree)):(send_bits(s,(DYN_TREES<<1)+(last?1:0),3),send_all_trees(s,s.l_desc.max_code+1,s.d_desc.max_code+1,max_blindex+1),compress_block(s,s.dyn_ltree,s.dyn_dtree)),init_block(s),last&&bi_windup(s)}function _tr_tally(s,dist,lc){return s.pending_buf[s.d_buf+2*s.last_lit]=dist>>>8&255,s.pending_buf[s.d_buf+2*s.last_lit+1]=255&dist,s.pending_buf[s.l_buf+s.last_lit]=255&lc,s.last_lit++,0===dist?s.dyn_ltree[2*lc]++:(s.matches++,dist--,s.dyn_ltree[2*(_length_code[lc]+LITERALS+1)]++,s.dyn_dtree[2*d_code(dist)]++),s.last_lit===s.lit_bufsize-1}var utils=require("../utils/common"),Z_FIXED=4,Z_BINARY=0,Z_TEXT=1,Z_UNKNOWN=2,STORED_BLOCK=0,STATIC_TREES=1,DYN_TREES=2,MIN_MATCH=3,MAX_MATCH=258,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,Buf_size=16,MAX_BL_BITS=7,END_BLOCK=256,REP_3_6=16,REPZ_3_10=17,REPZ_11_138=18,extra_lbits=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],extra_dbits=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],extra_blbits=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],bl_order=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],DIST_CODE_LEN=512,static_ltree=new Array(2*(L_CODES+2));zero(static_ltree);var static_dtree=new Array(2*D_CODES);zero(static_dtree);var _dist_code=new Array(DIST_CODE_LEN);zero(_dist_code);var _length_code=new Array(MAX_MATCH-MIN_MATCH+1);zero(_length_code);var base_length=new Array(LENGTH_CODES);zero(base_length);var base_dist=new Array(D_CODES);zero(base_dist);var static_l_desc,static_d_desc,static_bl_desc,StaticTreeDesc=function(static_tree,extra_bits,extra_base,elems,max_length){this.static_tree=static_tree,this.extra_bits=extra_bits,this.extra_base=extra_base,this.elems=elems,this.max_length=max_length,this.has_stree=static_tree&&static_tree.length},TreeDesc=function(dyn_tree,stat_desc){this.dyn_tree=dyn_tree,this.max_code=0,this.stat_desc=stat_desc},static_init_done=!1;exports._tr_init=_tr_init,exports._tr_stored_block=_tr_stored_block,exports._tr_flush_block=_tr_flush_block,exports._tr_tally=_tr_tally,exports._tr_align=_tr_align},{"../utils/common":93}],105:[function(require,module){"use strict";function ZStream(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}module.exports=ZStream},{}],106:[function(require,module){(function(Buffer){"use strict";function decodeB64(str){return new Buffer(str,"base64")}function unpackPNG(w,h,c,str){var pixels=parse(decodeB64(str));return ndarray(pixels.data,[h,w,pixels.channels],[pixels.channels*w,pixels.channels,1],0)}module.exports=unpackPNG;var ndarray=require("ndarray"),parse=require("pngparse-sync")}).call(this,require("buffer").Buffer)},{buffer:111,ndarray:87,"pngparse-sync":89}],107:[function(require,module,exports){!function(_global){"use strict";var shim={};"undefined"==typeof exports?"function"==typeof define&&"object"==typeof define.amd&&define.amd?(shim.exports={},define(function(){return shim.exports})):shim.exports="undefined"!=typeof window?window:_global:shim.exports=exports,function(exports){if(!GLMAT_EPSILON)var GLMAT_EPSILON=1e-6;if(!GLMAT_ARRAY_TYPE)var GLMAT_ARRAY_TYPE="undefined"!=typeof Float32Array?Float32Array:Array;if(!GLMAT_RANDOM)var GLMAT_RANDOM=Math.random;var glMatrix={};glMatrix.setMatrixArrayType=function(type){GLMAT_ARRAY_TYPE=type},"undefined"!=typeof exports&&(exports.glMatrix=glMatrix);var degree=Math.PI/180;glMatrix.toRadian=function(a){return a*degree};var vec2={};vec2.create=function(){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=0,out[1]=0,out},vec2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=a[0],out[1]=a[1],out},vec2.fromValues=function(x,y){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=x,out[1]=y,out},vec2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out},vec2.set=function(out,x,y){return out[0]=x,out[1]=y,out},vec2.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out},vec2.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out},vec2.sub=vec2.subtract,vec2.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out},vec2.mul=vec2.multiply,vec2.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out},vec2.div=vec2.divide,vec2.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out},vec2.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out},vec2.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out},vec2.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out},vec2.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return Math.sqrt(x*x+y*y)},vec2.dist=vec2.distance,vec2.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return x*x+y*y},vec2.sqrDist=vec2.squaredDistance,vec2.length=function(a){var x=a[0],y=a[1];return Math.sqrt(x*x+y*y)},vec2.len=vec2.length,vec2.squaredLength=function(a){var x=a[0],y=a[1];return x*x+y*y},vec2.sqrLen=vec2.squaredLength,vec2.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out},vec2.normalize=function(out,a){var x=a[0],y=a[1],len=x*x+y*y;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out +},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],108:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance +}function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":107}],109:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],110:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],111:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new TypeError("must start with number, buffer, array or string");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}if(length>kMaxLength)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+kMaxLength.toString(16)+" bytes");var buf;Buffer.TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(Buffer.TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!Buffer.TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return length>0&&length<=Buffer.poolSize&&(buf.parent=rootParent),buf}function SlowBuffer(subject,encoding,noZero){if(!(this instanceof SlowBuffer))return new SlowBuffer(subject,encoding,noZero);var buf=new Buffer(subject,encoding,noZero);return delete buf.parent,buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;if(strLen%2!==0)throw new Error("Invalid hex string");length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);if(isNaN(byte))throw new Error("Invalid hex string");buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string,buf.length-offset),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string,buf.length-offset),buf,offset,length,2);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(127&buf[i]);return ret}function binarySlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;ioffset)throw new RangeError("offset is not uint");if(offset+ext>length)throw new RangeError("Trying to access beyond buffer length")}function checkInt(buf,value,offset,ext,max,min){if(!Buffer.isBuffer(buf))throw new TypeError("buffer must be a Buffer instance");if(value>max||min>value)throw new RangeError("value is out of bounds");if(offset+ext>buf.length)throw new RangeError("index out of range")}function objectWriteUInt16(buf,value,offset,littleEndian){0>value&&(value=65535+value+1);for(var i=0,j=Math.min(buf.length-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i)}function objectWriteUInt32(buf,value,offset,littleEndian){0>value&&(value=4294967295+value+1);for(var i=0,j=Math.min(buf.length-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255}function checkIEEE754(buf,value,offset,ext,max,min){if(value>max||min>value)throw new RangeError("value is out of bounds");if(offset+ext>buf.length)throw new RangeError("index out of range");if(0>offset)throw new RangeError("index out of range")}function writeFloat(buf,value,offset,littleEndian,noAssert){return noAssert||checkIEEE754(buf,value,offset,4,3.4028234663852886e38,-3.4028234663852886e38),ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){return noAssert||checkIEEE754(buf,value,offset,8,1.7976931348623157e308,-1.7976931348623157e308),ieee754.write(buf,value,offset,littleEndian,52,8),offset+8}function base64clean(str){if(str=stringtrim(str).replace(INVALID_BASE64_RE,""),str.length<2)return"";for(;str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(string,units){var codePoint,length=string.length,leadSurrogate=null;units=units||1/0;for(var bytes=[],i=0;length>i;i++){if(codePoint=string.charCodeAt(i),codePoint>55295&&57344>codePoint){if(!leadSurrogate){if(codePoint>56319){(units-=3)>-1&&bytes.push(239,191,189);continue}if(i+1===length){(units-=3)>-1&&bytes.push(239,191,189);continue}leadSurrogate=codePoint;continue}if(56320>codePoint){(units-=3)>-1&&bytes.push(239,191,189),leadSurrogate=codePoint;continue}codePoint=leadSurrogate-55296<<10|codePoint-56320|65536,leadSurrogate=null}else leadSurrogate&&((units-=3)>-1&&bytes.push(239,191,189),leadSurrogate=null);if(128>codePoint){if((units-=1)<0)break;bytes.push(codePoint)}else if(2048>codePoint){if((units-=2)<0)break;bytes.push(codePoint>>6|192,63&codePoint|128)}else if(65536>codePoint){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,63&codePoint|128)}else{if(!(2097152>codePoint))throw new Error("Invalid code point");if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,63&codePoint|128)}}return bytes}function asciiToBytes(str){for(var byteArray=[],i=0;i>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(base64clean(str))}function blitBuffer(src,dst,offset,length,unitSize){unitSize&&(length-=length%unitSize);for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533)}}var base64=require("base64-js"),ieee754=require("ieee754"),isArray=require("is-array");exports.Buffer=Buffer,exports.SlowBuffer=SlowBuffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var kMaxLength=1073741823,rootParent={};Buffer.TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}(),Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.compare=function(a,b){if(!Buffer.isBuffer(a)||!Buffer.isBuffer(b))throw new TypeError("Arguments must be Buffers");for(var x=a.length,y=b.length,i=0,len=Math.min(x,y);len>i&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.concat=function(list,totalLength){if(!isArray(list))throw new TypeError("Usage: Buffer.concat(list[, length])");if(0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;i>>1;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"base64":ret=base64ToBytes(str).length;break;default:ret=str.length}return ret},Buffer.prototype.length=void 0,Buffer.prototype.parent=void 0,Buffer.prototype.toString=function(encoding,start,end){var loweredCase=!1;if(start>>>=0,end=void 0===end||1/0===end?this.length:end>>>0,encoding||(encoding="utf8"),0>start&&(start=0),end>this.length&&(end=this.length),start>=end)return"";for(;;)switch(encoding){case"hex":return hexSlice(this,start,end);case"utf8":case"utf-8":return utf8Slice(this,start,end);case"ascii":return asciiSlice(this,start,end);case"binary":return binarySlice(this,start,end);case"base64":return base64Slice(this,start,end);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,start,end);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(encoding+"").toLowerCase(),loweredCase=!0}},Buffer.prototype.equals=function(b){if(!Buffer.isBuffer(b))throw new TypeError("Argument must be a Buffer");return 0===Buffer.compare(this,b)},Buffer.prototype.inspect=function(){var str="",max=exports.INSPECT_MAX_BYTES;return this.length>0&&(str=this.toString("hex",0,max).match(/.{2}/g).join(" "),this.length>max&&(str+=" ... ")),""},Buffer.prototype.compare=function(b){if(!Buffer.isBuffer(b))throw new TypeError("Argument must be a Buffer");return Buffer.compare(this,b)},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}if(offset=Number(offset)||0,0>length||0>offset||offset>this.length)throw new RangeError("attempt to write outside buffer bounds");var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new TypeError("Unknown encoding: "+encoding)}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.slice=function(start,end){var len=this.length;start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start);var newBuf;if(Buffer.TYPED_ARRAY_SUPPORT)newBuf=Buffer._augment(this.subarray(start,end));else{var sliceLen=end-start;newBuf=new Buffer(sliceLen,void 0,!0);for(var i=0;sliceLen>i;i++)newBuf[i]=this[i+start]}return newBuf.length&&(newBuf.parent=this.parent||this),newBuf},Buffer.prototype.readUIntLE=function(offset,byteLength,noAssert){offset>>>=0,byteLength>>>=0,noAssert||checkOffset(offset,byteLength,this.length);for(var val=this[offset],mul=1,i=0;++i>>=0,byteLength>>>=0,noAssert||checkOffset(offset,byteLength,this.length);for(var val=this[offset+--byteLength],mul=1;byteLength>0&&(mul*=256);)val+=this[offset+--byteLength]*mul;return val},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||checkOffset(offset,1,this.length),this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return noAssert||checkOffset(offset,2,this.length),this[offset]|this[offset+1]<<8},Buffer.prototype.readUInt16BE=function(offset,noAssert){return noAssert||checkOffset(offset,2,this.length),this[offset]<<8|this[offset+1]},Buffer.prototype.readUInt32LE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),(this[offset]|this[offset+1]<<8|this[offset+2]<<16)+16777216*this[offset+3]},Buffer.prototype.readUInt32BE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),16777216*this[offset]+(this[offset+1]<<16|this[offset+2]<<8|this[offset+3])},Buffer.prototype.readIntLE=function(offset,byteLength,noAssert){offset>>>=0,byteLength>>>=0,noAssert||checkOffset(offset,byteLength,this.length);for(var val=this[offset],mul=1,i=0;++i=mul&&(val-=Math.pow(2,8*byteLength)),val},Buffer.prototype.readIntBE=function(offset,byteLength,noAssert){offset>>>=0,byteLength>>>=0,noAssert||checkOffset(offset,byteLength,this.length);for(var i=byteLength,mul=1,val=this[offset+--i];i>0&&(mul*=256);)val+=this[offset+--i]*mul;return mul*=128,val>=mul&&(val-=Math.pow(2,8*byteLength)),val},Buffer.prototype.readInt8=function(offset,noAssert){return noAssert||checkOffset(offset,1,this.length),128&this[offset]?-1*(255-this[offset]+1):this[offset]},Buffer.prototype.readInt16LE=function(offset,noAssert){noAssert||checkOffset(offset,2,this.length);var val=this[offset]|this[offset+1]<<8;return 32768&val?4294901760|val:val},Buffer.prototype.readInt16BE=function(offset,noAssert){noAssert||checkOffset(offset,2,this.length);var val=this[offset+1]|this[offset]<<8;return 32768&val?4294901760|val:val},Buffer.prototype.readInt32LE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),this[offset]|this[offset+1]<<8|this[offset+2]<<16|this[offset+3]<<24},Buffer.prototype.readInt32BE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),this[offset]<<24|this[offset+1]<<16|this[offset+2]<<8|this[offset+3]},Buffer.prototype.readFloatLE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),ieee754.read(this,offset,!0,23,4)},Buffer.prototype.readFloatBE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),ieee754.read(this,offset,!1,23,4)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return noAssert||checkOffset(offset,8,this.length),ieee754.read(this,offset,!0,52,8)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return noAssert||checkOffset(offset,8,this.length),ieee754.read(this,offset,!1,52,8)},Buffer.prototype.writeUIntLE=function(value,offset,byteLength,noAssert){value=+value,offset>>>=0,byteLength>>>=0,noAssert||checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength),0);var mul=1,i=0;for(this[offset]=255&value;++i>>0&255;return offset+byteLength},Buffer.prototype.writeUIntBE=function(value,offset,byteLength,noAssert){value=+value,offset>>>=0,byteLength>>>=0,noAssert||checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength),0);var i=byteLength-1,mul=1;for(this[offset+i]=255&value;--i>=0&&(mul*=256);)this[offset+i]=value/mul>>>0&255;return offset+byteLength},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,1,255,0),Buffer.TYPED_ARRAY_SUPPORT||(value=Math.floor(value)),this[offset]=value,offset+1},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value,this[offset+1]=value>>>8):objectWriteUInt16(this,value,offset,!0),offset+2},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value>>>8,this[offset+1]=value):objectWriteUInt16(this,value,offset,!1),offset+2},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[offset+3]=value>>>24,this[offset+2]=value>>>16,this[offset+1]=value>>>8,this[offset]=value):objectWriteUInt32(this,value,offset,!0),offset+4},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value>>>24,this[offset+1]=value>>>16,this[offset+2]=value>>>8,this[offset+3]=value):objectWriteUInt32(this,value,offset,!1),offset+4},Buffer.prototype.writeIntLE=function(value,offset,byteLength,noAssert){value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength-1)-1,-Math.pow(2,8*byteLength-1));var i=0,mul=1,sub=0>value?1:0;for(this[offset]=255&value;++i>0)-sub&255;return offset+byteLength},Buffer.prototype.writeIntBE=function(value,offset,byteLength,noAssert){value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength-1)-1,-Math.pow(2,8*byteLength-1));var i=byteLength-1,mul=1,sub=0>value?1:0;for(this[offset+i]=255&value;--i>=0&&(mul*=256);)this[offset+i]=(value/mul>>0)-sub&255;return offset+byteLength},Buffer.prototype.writeInt8=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,1,127,-128),Buffer.TYPED_ARRAY_SUPPORT||(value=Math.floor(value)),0>value&&(value=255+value+1),this[offset]=value,offset+1},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value,this[offset+1]=value>>>8):objectWriteUInt16(this,value,offset,!0),offset+2},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value>>>8,this[offset+1]=value):objectWriteUInt16(this,value,offset,!1),offset+2},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,4,2147483647,-2147483648),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value,this[offset+1]=value>>>8,this[offset+2]=value>>>16,this[offset+3]=value>>>24):objectWriteUInt32(this,value,offset,!0),offset+4},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,4,2147483647,-2147483648),0>value&&(value=4294967295+value+1),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value>>>24,this[offset+1]=value>>>16,this[offset+2]=value>>>8,this[offset+3]=value):objectWriteUInt32(this,value,offset,!1),offset+4},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert)},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start>=target.length&&(target_start=target.length),target_start||(target_start=0),end>0&&start>end&&(end=start),end===start)return 0;if(0===target.length||0===source.length)return 0;if(0>target_start)throw new RangeError("targetStart out of bounds");if(0>start||start>=source.length)throw new RangeError("sourceStart out of bounds");if(0>end)throw new RangeError("sourceEnd out of bounds");end>this.length&&(end=this.length),target.length-target_startlen||!Buffer.TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start);return len},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),start>end)throw new RangeError("end < start");if(end!==start&&0!==this.length){if(0>start||start>=this.length)throw new RangeError("start out of bounds");if(0>end||end>this.length)throw new RangeError("end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(Buffer.TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr.constructor=Buffer,arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUIntLE=BP.readUIntLE,arr.readUIntBE=BP.readUIntBE,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readIntLE=BP.readIntLE,arr.readIntBE=BP.readIntBE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUIntLE=BP.writeUIntLE,arr.writeUIntBE=BP.writeUIntBE,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeIntLE=BP.writeIntLE,arr.writeIntBE=BP.writeIntBE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z\-]/g},{"base64-js":112,ieee754:113,"is-array":114}],112:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS||code===PLUS_URL_SAFE?62:code===SLASH||code===SLASH_URL_SAFE?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0),PLUS_URL_SAFE="-".charCodeAt(0),SLASH_URL_SAFE="_".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],113:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],114:[function(require,module){var isArray=Array.isArray,str=Object.prototype.toString;module.exports=isArray||function(val){return!!val&&"[object Array]"==str.call(val)}},{}],115:[function(require,module){function drainQueue(){if(!draining){draining=!0;for(var currentQueue,len=queue.length;len;){currentQueue=queue,queue=[];for(var i=-1;++i-1||(list.push(token),setTokens(list))}function remove(token){var list=getTokens(),index=indexof(list,token);-1!==index&&(list.splice(index,1),setTokens(list))}function contains(token){return indexof(getTokens(),token)>-1}function toggle(token){return contains(token)?(remove(token),!1):(add(token),!0)}function $toString(){return elem.className}function item(index){var tokens=getTokens();return tokens[index]||null}function getTokens(){var className=elem.className;return filter(className.split(" "),isTruthy)}function setTokens(list){var length=list.length;elem.className=list.join(" "),classList.length=length;for(var i=0;iAn introduction to the WebGL API that runs in your browser. webgl-workshop\nis a NodeSchool workshop originally created for\nCampJS IV. Everything is powered by node.js, browserify and\na selection of stackgl packages under the hood.

            ',thumb:"http://i.imgur.com/vBJ7d6o.jpg",featured:!0,i:0},{name:"shader-school",link:"http://github.com/stackgl/shader-school",desc:"",thumb:"http://imgur.com/hegi9dZ.png",featured:!1,i:1},{name:"gl-surface-plot",link:"https://github.com/mikolalysenko/gl-surface-plot",desc:"",thumb:"http://i.imgur.com/z4xjpgu.jpg",featured:!1,i:2},{name:"bunny-walkthrough",link:"https://github.com/stackgl/bunny-walkthrough",desc:"",thumb:"http://i.imgur.com/OefbPjB.jpg",featured:!1,i:3},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:4},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:5},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:6},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:7},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:8},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:9},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:10},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:11},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:12},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:13}]},{}],2:[function(require,module){module.exports={"WebGL Core":[{name:"gl-vao",desc:"\n",link:"http://ghub.io/gl-vao",thumb:"http://imgur.com/iv3pOSh.png",featured:!1,i:0},{name:"gl-fbo",desc:"\n",link:"http://ghub.io/gl-fbo",thumb:"http://imgur.com/xiXCQGN.png",featured:!1,i:1},{name:"gl-texture2d",desc:"\n",link:"http://ghub.io/gl-texture2d",thumb:"http://imgur.com/ZkcCvzx.jpg",featured:!1,i:2},{name:"gl-buffer",desc:"\n",link:"http://ghub.io/gl-buffer",thumb:"http://imgur.com/JFZGJBx.png",featured:!1,i:3}],"WebGL API":[{name:"gl-state",desc:"",link:"http://ghub.io/gl-state",thumb:"default.jpg",featured:!1,i:0},{name:"gl-clear",desc:"",link:"http://ghub.io/gl-clear",thumb:"default.jpg",featured:!1,i:1},{name:"gl-fbo-matching",desc:"",link:"http://ghub.io/gl-fbo-matching",thumb:"default.jpg",featured:!1,i:2},{name:"gl-texture2d-display",desc:"\n",link:"http://ghub.io/gl-texture2d-display",thumb:"http://imgur.com/z6Cxsfy.png",featured:!1,i:3}],"Tools/Development":[{name:"glslify",desc:"\n",link:"http://ghub.io/glslify",thumb:"http://imgur.com/ThMYeUx.png",featured:!1,i:0},{name:"glslify-live",desc:"\n",link:"http://ghub.io/glslify-live",thumb:"http://imgur.com/9mmysos.png",featured:!1,i:1},{name:"glslify-optimize",desc:"\n",link:"http://ghub.io/glslify-optimize",thumb:"http://imgur.com/pF9tmNg.png",featured:!1,i:2},{name:"glslify-api",desc:"",link:"http://ghub.io/glslify-api",thumb:"default.jpg",featured:!1,i:3},{name:"glslify-resolve-remote",desc:"",link:"http://ghub.io/glslify-resolve-remote",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-testify",desc:"",link:"http://ghub.io/glsl-testify",thumb:"default.jpg",featured:!1,i:5},{name:"glsl-editor",desc:"",link:"http://ghub.io/glsl-editor",thumb:"default.jpg",featured:!1,i:6}],Math:[{name:"ndarray",desc:"",link:"http://ghub.io/ndarray",thumb:"default.jpg",featured:!1,i:0},{name:"gl-mat2",desc:"",link:"http://ghub.io/gl-mat2",thumb:"default.jpg",featured:!1,i:1},{name:"gl-mat3",desc:"",link:"http://ghub.io/gl-mat3",thumb:"default.jpg",featured:!1,i:2},{name:"gl-mat4",desc:"",link:"http://ghub.io/gl-mat4",thumb:"default.jpg",featured:!1,i:3},{name:"gl-matrix",desc:"",link:"http://ghub.io/gl-matrix",thumb:"default.jpg",featured:!1,i:4},{name:"cubic-hermite",desc:"",link:"http://ghub.io/cubic-hermite",thumb:"default.jpg",featured:!1,i:5}],"Camera Controls":[{name:"turntable-camera",desc:"\n",link:"http://ghub.io/turntable-camera",thumb:"http://imgur.com/3wiGD3K.png",featured:!1,i:0},{name:"orbit-camera",desc:"\n",link:"http://ghub.io/orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:1},{name:"game-shell-orbit-camera",desc:"\n",link:"http://ghub.io/game-shell-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:2},{name:"canvas-orbit-camera",desc:"\n",link:"http://ghub.io/canvas-orbit-camera",thumb:"http://imgur.com/BPkl0Yh.png",featured:!1,i:3}],Initialization:[{name:"gl-now",desc:"",link:"http://ghub.io/gl-now",thumb:"default.jpg",featured:!1,i:0},{name:"gl-context",desc:"",link:"http://ghub.io/gl-context",thumb:"default.jpg",featured:!1,i:1},{name:"webgl-context",desc:"",link:"http://ghub.io/webgl-context",thumb:"default.jpg",featured:!1,i:2}],Input:[{name:"key-pressed",desc:"",link:"http://ghub.io/key-pressed",thumb:"default.jpg",featured:!1,i:0},{name:"mouse-pressed",desc:"",link:"http://ghub.io/mouse-pressed",thumb:"default.jpg",featured:!1,i:1},{name:"mouse-speed",desc:"",link:"http://ghub.io/mouse-speed",thumb:"default.jpg",featured:!1,i:2},{name:"scroll-speed",desc:"",link:"http://ghub.io/scroll-speed",thumb:"default.jpg",featured:!1,i:3},{name:"canvas-fit",desc:"",link:"http://ghub.io/canvas-fit",thumb:"default.jpg",featured:!1,i:4},{name:"canvas-autoscale",desc:"",link:"http://ghub.io/canvas-autoscale",thumb:"default.jpg",featured:!1,i:5},{name:"vkey",desc:"",link:"http://ghub.io/vkey",thumb:"default.jpg",featured:!1,i:6}],"Shader Components":[{name:"glsl-luma",desc:"\n",link:"http://ghub.io/glsl-luma",thumb:"http://imgur.com/SRxqxj2.png",featured:!1,i:0},{name:"glsl-dither",desc:"\n",link:"http://ghub.io/glsl-dither",thumb:"http://imgur.com/D4ccYiJ.png",featured:!1,i:1},{name:"glsl-noise",desc:"\n",link:"http://ghub.io/glsl-noise",thumb:"http://imgur.com/BFITCvl.jpg",featured:!1,i:2},{name:"glsl-curl-noise",desc:"\n",link:"http://ghub.io/glsl-curl-noise",thumb:"http://imgur.com/ABlBkoE.png",featured:!1,i:3},{name:"glsl-random",desc:"\n",link:"http://ghub.io/glsl-random",thumb:"http://imgur.com/9EOo2or.png",featured:!1,i:4},{name:"glsl-fog",desc:"\n",link:"http://ghub.io/glsl-fog",thumb:"http://imgur.com/8l0otem.png",featured:!1,i:5},{name:"glsl-easings",desc:"",link:"http://ghub.io/glsl-easings",thumb:"default.jpg",featured:!1,i:6},{name:"glsl-fxaa",desc:"",link:"http://ghub.io/glsl-fxaa",thumb:"default.jpg",featured:!1,i:7},{name:"glsl-lut",desc:"",link:"http://ghub.io/glsl-lut",thumb:"default.jpg",featured:!1,i:8},{name:"glsl-range",desc:"",link:"http://ghub.io/glsl-range",thumb:"default.jpg",featured:!1,i:9},{name:"glsl-square-frame",desc:"",link:"http://ghub.io/glsl-square-frame",thumb:"default.jpg",featured:!1,i:10},{name:"glsl-hsv2rgb",desc:"",link:"http://ghub.io/glsl-hsv2rgb",thumb:"default.jpg",featured:!1,i:11},{name:"glsl-read-float",desc:"",link:"http://ghub.io/glsl-read-float",thumb:"default.jpg",featured:!1,i:12},{name:"matcap",desc:"",link:"http://ghub.io/matcap",thumb:"default.jpg",featured:!1,i:13}],"Shader Transforms":[{name:"glslify-hex",desc:"\n",link:"http://ghub.io/glslify-hex",thumb:"http://imgur.com/Dh8CPE9.png",featured:!1,i:0},{name:"glslify-import",desc:"\n",link:"http://ghub.io/glslify-import",thumb:"http://imgur.com/7trTmBF.png",featured:!1,i:1}],Visualisation:[{name:"gl-compare",desc:"\n",link:"http://ghub.io/gl-compare",thumb:"http://imgur.com/z8BkmZl.jpg",featured:!1,i:0},{name:"gl-surface-plot",desc:"",link:"http://ghub.io/gl-surface-plot",thumb:"default.jpg",featured:!1,i:1},{name:"canvas-pixels",desc:"",link:"http://ghub.io/canvas-pixels",thumb:"default.jpg",featured:!1,i:2},{name:"gl-line-plot",desc:"",link:"http://ghub.io/gl-line-plot",thumb:"default.jpg",featured:!1,i:3},{name:"gl-scatter-plot",desc:"",link:"http://ghub.io/gl-scatter-plot",thumb:"default.jpg",featured:!1,i:4},{name:"gl-axes",desc:"",link:"http://ghub.io/gl-axes",thumb:"default.jpg",featured:!1,i:5}],Internals:[{name:"webglew",desc:"",link:"http://ghub.io/webglew",thumb:"default.jpg",featured:!1,i:0},{name:"glsl-parser",desc:"",link:"http://ghub.io/glsl-parser",thumb:"default.jpg",featured:!1,i:1},{name:"glsl-tokenizer",desc:"",link:"http://ghub.io/glsl-tokenizer",thumb:"default.jpg",featured:!1,i:2},{name:"glsl-deparser",desc:"",link:"http://ghub.io/glsl-deparser",thumb:"default.jpg",featured:!1,i:3},{name:"glsl-extract",desc:"",link:"http://ghub.io/glsl-extract",thumb:"default.jpg",featured:!1,i:4},{name:"glsl-resolve",desc:"",link:"http://ghub.io/glsl-resolve",thumb:"default.jpg",featured:!1,i:5},{name:"glslify-stream",desc:"",link:"http://ghub.io/glslify-stream",thumb:"default.jpg",featured:!1,i:6},{name:"gl-shader-core",desc:"",link:"http://ghub.io/gl-shader-core",thumb:"default.jpg",featured:!1,i:7}],Assets:[{name:"lena",desc:"\n",link:"http://ghub.io/lena",thumb:"http://imgur.com/eSx2pBu.png",featured:!1,i:0},{name:"baboon-image",desc:"\n",link:"http://ghub.io/baboon-image",thumb:"http://imgur.com/63yazJ1.png",featured:!1,i:1},{name:"bunny",desc:"\n",link:"http://ghub.io/bunny",thumb:"http://imgur.com/5VIykyD.png",featured:!1,i:2},{name:"teapot",desc:"",link:"http://ghub.io/teapot",thumb:"default.jpg",featured:!1,i:3},{name:"stanford-dragon",desc:"\n",link:"http://ghub.io/stanford-dragon",thumb:"http://imgur.com/XWYMq6J.png",featured:!1,i:4},{name:"get-pixels",desc:"",link:"http://ghub.io/get-pixels",thumb:"default.jpg",featured:!1,i:5},{name:"save-pixels",desc:"",link:"http://ghub.io/save-pixels",thumb:"default.jpg",featured:!1,i:6},{name:"ndpack-image",desc:"",link:"http://ghub.io/ndpack-image",thumb:"default.jpg",featured:!1,i:7},{name:"font-atlas",desc:"",link:"http://ghub.io/font-atlas",thumb:"default.jpg",featured:!1,i:8},{name:"gl-gif",desc:"\n",link:"http://ghub.io/gl-gif",thumb:"http://imgur.com/AiC0Sab.gif",featured:!1,i:9}],Interoperability:[{name:"three-glslify",desc:"",link:"http://ghub.io/three-glslify",thumb:"default.jpg",featured:!1,i:0}],Geometry:[{name:"simplicial-complex",desc:"",link:"http://ghub.io/simplicial-complex",thumb:"default.jpg",featured:!1,i:0},{name:"gl-wireframe",desc:"",link:"http://ghub.io/gl-wireframe",thumb:"default.jpg",featured:!1,i:1},{name:"gl-geometry",desc:"",link:"http://ghub.io/gl-geometry",thumb:"default.jpg",featured:!1,i:2},{name:"normals",desc:"",link:"http://ghub.io/normals",thumb:"default.jpg",featured:!1,i:3},{name:"greedy-mesher",desc:"",link:"http://ghub.io/greedy-mesher",thumb:"default.jpg",featured:!1,i:4},{name:"voxelize",desc:"",link:"http://ghub.io/voxelize",thumb:"default.jpg",featured:!1,i:5},{name:"isosurface",desc:"",link:"http://ghub.io/isosurface",thumb:"default.jpg",featured:!1,i:6},{name:"icosphere",desc:"",link:"http://ghub.io/icosphere",thumb:"default.jpg",featured:!1,i:7},{name:"rectangular-prism",desc:"",link:"http://ghub.io/rectangular-prism",thumb:"default.jpg",featured:!1,i:8},{name:"face-normals",desc:"",link:"http://ghub.io/face-normals",thumb:"default.jpg",featured:!1,i:9},{name:"mesh-reindex",desc:"",link:"http://ghub.io/mesh-reindex",thumb:"default.jpg",featured:!1,i:10},{name:"mesh-combine",desc:"",link:"http://ghub.io/mesh-combine",thumb:"default.jpg",featured:!1,i:11},{name:"unindex-mesh",desc:"",link:"http://ghub.io/unindex-mesh",thumb:"default.jpg",featured:!1,i:12},{name:"vectorize-text",desc:"",link:"http://ghub.io/vectorize-text",thumb:"default.jpg",featured:!1,i:13},{name:"from-3d-to-2d",desc:"",link:"http://ghub.io/from-3d-to-2d",thumb:"default.jpg",featured:!1,i:14},{name:"surface-vectors",desc:"",link:"http://ghub.io/surface-vectors",thumb:"default.jpg",featured:!1,i:15},{name:"orthogami",desc:"",link:"http://ghub.io/orthogami",thumb:"default.jpg",featured:!1,i:16},{name:"plane-to-polygon",desc:"",link:"http://ghub.io/plane-to-polygon",thumb:"default.jpg",featured:!1,i:17},{name:"find-basis-3d",desc:"",link:"http://ghub.io/find-basis-3d",thumb:"default.jpg",featured:!1,i:18},{name:"box-frustum",desc:"",link:"http://ghub.io/box-frustum",thumb:"default.jpg",featured:!1,i:19},{name:"delaunay-triangulate",desc:"",link:"http://ghub.io/delaunay-triangulate",thumb:"default.jpg",featured:!1,i:20},{name:"svg-3d-simplicial-complex",desc:"",link:"http://ghub.io/svg-3d-simplicial-complex",thumb:"default.jpg",featured:!1,i:21}]}},{}],3:[function(require){!function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r,i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date,a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,m.parentNode.insertBefore(a,m)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-54792490-1","auto"),ga("send","pageview");{var filter=require("./lib/filter"),minstache=require("minstache"),domify=require("domify"),grid=(require("sliced"),document.getElementById("grid").querySelector("canvas"));document.getElementById("community").querySelector("canvas")}require("./lib/fill")(document.querySelectorAll("[data-fill]"));try{require("@stackgl/splash-grid")(grid)}catch(e){console.error(e.message)}var thumb=minstache.compile('
          • \n
            \n \n
            \n
            \n
            \n \n

            {{name}}

            \n
            \n
            \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
            \n
            \n
            \n
          • \n'),examples=require("./build/examples.json").map(function(meta){return thumb(meta)}).join("\n"),packages=require("./build/packages.json");packages=Object.keys(packages).reduce(function(pkgs,group){return pkgs.concat(packages[group].map(function(pkg){return pkg.group=group,pkg}))},[]).map(function(meta){return thumb(meta)}).join("\n"),document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples));var pkgEl=document.getElementById("packages");pkgEl.querySelector("ul.thumb-list").appendChild(domify(packages)),pkgEl.querySelector("ul.thumb-filter").appendChild(filter(pkgEl))},{"./build/examples.json":1,"./build/packages.json":2,"./lib/fill":4,"./lib/filter":5,"@stackgl/splash-grid":7,domify:116,minstache:120,sliced:121}],4:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;iheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":6,"a-big-triangle":24,"canvas-fit":25,clone:27,"cube-cube":28,"face-normals":31,"frame-debounce":32,"gl-clear":37,"gl-context":38,"gl-fbo":40,"gl-geometry":43,"gl-matrix":68,"gl-texture2d":81,glslify:83,"glslify/adapter.js":82,"mesh-combine":89,"orbit-camera":113,"right-now":114,"unindex-mesh":115}],8:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:14,"ndarray-ops":9,"typedarray-pool":18}],9:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":10}],10:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":12}],11:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:13}],12:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],14:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:123,"iota-array":15}],15:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],16:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],17:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],18:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n); -case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":16,dup:17}],19:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],20:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":19}],21:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":19}],22:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":30}],29:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],30:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],32:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:126,"raf-component":33,sliced:34}],33:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],34:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":35}],35:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],36:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],37:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":36}],38:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":39}],39:[function(require,module){module.exports=require(33)},{}],40:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT));var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options.float&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:45}],45:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],46:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t) -}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:52,"ndarray-ops":47,"typedarray-pool":56,webglew:58}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":50}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:51}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":49}],51:[function(require,module){module.exports=require(13)},{}],52:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":53}],53:[function(require,module){module.exports=require(15)},{}],54:[function(require,module){module.exports=require(16)},{}],55:[function(require,module){module.exports=require(17)},{}],56:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":54,buffer:123,dup:55}],57:[function(require,module){module.exports=require(41)},{}],58:[function(require,module){module.exports=require(42)},{weakmap:57}],59:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],60:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":59}],61:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out -},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],69:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{"cwise-compiler":70}],70:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{"./lib/thunk.js":72}],71:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{uniq:73}],72:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{"./compile.js":71}],73:[function(require,module){module.exports=require(13)},{}],74:[function(require,module,exports){arguments[4][14][0].apply(exports,arguments)},{buffer:123,"iota-array":75}],75:[function(require,module){module.exports=require(15)},{}],76:[function(require,module){module.exports=require(16)},{}],77:[function(require,module){module.exports=require(17)},{}],78:[function(require,module){module.exports=require(56)},{"bit-twiddle":76,buffer:123,dup:77}],79:[function(require,module){module.exports=require(41)},{}],80:[function(require,module){module.exports=require(42)},{weakmap:79}],81:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0;if(needsMip&&mipLevels.push(mip_level),type===ctype&&packed)0===array.offset&&array.data.length===size?needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data):needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,array.data.subarray(array.offset,array.offset+size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,array.data.subarray(array.offset,array.offset+size));else{var pack_buffer;pack_buffer=ctype===gl.FLOAT?pool.mallocFloat32(size):pool.mallocUint8(size);var pack_view=ndarray(pack_buffer,shape);type===gl.FLOAT&&ctype===gl.UNSIGNED_BYTE?convertFloatToUint8(pack_view,array):ops.assign(pack_view,array),needsMip?gl.texImage2D(gl.TEXTURE_2D,mip_level,cformat,shape[1],shape[0],0,cformat,ctype,pack_buffer.subarray(0,size)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,shape[1],shape[0],cformat,ctype,pack_buffer.subarray(0,size)),ctype===gl.FLOAT?pool.freeFloat32(pack_buffer):pool.freeUint8(pack_buffer)}}function initTexture(gl){var tex=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,tex),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),tex}function createTextureShape(gl,width,height,format,type){var maxTextureSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>width||width>maxTextureSize||0>height||height>maxTextureSize)throw new Error("gl-texture2d: Invalid texture shape");var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,width,height,0,format,type,null),new Texture2D(gl,tex,width,height,format,type)}function createTextureDOM(gl,element,format,type){var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,format,type,element),new Texture2D(gl,tex,0|element.width,0|element.height,format,type)}function isPacked(array){for(var shape=array.shape,stride=array.stride,s=1,i=shape.length-1;i>=0;--i){if(stride[i]!==s)return!1;s*=shape[i]}return!0}function createTextureArray(gl,array){var dtype=array.dtype,shape=array.shape.slice(),maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(shape[0]<0||shape[0]>maxSize||shape[1]<0||shape[1]>maxSize)throw new Error("gl-texture2d: Invalid texture size");var packed=isPacked(array),type=0;"float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8");var format=0;if(2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("Invalid shape for pixel coords");format=gl.RGBA}}type===gl.FLOAT&&webglew(gl).texture_float&&(type=gl.UNSIGNED_BYTE,packed=!1);var buffer,buf_store;if(packed){var array_size=array.size;buffer=array.data.subarray(array.offset,array.offset+array_size)}else{for(var sz=1,stride=new Array(shape.length),i=shape.length-1;i>=0;--i)stride[i]=sz,sz*=shape[i];buf_store=pool.malloc(sz,dtype);var buf_array=ndarray(buf_store,array.shape,stride,0);"float32"!==dtype&&"float64"!==dtype||type!==gl.UNSIGNED_BYTE?ops.assign(buf_array,array):convertFloatToUint8(buf_array,array),buffer=buf_store.subarray(0,sz)}var tex=initTexture(gl);return gl.texImage2D(gl.TEXTURE_2D,0,format,shape[1],shape[0],0,format,type,buffer),packed||pool.free(buf_store),new Texture2D(gl,tex,shape[1],shape[0],format,type)}function createTexture2D(gl){if(arguments.length<=1)throw new Error("Missing arguments for texture2d constructor");if(linearTypes||lazyInitLinearTypes(gl),"number"==typeof arguments[1])return createTextureShape(gl,arguments[1],arguments[2],arguments[3]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if(Array.isArray(arguments[1]))return createTextureShape(gl,0|arguments[1][1],0|arguments[1][0],arguments[2]||gl.RGBA,arguments[4]||gl.UNSIGNED_BYTE);if("object"==typeof arguments[1]){var obj=arguments[1];if(obj instanceof HTMLCanvasElement||obj instanceof HTMLImageElement||obj instanceof HTMLVideoElement||obj instanceof ImageData)return createTextureDOM(gl,obj,arguments[2]||gl.RGBA,arguments[3]||gl.UNSIGNED_BYTE);if(obj.shape&&obj.data&&obj.stride)return createTextureArray(gl,obj)}throw new Error("Invalid arguments for texture2d constructor")}var ndarray=require("ndarray"),ops=require("ndarray-ops"),pool=require("typedarray-pool"),webglew=require("webglew"),linearTypes=null,filterTypes=null,wrapTypes=null,convertFloatToUint8=function(out,inp){ops.muls(out,inp,255)};Object.defineProperty(Texture2D.prototype,"minFilter",{get:function(){return this._minFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,v),this._minFilter=v}});var proto=Texture2D.prototype;Object.defineProperty(proto,"magFilter",{get:function(){return this._magFilter},set:function(v){this.bind();var gl=this.gl;if(this.type===gl.FLOAT&&linearTypes.indexOf(v)>=0&&(webglew(gl).OES_texture_float_linear||(v=gl.NEAREST)),filterTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown filter mode "+v);return gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,v),this._magFilter=v}}),Object.defineProperty(proto,"wrapS",{get:function(){return this._wrapS},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,v),this._wrapS=v}}),Object.defineProperty(proto,"wrapT",{get:function(){return this._wrapT},set:function(v){if(this.bind(),wrapTypes.indexOf(v)<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);return this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,v),this._wrapT=v}}),Object.defineProperty(proto,"wrap",{get:function(){return[this._wrapT,this._wrapS]},set:function(v){if(Array.isArray(v)||(v=[v,v]),2!==v.length)throw new Error("gl-texture2d: Must specify wrap mode for rows and columns");for(var i=0;2>i;++i)if(wrapTypes.indexOf(v[i])<0)throw new Error("gl-texture2d: Unknown wrap mode "+v);this._wrapT=v[0],this._wrapS=v[1];var gl=this.gl;return this.bind(),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this._wrapT),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this._wrapS),v}}),Object.defineProperty(proto,"mipSamples",{get:function(){return this._anisoSamples},set:function(i){var psamples=this._anisoSamples;if(this._anisoSamples=0|Math.max(i,1),psamples!==this._anisoSamples){var ext=webglew(this.gl).EXT_texture_filter_anisotropic;ext&&this.gl.texParameterf(this.gl.TEXTURE_2D,ext.TEXTURE_MAX_ANISOTROPY_EXT,this._anisoSamples)}return this._anisoSamples}}),Object.defineProperty(proto,"shape",{get:function(){return this._shape},set:function(x){if(Array.isArray(x)){if(2!==x.length)throw new Error("gl-texture2d: Invalid texture shape")}else x=[0|x,0|x];var r=0|x[0],c=0|x[1];if(this.height===r&&this.width===c)return x;var gl=this.gl,maxSize=gl.getParameter(gl.MAX_TEXTURE_SIZE);if(0>c||c>maxSize||0>r||r>maxSize)throw new Error("gl-texture2d: Invalid texture size");return this._shape=[r,c],this.bind(),gl.texImage2D(gl.TEXTURE_2D,0,this.format,c,r,0,this.format,this.type,null),this._mipLevels=[0],x}}),proto.bind=function(unit){var gl=this.gl;return void 0!==unit&&gl.activeTexture(gl.TEXTURE0+(0|unit)),gl.bindTexture(gl.TEXTURE_2D,this.handle),void 0!==unit?unit:gl.getParameter(gl.ACTIVE_TEXTURE)-gl.TEXTURE0},proto.dispose=function(){this.gl.deleteTexture(this.handle)},proto.generateMipmap=function(){this.bind(),this.gl.generateMipmap(this.gl.TEXTURE_2D);for(var l=Math.min(this._shape[0],this._shape[1]),i=0;l>0;++i,l>>>=1)this._mipLevels.indexOf(i)<0&&this._mipLevels.push(i)},proto.setPixels=function(data,x_off,y_off,mip_level){var gl=this.gl;if(this.bind(),Array.isArray(x_off)?(mip_level=y_off,y_off=0|x_off[0],x_off=0|x_off[1]):(x_off=x_off||0,y_off=y_off||0),mip_level=mip_level||0,data instanceof HTMLCanvasElement||data instanceof ImageData||data instanceof HTMLImageElement||data instanceof HTMLVideoElement){var needsMip=this._mipLevels.indexOf(mip_level)<0;needsMip?(gl.texImage2D(gl.TEXTURE_2D,0,this.format,this.format,this.type,data),this._mipLevels.push(mip_level)):gl.texSubImage2D(gl.TEXTURE_2D,mip_level,x_off,y_off,this.format,this.type,data)}else{if(!(data.shape&&data.stride&&data.data))throw new Error("gl-texture2d: Unsupported data type");if(data.shape.length<2||x_off+data.shape[1]>this._shape[1]>>>mip_level||y_off+data.shape[0]>this._shape[0]>>>mip_level||0>x_off||0>y_off)throw new Error("gl-texture2d: Texture dimensions are out of bounds");texSubImageArray(gl,x_off,y_off,mip_level,this.format,this.type,this._mipLevels,data)}},module.exports=createTexture2D},{ndarray:74,"ndarray-ops":69,"typedarray-pool":78,webglew:80}],82:[function(require,module){function programify(vertex,fragment,uniforms,attributes){return function(gl){return shader(gl,vertex,fragment,uniforms,attributes)}}module.exports=programify;var shader=require("gl-shader-core")},{"gl-shader-core":88}],83:[function(require,module){function noop(){throw new Error("You should bundle your code using `glslify` as a transform.")}module.exports=noop},{}],84:[function(require,module){"use strict";function ShaderAttribute(gl,program,location,dimension,name,constFunc,relink){this._gl=gl,this._program=program,this._location=location,this._dimension=dimension,this._name=name,this._constFunc=constFunc,this._relink=relink}function addVectorAttribute(gl,program,location,dimension,obj,name,doLink){for(var constFuncArgs=["gl","v"],varNames=[],i=0;dimension>i;++i)constFuncArgs.push("x"+i),varNames.push("x"+i);constFuncArgs.push(["if(x0.length===undefined){return gl.vertexAttrib",dimension,"f(v,",varNames.join(","),")}else{return gl.vertexAttrib",dimension,"fv(v,x0)}"].join(""));var constFunc=Function.apply(void 0,constFuncArgs),attr=new ShaderAttribute(gl,program,location,dimension,name,constFunc,doLink);Object.defineProperty(obj,name,{set:function(x){return gl.disableVertexAttribArray(attr._location),constFunc(gl,attr._location,x),x},get:function(){return attr},enumerable:!0})}function createAttributeWrapper(gl,program,attributes,doLink){for(var obj={},i=0,n=attributes.length;n>i;++i){var a=attributes[i],name=a.name,type=a.type,location=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":addVectorAttribute(gl,program,location,1,obj,name,doLink);break;default:if(!(type.indexOf("vec")>=0))throw new Error("Unknown data type for attribute "+name+": "+type);var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type for attribute "+name+": "+type);addVectorAttribute(gl,program,location,d,obj,name,doLink)}}return obj}module.exports=createAttributeWrapper;var proto=ShaderAttribute.prototype;proto.pointer=function(type,normalized,stride,offset){var gl=this._gl;gl.vertexAttribPointer(this._location,this._dimension,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0),this._gl.enableVertexAttribArray(this._location)},Object.defineProperty(proto,"location",{get:function(){return this._location},set:function(v){v!==this._location&&(this._location=v,this._gl.bindAttribLocation(this._program,v,this._name),this._gl.linkProgram(this._program),this._relink())}})},{}],85:[function(require,module){"use strict";function identity(x){var c=new Function("y","return function(){return y}");return c(x)}function createUniformWrapper(gl,program,uniforms,locations){function makeGetter(index){var proc=new Function("gl","prog","locations","return function(){return gl.getUniform(prog,locations["+index+"])}");return proc(gl,program,locations)}function makePropSetter(path,index,type){switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":return"gl.uniform1i(locations["+index+"],obj"+path+")";case"float":return"gl.uniform1f(locations["+index+"],obj"+path+")";default:var vidx=type.indexOf("vec");if(!(vidx>=0&&1>=vidx&&type.length===4+vidx)){if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return"gl.uniformMatrix"+d+"fv(locations["+index+"],false,obj"+path+")"}throw new Error("Unknown uniform data type for "+name+": "+type)}var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");switch(type.charAt(0)){case"b":case"i":return"gl.uniform"+d+"iv(locations["+index+"],obj"+path+")";case"v":return"gl.uniform"+d+"fv(locations["+index+"],obj"+path+")";default:throw new Error("Unrecognized data type for vector "+name+": "+type)}}}function enumerateIndices(prefix,type){if("object"!=typeof type)return[[prefix,type]];var indices=[];for(var id in type){var prop=type[id],tprefix=prefix;tprefix+=parseInt(id)+""===id?"["+id+"]":"."+id,"object"==typeof prop?indices.push.apply(indices,enumerateIndices(tprefix,prop)):indices.push([tprefix,prop])}return indices}function makeSetter(type){for(var code=["return function updateProperty(obj){"],indices=enumerateIndices("",type),i=0;i=0&&1>=vidx&&type.length===4+vidx){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid data type");return"b"===type.charAt(0)?dup(d,!1):dup(d)}if(0===type.indexOf("mat")&&4===type.length){var d=type.charCodeAt(type.length-1)-48;if(2>d||d>4)throw new Error("Invalid uniform dimension type for matrix "+name+": "+type);return dup([d,d])}throw new Error("Unknown uniform data type for "+name+": "+type)}}function storeProperty(obj,prop,type){if("object"==typeof type){var child=processObject(type);Object.defineProperty(obj,prop,{get:identity(child),set:makeSetter(type),enumerable:!0,configurable:!1})}else locations[type]?Object.defineProperty(obj,prop,{get:makeGetter(type),set:makeSetter(type),enumerable:!0,configurable:!1}):obj[prop]=defaultValue(uniforms[type].type)}function processObject(obj){var result;if(Array.isArray(obj)){result=new Array(obj.length);for(var i=0;i1){x[0]in o||(o[x[0]]=[]),o=o[x[0]];for(var k=1;k=pa&&pc>=pa?a:pc>=pb?b:c}function parseData(dataBuffer){function inputData(data){for(var tmp,j,len=data.length,i=0;i!==len;)switch(state){case 0:if(data.readUInt8(i++)!==HEADER[off++])return!1;off===HEADER.length&&(state=1,off=0);break;case 1:if(8-off>len-i)data.copy(buf,off,i),off+=len-i,i=len;else switch(data.copy(buf,off,i,i+8-off),i+=8-off,off=0,chunkLength=buf.readUInt32BE(0),buf.toString("ascii",4,8)){case"IHDR":state=2;break;case"PLTE":if(3!==pngColorType)state=7;else{if(chunkLength%3!==0)return!1;pngPaletteEntries=chunkLength/3,pngPalette=new Buffer(chunkLength),state=3}break;case"tRNS":if(3!==pngColorType)return!1;idChannels++,pngAlphaEntries=chunkLength,pngAlpha=new Buffer(chunkLength),state=4;break;case"IDAT":pngPixels||(pngPixels=new Uint8Array(pngWidth*pngHeight*idChannels)),state=5;break;case"IEND":state=6;break;default:state=7}break;case 2:if(13!==chunkLength)return!1;if(chunkLength-off>len-i)data.copy(buf,off,i),off+=len-i,i=len;else{if(data.copy(buf,off,i,i+chunkLength-off),0!==buf.readUInt8(10))return!1;if(0!==buf.readUInt8(11))return!1;if(0!==buf.readUInt8(12))return!1;switch(i+=chunkLength-off,state=8,off=0,pngWidth=buf.readUInt32BE(0),pngHeight=buf.readUInt32BE(4),pngBitDepth=buf.readUInt8(8),pngDepthMult=255/((1<len-i)data.copy(pngPalette,off,i),off+=len-i,i=len;else for(data.copy(pngPalette,off,i,i+chunkLength-off),i+=chunkLength-off,state=8,off=0,idChannels=1,j=pngPaletteEntries;j--;)if(pngPalette[3*j+0]!==pngPalette[3*j+1]||pngPalette[3*j+0]!==pngPalette[3*j+2]){idChannels=3;break}break;case 4:chunkLength-off>len-i?(data.copy(pngAlpha,off,i),off+=len-i,i=len):(data.copy(pngAlpha,off,i,i+chunkLength-off),i+=chunkLength-off,state=8,off=0);break;case 5:chunkLength-off>len-i?(inflateQueue.push(data.slice(i)),off+=len-i,i=len):(inflateQueue.push(data.slice(i,i+chunkLength-off)),i+=chunkLength-off,state=8,off=0);break;case 6:if(0!==chunkLength)return!1;4-off>len-i?(off+=len-i,i=len):(pngTrailer=new Buffer(0),i+=4-off,state=9,off=0);break;case 7:chunkLength-off>len-i?(off+=len-i,i=len):(i+=chunkLength-off,state=8,off=0);break;case 8:4-off>len-i?(off+=len-i,i=len):(i+=4-off,state=1,off=0);break;case 9:tmp=new Buffer(off+len-i),pngTrailer.copy(tmp),data.copy(tmp,off,i,len),pngTrailer=tmp,off+=len-i,i=len}return!0}function unpackPixels(data){var i,tmp,x,j,k,len=data.length;for(i=0;i!==len;++i){if(-1===b)scanlineFilter=data[i],tmp=currentScanline,currentScanline=priorScanline,priorScanline=tmp;else switch(scanlineFilter){case 0:currentScanline[b]=data[i];break;case 1:currentScanline[b]=pngBytesPerPixel>b?data[i]:data[i]+currentScanline[b-pngBytesPerPixel]&255;break;case 2:currentScanline[b]=data[i]+priorScanline[b]&255;break;case 3:currentScanline[b]=data[i]+((pngBytesPerPixel>b?priorScanline[b]:currentScanline[b-pngBytesPerPixel]+priorScanline[b])>>>1)&255;break;case 4:currentScanline[b]=data[i]+(pngBytesPerPixel>b?priorScanline[b]:paeth(currentScanline[b-pngBytesPerPixel],priorScanline[b],priorScanline[b-pngBytesPerPixel]))&255;break;default:return null}if(++b===pngBytesPerScanline){if(p===pngPixels.length)return null;for(j=0,x=0;x!==pngWidth;++x){for(k=0;k!==pngSamplesPerPixel;++j,++k)switch(pngBitDepth){case 1:pngSamples[k]=currentScanline[j>>>3]>>7-(7&j)&1;break;case 2:pngSamples[k]=currentScanline[j>>>2]>>(3-(3&j)<<1)&3;break;case 4:pngSamples[k]=currentScanline[j>>>1]>>(1-(1&j)<<2)&15;break;case 8:pngSamples[k]=currentScanline[j];break;default:return null}switch(pngColorType){case 0:pngPixels[p++]=pngSamples[0]*pngDepthMult;break;case 2:pngPixels[p++]=pngSamples[0]*pngDepthMult,pngPixels[p++]=pngSamples[1]*pngDepthMult,pngPixels[p++]=pngSamples[2]*pngDepthMult;break;case 3:if(pngSamples[0]>=pngPaletteEntries)return null;switch(idChannels){case 1:pngPixels[p++]=pngPalette[3*pngSamples[0]];break;case 2:pngPixels[p++]=pngPalette[3*pngSamples[0]],pngPixels[p++]=pngSamples[0]0?opt.windowBits=-opt.windowBits:opt.gzip&&opt.windowBits>0&&opt.windowBits<16&&(opt.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;var status=zlib_deflate.deflateInit2(this.strm,opt.level,opt.method,opt.windowBits,opt.memLevel,opt.strategy);if(status!==Z_OK)throw new Error(msg[status]);opt.header&&zlib_deflate.deflateSetHeader(this.strm,opt.header)};Deflate.prototype.push=function(data,mode){var status,_mode,strm=this.strm,chunkSize=this.options.chunkSize;if(this.ended)return!1;_mode=mode===~~mode?mode:mode===!0?Z_FINISH:Z_NO_FLUSH,strm.input="string"==typeof data?strings.string2buf(data):data,strm.next_in=0,strm.avail_in=strm.input.length;do{if(0===strm.avail_out&&(strm.output=new utils.Buf8(chunkSize),strm.next_out=0,strm.avail_out=chunkSize),status=zlib_deflate.deflate(strm,_mode),status!==Z_STREAM_END&&status!==Z_OK)return this.onEnd(status),this.ended=!0,!1;(0===strm.avail_out||0===strm.avail_in&&_mode===Z_FINISH)&&this.onData("string"===this.options.to?strings.buf2binstring(utils.shrinkBuf(strm.output,strm.next_out)):utils.shrinkBuf(strm.output,strm.next_out))}while((strm.avail_in>0||0===strm.avail_out)&&status!==Z_STREAM_END);return _mode===Z_FINISH?(status=zlib_deflate.deflateEnd(this.strm),this.onEnd(status),this.ended=!0,status===Z_OK):!0},Deflate.prototype.onData=function(chunk){this.chunks.push(chunk)},Deflate.prototype.onEnd=function(status){status===Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):utils.flattenChunks(this.chunks)),this.chunks=[],this.err=status,this.msg=this.strm.msg},exports.Deflate=Deflate,exports.deflate=deflate,exports.deflateRaw=deflateRaw,exports.gzip=gzip},{"./utils/common":98,"./utils/strings":99,"./zlib/deflate.js":103,"./zlib/messages":108,"./zlib/zstream":110}],97:[function(require,module,exports){"use strict";function inflate(input,options){var inflator=new Inflate(options);if(inflator.push(input,!0),inflator.err)throw inflator.msg;return inflator.result}function inflateRaw(input,options){return options=options||{},options.raw=!0,inflate(input,options)}var zlib_inflate=require("./zlib/inflate.js"),utils=require("./utils/common"),strings=require("./utils/strings"),c=require("./zlib/constants"),msg=require("./zlib/messages"),zstream=require("./zlib/zstream"),gzheader=require("./zlib/gzheader"),Inflate=function(options){this.options=utils.assign({chunkSize:16384,windowBits:0,to:""},options||{});var opt=this.options;opt.raw&&opt.windowBits>=0&&opt.windowBits<16&&(opt.windowBits=-opt.windowBits,0===opt.windowBits&&(opt.windowBits=-15)),!(opt.windowBits>=0&&opt.windowBits<16)||options&&options.windowBits||(opt.windowBits+=32),opt.windowBits>15&&opt.windowBits<48&&0===(15&opt.windowBits)&&(opt.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;var status=zlib_inflate.inflateInit2(this.strm,opt.windowBits);if(status!==c.Z_OK)throw new Error(msg[status]);this.header=new gzheader,zlib_inflate.inflateGetHeader(this.strm,this.header)};Inflate.prototype.push=function(data,mode){var status,_mode,next_out_utf8,tail,utf8str,strm=this.strm,chunkSize=this.options.chunkSize;if(this.ended)return!1;_mode=mode===~~mode?mode:mode===!0?c.Z_FINISH:c.Z_NO_FLUSH,strm.input="string"==typeof data?strings.binstring2buf(data):data,strm.next_in=0,strm.avail_in=strm.input.length;do{if(0===strm.avail_out&&(strm.output=new utils.Buf8(chunkSize),strm.next_out=0,strm.avail_out=chunkSize),status=zlib_inflate.inflate(strm,c.Z_NO_FLUSH),status!==c.Z_STREAM_END&&status!==c.Z_OK)return this.onEnd(status),this.ended=!0,!1;strm.next_out&&(0===strm.avail_out||status===c.Z_STREAM_END||0===strm.avail_in&&_mode===c.Z_FINISH)&&("string"===this.options.to?(next_out_utf8=strings.utf8border(strm.output,strm.next_out),tail=strm.next_out-next_out_utf8,utf8str=strings.buf2string(strm.output,next_out_utf8),strm.next_out=tail,strm.avail_out=chunkSize-tail,tail&&utils.arraySet(strm.output,strm.output,next_out_utf8,tail,0),this.onData(utf8str)):this.onData(utils.shrinkBuf(strm.output,strm.next_out)))}while(strm.avail_in>0&&status!==c.Z_STREAM_END);return status===c.Z_STREAM_END&&(_mode=c.Z_FINISH),_mode===c.Z_FINISH?(status=zlib_inflate.inflateEnd(this.strm),this.onEnd(status),this.ended=!0,status===c.Z_OK):!0},Inflate.prototype.onData=function(chunk){this.chunks.push(chunk)},Inflate.prototype.onEnd=function(status){status===c.Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):utils.flattenChunks(this.chunks)),this.chunks=[],this.err=status,this.msg=this.strm.msg},exports.Inflate=Inflate,exports.inflate=inflate,exports.inflateRaw=inflateRaw,exports.ungzip=inflate},{"./utils/common":98,"./utils/strings":99,"./zlib/constants":101,"./zlib/gzheader":104,"./zlib/inflate.js":106,"./zlib/messages":108,"./zlib/zstream":110}],98:[function(require,module,exports){"use strict";var TYPED_OK="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;exports.assign=function(obj){for(var sources=Array.prototype.slice.call(arguments,1);sources.length;){var source=sources.shift();if(source){if("object"!=typeof source)throw new TypeError(source+"must be non-object");for(var p in source)source.hasOwnProperty(p)&&(obj[p]=source[p])}}return obj},exports.shrinkBuf=function(buf,size){return buf.length===size?buf:buf.subarray?buf.subarray(0,size):(buf.length=size,buf)};var fnTyped={arraySet:function(dest,src,src_offs,len,dest_offs){if(src.subarray&&dest.subarray)return void dest.set(src.subarray(src_offs,src_offs+len),dest_offs);for(var i=0;len>i;i++)dest[dest_offs+i]=src[src_offs+i]},flattenChunks:function(chunks){var i,l,len,pos,chunk,result;for(len=0,i=0,l=chunks.length;l>i;i++)len+=chunks[i].length;for(result=new Uint8Array(len),pos=0,i=0,l=chunks.length;l>i;i++)chunk=chunks[i],result.set(chunk,pos),pos+=chunk.length;return result}},fnUntyped={arraySet:function(dest,src,src_offs,len,dest_offs){for(var i=0;len>i;i++)dest[dest_offs+i]=src[src_offs+i]},flattenChunks:function(chunks){return[].concat.apply([],chunks)}};exports.setTyped=function(on){on?(exports.Buf8=Uint8Array,exports.Buf16=Uint16Array,exports.Buf32=Int32Array,exports.assign(exports,fnTyped)):(exports.Buf8=Array,exports.Buf16=Array,exports.Buf32=Array,exports.assign(exports,fnUntyped))},exports.setTyped(TYPED_OK)},{}],99:[function(require,module,exports){"use strict";function buf2binstring(buf,len){if(65537>len&&(buf.subarray&&STR_APPLY_UIA_OK||!buf.subarray&&STR_APPLY_OK))return String.fromCharCode.apply(null,utils.shrinkBuf(buf,len));for(var result="",i=0;len>i;i++)result+=String.fromCharCode(buf[i]);return result}var utils=require("./common"),STR_APPLY_OK=!0,STR_APPLY_UIA_OK=!0;try{String.fromCharCode.apply(null,[0])}catch(__){STR_APPLY_OK=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(__){STR_APPLY_UIA_OK=!1}for(var _utf8len=new utils.Buf8(256),i=0;256>i;i++)_utf8len[i]=i>=252?6:i>=248?5:i>=240?4:i>=224?3:i>=192?2:1;_utf8len[254]=_utf8len[254]=1,exports.string2buf=function(str){var buf,c,c2,m_pos,i,str_len=str.length,buf_len=0;for(m_pos=0;str_len>m_pos;m_pos++)c=str.charCodeAt(m_pos),55296===(64512&c)&&str_len>m_pos+1&&(c2=str.charCodeAt(m_pos+1),56320===(64512&c2)&&(c=65536+(c-55296<<10)+(c2-56320),m_pos++)),buf_len+=128>c?1:2048>c?2:65536>c?3:4;for(buf=new utils.Buf8(buf_len),i=0,m_pos=0;buf_len>i;m_pos++)c=str.charCodeAt(m_pos),55296===(64512&c)&&str_len>m_pos+1&&(c2=str.charCodeAt(m_pos+1),56320===(64512&c2)&&(c=65536+(c-55296<<10)+(c2-56320),m_pos++)),128>c?buf[i++]=c:2048>c?(buf[i++]=192|c>>>6,buf[i++]=128|63&c):65536>c?(buf[i++]=224|c>>>12,buf[i++]=128|c>>>6&63,buf[i++]=128|63&c):(buf[i++]=240|c>>>18,buf[i++]=128|c>>>12&63,buf[i++]=128|c>>>6&63,buf[i++]=128|63&c);return buf},exports.buf2binstring=function(buf){return buf2binstring(buf,buf.length)},exports.binstring2buf=function(str){for(var buf=new utils.Buf8(str.length),i=0,len=buf.length;len>i;i++)buf[i]=str.charCodeAt(i);return buf},exports.buf2string=function(buf,max){var i,out,c,c_len,len=max||buf.length,utf16buf=new Array(2*len);for(out=0,i=0;len>i;)if(c=buf[i++],128>c)utf16buf[out++]=c;else if(c_len=_utf8len[c],c_len>4)utf16buf[out++]=65533,i+=c_len-1;else{for(c&=2===c_len?31:3===c_len?15:7;c_len>1&&len>i;)c=c<<6|63&buf[i++],c_len--;c_len>1?utf16buf[out++]=65533:65536>c?utf16buf[out++]=c:(c-=65536,utf16buf[out++]=55296|c>>10&1023,utf16buf[out++]=56320|1023&c)}return buf2binstring(utf16buf,out)},exports.utf8border=function(buf,max){var pos;for(max=max||buf.length,max>buf.length&&(max=buf.length),pos=max-1;pos>=0&&128===(192&buf[pos]);)pos--;return 0>pos?max:0===pos?max:pos+_utf8len[buf[pos]]>max?pos:max}},{"./common":98}],100:[function(require,module){"use strict";function adler32(adler,buf,len,pos){for(var s1=65535&adler|0,s2=adler>>>16&65535|0,n=0;0!==len;){n=len>2e3?2e3:len,len-=n;do s1=s1+buf[pos++]|0,s2=s2+s1|0;while(--n);s1%=65521,s2%=65521}return s1|s2<<16|0}module.exports=adler32},{}],101:[function(require,module){module.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],102:[function(require,module){"use strict";function makeTable(){for(var c,table=[],n=0;256>n;n++){c=n;for(var k=0;8>k;k++)c=1&c?3988292384^c>>>1:c>>>1;table[n]=c}return table}function crc32(crc,buf,len,pos){var t=crcTable,end=pos+len;crc=-1^crc;for(var i=pos;end>i;i++)crc=crc>>>8^t[255&(crc^buf[i])];return-1^crc}var crcTable=makeTable();module.exports=crc32},{}],103:[function(require,module,exports){"use strict";function err(strm,errorCode){return strm.msg=msg[errorCode],errorCode}function rank(f){return(f<<1)-(f>4?9:0)}function zero(buf){for(var len=buf.length;--len>=0;)buf[len]=0}function flush_pending(strm){var s=strm.state,len=s.pending;len>strm.avail_out&&(len=strm.avail_out),0!==len&&(utils.arraySet(strm.output,s.pending_buf,s.pending_out,len,strm.next_out),strm.next_out+=len,s.pending_out+=len,strm.total_out+=len,strm.avail_out-=len,s.pending-=len,0===s.pending&&(s.pending_out=0))}function flush_block_only(s,last){trees._tr_flush_block(s,s.block_start>=0?s.block_start:-1,s.strstart-s.block_start,last),s.block_start=s.strstart,flush_pending(s.strm)}function put_byte(s,b){s.pending_buf[s.pending++]=b}function putShortMSB(s,b){s.pending_buf[s.pending++]=b>>>8&255,s.pending_buf[s.pending++]=255&b}function read_buf(strm,buf,start,size){var len=strm.avail_in;return len>size&&(len=size),0===len?0:(strm.avail_in-=len,utils.arraySet(buf,strm.input,strm.next_in,len,start),1===strm.state.wrap?strm.adler=adler32(strm.adler,buf,len,start):2===strm.state.wrap&&(strm.adler=crc32(strm.adler,buf,len,start)),strm.next_in+=len,strm.total_in+=len,len)}function longest_match(s,cur_match){var match,len,chain_length=s.max_chain_length,scan=s.strstart,best_len=s.prev_length,nice_match=s.nice_match,limit=s.strstart>s.w_size-MIN_LOOKAHEAD?s.strstart-(s.w_size-MIN_LOOKAHEAD):0,_win=s.window,wmask=s.w_mask,prev=s.prev,strend=s.strstart+MAX_MATCH,scan_end1=_win[scan+best_len-1],scan_end=_win[scan+best_len];s.prev_length>=s.good_match&&(chain_length>>=2),nice_match>s.lookahead&&(nice_match=s.lookahead);do if(match=cur_match,_win[match+best_len]===scan_end&&_win[match+best_len-1]===scan_end1&&_win[match]===_win[scan]&&_win[++match]===_win[scan+1]){scan+=2,match++;do;while(_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&strend>scan);if(len=MAX_MATCH-(strend-scan),scan=strend-MAX_MATCH,len>best_len){if(s.match_start=cur_match,best_len=len,len>=nice_match)break;scan_end1=_win[scan+best_len-1],scan_end=_win[scan+best_len]}}while((cur_match=prev[cur_match&wmask])>limit&&0!==--chain_length);return best_len<=s.lookahead?best_len:s.lookahead}function fill_window(s){var p,n,m,more,str,_w_size=s.w_size;do{if(more=s.window_size-s.lookahead-s.strstart,s.strstart>=_w_size+(_w_size-MIN_LOOKAHEAD)){utils.arraySet(s.window,s.window,_w_size,_w_size,0),s.match_start-=_w_size,s.strstart-=_w_size,s.block_start-=_w_size,n=s.hash_size,p=n;do m=s.head[--p],s.head[p]=m>=_w_size?m-_w_size:0;while(--n);n=_w_size,p=n;do m=s.prev[--p],s.prev[p]=m>=_w_size?m-_w_size:0;while(--n);more+=_w_size}if(0===s.strm.avail_in)break;if(n=read_buf(s.strm,s.window,s.strstart+s.lookahead,more),s.lookahead+=n,s.lookahead+s.insert>=MIN_MATCH)for(str=s.strstart-s.insert,s.ins_h=s.window[str],s.ins_h=(s.ins_h<s.pending_buf_size-5&&(max_block_size=s.pending_buf_size-5);;){if(s.lookahead<=1){if(fill_window(s),0===s.lookahead&&flush===Z_NO_FLUSH)return BS_NEED_MORE;if(0===s.lookahead)break}s.strstart+=s.lookahead,s.lookahead=0;var max_start=s.block_start+max_block_size;if((0===s.strstart||s.strstart>=max_start)&&(s.lookahead=s.strstart-max_start,s.strstart=max_start,flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE;if(s.strstart-s.block_start>=s.w_size-MIN_LOOKAHEAD&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.strstart>s.block_start&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_NEED_MORE}function deflate_fast(s,flush){for(var hash_head,bflush;;){if(s.lookahead=MIN_MATCH&&(s.ins_h=(s.ins_h<=MIN_MATCH)if(bflush=trees._tr_tally(s,s.strstart-s.match_start,s.match_length-MIN_MATCH),s.lookahead-=s.match_length,s.match_length<=s.max_lazy_match&&s.lookahead>=MIN_MATCH){s.match_length--;do s.strstart++,s.ins_h=(s.ins_h<=MIN_MATCH&&(s.ins_h=(s.ins_h<4096)&&(s.match_length=MIN_MATCH-1)),s.prev_length>=MIN_MATCH&&s.match_length<=s.prev_length){max_insert=s.strstart+s.lookahead-MIN_MATCH,bflush=trees._tr_tally(s,s.strstart-1-s.prev_match,s.prev_length-MIN_MATCH),s.lookahead-=s.prev_length-1,s.prev_length-=2;do++s.strstart<=max_insert&&(s.ins_h=(s.ins_h<=MIN_MATCH&&s.strstart>0&&(scan=s.strstart-1,prev=_win[scan],prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan])){strend=s.strstart+MAX_MATCH;do;while(prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&strend>scan);s.match_length=MAX_MATCH-(strend-scan),s.match_length>s.lookahead&&(s.match_length=s.lookahead)}if(s.match_length>=MIN_MATCH?(bflush=trees._tr_tally(s,1,s.match_length-MIN_MATCH),s.lookahead-=s.match_length,s.strstart+=s.match_length,s.match_length=0):(bflush=trees._tr_tally(s,0,s.window[s.strstart]),s.lookahead--,s.strstart++),bflush&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.last_lit&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE}function deflate_huff(s,flush){for(var bflush;;){if(0===s.lookahead&&(fill_window(s),0===s.lookahead)){if(flush===Z_NO_FLUSH)return BS_NEED_MORE;break}if(s.match_length=0,bflush=trees._tr_tally(s,0,s.window[s.strstart]),s.lookahead--,s.strstart++,bflush&&(flush_block_only(s,!1),0===s.strm.avail_out))return BS_NEED_MORE}return s.insert=0,flush===Z_FINISH?(flush_block_only(s,!0),0===s.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):s.last_lit&&(flush_block_only(s,!1),0===s.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE}function lm_init(s){s.window_size=2*s.w_size,zero(s.head),s.max_lazy_match=configuration_table[s.level].max_lazy,s.good_match=configuration_table[s.level].good_length,s.nice_match=configuration_table[s.level].nice_length,s.max_chain_length=configuration_table[s.level].max_chain,s.strstart=0,s.block_start=0,s.lookahead=0,s.insert=0,s.match_length=s.prev_length=MIN_MATCH-1,s.match_available=0,s.ins_h=0}function DeflateState(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Z_DEFLATED,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new utils.Buf16(2*HEAP_SIZE),this.dyn_dtree=new utils.Buf16(2*(2*D_CODES+1)),this.bl_tree=new utils.Buf16(2*(2*BL_CODES+1)),zero(this.dyn_ltree),zero(this.dyn_dtree),zero(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new utils.Buf16(MAX_BITS+1),this.heap=new utils.Buf16(2*L_CODES+1),zero(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new utils.Buf16(2*L_CODES+1),zero(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function deflateResetKeep(strm){var s;return strm&&strm.state?(strm.total_in=strm.total_out=0,strm.data_type=Z_UNKNOWN,s=strm.state,s.pending=0,s.pending_out=0,s.wrap<0&&(s.wrap=-s.wrap),s.status=s.wrap?INIT_STATE:BUSY_STATE,strm.adler=2===s.wrap?0:1,s.last_flush=Z_NO_FLUSH,trees._tr_init(s),Z_OK):err(strm,Z_STREAM_ERROR) -}function deflateReset(strm){var ret=deflateResetKeep(strm);return ret===Z_OK&&lm_init(strm.state),ret}function deflateSetHeader(strm,head){return strm&&strm.state?2!==strm.state.wrap?Z_STREAM_ERROR:(strm.state.gzhead=head,Z_OK):Z_STREAM_ERROR}function deflateInit2(strm,level,method,windowBits,memLevel,strategy){if(!strm)return Z_STREAM_ERROR;var wrap=1;if(level===Z_DEFAULT_COMPRESSION&&(level=6),0>windowBits?(wrap=0,windowBits=-windowBits):windowBits>15&&(wrap=2,windowBits-=16),1>memLevel||memLevel>MAX_MEM_LEVEL||method!==Z_DEFLATED||8>windowBits||windowBits>15||0>level||level>9||0>strategy||strategy>Z_FIXED)return err(strm,Z_STREAM_ERROR);8===windowBits&&(windowBits=9);var s=new DeflateState;return strm.state=s,s.strm=strm,s.wrap=wrap,s.gzhead=null,s.w_bits=windowBits,s.w_size=1<>1,s.l_buf=3*s.lit_bufsize,s.level=level,s.strategy=strategy,s.method=method,deflateReset(strm)}function deflateInit(strm,level){return deflateInit2(strm,level,Z_DEFLATED,MAX_WBITS,DEF_MEM_LEVEL,Z_DEFAULT_STRATEGY)}function deflate(strm,flush){var old_flush,s,beg,val;if(!strm||!strm.state||flush>Z_BLOCK||0>flush)return strm?err(strm,Z_STREAM_ERROR):Z_STREAM_ERROR;if(s=strm.state,!strm.output||!strm.input&&0!==strm.avail_in||s.status===FINISH_STATE&&flush!==Z_FINISH)return err(strm,0===strm.avail_out?Z_BUF_ERROR:Z_STREAM_ERROR);if(s.strm=strm,old_flush=s.last_flush,s.last_flush=flush,s.status===INIT_STATE)if(2===s.wrap)strm.adler=0,put_byte(s,31),put_byte(s,139),put_byte(s,8),s.gzhead?(put_byte(s,(s.gzhead.text?1:0)+(s.gzhead.hcrc?2:0)+(s.gzhead.extra?4:0)+(s.gzhead.name?8:0)+(s.gzhead.comment?16:0)),put_byte(s,255&s.gzhead.time),put_byte(s,s.gzhead.time>>8&255),put_byte(s,s.gzhead.time>>16&255),put_byte(s,s.gzhead.time>>24&255),put_byte(s,9===s.level?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0),put_byte(s,255&s.gzhead.os),s.gzhead.extra&&s.gzhead.extra.length&&(put_byte(s,255&s.gzhead.extra.length),put_byte(s,s.gzhead.extra.length>>8&255)),s.gzhead.hcrc&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending,0)),s.gzindex=0,s.status=EXTRA_STATE):(put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,0),put_byte(s,9===s.level?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0),put_byte(s,OS_CODE),s.status=BUSY_STATE);else{var header=Z_DEFLATED+(s.w_bits-8<<4)<<8,level_flags=-1;level_flags=s.strategy>=Z_HUFFMAN_ONLY||s.level<2?0:s.level<6?1:6===s.level?2:3,header|=level_flags<<6,0!==s.strstart&&(header|=PRESET_DICT),header+=31-header%31,s.status=BUSY_STATE,putShortMSB(s,header),0!==s.strstart&&(putShortMSB(s,strm.adler>>>16),putShortMSB(s,65535&strm.adler)),strm.adler=1}if(s.status===EXTRA_STATE)if(s.gzhead.extra){for(beg=s.pending;s.gzindex<(65535&s.gzhead.extra.length)&&(s.pending!==s.pending_buf_size||(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending!==s.pending_buf_size));)put_byte(s,255&s.gzhead.extra[s.gzindex]),s.gzindex++;s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),s.gzindex===s.gzhead.extra.length&&(s.gzindex=0,s.status=NAME_STATE)}else s.status=NAME_STATE;if(s.status===NAME_STATE)if(s.gzhead.name){beg=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending===s.pending_buf_size)){val=1;break}val=s.gzindexbeg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),0===val&&(s.gzindex=0,s.status=COMMENT_STATE)}else s.status=COMMENT_STATE;if(s.status===COMMENT_STATE)if(s.gzhead.comment){beg=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>beg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),flush_pending(strm),beg=s.pending,s.pending===s.pending_buf_size)){val=1;break}val=s.gzindexbeg&&(strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)),0===val&&(s.status=HCRC_STATE)}else s.status=HCRC_STATE;if(s.status===HCRC_STATE&&(s.gzhead.hcrc?(s.pending+2>s.pending_buf_size&&flush_pending(strm),s.pending+2<=s.pending_buf_size&&(put_byte(s,255&strm.adler),put_byte(s,strm.adler>>8&255),strm.adler=0,s.status=BUSY_STATE)):s.status=BUSY_STATE),0!==s.pending){if(flush_pending(strm),0===strm.avail_out)return s.last_flush=-1,Z_OK}else if(0===strm.avail_in&&rank(flush)<=rank(old_flush)&&flush!==Z_FINISH)return err(strm,Z_BUF_ERROR);if(s.status===FINISH_STATE&&0!==strm.avail_in)return err(strm,Z_BUF_ERROR);if(0!==strm.avail_in||0!==s.lookahead||flush!==Z_NO_FLUSH&&s.status!==FINISH_STATE){var bstate=s.strategy===Z_HUFFMAN_ONLY?deflate_huff(s,flush):s.strategy===Z_RLE?deflate_rle(s,flush):configuration_table[s.level].func(s,flush);if((bstate===BS_FINISH_STARTED||bstate===BS_FINISH_DONE)&&(s.status=FINISH_STATE),bstate===BS_NEED_MORE||bstate===BS_FINISH_STARTED)return 0===strm.avail_out&&(s.last_flush=-1),Z_OK;if(bstate===BS_BLOCK_DONE&&(flush===Z_PARTIAL_FLUSH?trees._tr_align(s):flush!==Z_BLOCK&&(trees._tr_stored_block(s,0,0,!1),flush===Z_FULL_FLUSH&&(zero(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),flush_pending(strm),0===strm.avail_out))return s.last_flush=-1,Z_OK}return flush!==Z_FINISH?Z_OK:s.wrap<=0?Z_STREAM_END:(2===s.wrap?(put_byte(s,255&strm.adler),put_byte(s,strm.adler>>8&255),put_byte(s,strm.adler>>16&255),put_byte(s,strm.adler>>24&255),put_byte(s,255&strm.total_in),put_byte(s,strm.total_in>>8&255),put_byte(s,strm.total_in>>16&255),put_byte(s,strm.total_in>>24&255)):(putShortMSB(s,strm.adler>>>16),putShortMSB(s,65535&strm.adler)),flush_pending(strm),s.wrap>0&&(s.wrap=-s.wrap),0!==s.pending?Z_OK:Z_STREAM_END)}function deflateEnd(strm){var status;return strm&&strm.state?(status=strm.state.status,status!==INIT_STATE&&status!==EXTRA_STATE&&status!==NAME_STATE&&status!==COMMENT_STATE&&status!==HCRC_STATE&&status!==BUSY_STATE&&status!==FINISH_STATE?err(strm,Z_STREAM_ERROR):(strm.state=null,status===BUSY_STATE?err(strm,Z_DATA_ERROR):Z_OK)):Z_STREAM_ERROR}var configuration_table,utils=require("../utils/common"),trees=require("./trees"),adler32=require("./adler32"),crc32=require("./crc32"),msg=require("./messages"),Z_NO_FLUSH=0,Z_PARTIAL_FLUSH=1,Z_FULL_FLUSH=3,Z_FINISH=4,Z_BLOCK=5,Z_OK=0,Z_STREAM_END=1,Z_STREAM_ERROR=-2,Z_DATA_ERROR=-3,Z_BUF_ERROR=-5,Z_DEFAULT_COMPRESSION=-1,Z_FILTERED=1,Z_HUFFMAN_ONLY=2,Z_RLE=3,Z_FIXED=4,Z_DEFAULT_STRATEGY=0,Z_UNKNOWN=2,Z_DEFLATED=8,MAX_MEM_LEVEL=9,MAX_WBITS=15,DEF_MEM_LEVEL=8,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,MIN_MATCH=3,MAX_MATCH=258,MIN_LOOKAHEAD=MAX_MATCH+MIN_MATCH+1,PRESET_DICT=32,INIT_STATE=42,EXTRA_STATE=69,NAME_STATE=73,COMMENT_STATE=91,HCRC_STATE=103,BUSY_STATE=113,FINISH_STATE=666,BS_NEED_MORE=1,BS_BLOCK_DONE=2,BS_FINISH_STARTED=3,BS_FINISH_DONE=4,OS_CODE=3,Config=function(good_length,max_lazy,nice_length,max_chain,func){this.good_length=good_length,this.max_lazy=max_lazy,this.nice_length=nice_length,this.max_chain=max_chain,this.func=func};configuration_table=[new Config(0,0,0,0,deflate_stored),new Config(4,4,8,4,deflate_fast),new Config(4,5,16,8,deflate_fast),new Config(4,6,32,32,deflate_fast),new Config(4,4,16,16,deflate_slow),new Config(8,16,32,32,deflate_slow),new Config(8,16,128,128,deflate_slow),new Config(8,32,128,256,deflate_slow),new Config(32,128,258,1024,deflate_slow),new Config(32,258,258,4096,deflate_slow)],exports.deflateInit=deflateInit,exports.deflateInit2=deflateInit2,exports.deflateReset=deflateReset,exports.deflateResetKeep=deflateResetKeep,exports.deflateSetHeader=deflateSetHeader,exports.deflate=deflate,exports.deflateEnd=deflateEnd,exports.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":98,"./adler32":100,"./crc32":102,"./messages":108,"./trees":109}],104:[function(require,module){"use strict";function GZheader(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}module.exports=GZheader},{}],105:[function(require,module){"use strict";var BAD=30,TYPE=12;module.exports=function(strm,start){var state,_in,last,_out,beg,end,dmax,wsize,whave,wnext,window,hold,bits,lcode,dcode,lmask,dmask,here,op,len,dist,from,from_source,input,output;state=strm.state,_in=strm.next_in,input=strm.input,last=_in+(strm.avail_in-5),_out=strm.next_out,output=strm.output,beg=_out-(start-strm.avail_out),end=_out+(strm.avail_out-257),dmax=state.dmax,wsize=state.wsize,whave=state.whave,wnext=state.wnext,window=state.window,hold=state.hold,bits=state.bits,lcode=state.lencode,dcode=state.distcode,lmask=(1<bits&&(hold+=input[_in++]<>>24,hold>>>=op,bits-=op,op=here>>>16&255,0===op)output[_out++]=65535&here;else{if(!(16&op)){if(0===(64&op)){here=lcode[(65535&here)+(hold&(1<bits&&(hold+=input[_in++]<>>=op,bits-=op),15>bits&&(hold+=input[_in++]<>>24,hold>>>=op,bits-=op,op=here>>>16&255,!(16&op)){if(0===(64&op)){here=dcode[(65535&here)+(hold&(1<bits&&(hold+=input[_in++]<bits&&(hold+=input[_in++]<dmax){strm.msg="invalid distance too far back",state.mode=BAD;break top}if(hold>>>=op,bits-=op,op=_out-beg,dist>op){if(op=dist-op,op>whave&&state.sane){strm.msg="invalid distance too far back",state.mode=BAD;break top}if(from=0,from_source=window,0===wnext){if(from+=wsize-op,len>op){len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}}else if(op>wnext){if(from+=wsize+wnext-op,op-=wnext,len>op){len-=op;do output[_out++]=window[from++];while(--op);if(from=0,len>wnext){op=wnext,len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}}}else if(from+=wnext-op,len>op){len-=op;do output[_out++]=window[from++];while(--op);from=_out-dist,from_source=output}for(;len>2;)output[_out++]=from_source[from++],output[_out++]=from_source[from++],output[_out++]=from_source[from++],len-=3;len&&(output[_out++]=from_source[from++],len>1&&(output[_out++]=from_source[from++]))}else{from=_out-dist;do output[_out++]=output[from++],output[_out++]=output[from++],output[_out++]=output[from++],len-=3;while(len>2);len&&(output[_out++]=output[from++],len>1&&(output[_out++]=output[from++]))}break}}break}}while(last>_in&&end>_out);len=bits>>3,_in-=len,bits-=len<<3,hold&=(1<_in?5+(last-_in):5-(_in-last),strm.avail_out=end>_out?257+(end-_out):257-(_out-end),state.hold=hold,state.bits=bits}},{}],106:[function(require,module,exports){"use strict";function ZSWAP32(q){return(q>>>24&255)+(q>>>8&65280)+((65280&q)<<8)+((255&q)<<24)}function InflateState(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new utils.Buf16(320),this.work=new utils.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function inflateResetKeep(strm){var state;return strm&&strm.state?(state=strm.state,strm.total_in=strm.total_out=state.total=0,strm.msg="",state.wrap&&(strm.adler=1&state.wrap),state.mode=HEAD,state.last=0,state.havedict=0,state.dmax=32768,state.head=null,state.hold=0,state.bits=0,state.lencode=state.lendyn=new utils.Buf32(ENOUGH_LENS),state.distcode=state.distdyn=new utils.Buf32(ENOUGH_DISTS),state.sane=1,state.back=-1,Z_OK):Z_STREAM_ERROR}function inflateReset(strm){var state;return strm&&strm.state?(state=strm.state,state.wsize=0,state.whave=0,state.wnext=0,inflateResetKeep(strm)):Z_STREAM_ERROR}function inflateReset2(strm,windowBits){var wrap,state;return strm&&strm.state?(state=strm.state,0>windowBits?(wrap=0,windowBits=-windowBits):(wrap=(windowBits>>4)+1,48>windowBits&&(windowBits&=15)),windowBits&&(8>windowBits||windowBits>15)?Z_STREAM_ERROR:(null!==state.window&&state.wbits!==windowBits&&(state.window=null),state.wrap=wrap,state.wbits=windowBits,inflateReset(strm))):Z_STREAM_ERROR}function inflateInit2(strm,windowBits){var ret,state;return strm?(state=new InflateState,strm.state=state,state.window=null,ret=inflateReset2(strm,windowBits),ret!==Z_OK&&(strm.state=null),ret):Z_STREAM_ERROR}function inflateInit(strm){return inflateInit2(strm,DEF_WBITS)}function fixedtables(state){if(virgin){var sym;for(lenfix=new utils.Buf32(512),distfix=new utils.Buf32(32),sym=0;144>sym;)state.lens[sym++]=8;for(;256>sym;)state.lens[sym++]=9;for(;280>sym;)state.lens[sym++]=7;for(;288>sym;)state.lens[sym++]=8;for(inflate_table(LENS,state.lens,0,288,lenfix,0,state.work,{bits:9}),sym=0;32>sym;)state.lens[sym++]=5;inflate_table(DISTS,state.lens,0,32,distfix,0,state.work,{bits:5}),virgin=!1}state.lencode=lenfix,state.lenbits=9,state.distcode=distfix,state.distbits=5}function updatewindow(strm,src,end,copy){var dist,state=strm.state;return null===state.window&&(state.wsize=1<=state.wsize?(utils.arraySet(state.window,src,end-state.wsize,state.wsize,0),state.wnext=0,state.whave=state.wsize):(dist=state.wsize-state.wnext,dist>copy&&(dist=copy),utils.arraySet(state.window,src,end-copy,dist,state.wnext),copy-=dist,copy?(utils.arraySet(state.window,src,end-copy,copy,0),state.wnext=copy,state.whave=state.wsize):(state.wnext+=dist,state.wnext===state.wsize&&(state.wnext=0),state.whavebits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,state.check=crc32(state.check,hbuf,2,0),hold=0,bits=0,state.mode=FLAGS;break}if(state.flags=0,state.head&&(state.head.done=!1),!(1&state.wrap)||(((255&hold)<<8)+(hold>>8))%31){strm.msg="incorrect header check",state.mode=BAD;break}if((15&hold)!==Z_DEFLATED){strm.msg="unknown compression method",state.mode=BAD;break}if(hold>>>=4,bits-=4,len=(15&hold)+8,0===state.wbits)state.wbits=len;else if(len>state.wbits){strm.msg="invalid window size",state.mode=BAD;break}state.dmax=1<bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>8&1),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=TIME;case TIME:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,hbuf[2]=hold>>>16&255,hbuf[3]=hold>>>24&255,state.check=crc32(state.check,hbuf,4,0)),hold=0,bits=0,state.mode=OS;case OS:for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>8),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=EXLEN;case EXLEN:if(1024&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0}else state.head&&(state.head.extra=null);state.mode=EXTRA;case EXTRA:if(1024&state.flags&&(copy=state.length,copy>have&&(copy=have),copy&&(state.head&&(len=state.head.extra_len-state.length,state.head.extra||(state.head.extra=new Array(state.head.extra_len)),utils.arraySet(state.head.extra,input,next,copy,len)),512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,state.length-=copy),state.length))break inf_leave;state.length=0,state.mode=NAME;case NAME:if(2048&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.name+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.name=null);state.length=0,state.mode=COMMENT;case COMMENT:if(4096&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.comment+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.comment=null);state.mode=HCRC;case HCRC:if(512&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>9&1,state.head.done=!0),strm.adler=state.check=0,state.mode=TYPE;break;case DICTID:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=7&bits,bits-=7&bits,state.mode=CHECK;break}for(;3>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=1,bits-=1,3&hold){case 0:state.mode=STORED;break;case 1:if(fixedtables(state),state.mode=LEN_,flush===Z_TREES){hold>>>=2,bits-=2;break inf_leave}break;case 2:state.mode=TABLE;break;case 3:strm.msg="invalid block type",state.mode=BAD}hold>>>=2,bits-=2;break;case STORED:for(hold>>>=7&bits,bits-=7&bits;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>16^65535)){strm.msg="invalid stored block lengths",state.mode=BAD;break}if(state.length=65535&hold,hold=0,bits=0,state.mode=COPY_,flush===Z_TREES)break inf_leave;case COPY_:state.mode=COPY;case COPY:if(copy=state.length){if(copy>have&&(copy=have),copy>left&&(copy=left),0===copy)break inf_leave;utils.arraySet(output,input,next,copy,put),have-=copy,next+=copy,left-=copy,put+=copy,state.length-=copy;break}state.mode=TYPE;break;case TABLE:for(;14>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=5,bits-=5,state.ndist=(31&hold)+1,hold>>>=5,bits-=5,state.ncode=(15&hold)+4,hold>>>=4,bits-=4,state.nlen>286||state.ndist>30){strm.msg="too many length or distance symbols",state.mode=BAD;break}state.have=0,state.mode=LENLENS;case LENLENS:for(;state.havebits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=3,bits-=3}for(;state.have<19;)state.lens[order[state.have++]]=0;if(state.lencode=state.lendyn,state.lenbits=7,opts={bits:state.lenbits},ret=inflate_table(CODES,state.lens,0,19,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid code lengths set",state.mode=BAD;break}state.have=0,state.mode=CODELENS;case CODELENS:for(;state.have>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<here_val)hold>>>=here_bits,bits-=here_bits,state.lens[state.have++]=here_val;else{if(16===here_val){for(n=here_bits+2;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,0===state.have){strm.msg="invalid bit length repeat",state.mode=BAD;break}len=state.lens[state.have-1],copy=3+(3&hold),hold>>>=2,bits-=2}else if(17===here_val){for(n=here_bits+3;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=3+(7&hold),hold>>>=3,bits-=3}else{for(n=here_bits+7;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=11+(127&hold),hold>>>=7,bits-=7}if(state.have+copy>state.nlen+state.ndist){strm.msg="invalid bit length repeat",state.mode=BAD;break}for(;copy--;)state.lens[state.have++]=len}}if(state.mode===BAD)break;if(0===state.lens[256]){strm.msg="invalid code -- missing end-of-block",state.mode=BAD;break}if(state.lenbits=9,opts={bits:state.lenbits},ret=inflate_table(LENS,state.lens,0,state.nlen,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid literal/lengths set",state.mode=BAD;break}if(state.distbits=6,state.distcode=state.distdyn,opts={bits:state.distbits},ret=inflate_table(DISTS,state.lens,state.nlen,state.ndist,state.distcode,0,state.work,opts),state.distbits=opts.bits,ret){strm.msg="invalid distances set",state.mode=BAD;break}if(state.mode=LEN_,flush===Z_TREES)break inf_leave;case LEN_:state.mode=LEN;case LEN:if(have>=6&&left>=258){strm.next_out=put,strm.avail_out=left,strm.next_in=next,strm.avail_in=have,state.hold=hold,state.bits=bits,inflate_fast(strm,_out),put=strm.next_out,output=strm.output,left=strm.avail_out,next=strm.next_in,input=strm.input,have=strm.avail_in,hold=state.hold,bits=state.bits,state.mode===TYPE&&(state.back=-1);break}for(state.back=0;here=state.lencode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,state.length=here_val,0===here_op){state.mode=LIT;break}if(32&here_op){state.back=-1,state.mode=TYPE;break}if(64&here_op){strm.msg="invalid literal/length code",state.mode=BAD;break}state.extra=15&here_op,state.mode=LENEXT;case LENEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}state.was=state.length,state.mode=DIST;case DIST:for(;here=state.distcode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,64&here_op){strm.msg="invalid distance code",state.mode=BAD;break}state.offset=here_val,state.extra=15&here_op,state.mode=DISTEXT;case DISTEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}if(state.offset>state.dmax){strm.msg="invalid distance too far back",state.mode=BAD;break}state.mode=MATCH;case MATCH:if(0===left)break inf_leave;if(copy=_out-left,state.offset>copy){if(copy=state.offset-copy,copy>state.whave&&state.sane){strm.msg="invalid distance too far back",state.mode=BAD;break}copy>state.wnext?(copy-=state.wnext,from=state.wsize-copy):from=state.wnext-copy,copy>state.length&&(copy=state.length),from_source=state.window}else from_source=output,from=put-state.offset,copy=state.length;copy>left&&(copy=left),left-=copy,state.length-=copy;do output[put++]=from_source[from++];while(--copy);0===state.length&&(state.mode=LEN);break;case LIT:if(0===left)break inf_leave;output[put++]=state.length,left--,state.mode=LEN;break;case CHECK:if(state.wrap){for(;32>bits;){if(0===have)break inf_leave;have--,hold|=input[next++]<bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<=len;len++)count[len]=0;for(sym=0;codes>sym;sym++)count[lens[lens_index+sym]]++;for(root=bits,max=MAXBITS;max>=1&&0===count[max];max--);if(root>max&&(root=max),0===max)return table[table_index++]=20971520,table[table_index++]=20971520,opts.bits=1,0;for(min=1;max>min&&0===count[min];min++);for(min>root&&(root=min),left=1,len=1;MAXBITS>=len;len++)if(left<<=1,left-=count[len],0>left)return-1;if(left>0&&(type===CODES||1!==max))return-1;for(offs[1]=0,len=1;MAXBITS>len;len++)offs[len+1]=offs[len]+count[len];for(sym=0;codes>sym;sym++)0!==lens[lens_index+sym]&&(work[offs[lens[lens_index+sym]]++]=sym);if(type===CODES?(base=extra=work,end=19):type===LENS?(base=lbase,base_index-=257,extra=lext,extra_index-=257,end=256):(base=dbase,extra=dext,end=-1),huff=0,sym=0,len=min,next=table_index,curr=root,drop=0,low=-1,used=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;for(var i=0;;){i++,here_bits=len-drop,work[sym]end?(here_op=extra[extra_index+work[sym]],here_val=base[base_index+work[sym]]):(here_op=96,here_val=0),incr=1<>drop)+fill]=here_bits<<24|here_op<<16|here_val|0;while(0!==fill);for(incr=1<>=1;if(0!==incr?(huff&=incr-1,huff+=incr):huff=0,sym++,0===--count[len]){if(len===max)break;len=lens[lens_index+work[sym]]}if(len>root&&(huff&mask)!==low){for(0===drop&&(drop=root),next+=min,curr=len-drop,left=1<curr+drop&&(left-=count[curr+drop],!(0>=left));)curr++,left<<=1;if(used+=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;low=huff&mask,table[low]=root<<24|curr<<16|next-table_index|0 -}}return 0!==huff&&(table[next+huff]=len-drop<<24|64<<16|0),opts.bits=root,0}},{"../utils/common":98}],108:[function(require,module){"use strict";module.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],109:[function(require,module,exports){"use strict";function zero(buf){for(var len=buf.length;--len>=0;)buf[len]=0}function d_code(dist){return 256>dist?_dist_code[dist]:_dist_code[256+(dist>>>7)]}function put_short(s,w){s.pending_buf[s.pending++]=255&w,s.pending_buf[s.pending++]=w>>>8&255}function send_bits(s,value,length){s.bi_valid>Buf_size-length?(s.bi_buf|=value<>Buf_size-s.bi_valid,s.bi_valid+=length-Buf_size):(s.bi_buf|=value<>>=1,res<<=1;while(--len>0);return res>>>1}function bi_flush(s){16===s.bi_valid?(put_short(s,s.bi_buf),s.bi_buf=0,s.bi_valid=0):s.bi_valid>=8&&(s.pending_buf[s.pending++]=255&s.bi_buf,s.bi_buf>>=8,s.bi_valid-=8)}function gen_bitlen(s,desc){var h,n,m,bits,xbits,f,tree=desc.dyn_tree,max_code=desc.max_code,stree=desc.stat_desc.static_tree,has_stree=desc.stat_desc.has_stree,extra=desc.stat_desc.extra_bits,base=desc.stat_desc.extra_base,max_length=desc.stat_desc.max_length,overflow=0;for(bits=0;MAX_BITS>=bits;bits++)s.bl_count[bits]=0;for(tree[2*s.heap[s.heap_max]+1]=0,h=s.heap_max+1;HEAP_SIZE>h;h++)n=s.heap[h],bits=tree[2*tree[2*n+1]+1]+1,bits>max_length&&(bits=max_length,overflow++),tree[2*n+1]=bits,n>max_code||(s.bl_count[bits]++,xbits=0,n>=base&&(xbits=extra[n-base]),f=tree[2*n],s.opt_len+=f*(bits+xbits),has_stree&&(s.static_len+=f*(stree[2*n+1]+xbits)));if(0!==overflow){do{for(bits=max_length-1;0===s.bl_count[bits];)bits--;s.bl_count[bits]--,s.bl_count[bits+1]+=2,s.bl_count[max_length]--,overflow-=2}while(overflow>0);for(bits=max_length;0!==bits;bits--)for(n=s.bl_count[bits];0!==n;)m=s.heap[--h],m>max_code||(tree[2*m+1]!==bits&&(s.opt_len+=(bits-tree[2*m+1])*tree[2*m],tree[2*m+1]=bits),n--)}}function gen_codes(tree,max_code,bl_count){var bits,n,next_code=new Array(MAX_BITS+1),code=0;for(bits=1;MAX_BITS>=bits;bits++)next_code[bits]=code=code+bl_count[bits-1]<<1;for(n=0;max_code>=n;n++){var len=tree[2*n+1];0!==len&&(tree[2*n]=bi_reverse(next_code[len]++,len))}}function tr_static_init(){var n,bits,length,code,dist,bl_count=new Array(MAX_BITS+1);for(length=0,code=0;LENGTH_CODES-1>code;code++)for(base_length[code]=length,n=0;n<1<code;code++)for(base_dist[code]=dist,n=0;n<1<>=7;D_CODES>code;code++)for(base_dist[code]=dist<<7,n=0;n<1<=bits;bits++)bl_count[bits]=0;for(n=0;143>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(;255>=n;)static_ltree[2*n+1]=9,n++,bl_count[9]++;for(;279>=n;)static_ltree[2*n+1]=7,n++,bl_count[7]++;for(;287>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(gen_codes(static_ltree,L_CODES+1,bl_count),n=0;D_CODES>n;n++)static_dtree[2*n+1]=5,static_dtree[2*n]=bi_reverse(n,5);static_l_desc=new StaticTreeDesc(static_ltree,extra_lbits,LITERALS+1,L_CODES,MAX_BITS),static_d_desc=new StaticTreeDesc(static_dtree,extra_dbits,0,D_CODES,MAX_BITS),static_bl_desc=new StaticTreeDesc(new Array(0),extra_blbits,0,BL_CODES,MAX_BL_BITS)}function init_block(s){var n;for(n=0;L_CODES>n;n++)s.dyn_ltree[2*n]=0;for(n=0;D_CODES>n;n++)s.dyn_dtree[2*n]=0;for(n=0;BL_CODES>n;n++)s.bl_tree[2*n]=0;s.dyn_ltree[2*END_BLOCK]=1,s.opt_len=s.static_len=0,s.last_lit=s.matches=0}function bi_windup(s){s.bi_valid>8?put_short(s,s.bi_buf):s.bi_valid>0&&(s.pending_buf[s.pending++]=s.bi_buf),s.bi_buf=0,s.bi_valid=0}function copy_block(s,buf,len,header){bi_windup(s),header&&(put_short(s,len),put_short(s,~len)),utils.arraySet(s.pending_buf,s.window,buf,len,s.pending),s.pending+=len}function smaller(tree,n,m,depth){var _n2=2*n,_m2=2*m;return tree[_n2]n;n++)0!==tree[2*n]?(s.heap[++s.heap_len]=max_code=n,s.depth[n]=0):tree[2*n+1]=0;for(;s.heap_len<2;)node=s.heap[++s.heap_len]=2>max_code?++max_code:0,tree[2*node]=1,s.depth[node]=0,s.opt_len--,has_stree&&(s.static_len-=stree[2*node+1]);for(desc.max_code=max_code,n=s.heap_len>>1;n>=1;n--)pqdownheap(s,tree,n);node=elems;do n=s.heap[1],s.heap[1]=s.heap[s.heap_len--],pqdownheap(s,tree,1),m=s.heap[1],s.heap[--s.heap_max]=n,s.heap[--s.heap_max]=m,tree[2*node]=tree[2*n]+tree[2*m],s.depth[node]=(s.depth[n]>=s.depth[m]?s.depth[n]:s.depth[m])+1,tree[2*n+1]=tree[2*m+1]=node,s.heap[1]=node++,pqdownheap(s,tree,1);while(s.heap_len>=2);s.heap[--s.heap_max]=s.heap[1],gen_bitlen(s,desc),gen_codes(tree,max_code,s.bl_count)}function scan_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),tree[2*(max_code+1)+1]=65535,n=0;max_code>=n;n++)curlen=nextlen,nextlen=tree[2*(n+1)+1],++countcount?s.bl_tree[2*curlen]+=count:0!==curlen?(curlen!==prevlen&&s.bl_tree[2*curlen]++,s.bl_tree[2*REP_3_6]++):10>=count?s.bl_tree[2*REPZ_3_10]++:s.bl_tree[2*REPZ_11_138]++,count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4))}function send_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),n=0;max_code>=n;n++)if(curlen=nextlen,nextlen=tree[2*(n+1)+1],!(++countcount){do send_code(s,curlen,s.bl_tree);while(0!==--count)}else 0!==curlen?(curlen!==prevlen&&(send_code(s,curlen,s.bl_tree),count--),send_code(s,REP_3_6,s.bl_tree),send_bits(s,count-3,2)):10>=count?(send_code(s,REPZ_3_10,s.bl_tree),send_bits(s,count-3,3)):(send_code(s,REPZ_11_138,s.bl_tree),send_bits(s,count-11,7));count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4)}}function build_bl_tree(s){var max_blindex;for(scan_tree(s,s.dyn_ltree,s.l_desc.max_code),scan_tree(s,s.dyn_dtree,s.d_desc.max_code),build_tree(s,s.bl_desc),max_blindex=BL_CODES-1;max_blindex>=3&&0===s.bl_tree[2*bl_order[max_blindex]+1];max_blindex--);return s.opt_len+=3*(max_blindex+1)+5+5+4,max_blindex}function send_all_trees(s,lcodes,dcodes,blcodes){var rank;for(send_bits(s,lcodes-257,5),send_bits(s,dcodes-1,5),send_bits(s,blcodes-4,4),rank=0;blcodes>rank;rank++)send_bits(s,s.bl_tree[2*bl_order[rank]+1],3);send_tree(s,s.dyn_ltree,lcodes-1),send_tree(s,s.dyn_dtree,dcodes-1)}function detect_data_type(s){var n,black_mask=4093624447;for(n=0;31>=n;n++,black_mask>>>=1)if(1&black_mask&&0!==s.dyn_ltree[2*n])return Z_BINARY;if(0!==s.dyn_ltree[18]||0!==s.dyn_ltree[20]||0!==s.dyn_ltree[26])return Z_TEXT;for(n=32;LITERALS>n;n++)if(0!==s.dyn_ltree[2*n])return Z_TEXT;return Z_BINARY}function _tr_init(s){static_init_done||(tr_static_init(),static_init_done=!0),s.l_desc=new TreeDesc(s.dyn_ltree,static_l_desc),s.d_desc=new TreeDesc(s.dyn_dtree,static_d_desc),s.bl_desc=new TreeDesc(s.bl_tree,static_bl_desc),s.bi_buf=0,s.bi_valid=0,init_block(s)}function _tr_stored_block(s,buf,stored_len,last){send_bits(s,(STORED_BLOCK<<1)+(last?1:0),3),copy_block(s,buf,stored_len,!0)}function _tr_align(s){send_bits(s,STATIC_TREES<<1,3),send_code(s,END_BLOCK,static_ltree),bi_flush(s)}function _tr_flush_block(s,buf,stored_len,last){var opt_lenb,static_lenb,max_blindex=0;s.level>0?(s.strm.data_type===Z_UNKNOWN&&(s.strm.data_type=detect_data_type(s)),build_tree(s,s.l_desc),build_tree(s,s.d_desc),max_blindex=build_bl_tree(s),opt_lenb=s.opt_len+3+7>>>3,static_lenb=s.static_len+3+7>>>3,opt_lenb>=static_lenb&&(opt_lenb=static_lenb)):opt_lenb=static_lenb=stored_len+5,opt_lenb>=stored_len+4&&-1!==buf?_tr_stored_block(s,buf,stored_len,last):s.strategy===Z_FIXED||static_lenb===opt_lenb?(send_bits(s,(STATIC_TREES<<1)+(last?1:0),3),compress_block(s,static_ltree,static_dtree)):(send_bits(s,(DYN_TREES<<1)+(last?1:0),3),send_all_trees(s,s.l_desc.max_code+1,s.d_desc.max_code+1,max_blindex+1),compress_block(s,s.dyn_ltree,s.dyn_dtree)),init_block(s),last&&bi_windup(s)}function _tr_tally(s,dist,lc){return s.pending_buf[s.d_buf+2*s.last_lit]=dist>>>8&255,s.pending_buf[s.d_buf+2*s.last_lit+1]=255&dist,s.pending_buf[s.l_buf+s.last_lit]=255&lc,s.last_lit++,0===dist?s.dyn_ltree[2*lc]++:(s.matches++,dist--,s.dyn_ltree[2*(_length_code[lc]+LITERALS+1)]++,s.dyn_dtree[2*d_code(dist)]++),s.last_lit===s.lit_bufsize-1}var utils=require("../utils/common"),Z_FIXED=4,Z_BINARY=0,Z_TEXT=1,Z_UNKNOWN=2,STORED_BLOCK=0,STATIC_TREES=1,DYN_TREES=2,MIN_MATCH=3,MAX_MATCH=258,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,Buf_size=16,MAX_BL_BITS=7,END_BLOCK=256,REP_3_6=16,REPZ_3_10=17,REPZ_11_138=18,extra_lbits=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],extra_dbits=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],extra_blbits=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],bl_order=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],DIST_CODE_LEN=512,static_ltree=new Array(2*(L_CODES+2));zero(static_ltree);var static_dtree=new Array(2*D_CODES);zero(static_dtree);var _dist_code=new Array(DIST_CODE_LEN);zero(_dist_code);var _length_code=new Array(MAX_MATCH-MIN_MATCH+1);zero(_length_code);var base_length=new Array(LENGTH_CODES);zero(base_length);var base_dist=new Array(D_CODES);zero(base_dist);var static_l_desc,static_d_desc,static_bl_desc,StaticTreeDesc=function(static_tree,extra_bits,extra_base,elems,max_length){this.static_tree=static_tree,this.extra_bits=extra_bits,this.extra_base=extra_base,this.elems=elems,this.max_length=max_length,this.has_stree=static_tree&&static_tree.length},TreeDesc=function(dyn_tree,stat_desc){this.dyn_tree=dyn_tree,this.max_code=0,this.stat_desc=stat_desc},static_init_done=!1;exports._tr_init=_tr_init,exports._tr_stored_block=_tr_stored_block,exports._tr_flush_block=_tr_flush_block,exports._tr_tally=_tr_tally,exports._tr_align=_tr_align},{"../utils/common":98}],110:[function(require,module){"use strict";function ZStream(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}module.exports=ZStream},{}],111:[function(require,module){(function(Buffer){"use strict";function decodeB64(str){return new Buffer(str,"base64")}function unpackPNG(w,h,c,str){var pixels=parse(decodeB64(str));return ndarray(pixels.data,[h,w,pixels.channels],[pixels.channels*w,pixels.channels,1],0)}module.exports=unpackPNG;var ndarray=require("ndarray"),parse=require("pngparse-sync")}).call(this,require("buffer").Buffer)},{buffer:123,ndarray:92,"pngparse-sync":94}],112:[function(require,module,exports){!function(_global){"use strict";var shim={};"undefined"==typeof exports?"function"==typeof define&&"object"==typeof define.amd&&define.amd?(shim.exports={},define(function(){return shim.exports})):shim.exports="undefined"!=typeof window?window:_global:shim.exports=exports,function(exports){if(!GLMAT_EPSILON)var GLMAT_EPSILON=1e-6;if(!GLMAT_ARRAY_TYPE)var GLMAT_ARRAY_TYPE="undefined"!=typeof Float32Array?Float32Array:Array;if(!GLMAT_RANDOM)var GLMAT_RANDOM=Math.random;var glMatrix={};glMatrix.setMatrixArrayType=function(type){GLMAT_ARRAY_TYPE=type},"undefined"!=typeof exports&&(exports.glMatrix=glMatrix);var degree=Math.PI/180;glMatrix.toRadian=function(a){return a*degree};var vec2={};vec2.create=function(){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=0,out[1]=0,out},vec2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=a[0],out[1]=a[1],out},vec2.fromValues=function(x,y){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=x,out[1]=y,out},vec2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out},vec2.set=function(out,x,y){return out[0]=x,out[1]=y,out},vec2.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out},vec2.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out},vec2.sub=vec2.subtract,vec2.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out},vec2.mul=vec2.multiply,vec2.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out},vec2.div=vec2.divide,vec2.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out},vec2.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out},vec2.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out},vec2.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out},vec2.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return Math.sqrt(x*x+y*y)},vec2.dist=vec2.distance,vec2.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return x*x+y*y},vec2.sqrDist=vec2.squaredDistance,vec2.length=function(a){var x=a[0],y=a[1];return Math.sqrt(x*x+y*y)},vec2.len=vec2.length,vec2.squaredLength=function(a){var x=a[0],y=a[1];return x*x+y*y},vec2.sqrLen=vec2.squaredLength,vec2.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out},vec2.normalize=function(out,a){var x=a[0],y=a[1],len=x*x+y*y;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null -},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],113:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance}function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":112}],114:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],115:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],116:[function(require,module){function parse(html,doc){if("string"!=typeof html)throw new TypeError("String expected");doc||(doc=document);var m=/<([\w:]+)/.exec(html);if(!m)return doc.createTextNode(html);html=html.replace(/^\s+|\s+$/g,"");var tag=m[1];if("body"==tag){var el=doc.createElement("html");return el.innerHTML=html,el.removeChild(el.lastChild)}var wrap=map[tag]||map._default,depth=wrap[0],prefix=wrap[1],suffix=wrap[2],el=doc.createElement("div");for(el.innerHTML=prefix+html+suffix;depth--;)el=el.lastChild;if(el.firstChild==el.lastChild)return el.removeChild(el.firstChild);for(var fragment=doc.createDocumentFragment();el.firstChild;)fragment.appendChild(el.removeChild(el.firstChild));return fragment}module.exports=parse;var map={legend:[1,"
            ","
            "],tr:[2,"","
            "],col:[2,"","
            "],_default:[0,"",""]};map.td=map.th=[3,"","
            "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
            "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],117:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],118:[function(require,module,exports){arguments[4][32][0].apply(exports,arguments)},{_process:126,"raf-component":119,sliced:121}],119:[function(require,module){module.exports=require(33)},{}],120:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],121:[function(require,module,exports){arguments[4][34][0].apply(exports,arguments)},{"./lib/sliced":122}],122:[function(require,module){module.exports=require(35)},{}],123:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)"base64"===encoding&&(subject=base64clean(subject)),length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new Error("First argument needs to be a number, array or string.");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}var buf;TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;assert(strLen%2===0,"Invalid hex string"),length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);assert(!isNaN(byte),"Invalid hex string"),buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string),buf,offset,length);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function binarySlice(buf,start,end){return asciiSlice(buf,start,end)}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;i=len)){var val;return littleEndian?(val=buf[offset],len>offset+1&&(val|=buf[offset+1]<<8)):(val=buf[offset]<<8,len>offset+1&&(val|=buf[offset+1])),val}}function readUInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val;return littleEndian?(len>offset+2&&(val=buf[offset+2]<<16),len>offset+1&&(val|=buf[offset+1]<<8),val|=buf[offset],len>offset+3&&(val+=buf[offset+3]<<24>>>0)):(len>offset+1&&(val=buf[offset+1]<<16),len>offset+2&&(val|=buf[offset+2]<<8),len>offset+3&&(val|=buf[offset+3]),val+=buf[offset]<<24>>>0),val}}function readInt16(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len)){var val=readUInt16(buf,offset,littleEndian,!0),neg=32768&val;return neg?-1*(65535-val+1):val}}function readInt32(buf,offset,littleEndian,noAssert){noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){var val=readUInt32(buf,offset,littleEndian,!0),neg=2147483648&val;return neg?-1*(4294967295-val+1):val}}function readFloat(buf,offset,littleEndian,noAssert){return noAssert||(assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i);return offset+2}}function writeUInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len)){for(var i=0,j=Math.min(len-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255;return offset+4}}function writeInt16(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+1=len))return value>=0?writeUInt16(buf,value,offset,littleEndian,noAssert):writeUInt16(buf,65535+value+1,offset,littleEndian,noAssert),offset+2}function writeInt32(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return value>=0?writeUInt32(buf,value,offset,littleEndian,noAssert):writeUInt32(buf,4294967295+value+1,offset,littleEndian,noAssert),offset+4}function writeFloat(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+3=len))return ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert("boolean"==typeof littleEndian,"missing or invalid endian"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset+7=len))return ieee754.write(buf,value,offset,littleEndian,52,8),offset+8}function base64clean(str){for(str=stringtrim(str).replace(INVALID_BASE64_RE,"");str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArray(subject){return(Array.isArray||function(subject){return"[object Array]"===Object.prototype.toString.call(subject)})(subject)}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(str){for(var byteArray=[],i=0;i=b)byteArray.push(b);else{var start=i;b>=55296&&57343>=b&&i++;for(var h=encodeURIComponent(str.slice(start,i+1)).substr(1).split("%"),j=0;j>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(str)}function blitBuffer(src,dst,offset,length){for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533) -}}function verifuint(value,max){assert("number"==typeof value,"cannot write a non-number as a number"),assert(value>=0,"specified a negative value for writing an unsigned value"),assert(max>=value,"value is larger than maximum value for type"),assert(Math.floor(value)===value,"value has a fractional component")}function verifsint(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value"),assert(Math.floor(value)===value,"value has a fractional component")}function verifIEEE754(value,max,min){assert("number"==typeof value,"cannot write a non-number as a number"),assert(max>=value,"value larger than maximum allowed value"),assert(value>=min,"value smaller than minimum allowed value")}function assert(test,message){if(!test)throw new Error(message||"Failed assertion")}var base64=require("base64-js"),ieee754=require("ieee754");exports.Buffer=Buffer,exports.SlowBuffer=Buffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}();Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.byteLength=function(str,encoding){var ret;switch(str=str.toString(),encoding||"utf8"){case"hex":ret=str.length/2;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"ascii":case"binary":case"raw":ret=str.length;break;case"base64":ret=base64ToBytes(str).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=2*str.length;break;default:throw new Error("Unknown encoding")}return ret},Buffer.concat=function(list,totalLength){if(assert(isArray(list),"Usage: Buffer.concat(list[, length])"),0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;ii&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}offset=Number(offset)||0;var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toString=function(encoding,start,end){var self=this;if(encoding=String(encoding||"utf8").toLowerCase(),start=Number(start)||0,end=void 0===end?self.length:Number(end),end===start)return"";var ret;switch(encoding){case"hex":ret=hexSlice(self,start,end);break;case"utf8":case"utf-8":ret=utf8Slice(self,start,end);break;case"ascii":ret=asciiSlice(self,start,end);break;case"binary":ret=binarySlice(self,start,end);break;case"base64":ret=base64Slice(self,start,end);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leSlice(self,start,end);break;default:throw new Error("Unknown encoding")}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.equals=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),0===Buffer.compare(this,b)},Buffer.prototype.compare=function(b){return assert(Buffer.isBuffer(b),"Argument must be a Buffer"),Buffer.compare(this,b)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start||(target_start=0),end!==start&&0!==target.length&&0!==source.length){assert(end>=start,"sourceEnd < sourceStart"),assert(target_start>=0&&target_start=0&&start=0&&end<=source.length,"sourceEnd out of bounds"),end>this.length&&(end=this.length),target.length-target_startlen||!TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start)}},Buffer.prototype.slice=function(start,end){var len=this.length;if(start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start),TYPED_ARRAY_SUPPORT)return Buffer._augment(this.subarray(start,end));for(var sliceLen=end-start,newBuf=new Buffer(sliceLen,void 0,!0),i=0;sliceLen>i;i++)newBuf[i]=this[i+start];return newBuf},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return readUInt16(this,offset,!0,noAssert)},Buffer.prototype.readUInt16BE=function(offset,noAssert){return readUInt16(this,offset,!1,noAssert)},Buffer.prototype.readUInt32LE=function(offset,noAssert){return readUInt32(this,offset,!0,noAssert)},Buffer.prototype.readUInt32BE=function(offset,noAssert){return readUInt32(this,offset,!1,noAssert)},Buffer.prototype.readInt8=function(offset,noAssert){if(noAssert||(assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length)){var neg=128&this[offset];return neg?-1*(255-this[offset]+1):this[offset]}},Buffer.prototype.readInt16LE=function(offset,noAssert){return readInt16(this,offset,!0,noAssert)},Buffer.prototype.readInt16BE=function(offset,noAssert){return readInt16(this,offset,!1,noAssert)},Buffer.prototype.readInt32LE=function(offset,noAssert){return readInt32(this,offset,!0,noAssert)},Buffer.prototype.readInt32BE=function(offset,noAssert){return readInt32(this,offset,!1,noAssert)},Buffer.prototype.readFloatLE=function(offset,noAssert){return readFloat(this,offset,!0,noAssert)},Buffer.prototype.readFloatBE=function(offset,noAssert){return readFloat(this,offset,!1,noAssert)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return readDouble(this,offset,!0,noAssert)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return readDouble(this,offset,!1,noAssert)},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(this[offset]=value,offset+1)},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return writeUInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return writeUInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt8=function(value,offset,noAssert){return noAssert||(assert(void 0!==value&&null!==value,"missing value"),assert(void 0!==offset&&null!==offset,"missing offset"),assert(offset=this.length?void 0:(value>=0?this.writeUInt8(value,offset,noAssert):this.writeUInt8(255+value+1,offset,noAssert),offset+1)},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return writeInt16(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return writeInt16(this,value,offset,!1,noAssert)},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return writeInt32(this,value,offset,!0,noAssert)},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return writeInt32(this,value,offset,!1,noAssert)},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert)},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),assert(end>=start,"end < start"),end!==start&&0!==this.length){assert(start>=0&&start=0&&end<=this.length,"end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.inspect=function(){for(var out=[],len=this.length,i=0;len>i;i++)if(out[i]=toHex(this[i]),i===exports.INSPECT_MAX_BYTES){out[i+1]="...";break}return""},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z]/g},{"base64-js":124,ieee754:125}],124:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS?62:code===SLASH?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],125:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],126:[function(require,module){function noop(){}var process=module.exports={};process.nextTick=function(){var canSetImmediate="undefined"!=typeof window&&window.setImmediate,canPost="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(canSetImmediate)return function(f){return window.setImmediate(f)};if(canPost){var queue=[];return window.addEventListener("message",function(ev){var source=ev.source;if((source===window||null===source)&&"process-tick"===ev.data&&(ev.stopPropagation(),queue.length>0)){var fn=queue.shift();fn()}},!0),function(fn){queue.push(fn),window.postMessage("process-tick","*")}}return function(fn){setTimeout(fn,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[3]); \ No newline at end of file diff --git a/index.html b/index.html index 8eabdeb..2f1729b 100644 --- a/index.html +++ b/index.html @@ -76,7 +76,6 @@

            community

            - - + + + diff --git a/index.js b/index.js deleted file mode 100644 index d8386e9..0000000 --- a/index.js +++ /dev/null @@ -1,40 +0,0 @@ -var filter = require('./lib/filter') -var cl = require('class-list') -var minstache = require('minstache') -var domify = require('domify') -var slice = require('sliced') -var fs = require('fs') - -var grid = document.getElementById('grid').querySelector('canvas') - -require('./lib/fill')(document.querySelectorAll('[data-fill]')) - -try { - require('@stackgl/splash-grid')(grid) -} catch(e) { - console.error(e.message) - cl(document.body).add('no-webgl') -} - -var thumb = minstache.compile(fs.readFileSync( - __dirname + '/lib/thumb.html' -, 'utf8')) - -var examples = require('./build/examples.json').map(function(meta) { - return thumb(meta) -}).join('\n') - -document - .getElementById('examples') - .querySelector('ul.thumb-list') - .appendChild(domify(examples)) - -var pkgEl = document.getElementById('packages') - -pkgEl - .querySelector('ul.thumb-list') - .appendChild(domify(packages)) - -pkgEl - .querySelector('ul.thumb-filter') - .appendChild(filter(pkgEl)) diff --git a/package.json b/package.json index 372f5cf..9666c93 100644 --- a/package.json +++ b/package.json @@ -29,13 +29,10 @@ ] }, "scripts": { - "prestart": "npm run links && node data/regenerate", - "start": "wzrd index.js:bundle.js", - "postinstall": "npm run links && scoped-bulk stackgl npm install && npm dedupe && npm run sync", - "bundle": "npm run prestart && browserify index.js | uglifyjs -c > bundle.js", - "links": "district stackgl splash-grid", - "sync": "node data/sync", - "disc": "browserify index.js --full-paths | uglifyjs -c | discify --open" + "start": "make start", + "clean": "make clean", + "postinstall": "make postinstall", + "prepublish": "make build/bundle.min.js build/splash.min.js" }, "repository": { "type": "git", diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..19aa5bb --- /dev/null +++ b/src/index.js @@ -0,0 +1,21 @@ +var filter = require('../lib/filter') +var cl = require('class-list') +var minstache = require('minstache') +var domify = require('domify') +var slice = require('sliced') +var fs = require('fs') + +require('../lib/fill')(document.querySelectorAll('[data-fill]')) + +var thumb = minstache.compile(fs.readFileSync( + __dirname + '/../lib/thumb.html' +, 'utf8')) + +var examples = require('../build/examples.json').map(function(meta) { + return thumb(meta) +}).join('\n') + +document + .getElementById('examples') + .querySelector('ul.thumb-list') + .appendChild(domify(examples)) diff --git a/src/splash.js b/src/splash.js new file mode 100644 index 0000000..9b4b65e --- /dev/null +++ b/src/splash.js @@ -0,0 +1,9 @@ +var cl = require('class-list') + +try { + require('@stackgl/splash-grid')( + document.getElementById('grid').querySelector('canvas') + ) +} catch(e) { + cl(document.body).add('no-webgl') +} From 9411c7bfaaec0f18b69531d9ca8d8754c8b36557 Mon Sep 17 00:00:00 2001 From: Hugh Kennedy Date: Sat, 17 Jan 2015 23:26:01 +0800 Subject: [PATCH 44/64] Change up the design of the site --- build/bundle.min.js | 2 +- build/splash.min.js | 4 +- index.css | 143 +++++++++++++++++++++++++++++++++++-------- index.html | 143 +++++++++++++++++++++++++------------------ lib/thumb.html | 21 ++----- splash-grid/index.js | 3 +- src/index.js | 4 +- src/splash.js | 2 +- 8 files changed, 215 insertions(+), 107 deletions(-) diff --git a/build/bundle.min.js b/build/bundle.min.js index 179d47f..c9b5277 100644 --- a/build/bundle.min.js +++ b/build/bundle.min.js @@ -1 +1 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to the WebGL API that runs in your browser. webgl-workshop\nis a NodeSchool workshop originally created for\nCampJS IV. Everything is powered by node.js, browserify and\na selection of stackgl packages under the hood.

            ',thumb:"http://i.imgur.com/vBJ7d6o.jpg",featured:!0,i:0},{name:"shader-school",link:"http://github.com/stackgl/shader-school",desc:"",thumb:"http://imgur.com/hegi9dZ.png",featured:!1,i:1},{name:"gl-surface-plot",link:"https://github.com/mikolalysenko/gl-surface-plot",desc:"",thumb:"http://i.imgur.com/z4xjpgu.jpg",featured:!1,i:2},{name:"bunny-walkthrough",link:"https://github.com/stackgl/bunny-walkthrough",desc:"",thumb:"http://i.imgur.com/OefbPjB.jpg",featured:!1,i:3},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:4},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:5},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:6},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:7},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:8},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:9},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:10},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:11},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:12},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:13}]},{}],2:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;i-1||(list.push(token),setTokens(list))}function remove(token){var list=getTokens(),index=indexof(list,token);-1!==index&&(list.splice(index,1),setTokens(list))}function contains(token){return indexof(getTokens(),token)>-1}function toggle(token){return contains(token)?(remove(token),!1):(add(token),!0)}function $toString(){return elem.className}function item(index){var tokens=getTokens();return tokens[index]||null}function getTokens(){var className=elem.className;return filter(className.split(" "),isTruthy)}function setTokens(list){var length=list.length;elem.className=list.join(" "),classList.length=length;for(var i=0;i
            a';var innerHTMLBug=!div.getElementsByTagName("link").length;div=void 0;var map={legend:[1,"
            ","
            "],tr:[2,"","
            "],col:[2,"","
            "],_default:innerHTMLBug?[1,"X
            ","
            "]:[0,"",""]};map.td=map.th=[3,"","
            "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
            "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],8:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],9:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:4,"raf-component":10,sliced:12}],10:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],11:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],12:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":13}],13:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],14:[function(require){{var minstache=(require("../lib/filter"),require("class-list"),require("minstache")),domify=require("domify");require("sliced")}require("../lib/fill")(document.querySelectorAll("[data-fill]"));var thumb=minstache.compile('
          • \n
            \n \n
            \n
            \n
            \n \n

            {{name}}

            \n
            \n
            \n {{#featured}}\n {{!desc}}\n {{/featured}}\n
            \n
            \n
            \n
          • \n'),examples=require("../build/examples.json").map(function(meta){return thumb(meta)}).join("\n");document.getElementById("examples").querySelector("ul.thumb-list").appendChild(domify(examples))},{"../build/examples.json":1,"../lib/fill":2,"../lib/filter":3,"class-list":5,domify:7,minstache:11,sliced:12}]},{},[14]); \ No newline at end of file +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oAn introduction to the WebGL API that runs in your browser. webgl-workshop\nis a NodeSchool workshop originally created for\nCampJS IV. Everything is powered by node.js, browserify and\na selection of stackgl packages under the hood.

            ',thumb:"http://i.imgur.com/vBJ7d6o.jpg",featured:!0,i:0},{name:"shader-school",link:"http://github.com/stackgl/shader-school",desc:"",thumb:"http://imgur.com/hegi9dZ.png",featured:!1,i:1},{name:"gl-surface-plot",link:"https://github.com/mikolalysenko/gl-surface-plot",desc:"",thumb:"http://i.imgur.com/z4xjpgu.jpg",featured:!1,i:2},{name:"bunny-walkthrough",link:"https://github.com/stackgl/bunny-walkthrough",desc:"",thumb:"http://i.imgur.com/OefbPjB.jpg",featured:!1,i:3},{name:"glsl.io",link:"http://glsl.io/",desc:"",thumb:"http://imgur.com/56SPiLL.png",featured:!1,i:4},{name:"kami",link:"https://github.com/mattdesl/kami",desc:"",thumb:"http://imgur.com/j5W3Tuw.png",featured:!1,i:5},{name:"run.south.im",link:"http://run.south.im/",desc:"",thumb:"http://imgur.com/kZjW5QD.png",featured:!1,i:6},{name:"nodesource.com",link:"http://nodesource.com/",desc:"",thumb:"http://imgur.com/tCKuJfx.png",featured:!1,i:7},{name:"voxel-mipmap-demo",link:"https://github.com/mikolalysenko/voxel-mipmap-demo/",desc:"",thumb:"http://imgur.com/9eUBmfB.png",featured:!1,i:8},{name:"gif-3d",link:"http://mikolalysenko.github.io/gif-3d/",desc:"",thumb:"http://imgur.com/gItopw0.jpg",featured:!1,i:9},{name:"moire #1",link:"http://hughsk.io/moire-1",desc:"",thumb:"http://imgur.com/9tbJfnF.png",featured:!1,i:10},{name:"campjs.com",link:"http://campjs.com/",desc:"",thumb:"http://imgur.com/d47Vesp.png",featured:!1,i:11},{name:"particle-excess-demo",link:"https://github.com/hughsk/particle-excess-demo/",desc:"",thumb:"http://imgur.com/YyrtLqM.png",featured:!1,i:12},{name:"web-audio-analyser",link:"https://github.com/hughsk/web-audio-analyser/",desc:"",thumb:"http://imgur.com/xhPfMFP.png",featured:!1,i:13}]},{}],2:[function(require,module){function fill(elements){function refill(){for(var width=window.innerWidth+"px",height=window.innerHeight+"px",i=0;i{{name}}\n{{/category}}\n');module.exports=function(thumbs){var filtered=slice(thumbs.querySelectorAll("[data-filter]")),categories=filtered.reduce(function(categories,el){var cat=el.getAttribute("data-filter");return-1===categories.indexOf(cat)&&categories.push(cat),categories},[]);categories.unshift(all),categories=categories.map(function(name){return{name:name}});var list=domify(template({category:categories})),children=slice(list.childNodes).filter(function(node){return node.nodeType===Node.ELEMENT_NODE}),prev=children[0];return children[0].setAttribute("class","selected"),children.forEach(function(child){var name=child.getAttribute("data-name");child.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation();var target=findup(e.target,"li");if(target!==child)return!1;prev.setAttribute("class",""),prev=target,prev.setAttribute("class","selected");for(var i=0;i-1||(list.push(token),setTokens(list))}function remove(token){var list=getTokens(),index=indexof(list,token);-1!==index&&(list.splice(index,1),setTokens(list))}function contains(token){return indexof(getTokens(),token)>-1}function toggle(token){return contains(token)?(remove(token),!1):(add(token),!0)}function $toString(){return elem.className}function item(index){var tokens=getTokens();return tokens[index]||null}function getTokens(){var className=elem.className;return filter(className.split(" "),isTruthy)}function setTokens(list){var length=list.length;elem.className=list.join(" "),classList.length=length;for(var i=0;i
            a';var innerHTMLBug=!div.getElementsByTagName("link").length;div=void 0;var map={legend:[1,"
            ","
            "],tr:[2,"","
            "],col:[2,"","
            "],_default:innerHTMLBug?[1,"X
            ","
            "]:[0,"",""]};map.td=map.th=[3,"","
            "],map.option=map.optgroup=[1,'"],map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"","
            "],map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'',""]},{}],8:[function(require,module){function findup(child,check){for("string"==typeof check&&(check=byName(check)),"function"!=typeof check&&(check=byExact(check));child&&!check(child);)child=child.parentNode;return child||null}function byName(name){return name=String(name).toUpperCase(),function(element){return name===element.nodeName}}function byExact(el){return function(element){return el===element}}module.exports=findup},{}],9:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:4,"raf-component":10,sliced:12}],10:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],11:[function(require,module,exports){function render(str,obj){obj=obj||{};var fn=compile(str);return fn(obj)}function compile(str){for(var tok,js=[],toks=parse(str),i=0;i/g,">")}exports=module.exports=render,exports.compile=compile},{}],12:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":13}],13:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],14:[function(require){{var minstache=(require("../lib/filter"),require("class-list"),require("minstache")),domify=require("domify");require("sliced")}require("../lib/fill")(document.querySelectorAll("[data-fill]"));var thumb=minstache.compile('
          • \n \n
            \n

            {{name}}

            \n
            \n
          • \n'),examples=require("../build/examples.json").map(function(meta){return thumb(meta)}).join("\n");console.log(examples),document.getElementById("examples").querySelector("ul.thumbs").appendChild(domify(examples))},{"../build/examples.json":1,"../lib/fill":2,"../lib/filter":3,"class-list":5,domify:7,minstache:11,sliced:12}]},{},[14]); \ No newline at end of file diff --git a/build/splash.min.js b/build/splash.min.js index f1df359..e6f33a5 100644 --- a/build/splash.min.js +++ b/build/splash.min.js @@ -1,4 +1,4 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;oheight)){var now=getTime()*TIMESCALE;heightmap.bind(),gl.viewport(0,0,SIZE,SIZE),gl.disable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),heightShader.bind(),heightShader.uniforms.uTime=now,heightShader.uniforms.uResolution=RES,triangle(gl),gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.viewport(0,0,width,height),gl.enable(gl.DEPTH_TEST),gl.enable(gl.CULL_FACE),clear(gl),mat4.perspective(projection,Math.PI/4,width/height,.001,100),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),quat.rotateX(camera.rotation,camera.rotation,-.5),camera.view(view),quat.identity(camera.rotation),quat.rotateY(camera.rotation,camera.rotation,2e-4*now),geom.bind(shader),shader.uniforms.uResolution=RES,shader.uniforms.uViewRotation=mat4.fromQuat(viewrot,camera.rotation),shader.uniforms.uProjection=projection,shader.uniforms.uModel=model,shader.uniforms.uView=view,shader.uniforms.tHeightmap=heightmap.color[0].bind(0),shader.uniforms.tGradient=gradient.bind(1),geom.draw(),geom.unbind()}}var gl=require("gl-context")(canvas,render),heightmap=createFBO(gl,[SIZE,SIZE],{"float":!0}),gradient=createTex2d(gl,require("./gradient-map")),voxels=createMesh(),projection=mat4.create(),viewrot=mat4.create(),view=mat4.create(),model=mat4.create(),camera=createCamera([0,10,30],[0,0,0],[0,1,0]),shader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec3 aPosition;\nattribute vec3 aCentroid;\nattribute vec3 aNormal;\nattribute vec3 aEdge;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\nuniform sampler2D tHeightmap;\nuniform vec2 uResolution;\nuniform mat4 uProjection;\nuniform mat4 uModel;\nuniform mat4 uView;\nconst float threshold = 1.0 / 0.01;\nvoid main() {\n vec3 position = aPosition;\n vec2 coord = aCentroid.xz;\n float height = texture2D(tHeightmap, aCentroid.xz).r;\n float nht = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, -1.0)).r;\n float nhb = texture2D(tHeightmap, coord + uResolution * vec2(+0.0, +1.0)).r;\n float nhl = texture2D(tHeightmap, coord + uResolution * vec2(-1.0, +0.0)).r;\n float nhr = texture2D(tHeightmap, coord + uResolution * vec2(+1.0, +0.0)).r;\n position.y = mix(position.y, height, position.y);\n gl_Position = (uProjection * uView * uModel * vec4(position, 1.0)) + vec4(0.35, -0.2, 0.0, 0.0);\n vNormal = aNormal;\n vEdge = aEdge.xz;\n vNeighbours = vec4(clamp((nht - height) * threshold, -1.0, 1.0), clamp((nhb - height) * threshold, -1.0, 1.0), clamp((nhl - height) * threshold, -1.0, 1.0), clamp((nhr - height) * threshold, -1.0, 1.0));\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform sampler2D tGradient;\nuniform mat4 uViewRotation;\nvarying vec4 vNeighbours;\nvarying vec3 vNormal;\nvarying vec2 vEdge;\n#define EDGE_SHARPNESS 1.8\n\n#define EDGE_SHADOW 0.2\n\n#define BLOCK_COLOR 1.1\n\nvoid main() {\n vec4 lightDirection = vec4(normalize(vec3(-0.2, 1.2, 0.8)), 1.0);\n lightDirection = uViewRotation * lightDirection;\n float nhr = max(0.0, vNeighbours.x);\n float nhl = max(0.0, vNeighbours.y);\n float nhb = max(0.0, vNeighbours.z);\n float nht = max(0.0, vNeighbours.w);\n float top = abs(vNormal.y);\n vec2 de = vec2(max(0.0, nht * vEdge.x) - min(0.0, nhb * vEdge.x), max(0.0, nhl * vEdge.y) - min(0.0, nhr * vEdge.y));\n float d1 = smoothstep(0.0, 1.0, abs(de.x));\n float d2 = smoothstep(0.0, 1.0, abs(de.y));\n float d = (pow(d1, EDGE_SHARPNESS) + pow(d2, EDGE_SHARPNESS));\n vec3 diffuse = vec3(1.0 - min(d, 1.0) * top * EDGE_SHADOW) * BLOCK_COLOR;\n vec3 ambient = vec3(0.1);\n float lambert = max(0.0, dot(vNormal, normalize(lightDirection.xyz)));\n vec3 color = diffuse * lambert + ambient;\n gl_FragColor.rgb = texture2D(tGradient, vec2(0.0, color.r)).rgb;\n gl_FragColor.a = 1.0;\n}",[{name:"tHeightmap",type:"sampler2D"},{name:"uResolution",type:"vec2"},{name:"uProjection",type:"mat4"},{name:"uModel",type:"mat4"},{name:"uView",type:"mat4"},{name:"tGradient",type:"sampler2D"},{name:"uViewRotation",type:"mat4"}],[{name:"aPosition",type:"vec3"},{name:"aCentroid",type:"vec3"},{name:"aNormal",type:"vec3"},{name:"aEdge",type:"vec3"}])(gl),heightShader=require("glslify/adapter.js")("\n#define GLSLIFY 1\n\nprecision mediump float;\nattribute vec2 position;\nvoid main() {\n gl_Position = vec4(position.xy, 1.0, 1.0);\n}","\n#define GLSLIFY 1\n\nprecision mediump float;\nuniform vec2 uResolution;\nuniform float uTime;\nvoid main() {\n vec2 coord = (gl_FragCoord.xy * uResolution - 0.5) * 2.0;\n float height = 0.0;\n height += sin(uTime * 0.00062 + coord.y * 2.5) * 0.4;\n height += cos(uTime * 0.00048 + coord.x * 1.8) * 0.6;\n height += sin(uTime * 0.0048 + coord.x * 7.9) * 0.2;\n height += cos(uTime * 0.0038 + coord.y * 6.8) * 0.1;\n height += sin(uTime * 0.0028 + coord.y * 2.8 + 0.5) * 0.3;\n height -= clamp(1.0 - uTime * 0.0005, 0.0, 1.0) * 2.0;\n height = max(0.0, height * 0.2);\n height *= max(0.0, 0.85 - max(0.0, coord.x * coord.x + coord.y * coord.y));\n gl_FragColor.r = height;\n gl_FragColor.gba = vec3(1.0);\n}",[{name:"uResolution",type:"vec2"},{name:"uTime",type:"float"}],[{name:"position",type:"vec2"}])(gl),geom=createGeom(gl).attr("aPosition",voxels.positions).attr("aCentroid",voxels.centroids).attr("aNormal",voxels.normals).attr("aEdge",voxels.edges);camera.distance=1.5,heightmap.color[0].wrap=gl.CLAMP_TO_EDGE,heightmap.color[0].minFilter=gl.NEAREST,heightmap.color[0].maxFilter=gl.NEAREST,mat4.translate(model,model,[-.5,0,-.5]),window.addEventListener("resize",debounce(fit(canvas,window)),!1)}},{"./gradient-map":1,"a-big-triangle":19,"canvas-fit":20,clone:22,"cube-cube":23,"face-normals":26,"frame-debounce":27,"gl-clear":32,"gl-context":33,"gl-fbo":35,"gl-geometry":38,"gl-matrix":63,"gl-texture2d":76,glslify:78,"glslify/adapter.js":77,"mesh-combine":84,"orbit-camera":108,"right-now":109,"unindex-mesh":110}],3:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){if(0>=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:9,"ndarray-ops":4,"typedarray-pool":13}],4:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":5}],5:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":7}],6:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:8}],7:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;i=offset&&data.length>len)return gl.bufferData(type,data,usage),data.length;if(data.length+offset>len)throw new Error("gl-buffer: If resizing buffer, offset must be 0");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function createBuffer(gl,type,data,usage){void 0===data&&(data=type,type=gl.ARRAY_BUFFER),usage||(usage=gl.DYNAMIC_DRAW);var len=0,handle=gl.createBuffer();if(gl.bindBuffer(type,handle),"number"==typeof data)gl.bufferData(type,data,usage),len=data;else if(data instanceof Array)type===gl.ELEMENT_ARRAY_BUFFER?gl.bufferData(type,new Uint16Array(data),usage):gl.bufferData(type,new Float32Array(data),usage),len=data.length;else if(data.length)gl.bufferData(type,data,usage),len=data.length;else{if(!data.shape)throw new Error("gl-buffer: Invalid format for buffer data");var dtype=data.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),type===gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==data.shape.length)throw new Error("gl-buffer: Array shape must be 1D");var len=data.shape[0];if(dtype===data.type&&1===data.stride[0])gl.bufferData(type,data.data.subarray(data.offset,data.offset+len),usage);else{var tmp=pool.malloc(data.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,data),gl.bufferData(type,tmp,usage),pool.free(tmp)}}if(type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer");return new GLBuffer(gl,type,handle,len,usage)}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray");GLBuffer.prototype.bind=function(){this.gl.bindBuffer(this.type,this.handle)},GLBuffer.prototype.dispose=function(){this.gl.deleteBuffer(this.handle)},GLBuffer.prototype.update=function(array,offset){if(offset||(offset=0),this.bind(),"number"==typeof array){if(offset>0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");this.gl.bufferData(this.type,array,this.usage),this.length=array}else if(array.shape){var dtype=array.dtype;if(("float64"===dtype||"array"===dtype||"generic"===dtype)&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER&&(dtype="uint16"),1!==array.shape.length)throw new Error("gl-buffer: Array length must be 1");if(dtype===array.dtype&&1===array.stride[0])this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.shape[0],dtype),ndt=ndarray(tmp);ops.assign(ndt,array),this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset),pool.free(tmp)}}else if(Array.isArray(array))if(this.type===this.gl.ELEMENT_ARRAY_BUFFER){var t=makeScratchTypeArray(array,"uint16");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeUint16(t)}else{var t=makeScratchTypeArray(array,"float32");this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.freeFloat32(t)}else this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset)},GLBuffer.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this.type===gl.ARRAY_BUFFER)gl.drawArrays(mode,offset,count);else{if(this.type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("Invalid type for WebGL buffer");this.bind(),gl.drawElements(mode,count,gl.UNSIGNED_SHORT,offset)}},module.exports=createBuffer},{ndarray:9,"ndarray-ops":4,"typedarray-pool":13}],4:[function(require,module,exports){"use strict";function fixup(x){if(!x)return EmptyProc;for(var i=0;i>",rrshift:">>>"};!function(){for(var id in assign_ops){var op=assign_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a"+op+"=b"},rvalue:!0,funcName:id+"eq"}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a"+op+"=s"},rvalue:!0,funcName:id+"seq"})}}();var unary_ops={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var id in unary_ops){var op=unary_ops[id];exports[id]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a="+op+"b"},funcName:id}),exports[id+"eq"]=makeOp({args:["array"],body:{args:["a"],body:"a="+op+"a"},rvalue:!0,count:2,funcName:id+"eq"})}}();var binary_ops={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var id in binary_ops){var op=binary_ops[id];exports[id]=makeOp({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+op+"c"},funcName:id}),exports[id+"s"]=makeOp({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+op+"s"},funcName:id+"s"}),exports[id+"eq"]=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=a"+op+"b"},rvalue:!0,count:2,funcName:id+"eq"}),exports[id+"seq"]=makeOp({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+op+"s"},rvalue:!0,count:2,funcName:id+"seq"})}}();var math_unary=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var i=0;ithis_s){this_s=-a}else if(a>this_s){this_s=a}",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norminf"}),exports.norm1=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:!1,rvalue:!0,count:3}],body:"this_s+=a<0?-a:a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm1"}),exports.sup=compile({args:["array"],pre:{body:"this_h=-Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_h"],localVars:[]},post:{body:"return this_h",args:[],thisVars:["this_h"],localVars:[]}}),exports.inf=compile({args:["array"],pre:{body:"this_h=Infinity",args:[],thisVars:["this_h"],localVars:[]},body:{body:"if(_inline_1_arg0_this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}",args:[{name:"_inline_1_arg0_",lvalue:!1,rvalue:!0,count:2},{name:"_inline_1_arg1_",lvalue:!1,rvalue:!0,count:2}],thisVars:["this_i","this_v"],localVars:["_inline_1_k"]},post:{body:"{return this_i}",args:[],thisVars:["this_i"],localVars:[]}}),exports.random=makeOp({args:["array"],pre:{args:[],body:"this_f=Math.random",thisVars:["this_f"]},body:{args:["a"],body:"a=this_f()",thisVars:["this_f"]},funcName:"random"}),exports.assign=makeOp({args:["array","array"],body:{args:["a","b"],body:"a=b"},funcName:"assign"}),exports.assigns=makeOp({args:["array","scalar"],body:{args:["a","b"],body:"a=b"},funcName:"assigns"}),exports.equals=compile({args:["array","array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:!1,rvalue:!0,count:1},{name:"y",lvalue:!1,rvalue:!0,count:1}],body:"if(x!==y){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"equals"})},{"cwise-compiler":5}],5:[function(require,module){"use strict";function Procedure(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}function compileCwise(user_args){var proc=new Procedure;proc.pre=user_args.pre,proc.body=user_args.body,proc.post=user_args.post;var proc_args=user_args.args.slice(0);proc.argTypes=proc_args;for(var i=0;i0)throw new Error("cwise: pre() block may not reference array args");if(i0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===arg_type)proc.scalarArgs.push(i),proc.shimArgs.push("scalar"+i);else if("index"===arg_type){if(proc.indexArgs.push(i),i0)throw new Error("cwise: pre() block may not reference array index");if(i0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===arg_type){if(proc.shapeArgs.push(i),iproc_args.length)throw new Error("cwise: Too many arguments in pre() block");if(proc.body.args.length>proc_args.length)throw new Error("cwise: Too many arguments in body() block");if(proc.post.args.length>proc_args.length)throw new Error("cwise: Too many arguments in post() block");return proc.debug=!!user_args.printCode||!!user_args.debug,proc.funcName=user_args.funcName||"cwise",proc.blockSize=user_args.blockSize||64,createThunk(proc)}var createThunk=require("./lib/thunk.js");module.exports=compileCwise},{"./lib/thunk.js":7}],6:[function(require,module){"use strict";function innerFill(order,proc,body){var i,j,dimension=order.length,nargs=proc.arrayArgs.length,has_index=proc.indexArgs.length>0,code=[],vars=[],idx=0,pidx=0;for(i=0;dimension>i;++i)vars.push(["i",i,"=0"].join(""));for(j=0;nargs>j;++j)for(i=0;dimension>i;++i)pidx=idx,idx=order[i],vars.push(0===i?["d",j,"s",i,"=t",j,"p",idx].join(""):["d",j,"s",i,"=(t",j,"p",idx,"-s",pidx,"*t",j,"p",pidx,")"].join(""));for(code.push("var "+vars.join(",")),i=dimension-1;i>=0;--i)idx=order[i],code.push(["for(i",i,"=0;i",i,"i;++i){for(pidx=idx,idx=order[i],j=0;nargs>j;++j)code.push(["p",j,"+=d",j,"s",i].join(""));has_index&&(i>0&&code.push(["index[",pidx,"]-=s",pidx].join("")),code.push(["++index[",idx,"]"].join(""))),code.push("}")}return code.join("\n")}function outerFill(matched,order,proc,body){for(var dimension=order.length,nargs=proc.arrayArgs.length,blockSize=proc.blockSize,has_index=proc.indexArgs.length>0,code=[],i=0;nargs>i;++i)code.push(["var offset",i,"=p",i].join(""));for(var i=matched;dimension>i;++i)code.push(["for(var j"+i+"=SS[",order[i],"]|0;j",i,">0;){"].join("")),code.push(["if(j",i,"<",blockSize,"){"].join("")),code.push(["s",order[i],"=j",i].join("")),code.push(["j",i,"=0"].join("")),code.push(["}else{s",order[i],"=",blockSize].join("")),code.push(["j",i,"-=",blockSize,"}"].join("")),has_index&&code.push(["index[",order[i],"]=j",i].join(""));for(var i=0;nargs>i;++i){for(var indexStr=["offset"+i],j=matched;dimension>j;++j)indexStr.push(["j",j,"*t",i,"p",order[j]].join(""));code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;dimension>i;++i)code.push("}");return code.join("\n")}function countMatches(orders){for(var matched=0,dimension=orders[0].length;dimension>matched;){for(var j=1;j0&&(allEqual=allEqual&&summary[i]===summary[i-1])}return allEqual?summary[0]:summary.join("")}function generateCWiseOp(proc,typesig){for(var dimension=0|typesig[1].length,orders=new Array(proc.arrayArgs.length),dtypes=new Array(proc.arrayArgs.length),arglist=["SS"],code=["'use strict'"],vars=[],j=0;dimension>j;++j)vars.push(["s",j,"=SS[",j,"]"].join(""));for(var i=0;ij;++j)vars.push(["t",i,"p",j,"=t",i,"[",j,"]"].join(""))}for(var i=0;i0&&vars.push("shape=SS.slice(0)"),proc.indexArgs.length>0){for(var zeros=new Array(dimension),i=0;dimension>i;++i)zeros[i]="0";vars.push(["index=[",zeros.join(","),"]"].join(""))}for(var i=0;i3&&code.push(processBlock(proc.pre,proc,dtypes));var body=processBlock(proc.body,proc,dtypes),matched=countMatches(orders);code.push(dimension>matched?outerFill(matched,orders[0],proc,body):innerFill(orders[0],proc,body)),proc.post.body.length>3&&code.push(processBlock(proc.post,proc,dtypes)),proc.debug&&console.log("Generated cwise routine for ",typesig,":\n\n",code.join("\n"));var loopName=[proc.funcName||"unnamed","_cwise_loop_",orders[0].join("s"),"m",matched,typeSummary(dtypes)].join(""),f=new Function(["function ",loopName,"(",arglist.join(","),"){",code.join("\n"),"} return ",loopName].join(""));return f()}var uniq=require("uniq");module.exports=generateCWiseOp},{uniq:8}],7:[function(require,module){"use strict";function createThunk(proc){var code=["'use strict'","var CACHED={}"],vars=[],thunkName=proc.funcName+"_cwise_thunk";code.push(["return function ",thunkName,"(",proc.shimArgs.join(","),"){"].join(""));for(var typesig=[],string_typesig=[],proc_args=[["array",proc.arrayArgs[0],".shape"].join("")],i=0;ii;++i)if(b=a,a=list[i],compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique_eq(list){for(var ptr=1,len=list.length,a=list[0],b=list[0],i=1;len>i;++i,b=a)if(b=a,a=list[i],a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}return list.length=ptr,list}function unique(list,compare,sorted){return 0===list.length?list:compare?(sorted||list.sort(compare),unique_pred(list,compare)):(sorted||list.sort(),unique_eq(list))}module.exports=unique},{}],9:[function(require,module){(function(Buffer){function compare1st(a,b){return a[0]-b[0]}function order(){var i,stride=this.stride,terms=new Array(stride.length);for(i=0;idimension&&(className="View_Nil"+dtype);var useGetters="generic"===dtype;if(-1===dimension){var code="function "+className+"(a){this.data=a;};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+className+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+className+"(a){return new "+className+"(a);}",procedure=new Function(code);return procedure()}if(0===dimension){var code="function "+className+"(a,d) {this.data = a;this.offset = d};var proto="+className+".prototype;proto.dtype='"+dtype+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+className+"_copy() {return new "+className+"(this.data,this.offset)};proto.pick=function "+className+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+className+"_get(){return "+(useGetters?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+className+"_set(v){return "+(useGetters?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}",procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"],indices=iota(dimension),args=indices.map(function(i){return"i"+i}),index_str="this.offset+"+indices.map(function(i){return"this._stride"+i+"*i"+i}).join("+");code.push("function "+className+"(a,"+indices.map(function(i){return"b"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",d){this.data=a");for(var i=0;dimension>i;++i)code.push("this._shape"+i+"=b"+i+"|0");for(var i=0;dimension>i;++i)code.push("this._stride"+i+"=c"+i+"|0");code.push("this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);var strideClassName="VStride"+dimension+"d"+dtype,shapeClassName="VShape"+dimension+"d"+dtype,props={stride:strideClassName,shape:shapeClassName};for(var prop in props){var arrayName=props[prop];code.push("function "+arrayName+"(v) {this._v=v} var aproto="+arrayName+".prototype","aproto.length="+dimension);for(var array_elements=[],i=0;dimension>i;++i)array_elements.push(["this._v._",prop,i].join(""));code.push("aproto.toJSON=function "+arrayName+"_toJSON(){return ["+array_elements.join(",")+"]}","aproto.valueOf=aproto.toString=function "+arrayName+"_toString(){return ["+array_elements.join(",")+"].join()}");for(var i=0;dimension>i;++i)code.push("Object.defineProperty(aproto,"+i+",{get:function(){return this._v._"+prop+i+"},set:function(v){return this._v._"+prop+i+"=v|0},enumerable:true})");for(var i=0;ii;++i)code.push("this._"+prop+i+"=v["+i+"]|0");code.push("return v}})")}code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this._shape"+i}).join("*"),"}})"),1===dimension?code.push("proto.order=[0]"):(code.push("Object.defineProperty(proto,'order',{get:"),4>dimension?(code.push("function "+className+"_order(){"),2===dimension?code.push("return (Math.abs(this._stride0)>Math.abs(this._stride1))?[1,0]:[0,1]}})"):3===dimension&&code.push("var s0=Math.abs(this._stride0),s1=Math.abs(this._stride1),s2=Math.abs(this._stride2);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):code.push("ORDER})")),code.push("proto.set=function "+className+"_set("+args.join(",")+",v){"),code.push(useGetters?"return this.data.set("+index_str+",v)}":"return this.data["+index_str+"]=v}"),code.push("proto.get=function "+className+"_get("+args.join(",")+"){"),code.push(useGetters?"return this.data.get("+index_str+")}":"return this.data["+index_str+"]}"),code.push("proto.index=function "+className+"_index(",args.join(),"){return "+index_str+"}"),code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+indices.map(function(i){return["(typeof i",i,"!=='number'||i",i,"<0)?this._shape",i,":i",i,"|0"].join("")}).join(",")+","+indices.map(function(i){return"this._stride"+i}).join(",")+",this.offset)}");var a_vars=indices.map(function(i){return"a"+i+"=this._shape"+i}),c_vars=indices.map(function(i){return"c"+i+"=this._stride"+i});code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(","));for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){d=i"+i+"|0;b+=c"+i+"*d;a"+i+"-=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"c"+i}).join(",")+",b)}"),code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+indices.map(function(i){return"a"+i+"=this._shape"+i}).join(",")+","+indices.map(function(i){return"b"+i+"=this._stride"+i}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'){d=i"+i+"|0;if(d<0){c+=b"+i+"*(a"+i+"-1);a"+i+"=ceil(-a"+i+"/d)}else{a"+i+"=ceil(a"+i+"/d)}b"+i+"*=d}");code.push("return new "+className+"(this.data,"+indices.map(function(i){return"a"+i}).join(",")+","+indices.map(function(i){return"b"+i}).join(",")+",c)}");for(var tShape=new Array(dimension),tStride=new Array(dimension),i=0;dimension>i;++i)tShape[i]="a[i"+i+"]",tStride[i]="b[i"+i+"]";code.push("proto.transpose=function "+className+"_transpose("+args+"){"+args.map(function(n,idx){return n+"=("+n+"===undefined?"+idx+":"+n+"|0)"}).join(";"),"var a=this.shape,b=this.stride;return new "+className+"(this.data,"+tShape.join(",")+","+tStride.join(",")+",this.offset)}"),code.push("proto.pick=function "+className+"_pick("+args+"){var a=[],b=[],c=this.offset");for(var i=0;dimension>i;++i)code.push("if(typeof i"+i+"==='number'&&i"+i+">=0){c=(c+this._stride"+i+"*i"+i+")|0}else{a.push(this._shape"+i+");b.push(this._stride"+i+")}");code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+indices.map(function(i){return"shape["+i+"]"}).join(",")+","+indices.map(function(i){return"stride["+i+"]"}).join(",")+",offset)}");var procedure=new Function("CTOR_LIST","ORDER",code.join("\n"));return procedure(CACHED_CONSTRUCTORS[dtype],order)}function arrayDType(data){if(hasBuffer&&Buffer.isBuffer(data))return"buffer";if(hasTypedArrays)switch(Object.prototype.toString.call(data)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped"}return Array.isArray(data)?"array":"generic"}function wrappedNDArrayCtor(data,shape,stride,offset){if(void 0===data){var ctor=CACHED_CONSTRUCTORS.array[0];return ctor([])}"number"==typeof data&&(data=[data]),void 0===shape&&(shape=[data.length]);var d=shape.length;if(void 0===stride){stride=new Array(d);for(var i=d-1,sz=1;i>=0;--i)stride[i]=sz,sz*=shape[i]}if(void 0===offset){offset=0;for(var i=0;d>i;++i)stride[i]<0&&(offset-=(shape[i]-1)*stride[i])}for(var dtype=arrayDType(data),ctor_list=CACHED_CONSTRUCTORS[dtype];ctor_list.length<=d+1;)ctor_list.push(compileConstructor(dtype,ctor_list.length-1));var ctor=ctor_list[d+1];return ctor(data,shape,stride,offset)}var iota=require("iota-array"),arrayMethods=["concat","join","slice","toString","indexOf","lastIndexOf","forEach","every","some","filter","map","reduce","reduceRight"],hasTypedArrays="undefined"!=typeof Float64Array,hasBuffer="undefined"!=typeof Buffer,CACHED_CONSTRUCTORS={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],buffer:[],generic:[]};module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:111,"iota-array":10}],10:[function(require,module){"use strict";function iota(n){for(var result=new Array(n),i=0;n>i;++i)result[i]=i;return result}module.exports=iota},{}],11:[function(require,module,exports){"use strict";"use restrict";function countTrailingZeros(v){var c=32;return v&=-v,v&&c--,65535&v&&(c-=16),16711935&v&&(c-=8),252645135&v&&(c-=4),858993459&v&&(c-=2),1431655765&v&&(c-=1),c}var INT_BITS=32;exports.INT_BITS=INT_BITS,exports.INT_MAX=2147483647,exports.INT_MIN=-1<0)-(0>v)},exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask},exports.min=function(x,y){return y^(x^y)&-(y>x)},exports.max=function(x,y){return x^(x^y)&-(y>x)},exports.isPow2=function(v){return!(v&v-1||!v)},exports.log2=function(v){var r,shift;return r=(v>65535)<<4,v>>>=r,shift=(v>255)<<3,v>>>=shift,r|=shift,shift=(v>15)<<2,v>>>=shift,r|=shift,shift=(v>3)<<1,v>>>=shift,r|=shift,r|v>>1},exports.log10=function(v){return v>=1e9?9:v>=1e8?8:v>=1e7?7:v>=1e6?6:v>=1e5?5:v>=1e4?4:v>=1e3?3:v>=100?2:v>=10?1:0},exports.popCount=function(v){return v-=v>>>1&1431655765,v=(858993459&v)+(v>>>2&858993459),16843009*(v+(v>>>4)&252645135)>>>24},exports.countTrailingZeros=countTrailingZeros,exports.nextPow2=function(v){return v+=0===v,--v,v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v+1},exports.prevPow2=function(v){return v|=v>>>1,v|=v>>>2,v|=v>>>4,v|=v>>>8,v|=v>>>16,v-(v>>>1)},exports.parity=function(v){return v^=v>>>16,v^=v>>>8,v^=v>>>4,v&=15,27030>>>v&1};var REVERSE_TABLE=new Array(256);!function(tab){for(var i=0;256>i;++i){var v=i,r=i,s=7;for(v>>>=1;v;v>>>=1)r<<=1,r|=1&v,--s;tab[i]=r<>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]},exports.interleave2=function(x,y){return x&=65535,x=16711935&(x|x<<8),x=252645135&(x|x<<4),x=858993459&(x|x<<2),x=1431655765&(x|x<<1),y&=65535,y=16711935&(y|y<<8),y=252645135&(y|y<<4),y=858993459&(y|y<<2),y=1431655765&(y|y<<1),x|y<<1},exports.deinterleave2=function(v,n){return v=v>>>n&1431655765,v=858993459&(v|v>>>1),v=252645135&(v|v>>>2),v=16711935&(v|v>>>4),v=65535&(v|v>>>16),v<<16>>16},exports.interleave3=function(x,y,z){return x&=1023,x=4278190335&(x|x<<16),x=251719695&(x|x<<8),x=3272356035&(x|x<<4),x=1227133513&(x|x<<2),y&=1023,y=4278190335&(y|y<<16),y=251719695&(y|y<<8),y=3272356035&(y|y<<4),y=1227133513&(y|y<<2),x|=y<<1,z&=1023,z=4278190335&(z|z<<16),z=251719695&(z|z<<8),z=3272356035&(z|z<<4),z=1227133513&(z|z<<2),x|z<<2},exports.deinterleave3=function(v,n){return v=v>>>n&1227133513,v=3272356035&(v|v>>>2),v=251719695&(v|v>>>4),v=4278190335&(v|v>>>8),v=1023&(v|v>>>16),v<<22>>22},exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],12:[function(require,module){"use strict";function dupe_array(count,value,i){var c=0|count[i];if(0>=c)return[];var j,result=new Array(c);if(i===count.length-1)for(j=0;c>j;++j)result[j]=value;else for(j=0;c>j;++j)result[j]=dupe_array(count,value,i+1);return result}function dupe_number(count,value){var result,i;for(result=new Array(count),i=0;count>i;++i)result[i]=value;return result}function dupe(count,value){switch("undefined"==typeof value&&(value=0),typeof count){case"number":if(count>0)return dupe_number(0|count,value);break;case"object":if("number"==typeof count.length)return dupe_array(count,value,0)}return[]}module.exports=dupe},{}],13:[function(require,module,exports){(function(global){"use strict";var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0])});var POOL=global.__TYPEDARRAY_POOL,UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA;exports.free=function(array){if(array instanceof ArrayBuffer){var n=0|array.byteLength,log_n=bits.log2(n);DATA[log_n].push(array)}else{var n=0|array.length,log_n=bits.log2(n);array instanceof Uint8Array?UINT8[log_n].push(array):array instanceof Uint16Array?UINT16[log_n].push(array):array instanceof Uint32Array?UINT32[log_n].push(array):array instanceof Int8Array?INT8[log_n].push(array):array instanceof Int16Array?INT16[log_n].push(array):array instanceof Int32Array?INT32[log_n].push(array):array instanceof Float32Array?FLOAT[log_n].push(array):array instanceof Float64Array&&DOUBLE[log_n].push(array)}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"bit-twiddle":11,dup:12}],14:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],15:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this.elements=null,this.attributes=null}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this.elements,this.attributes)},VAOEmulated.prototype.update=function(elements,attributes){this.elements=elements,this.attributes=attributes},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},module.exports=createVAOEmulated},{"./do-bind.js":14}],16:[function(require,module){"use strict";function VAONative(gl,ext,handle){this.gl=gl,this.ext=ext,this.handle=handle}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VAONative.prototype.bind=function(){this.ext.bindVertexArrayOES(this.handle)},VAONative.prototype.unbind=function(){this.ext.bindVertexArrayOES(null)},VAONative.prototype.dispose=function(){this.ext.deleteVertexArrayOES(this.handle)},VAONative.prototype.update=function(elements,attributes){this.bind(),bindAttribs(this.gl,elements,attributes),this.unbind()},module.exports=createVAONative},{"./do-bind.js":14}],17:[function(require,module){"use strict";function baseName(ext_name){for(var i=0;ix;x++)for(var y=0;h>y;y++)for(var z=0;d>z;z++)if(filter(x,y,z)){var cube=prism(size,[x/w,y/h,z/d]);cubes.push(cube),cube.centroid=[(x+.5)/w,(y+.5)/h,(z+.5)/d],cube.index=[x,y,z]}return cubes}var prism=require("rectangular-prism"),truthy=function(){return!0};module.exports=cubecube},{"rectangular-prism":25}],24:[function(require,module){module.exports={cells:[[1,0,2],[3,1,2],[4,5,6],[5,7,6],[0,1,5],[4,0,5],[1,3,5],[3,7,5],[2,0,4],[2,4,6],[2,6,3],[6,7,3]],positions:[[0,0,0],[0,0,1],[1,0,0],[1,0,1],[0,1,0],[0,1,1],[1,1,0],[1,1,1]]}},{}],25:[function(require,module){function createPrism(size,pos){pos=pos||[0,0,0],size=size||[1,1,1],Array.isArray(size)||(size=[size,size,size]);for(var prism=clonePrism(),i=0;ii;i+=9){var p1x=verts[i+3]-verts[i],p1y=verts[i+4]-verts[i+1],p1z=verts[i+5]-verts[i+2],p2x=verts[i+6]-verts[i],p2y=verts[i+7]-verts[i+1],p2z=verts[i+8]-verts[i+2],p3x=p1y*p2z-p1z*p2y,p3y=p1z*p2x-p1x*p2z,p3z=p1x*p2y-p1y*p2x,mag=Math.sqrt(p3x*p3x+p3y*p3y+p3z*p3z);0===mag?(output[i]=0,output[i+1]=0,output[i+2]=0,output[i+3]=0,output[i+4]=0,output[i+5]=0,output[i+6]=0,output[i+7]=0,output[i+8]=0):(p3x/=mag,p3y/=mag,p3z/=mag,output[i]=p3x,output[i+1]=p3y,output[i+2]=p3z,output[i+3]=p3x,output[i+4]=p3y,output[i+5]=p3z,output[i+6]=p3x,output[i+7]=p3y,output[i+8]=p3z)}return output}module.exports=faceNormals},{}],27:[function(require,module){(function(process){function debounce(fn,now){function debounced(){null===args&&(args=slice(arguments),ctx=this,now&&fn.apply(ctx,args),raf(next))}function next(){now||fn.apply(ctx,args),args=null,ctx=null}var args=null,ctx=null;return debounced}var slice=require("sliced");if(process.browser)var raf=require("raf-component");else var raf="undefined"!=typeof setImmediate?setImmediate:process.nextTick;module.exports=debounce}).call(this,require("_process"))},{_process:115,"raf-component":28,sliced:29}],28:[function(require,module,exports){function fallback(fn){var curr=(new Date).getTime(),ms=Math.max(0,16-(curr-prev)),req=setTimeout(fn,ms);return prev=curr,req}exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||fallback;var prev=(new Date).getTime(),cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],29:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":30}],30:[function(require,module){module.exports=function(args,slice,sliceEnd){var ret=[],len=args.length;if(0===len)return ret;var start=0>slice?Math.max(0,slice+len):slice||0;for(void 0!==sliceEnd&&(len=0>sliceEnd?sliceEnd+len:sliceEnd);len-->start;)ret[len-start]=args[len];return ret}},{}],31:[function(require,module){function defaults(opts){return{color:array(opts.color,[0,0,0,1]),depth:number(opts.depth,1),stencil:number(opts.stencil,!1)}}function number(n,def){return n===!1?!1:"undefined"==typeof n?def:n+0}function array(a,def){return a===!1?!1:Array.isArray(a)?a||def:def}module.exports=defaults},{}],32:[function(require,module){function clear(opts){opts=defaults(opts||{});var stencil=opts.stencil,color=opts.color,depth=opts.depth;return function(gl){var flags=0;return color!==!1&&(gl.clearColor(color[0],color[1],color[2],color[3]),flags|=gl.COLOR_BUFFER_BIT),depth!==!1&&(gl.clearDepth(depth),flags|=gl.DEPTH_BUFFER_BIT),stencil!==!1&&(gl.clearStencil(stencil),flags|=gl.STENCIL_BUFFER_BIT),gl.clear(flags),gl}}var defaults=require("./defaults");module.exports=clear},{"./defaults":31}],33:[function(require,module){function createContext(canvas,opts,render){function tick(){render(gl),raf(tick)}"function"==typeof opts?(render=opts,opts={}):opts=opts||{};var gl=canvas.getContext("webgl",opts)||canvas.getContext("webgl-experimental",opts)||canvas.getContext("experimental-webgl",opts);if(!gl)throw new Error("Unable to initialize WebGL");return render&&raf(tick),gl}var raf=require("raf-component");module.exports=createContext},{"raf-component":34}],34:[function(require,module,exports){arguments[4][28][0].apply(exports,arguments)},{dup:28}],35:[function(require,module){"use strict";function lazyInitColorAttachments(gl,ext){var maxColorAttachments=gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL);colorAttachmentArrays=new Array(maxColorAttachments+1);for(var i=0;maxColorAttachments>=i;++i){for(var x=new Array(maxColorAttachments),j=0;i>j;++j)x[j]=gl.COLOR_ATTACHMENT0+j;for(var j=i;maxColorAttachments>j;++j)x[j]=gl.NONE;colorAttachmentArrays[i]=x}}function throwFBOError(status){switch(status){case FRAMEBUFFER_UNSUPPORTED:throw new Error("gl-fbo: Framebuffer unsupported");case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete attachment");case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw new Error("gl-fbo: Framebuffer incomplete dimensions");case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw new Error("gl-fbo: Framebuffer incomplete missing attachment");default:throw new Error("gl-fbo: Framebuffer failed for unspecified reason")}}function initTexture(gl,width,height,type,format,attachment){if(!type)return null;var result=createTexture(gl,width,height,format,type);return result.magFilter=gl.NEAREST,result.minFilter=gl.NEAREST,result.mipSamples=1,gl.framebufferTexture2D(gl.FRAMEBUFFER,attachment,gl.TEXTURE_2D,result.handle,0),gl.bindTexture(gl.TEXTURE_2D,null),result}function initRenderBuffer(gl,width,height,component,attachment){var result=gl.createRenderbuffer();return gl.bindRenderbuffer(gl.RENDERBUFFER,result),gl.renderbufferStorage(gl.RENDERBUFFER,component,width,height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,attachment,gl.RENDERBUFFER,result),result}function rebuildFBO(fbo){var gl=fbo.gl,handle=fbo.handle=gl.createFramebuffer(),height=fbo._shape[0],width=fbo._shape[1],numColors=fbo.color.length,ext=fbo._ext,useStencil=fbo._useStencil,useDepth=fbo._useDepth,colorType=fbo._colorType,extensions=webglew(gl);gl.bindFramebuffer(gl.FRAMEBUFFER,handle);for(var i=0;numColors>i;++i)fbo.color[i]=initTexture(gl,width,height,colorType,gl.RGBA,gl.COLOR_ATTACHMENT0+i);0===numColors?(fbo._color_rb=initRenderBuffer(gl,width,height,gl.RGBA4,gl.COLOR_ATTACHMENT0),ext&&ext.drawBuffersWEBGL(colorAttachmentArrays[0])):numColors>1&&ext.drawBuffersWEBGL(colorAttachmentArrays[numColor]),extensions.WEBGL_depth_texture?useStencil?fbo.depth=initTexture(gl,width,height,extensions.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth&&(fbo.depth=initTexture(gl,width,height,gl.UNSIGNED_SHORT,gl.DEPTH_COMPONENT,gl.DEPTH_ATTACHMENT)):useDepth&&useStencil?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_STENCIL,gl.DEPTH_STENCIL_ATTACHMENT):useDepth?fbo._depth_rb=initRenderBuffer(gl,width,height,gl.DEPTH_COMPONENT16,gl.DEPTH_ATTACHMENT):useStencil&&(fbo._depth_rb=initRenderBuffer(gl,width,height,gl.STENCIL_INDEX,gl.STENCIL_ATTACHMENT)); var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAMEBUFFER_COMPLETE){fbo._destroyed=!0,gl.bindFramebuffer(gl.FRAMEBUFFER,null),gl.deleteFramebuffer(fbo.handle),fbo.handle=null,fbo.depth&&(fbo.depth.dispose(),fbo.depth=null),fbo._depth_rb&&(gl.deleteRenderbuffer(fbo._depth_rb),fbo._depth_rb=null);for(var i=0;iwidth||width>maxFBOSize||0>height||height>maxFBOSize)throw new Error("gl-fbo: Parameters are too large for FBO");options=options||{};var numColors=1;if("color"in options){if(numColors=Math.max(0|options.color,0),0>numColors)throw new Error("gl-fbo: Must specify a nonnegative number of colors");if(numColors>1){var mrtext=extensions.WEBGL_draw_buffers;if(!mrtext)throw new Error("gl-fbo: Multiple draw buffer extension not supported");if(numColors>gl.getParameter(mrtext.MAX_COLOR_ATTACHMENTS_WEBGL))throw new Error("gl-fbo: Context does not support "+numColors+" draw buffers")}}var colorType=gl.UNSIGNED_BYTE;if(options["float"]&&numColors>0){if(!extensions.OES_texture_float)throw new Error("gl-fbo: Context does not support floating point textures");colorType=gl.FLOAT}else options.preferFloat&&numColors>0&&extensions.OES_texture_float&&(colorType=gl.FLOAT);var useDepth=!0;"depth"in options&&(useDepth=!!options.depth);var useStencil=!1;return"stencil"in options&&(useStencil=!!options.stencil),new Framebuffer(gl,width,height,colorType,numColors,useDepth,useStencil,extensions.WEBGL_draw_buffers)}var webglew=require("webglew"),createTexture=require("gl-texture2d");module.exports=createFBO;var FRAMEBUFFER_UNSUPPORTED,FRAMEBUFFER_INCOMPLETE_ATTACHMENT,FRAMEBUFFER_INCOMPLETE_DIMENSIONS,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,colorAttachmentArrays=null,proto=Framebuffer.prototype;Object.defineProperty(proto,"valid",{get:function(){return!this._destroyed}}),Object.defineProperty(proto,"shape",{get:function(){return this._destroyed?[0,0]:this._shape},set:function(x){if(this._destroyed)throw new Error("gl-fbo: Can't resize destroyed FBO");if(!(this._shape[0]===x[0]|0&&this._shape[1]===x[1]|0)){var gl=this.gl,maxFBOSize=gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);if(!Array.isArray(x)||2!==x.length||x[0]<0||x[0]>maxFBOSize||x[1]<0||x[1]>maxFBOSize)throw new Error("gl-fbo: Can't resize FBO, invalid dimensions");this._shape[0]=0|x[0],this._shape[1]=0|x[1];for(var i=0;ij;j++)out[k++]=arr[i][j];return out}var dtype=require("dtype");module.exports=pack},{dtype:40}],40:[function(require,module){module.exports=function(dtype){switch(dtype){case"int8":return Int8Array;case"int16":return Int16Array;case"int32":return Int32Array;case"uint8":return Uint8Array;case"uint16":return Uint16Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;case"array":return Array}}},{}],41:[function(require,module){"use strict";function GLBuffer(gl,type,handle,length,usage){this.gl=gl,this.type=type,this.handle=handle,this.length=length,this.usage=usage}function updateTypeArray(gl,type,len,usage,data,offset){var dataLen=data.length*data.BYTES_PER_ELEMENT;if(0>offset)return gl.bufferData(type,data,usage),dataLen;if(dataLen+offset>len)throw new Error("gl-buffer: If resizing buffer, must not specify offset");return gl.bufferSubData(type,offset,data),len}function makeScratchTypeArray(array,dtype){for(var res=pool.malloc(array.length,dtype),n=array.length,i=0;n>i;++i)res[i]=array[i];return res}function isPacked(shape,stride){for(var n=1,i=stride.length-1;i>=0;--i){if(stride[i]!==n)return!1;n*=shape[i]}return!0}function createBuffer(gl,data,type,usage){if(webglew(gl),type=type||gl.ARRAY_BUFFER,usage=usage||gl.DYNAMIC_DRAW,type!==gl.ARRAY_BUFFER&&type!==gl.ELEMENT_ARRAY_BUFFER)throw new Error("gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER");if(usage!==gl.DYNAMIC_DRAW&&usage!==gl.STATIC_DRAW&&usage!==gl.STREAM_DRAW)throw new Error("gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW");var handle=gl.createBuffer(),result=new GLBuffer(gl,type,handle,0,usage);return result.update(data),result}var pool=require("typedarray-pool"),ops=require("ndarray-ops"),ndarray=require("ndarray"),webglew=require("webglew"),SUPPORTED_TYPES=["uint8","uint8_clamped","uint16","uint32","int8","int16","int32","float32"],proto=GLBuffer.prototype;proto.bind=function(){this.gl.bindBuffer(this.type,this.handle)},proto.dispose=function(){this.gl.deleteBuffer(this.handle)},proto.update=function(array,offset){if("number"!=typeof offset&&(offset=-1),this.bind(),"object"==typeof array&&"undefined"!=typeof array.shape){var dtype=array.dtype;if(SUPPORTED_TYPES.indexOf(dtype)<0&&(dtype="float32"),this.type===this.gl.ELEMENT_ARRAY_BUFFER){var wgl=webglew(this.gl),ext=wgl.OES_element_index_uint;dtype=ext&&"uint16"!==dtype?"uint32":"uint16"}if(dtype===array.dtype&&isPacked(array.shape,array.stride))this.length=0===array.offset&&array.data.length===array.shape[0]?updateTypeArray(this.gl,this.type,this.length,this.usage,array.data,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,array.data.subarray(array.offset,array.shape[0]),offset);else{var tmp=pool.malloc(array.size,dtype),ndt=ndarray(tmp,array.shape);ops.assign(ndt,array),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,tmp,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,tmp.subarray(0,array.size),offset),pool.free(tmp)}}else if(Array.isArray(array)){var t;t=this.type===this.gl.ELEMENT_ARRAY_BUFFER?makeScratchTypeArray(array,"uint16"):makeScratchTypeArray(array,"float32"),this.length=0>offset?updateTypeArray(this.gl,this.type,this.length,this.usage,t,offset):updateTypeArray(this.gl,this.type,this.length,this.usage,t.subarray(0,array.length),offset),pool.free(t)}else if("object"==typeof array&&"number"==typeof array.length)this.length=updateTypeArray(this.gl,this.type,this.length,this.usage,array,offset);else{if("number"!=typeof array&&void 0!==array)throw new Error("gl-buffer: Invalid data type");if(offset>=0)throw new Error("gl-buffer: Cannot specify offset when resizing buffer");array=0|array,0>=array&&(array=1),this.gl.bufferData(this.type,0|array,this.usage),this.length=array}},module.exports=createBuffer},{ndarray:47,"ndarray-ops":42,"typedarray-pool":51,webglew:53}],42:[function(require,module,exports){arguments[4][4][0].apply(exports,arguments)},{"cwise-compiler":43,dup:4}],43:[function(require,module,exports){arguments[4][5][0].apply(exports,arguments)},{"./lib/thunk.js":45,dup:5}],44:[function(require,module,exports){arguments[4][6][0].apply(exports,arguments)},{dup:6,uniq:46}],45:[function(require,module,exports){arguments[4][7][0].apply(exports,arguments)},{"./compile.js":44,dup:7}],46:[function(require,module,exports){arguments[4][8][0].apply(exports,arguments)},{dup:8}],47:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{buffer:111,dup:9,"iota-array":48}],48:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{dup:10}],49:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{dup:11}],50:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{dup:12}],51:[function(require,module,exports){(function(global,Buffer){var bits=require("bit-twiddle"),dup=require("dup");global.__TYPEDARRAY_POOL||(global.__TYPEDARRAY_POOL={UINT8:dup([32,0]),UINT16:dup([32,0]),UINT32:dup([32,0]),INT8:dup([32,0]),INT16:dup([32,0]),INT32:dup([32,0]),FLOAT:dup([32,0]),DOUBLE:dup([32,0]),DATA:dup([32,0]),UINT8C:dup([32,0]),BUFFER:dup([32,0])});var hasUint8C="undefined"!=typeof Uint8ClampedArray,POOL=global.__TYPEDARRAY_POOL;POOL.UINT8C||(POOL.UINT8C=dup([32,0])),POOL.BUFFER||(POOL.BUFFER=dup([32,0]));var UINT8=POOL.UINT8,UINT16=POOL.UINT16,UINT32=POOL.UINT32,INT8=POOL.INT8,INT16=POOL.INT16,INT32=POOL.INT32,FLOAT=POOL.FLOAT,DOUBLE=POOL.DOUBLE,DATA=POOL.DATA,UINT8C=POOL.UINT8C,BUFFER=POOL.BUFFER;exports.free=function(array){var n=0|array.length,log_n=bits.log2(n);if(Buffer.isBuffer(array))BUFFER[log_n].push(array);else switch(Object.prototype.toString.call(array)){case"[object Uint8Array]":UINT8[log_n].push(array);break;case"[object Uint16Array]":UINT16[log_n].push(array);break;case"[object Uint32Array]":UINT32[log_n].push(array);break;case"[object Int8Array]":INT8[log_n].push(array);break;case"[object Int16Array]":INT16[log_n].push(array);break;case"[object Int32Array]":INT32[log_n].push(array);break;case"[object Uint8ClampedArray]":UINT8C[log_n].push(array);break;case"[object Float32Array]":FLOAT[log_n].push(array);break;case"[object Float64Array]":DOUBLE[log_n].push(array);break;case"[object ArrayBuffer]":DATA[log_n].push(array);break;default:throw new Error("typedarray-pool: Unspecified array type")}},exports.freeUint8=function(array){UINT8[bits.log2(array.length)].push(array)},exports.freeUint16=function(array){UINT16[bits.log2(array.length)].push(array)},exports.freeUint32=function(array){UINT32[bits.log2(array.length)].push(array)},exports.freeInt8=function(array){INT8[bits.log2(array.length)].push(array)},exports.freeInt16=function(array){INT16[bits.log2(array.length)].push(array)},exports.freeInt32=function(array){INT32[bits.log2(array.length)].push(array)},exports.freeFloat32=exports.freeFloat=function(array){FLOAT[bits.log2(array.length)].push(array)},exports.freeFloat64=exports.freeDouble=function(array){DOUBLE[bits.log2(array.length)].push(array)},exports.freeArrayBuffer=function(array){DATA[bits.log2(array.length)].push(array)},exports.freeUint8Clamped=hasUint8C?function(array){UINT8C[bits.log2(array.length)].push(array)}:exports.freeUint8,exports.freeBuffer=function(array){BUFFER[bits.log2(array.length)].push(array)},exports.malloc=function(n,dtype){n=bits.nextPow2(n);var log_n=bits.log2(n);if(void 0===dtype||"arraybuffer"===dtype){var d=DATA[log_n];if(d.length>0){var r=d[d.length-1];return d.pop(),r}return new ArrayBuffer(n)}switch(dtype){case"uint8":var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"uint16":var u16=UINT16[log_n];return u16.length>0?u16.pop():new Uint16Array(n);case"uint32":var u32=UINT32[log_n];return u32.length>0?u32.pop():new Uint32Array(n);case"int8":var i8=INT8[log_n];return i8.length>0?i8.pop():new Int8Array(n);case"int16":var i16=INT16[log_n];return i16.length>0?i16.pop():new Int16Array(n);case"int32":var i32=INT32[log_n];return i32.length>0?i32.pop():new Int32Array(n);case"float":case"float32":var f=FLOAT[log_n];return f.length>0?f.pop():new Float32Array(n);case"double":case"float64":var dd=DOUBLE[log_n];return dd.length>0?dd.pop():new Float64Array(n);case"uint8_clamped":if(hasUint8C){var u8c=UINT8C[log_n];return u8c.length>0?u8c.pop():new Uint8ClampedArray(n)}var u8=UINT8[log_n];return u8.length>0?u8.pop():new Uint8Array(n);case"buffer":var buf=BUFFER[log_n];return buf.length>0?buf.pop():new Buffer(n);default:return null}return null},exports.mallocUint8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8[log_n];return cache.length>0?cache.pop():new Uint8Array(n)},exports.mallocUint16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT16[log_n];return cache.length>0?cache.pop():new Uint16Array(n)},exports.mallocUint32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT32[log_n];return cache.length>0?cache.pop():new Uint32Array(n)},exports.mallocInt8=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT8[log_n];return cache.length>0?cache.pop():new Int8Array(n)},exports.mallocInt16=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT16[log_n];return cache.length>0?cache.pop():new Int16Array(n)},exports.mallocInt32=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=INT32[log_n];return cache.length>0?cache.pop():new Int32Array(n)},exports.mallocFloat32=exports.mallocFloat=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=FLOAT[log_n];return cache.length>0?cache.pop():new Float32Array(n)},exports.mallocFloat64=exports.mallocDouble=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DOUBLE[log_n];return cache.length>0?cache.pop():new Float64Array(n)},exports.mallocArrayBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=DATA[log_n];return cache.length>0?cache.pop():new ArrayBuffer(n)},exports.mallocUint8Clamped=hasUint8C?function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=UINT8C[log_n];return cache.length>0?cache.pop():new Uint8ClampedArray(n)}:exports.mallocUint8,exports.mallocBuffer=function(n){n=bits.nextPow2(n);var log_n=bits.log2(n),cache=BUFFER[log_n];return cache.length>0?cache.pop():new Buffer(n)},exports.clearCache=function(){for(var i=0;32>i;++i)UINT8[i].length=0,UINT16[i].length=0,UINT32[i].length=0,INT8[i].length=0,INT16[i].length=0,INT32[i].length=0,FLOAT[i].length=0,DOUBLE[i].length=0,DATA[i].length=0,UINT8C[i].length=0,BUFFER[i].length=0}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},require("buffer").Buffer)},{"bit-twiddle":49,buffer:111,dup:50}],52:[function(require,module,exports){arguments[4][36][0].apply(exports,arguments)},{dup:36}],53:[function(require,module,exports){arguments[4][37][0].apply(exports,arguments)},{dup:37,weakmap:52}],54:[function(require,module){"use strict";function doBind(gl,elements,attributes){elements?elements.bind():gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,null);var nattribs=0|gl.getParameter(gl.MAX_VERTEX_ATTRIBS);if(attributes){if(attributes.length>nattribs)throw new Error("gl-vao: Too many vertex attributes");for(var i=0;ii;++i)gl.disableVertexAttribArray(i)}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;nattribs>i;++i)gl.disableVertexAttribArray(i)}}module.exports=doBind},{}],55:[function(require,module){"use strict";function VAOEmulated(gl){this.gl=gl,this._elements=null,this._attributes=null,this._elementsType=gl.UNSIGNED_SHORT}function createVAOEmulated(gl){return new VAOEmulated(gl)}var bindAttribs=require("./do-bind.js");VAOEmulated.prototype.bind=function(){bindAttribs(this.gl,this._elements,this._attributes)},VAOEmulated.prototype.update=function(attributes,elements,elementsType){this._elements=elements,this._attributes=attributes,this._elementsType=elementsType||this.gl.UNSIGNED_SHORT},VAOEmulated.prototype.dispose=function(){},VAOEmulated.prototype.unbind=function(){},VAOEmulated.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;this._elements?gl.drawElements(mode,count,this._elementsType,offset):gl.drawArrays(mode,offset,count)},module.exports=createVAOEmulated},{"./do-bind.js":54}],56:[function(require,module){"use strict";function VertexAttribute(location,dimension,a,b,c,d){this.location=location,this.dimension=dimension,this.a=a,this.b=b,this.c=c,this.d=d}function VAONative(gl,ext,handle){this.gl=gl,this._ext=ext,this.handle=handle,this._attribs=[],this._useElements=!1,this._elementsType=gl.UNSIGNED_SHORT}function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}var bindAttribs=require("./do-bind.js");VertexAttribute.prototype.bind=function(gl){switch(this.dimension){case 1:gl.vertexAttrib1f(this.location,this.a);break;case 2:gl.vertexAttrib2f(this.location,this.a,this.b);break;case 3:gl.vertexAttrib3f(this.location,this.a,this.b,this.c);break;case 4:gl.vertexAttrib4f(this.location,this.a,this.b,this.c,this.d)}},VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1]; return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out},vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);{var mat2={};new Float32Array([1,0,0,1])}mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a1*b2,out[1]=a0*b1+a1*b3,out[2]=a2*b0+a3*b2,out[3]=a2*b1+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a1*s,out[1]=a0*-s+a1*c,out[2]=a2*c+a3*s,out[3]=a2*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v1,out[2]=a2*v0,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.mat2=mat2);{var mat2d={};new Float32Array([1,0,0,1,0,0])}mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],ba=b[0],bb=b[1],bc=b[2],bd=b[3],btx=b[4],bty=b[5];return out[0]=aa*ba+ab*bc,out[1]=aa*bb+ab*bd,out[2]=ac*ba+ad*bc,out[3]=ac*bb+ad*bd,out[4]=ba*atx+bc*aty+btx,out[5]=bb*atx+bd*aty+bty,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],st=Math.sin(rad),ct=Math.cos(rad);return out[0]=aa*ct+ab*st,out[1]=-aa*st+ab*ct,out[2]=ac*ct+ad*st,out[3]=-ac*st+ct*ad,out[4]=ct*atx+st*aty,out[5]=ct*aty-st*atx,out},mat2d.scale=function(out,a,v){var vx=v[0],vy=v[1];return out[0]=a[0]*vx,out[1]=a[1]*vy,out[2]=a[2]*vx,out[3]=a[3]*vy,out[4]=a[4]*vx,out[5]=a[5]*vy,out},mat2d.translate=function(out,a,v){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4]+v[0],out[5]=a[5]+v[1],out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof exports&&(exports.mat2d=mat2d);{var mat3={};new Float32Array([1,0,0,0,1,0,0,0,1])}mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[2];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-(yy+zz),out[1]=xy+wz,out[2]=xz-wy,out[3]=xy-wz,out[4]=1-(xx+zz),out[5]=yz+wx,out[6]=xz+wy,out[7]=yz-wx,out[8]=1-(xx+yy),out},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof exports&&(exports.mat3=mat3);{var mat4={};new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)=1?(out!==a&&(out[0]=ax,out[1]=ay,out[2]=az,out[3]=aw),out):(halfTheta=Math.acos(cosHalfTheta),sinHalfTheta=Math.sqrt(1-cosHalfTheta*cosHalfTheta),Math.abs(sinHalfTheta)<.001?(out[0]=.5*ax+.5*bx,out[1]=.5*ay+.5*by,out[2]=.5*az+.5*bz,out[3]=.5*aw+.5*bw,out):(ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta,out[0]=ax*ratioA+bx*ratioB,out[1]=ay*ratioA+by*ratioB,out[2]=az*ratioA+bz*ratioB,out[3]=aw*ratioA+bw*ratioB,out))},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(){var s_iNext=[1,2,0];return function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=s_iNext[i],k=s_iNext[j];fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out}}(),quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}()},{}],64:[function(require,module,exports){arguments[4][4][0].apply(exports,arguments)},{"cwise-compiler":65,dup:4}],65:[function(require,module,exports){arguments[4][5][0].apply(exports,arguments)},{"./lib/thunk.js":67,dup:5}],66:[function(require,module,exports){arguments[4][6][0].apply(exports,arguments)},{dup:6,uniq:68}],67:[function(require,module,exports){arguments[4][7][0].apply(exports,arguments)},{"./compile.js":66,dup:7}],68:[function(require,module,exports){arguments[4][8][0].apply(exports,arguments)},{dup:8}],69:[function(require,module,exports){arguments[4][9][0].apply(exports,arguments)},{buffer:111,dup:9,"iota-array":70}],70:[function(require,module,exports){arguments[4][10][0].apply(exports,arguments)},{dup:10}],71:[function(require,module,exports){arguments[4][11][0].apply(exports,arguments)},{dup:11}],72:[function(require,module,exports){arguments[4][12][0].apply(exports,arguments)},{dup:12}],73:[function(require,module,exports){arguments[4][51][0].apply(exports,arguments)},{"bit-twiddle":71,buffer:111,dup:51}],74:[function(require,module,exports){arguments[4][36][0].apply(exports,arguments)},{dup:36}],75:[function(require,module,exports){arguments[4][37][0].apply(exports,arguments)},{dup:37,weakmap:74}],76:[function(require,module){"use strict";function lazyInitLinearTypes(gl){linearTypes=[gl.LINEAR,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_NEAREST],filterTypes=[gl.NEAREST,gl.LINEAR,gl.NEAREST_MIPMAP_NEAREST,gl.NEAREST_MIPMAP_LINEAR,gl.LINEAR_MIPMAP_NEAREST,gl.LINEAR_MIPMAP_LINEAR],wrapTypes=[gl.REPEAT,gl.CLAMP_TO_EDGE,gl.MIRRORED_REPEAT]}function Texture2D(gl,handle,width,height,format,type){this.gl=gl,this.handle=handle,this.format=format,this.type=type,this._shape=[height,width],this._mipLevels=[0],this._magFilter=gl.NEAREST,this._minFilter=gl.NEAREST,this._wrapS=gl.CLAMP_TO_EDGE,this._wrapT=gl.CLAMP_TO_EDGE,this._anisoSamples=1}function texSubImageArray(gl,x_off,y_off,mip_level,cformat,ctype,mipLevels,array){var dtype=array.dtype,shape=array.shape,packed=isPacked(array),type=0,format=0;if("float32"===dtype?type=gl.FLOAT:"float64"===dtype?(type=gl.FLOAT,packed=!1,dtype="float32"):"uint8"===dtype?type=gl.UNSIGNED_BYTE:(type=gl.UNSIGNED_BYTE,packed=!1,dtype="uint8"),2===shape.length)format=gl.LUMINANCE;else{if(3!==shape.length)throw new Error("gl-texture2d: Invalid shape for texture");if(1===shape[2])format=gl.ALPHA;else if(2===shape[2])format=gl.LUMINANCE_ALPHA;else if(3===shape[2])format=gl.RGB;else{if(4!==shape[2])throw new Error("gl-texture2d: Invalid shape for pixel coords");format=gl.RGBA}}if(format!==gl.LUMINANCE&&format!==gl.ALPHA||cformat!==gl.LUMINANCE&&cformat!==gl.ALPHA||(format=cformat),format!==cformat)throw new Error("gl-texture2d: Incompatible texture format for setPixels");var size=array.size,needsMip=mipLevels.indexOf(mip_level)<0; @@ -7,4 +7,4 @@ if(source){if("object"!=typeof source)throw new TypeError(source+"must be non-ob have--,hold+=input[next++]<>8&1),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=TIME;case TIME:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,hbuf[2]=hold>>>16&255,hbuf[3]=hold>>>24&255,state.check=crc32(state.check,hbuf,4,0)),hold=0,bits=0,state.mode=OS;case OS:for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>8),512&state.flags&&(hbuf[0]=255&hold,hbuf[1]=hold>>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0,state.mode=EXLEN;case EXLEN:if(1024&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>8&255,state.check=crc32(state.check,hbuf,2,0)),hold=0,bits=0}else state.head&&(state.head.extra=null);state.mode=EXTRA;case EXTRA:if(1024&state.flags&&(copy=state.length,copy>have&&(copy=have),copy&&(state.head&&(len=state.head.extra_len-state.length,state.head.extra||(state.head.extra=new Array(state.head.extra_len)),utils.arraySet(state.head.extra,input,next,copy,len)),512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,state.length-=copy),state.length))break inf_leave;state.length=0,state.mode=NAME;case NAME:if(2048&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.name+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.name=null);state.length=0,state.mode=COMMENT;case COMMENT:if(4096&state.flags){if(0===have)break inf_leave;copy=0;do len=input[next+copy++],state.head&&len&&state.length<65536&&(state.head.comment+=String.fromCharCode(len));while(len&&have>copy);if(512&state.flags&&(state.check=crc32(state.check,input,copy,next)),have-=copy,next+=copy,len)break inf_leave}else state.head&&(state.head.comment=null);state.mode=HCRC;case HCRC:if(512&state.flags){for(;16>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>9&1,state.head.done=!0),strm.adler=state.check=0,state.mode=TYPE;break;case DICTID:for(;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=7&bits,bits-=7&bits,state.mode=CHECK;break}for(;3>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=1,bits-=1,3&hold){case 0:state.mode=STORED;break;case 1:if(fixedtables(state),state.mode=LEN_,flush===Z_TREES){hold>>>=2,bits-=2;break inf_leave}break;case 2:state.mode=TABLE;break;case 3:strm.msg="invalid block type",state.mode=BAD}hold>>>=2,bits-=2;break;case STORED:for(hold>>>=7&bits,bits-=7&bits;32>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>16^65535)){strm.msg="invalid stored block lengths",state.mode=BAD;break}if(state.length=65535&hold,hold=0,bits=0,state.mode=COPY_,flush===Z_TREES)break inf_leave;case COPY_:state.mode=COPY;case COPY:if(copy=state.length){if(copy>have&&(copy=have),copy>left&&(copy=left),0===copy)break inf_leave;utils.arraySet(output,input,next,copy,put),have-=copy,next+=copy,left-=copy,put+=copy,state.length-=copy;break}state.mode=TYPE;break;case TABLE:for(;14>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=5,bits-=5,state.ndist=(31&hold)+1,hold>>>=5,bits-=5,state.ncode=(15&hold)+4,hold>>>=4,bits-=4,state.nlen>286||state.ndist>30){strm.msg="too many length or distance symbols",state.mode=BAD;break}state.have=0,state.mode=LENLENS;case LENLENS:for(;state.havebits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=3,bits-=3}for(;state.have<19;)state.lens[order[state.have++]]=0;if(state.lencode=state.lendyn,state.lenbits=7,opts={bits:state.lenbits},ret=inflate_table(CODES,state.lens,0,19,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid code lengths set",state.mode=BAD;break}state.have=0,state.mode=CODELENS;case CODELENS:for(;state.have>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<here_val)hold>>>=here_bits,bits-=here_bits,state.lens[state.have++]=here_val;else{if(16===here_val){for(n=here_bits+2;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,0===state.have){strm.msg="invalid bit length repeat",state.mode=BAD;break}len=state.lens[state.have-1],copy=3+(3&hold),hold>>>=2,bits-=2}else if(17===here_val){for(n=here_bits+3;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=3+(7&hold),hold>>>=3,bits-=3}else{for(n=here_bits+7;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=here_bits,bits-=here_bits,len=0,copy=11+(127&hold),hold>>>=7,bits-=7}if(state.have+copy>state.nlen+state.ndist){strm.msg="invalid bit length repeat",state.mode=BAD;break}for(;copy--;)state.lens[state.have++]=len}}if(state.mode===BAD)break;if(0===state.lens[256]){strm.msg="invalid code -- missing end-of-block",state.mode=BAD;break}if(state.lenbits=9,opts={bits:state.lenbits},ret=inflate_table(LENS,state.lens,0,state.nlen,state.lencode,0,state.work,opts),state.lenbits=opts.bits,ret){strm.msg="invalid literal/lengths set",state.mode=BAD;break}if(state.distbits=6,state.distcode=state.distdyn,opts={bits:state.distbits},ret=inflate_table(DISTS,state.lens,state.nlen,state.ndist,state.distcode,0,state.work,opts),state.distbits=opts.bits,ret){strm.msg="invalid distances set",state.mode=BAD;break}if(state.mode=LEN_,flush===Z_TREES)break inf_leave;case LEN_:state.mode=LEN;case LEN:if(have>=6&&left>=258){strm.next_out=put,strm.avail_out=left,strm.next_in=next,strm.avail_in=have,state.hold=hold,state.bits=bits,inflate_fast(strm,_out),put=strm.next_out,output=strm.output,left=strm.avail_out,next=strm.next_in,input=strm.input,have=strm.avail_in,hold=state.hold,bits=state.bits,state.mode===TYPE&&(state.back=-1);break}for(state.back=0;here=state.lencode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,state.length=here_val,0===here_op){state.mode=LIT;break}if(32&here_op){state.back=-1,state.mode=TYPE;break}if(64&here_op){strm.msg="invalid literal/length code",state.mode=BAD;break}state.extra=15&here_op,state.mode=LENEXT;case LENEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}state.was=state.length,state.mode=DIST;case DIST:for(;here=state.distcode[hold&(1<>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>last_bits)],here_bits=here>>>24,here_op=here>>>16&255,here_val=65535&here,!(bits>=last_bits+here_bits);){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=last_bits,bits-=last_bits,state.back+=last_bits}if(hold>>>=here_bits,bits-=here_bits,state.back+=here_bits,64&here_op){strm.msg="invalid distance code",state.mode=BAD;break}state.offset=here_val,state.extra=15&here_op,state.mode=DISTEXT;case DISTEXT:if(state.extra){for(n=state.extra;n>bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<>>=state.extra,bits-=state.extra,state.back+=state.extra}if(state.offset>state.dmax){strm.msg="invalid distance too far back",state.mode=BAD;break}state.mode=MATCH;case MATCH:if(0===left)break inf_leave;if(copy=_out-left,state.offset>copy){if(copy=state.offset-copy,copy>state.whave&&state.sane){strm.msg="invalid distance too far back",state.mode=BAD;break}copy>state.wnext?(copy-=state.wnext,from=state.wsize-copy):from=state.wnext-copy,copy>state.length&&(copy=state.length),from_source=state.window}else from_source=output,from=put-state.offset,copy=state.length;copy>left&&(copy=left),left-=copy,state.length-=copy;do output[put++]=from_source[from++];while(--copy);0===state.length&&(state.mode=LEN);break;case LIT:if(0===left)break inf_leave;output[put++]=state.length,left--,state.mode=LEN;break;case CHECK:if(state.wrap){for(;32>bits;){if(0===have)break inf_leave;have--,hold|=input[next++]<bits;){if(0===have)break inf_leave;have--,hold+=input[next++]<=len;len++)count[len]=0;for(sym=0;codes>sym;sym++)count[lens[lens_index+sym]]++;for(root=bits,max=MAXBITS;max>=1&&0===count[max];max--);if(root>max&&(root=max),0===max)return table[table_index++]=20971520,table[table_index++]=20971520,opts.bits=1,0;for(min=1;max>min&&0===count[min];min++);for(min>root&&(root=min),left=1,len=1;MAXBITS>=len;len++)if(left<<=1,left-=count[len],0>left)return-1;if(left>0&&(type===CODES||1!==max))return-1;for(offs[1]=0,len=1;MAXBITS>len;len++)offs[len+1]=offs[len]+count[len];for(sym=0;codes>sym;sym++)0!==lens[lens_index+sym]&&(work[offs[lens[lens_index+sym]]++]=sym);if(type===CODES?(base=extra=work,end=19):type===LENS?(base=lbase,base_index-=257,extra=lext,extra_index-=257,end=256):(base=dbase,extra=dext,end=-1),huff=0,sym=0,len=min,next=table_index,curr=root,drop=0,low=-1,used=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;for(var i=0;;){i++,here_bits=len-drop,work[sym]end?(here_op=extra[extra_index+work[sym]],here_val=base[base_index+work[sym]]):(here_op=96,here_val=0),incr=1<>drop)+fill]=here_bits<<24|here_op<<16|here_val|0;while(0!==fill);for(incr=1<>=1;if(0!==incr?(huff&=incr-1,huff+=incr):huff=0,sym++,0===--count[len]){if(len===max)break;len=lens[lens_index+work[sym]]}if(len>root&&(huff&mask)!==low){for(0===drop&&(drop=root),next+=min,curr=len-drop,left=1<curr+drop&&(left-=count[curr+drop],!(0>=left));)curr++,left<<=1;if(used+=1<ENOUGH_LENS||type===DISTS&&used>ENOUGH_DISTS)return 1;low=huff&mask,table[low]=root<<24|curr<<16|next-table_index|0}}return 0!==huff&&(table[next+huff]=len-drop<<24|64<<16|0),opts.bits=root,0}},{"../utils/common":93}],103:[function(require,module){"use strict";module.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],104:[function(require,module,exports){"use strict";function zero(buf){for(var len=buf.length;--len>=0;)buf[len]=0}function d_code(dist){return 256>dist?_dist_code[dist]:_dist_code[256+(dist>>>7)]}function put_short(s,w){s.pending_buf[s.pending++]=255&w,s.pending_buf[s.pending++]=w>>>8&255}function send_bits(s,value,length){s.bi_valid>Buf_size-length?(s.bi_buf|=value<>Buf_size-s.bi_valid,s.bi_valid+=length-Buf_size):(s.bi_buf|=value<>>=1,res<<=1;while(--len>0);return res>>>1}function bi_flush(s){16===s.bi_valid?(put_short(s,s.bi_buf),s.bi_buf=0,s.bi_valid=0):s.bi_valid>=8&&(s.pending_buf[s.pending++]=255&s.bi_buf,s.bi_buf>>=8,s.bi_valid-=8)}function gen_bitlen(s,desc){var h,n,m,bits,xbits,f,tree=desc.dyn_tree,max_code=desc.max_code,stree=desc.stat_desc.static_tree,has_stree=desc.stat_desc.has_stree,extra=desc.stat_desc.extra_bits,base=desc.stat_desc.extra_base,max_length=desc.stat_desc.max_length,overflow=0;for(bits=0;MAX_BITS>=bits;bits++)s.bl_count[bits]=0;for(tree[2*s.heap[s.heap_max]+1]=0,h=s.heap_max+1;HEAP_SIZE>h;h++)n=s.heap[h],bits=tree[2*tree[2*n+1]+1]+1,bits>max_length&&(bits=max_length,overflow++),tree[2*n+1]=bits,n>max_code||(s.bl_count[bits]++,xbits=0,n>=base&&(xbits=extra[n-base]),f=tree[2*n],s.opt_len+=f*(bits+xbits),has_stree&&(s.static_len+=f*(stree[2*n+1]+xbits)));if(0!==overflow){do{for(bits=max_length-1;0===s.bl_count[bits];)bits--;s.bl_count[bits]--,s.bl_count[bits+1]+=2,s.bl_count[max_length]--,overflow-=2}while(overflow>0);for(bits=max_length;0!==bits;bits--)for(n=s.bl_count[bits];0!==n;)m=s.heap[--h],m>max_code||(tree[2*m+1]!==bits&&(s.opt_len+=(bits-tree[2*m+1])*tree[2*m],tree[2*m+1]=bits),n--)}}function gen_codes(tree,max_code,bl_count){var bits,n,next_code=new Array(MAX_BITS+1),code=0;for(bits=1;MAX_BITS>=bits;bits++)next_code[bits]=code=code+bl_count[bits-1]<<1;for(n=0;max_code>=n;n++){var len=tree[2*n+1];0!==len&&(tree[2*n]=bi_reverse(next_code[len]++,len))}}function tr_static_init(){var n,bits,length,code,dist,bl_count=new Array(MAX_BITS+1);for(length=0,code=0;LENGTH_CODES-1>code;code++)for(base_length[code]=length,n=0;n<1<code;code++)for(base_dist[code]=dist,n=0;n<1<>=7;D_CODES>code;code++)for(base_dist[code]=dist<<7,n=0;n<1<=bits;bits++)bl_count[bits]=0;for(n=0;143>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(;255>=n;)static_ltree[2*n+1]=9,n++,bl_count[9]++;for(;279>=n;)static_ltree[2*n+1]=7,n++,bl_count[7]++;for(;287>=n;)static_ltree[2*n+1]=8,n++,bl_count[8]++;for(gen_codes(static_ltree,L_CODES+1,bl_count),n=0;D_CODES>n;n++)static_dtree[2*n+1]=5,static_dtree[2*n]=bi_reverse(n,5);static_l_desc=new StaticTreeDesc(static_ltree,extra_lbits,LITERALS+1,L_CODES,MAX_BITS),static_d_desc=new StaticTreeDesc(static_dtree,extra_dbits,0,D_CODES,MAX_BITS),static_bl_desc=new StaticTreeDesc(new Array(0),extra_blbits,0,BL_CODES,MAX_BL_BITS)}function init_block(s){var n;for(n=0;L_CODES>n;n++)s.dyn_ltree[2*n]=0;for(n=0;D_CODES>n;n++)s.dyn_dtree[2*n]=0;for(n=0;BL_CODES>n;n++)s.bl_tree[2*n]=0;s.dyn_ltree[2*END_BLOCK]=1,s.opt_len=s.static_len=0,s.last_lit=s.matches=0}function bi_windup(s){s.bi_valid>8?put_short(s,s.bi_buf):s.bi_valid>0&&(s.pending_buf[s.pending++]=s.bi_buf),s.bi_buf=0,s.bi_valid=0}function copy_block(s,buf,len,header){bi_windup(s),header&&(put_short(s,len),put_short(s,~len)),utils.arraySet(s.pending_buf,s.window,buf,len,s.pending),s.pending+=len}function smaller(tree,n,m,depth){var _n2=2*n,_m2=2*m;return tree[_n2]n;n++)0!==tree[2*n]?(s.heap[++s.heap_len]=max_code=n,s.depth[n]=0):tree[2*n+1]=0;for(;s.heap_len<2;)node=s.heap[++s.heap_len]=2>max_code?++max_code:0,tree[2*node]=1,s.depth[node]=0,s.opt_len--,has_stree&&(s.static_len-=stree[2*node+1]);for(desc.max_code=max_code,n=s.heap_len>>1;n>=1;n--)pqdownheap(s,tree,n);node=elems;do n=s.heap[1],s.heap[1]=s.heap[s.heap_len--],pqdownheap(s,tree,1),m=s.heap[1],s.heap[--s.heap_max]=n,s.heap[--s.heap_max]=m,tree[2*node]=tree[2*n]+tree[2*m],s.depth[node]=(s.depth[n]>=s.depth[m]?s.depth[n]:s.depth[m])+1,tree[2*n+1]=tree[2*m+1]=node,s.heap[1]=node++,pqdownheap(s,tree,1);while(s.heap_len>=2);s.heap[--s.heap_max]=s.heap[1],gen_bitlen(s,desc),gen_codes(tree,max_code,s.bl_count)}function scan_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),tree[2*(max_code+1)+1]=65535,n=0;max_code>=n;n++)curlen=nextlen,nextlen=tree[2*(n+1)+1],++countcount?s.bl_tree[2*curlen]+=count:0!==curlen?(curlen!==prevlen&&s.bl_tree[2*curlen]++,s.bl_tree[2*REP_3_6]++):10>=count?s.bl_tree[2*REPZ_3_10]++:s.bl_tree[2*REPZ_11_138]++,count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4))}function send_tree(s,tree,max_code){var n,curlen,prevlen=-1,nextlen=tree[1],count=0,max_count=7,min_count=4;for(0===nextlen&&(max_count=138,min_count=3),n=0;max_code>=n;n++)if(curlen=nextlen,nextlen=tree[2*(n+1)+1],!(++countcount){do send_code(s,curlen,s.bl_tree);while(0!==--count)}else 0!==curlen?(curlen!==prevlen&&(send_code(s,curlen,s.bl_tree),count--),send_code(s,REP_3_6,s.bl_tree),send_bits(s,count-3,2)):10>=count?(send_code(s,REPZ_3_10,s.bl_tree),send_bits(s,count-3,3)):(send_code(s,REPZ_11_138,s.bl_tree),send_bits(s,count-11,7));count=0,prevlen=curlen,0===nextlen?(max_count=138,min_count=3):curlen===nextlen?(max_count=6,min_count=3):(max_count=7,min_count=4)}}function build_bl_tree(s){var max_blindex;for(scan_tree(s,s.dyn_ltree,s.l_desc.max_code),scan_tree(s,s.dyn_dtree,s.d_desc.max_code),build_tree(s,s.bl_desc),max_blindex=BL_CODES-1;max_blindex>=3&&0===s.bl_tree[2*bl_order[max_blindex]+1];max_blindex--);return s.opt_len+=3*(max_blindex+1)+5+5+4,max_blindex}function send_all_trees(s,lcodes,dcodes,blcodes){var rank;for(send_bits(s,lcodes-257,5),send_bits(s,dcodes-1,5),send_bits(s,blcodes-4,4),rank=0;blcodes>rank;rank++)send_bits(s,s.bl_tree[2*bl_order[rank]+1],3);send_tree(s,s.dyn_ltree,lcodes-1),send_tree(s,s.dyn_dtree,dcodes-1)}function detect_data_type(s){var n,black_mask=4093624447;for(n=0;31>=n;n++,black_mask>>>=1)if(1&black_mask&&0!==s.dyn_ltree[2*n])return Z_BINARY;if(0!==s.dyn_ltree[18]||0!==s.dyn_ltree[20]||0!==s.dyn_ltree[26])return Z_TEXT;for(n=32;LITERALS>n;n++)if(0!==s.dyn_ltree[2*n])return Z_TEXT;return Z_BINARY}function _tr_init(s){static_init_done||(tr_static_init(),static_init_done=!0),s.l_desc=new TreeDesc(s.dyn_ltree,static_l_desc),s.d_desc=new TreeDesc(s.dyn_dtree,static_d_desc),s.bl_desc=new TreeDesc(s.bl_tree,static_bl_desc),s.bi_buf=0,s.bi_valid=0,init_block(s)}function _tr_stored_block(s,buf,stored_len,last){send_bits(s,(STORED_BLOCK<<1)+(last?1:0),3),copy_block(s,buf,stored_len,!0)}function _tr_align(s){send_bits(s,STATIC_TREES<<1,3),send_code(s,END_BLOCK,static_ltree),bi_flush(s)}function _tr_flush_block(s,buf,stored_len,last){var opt_lenb,static_lenb,max_blindex=0;s.level>0?(s.strm.data_type===Z_UNKNOWN&&(s.strm.data_type=detect_data_type(s)),build_tree(s,s.l_desc),build_tree(s,s.d_desc),max_blindex=build_bl_tree(s),opt_lenb=s.opt_len+3+7>>>3,static_lenb=s.static_len+3+7>>>3,opt_lenb>=static_lenb&&(opt_lenb=static_lenb)):opt_lenb=static_lenb=stored_len+5,opt_lenb>=stored_len+4&&-1!==buf?_tr_stored_block(s,buf,stored_len,last):s.strategy===Z_FIXED||static_lenb===opt_lenb?(send_bits(s,(STATIC_TREES<<1)+(last?1:0),3),compress_block(s,static_ltree,static_dtree)):(send_bits(s,(DYN_TREES<<1)+(last?1:0),3),send_all_trees(s,s.l_desc.max_code+1,s.d_desc.max_code+1,max_blindex+1),compress_block(s,s.dyn_ltree,s.dyn_dtree)),init_block(s),last&&bi_windup(s)}function _tr_tally(s,dist,lc){return s.pending_buf[s.d_buf+2*s.last_lit]=dist>>>8&255,s.pending_buf[s.d_buf+2*s.last_lit+1]=255&dist,s.pending_buf[s.l_buf+s.last_lit]=255&lc,s.last_lit++,0===dist?s.dyn_ltree[2*lc]++:(s.matches++,dist--,s.dyn_ltree[2*(_length_code[lc]+LITERALS+1)]++,s.dyn_dtree[2*d_code(dist)]++),s.last_lit===s.lit_bufsize-1}var utils=require("../utils/common"),Z_FIXED=4,Z_BINARY=0,Z_TEXT=1,Z_UNKNOWN=2,STORED_BLOCK=0,STATIC_TREES=1,DYN_TREES=2,MIN_MATCH=3,MAX_MATCH=258,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,Buf_size=16,MAX_BL_BITS=7,END_BLOCK=256,REP_3_6=16,REPZ_3_10=17,REPZ_11_138=18,extra_lbits=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],extra_dbits=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],extra_blbits=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],bl_order=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],DIST_CODE_LEN=512,static_ltree=new Array(2*(L_CODES+2));zero(static_ltree);var static_dtree=new Array(2*D_CODES);zero(static_dtree);var _dist_code=new Array(DIST_CODE_LEN);zero(_dist_code);var _length_code=new Array(MAX_MATCH-MIN_MATCH+1);zero(_length_code);var base_length=new Array(LENGTH_CODES);zero(base_length);var base_dist=new Array(D_CODES);zero(base_dist);var static_l_desc,static_d_desc,static_bl_desc,StaticTreeDesc=function(static_tree,extra_bits,extra_base,elems,max_length){this.static_tree=static_tree,this.extra_bits=extra_bits,this.extra_base=extra_base,this.elems=elems,this.max_length=max_length,this.has_stree=static_tree&&static_tree.length},TreeDesc=function(dyn_tree,stat_desc){this.dyn_tree=dyn_tree,this.max_code=0,this.stat_desc=stat_desc},static_init_done=!1;exports._tr_init=_tr_init,exports._tr_stored_block=_tr_stored_block,exports._tr_flush_block=_tr_flush_block,exports._tr_tally=_tr_tally,exports._tr_align=_tr_align},{"../utils/common":93}],105:[function(require,module){"use strict";function ZStream(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}module.exports=ZStream},{}],106:[function(require,module){(function(Buffer){"use strict";function decodeB64(str){return new Buffer(str,"base64")}function unpackPNG(w,h,c,str){var pixels=parse(decodeB64(str));return ndarray(pixels.data,[h,w,pixels.channels],[pixels.channels*w,pixels.channels,1],0)}module.exports=unpackPNG;var ndarray=require("ndarray"),parse=require("pngparse-sync")}).call(this,require("buffer").Buffer)},{buffer:111,ndarray:87,"pngparse-sync":89}],107:[function(require,module,exports){!function(_global){"use strict";var shim={};"undefined"==typeof exports?"function"==typeof define&&"object"==typeof define.amd&&define.amd?(shim.exports={},define(function(){return shim.exports})):shim.exports="undefined"!=typeof window?window:_global:shim.exports=exports,function(exports){if(!GLMAT_EPSILON)var GLMAT_EPSILON=1e-6;if(!GLMAT_ARRAY_TYPE)var GLMAT_ARRAY_TYPE="undefined"!=typeof Float32Array?Float32Array:Array;if(!GLMAT_RANDOM)var GLMAT_RANDOM=Math.random;var glMatrix={};glMatrix.setMatrixArrayType=function(type){GLMAT_ARRAY_TYPE=type},"undefined"!=typeof exports&&(exports.glMatrix=glMatrix);var degree=Math.PI/180;glMatrix.toRadian=function(a){return a*degree};var vec2={};vec2.create=function(){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=0,out[1]=0,out},vec2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=a[0],out[1]=a[1],out},vec2.fromValues=function(x,y){var out=new GLMAT_ARRAY_TYPE(2);return out[0]=x,out[1]=y,out},vec2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out},vec2.set=function(out,x,y){return out[0]=x,out[1]=y,out},vec2.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out},vec2.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out},vec2.sub=vec2.subtract,vec2.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out},vec2.mul=vec2.multiply,vec2.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out},vec2.div=vec2.divide,vec2.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out},vec2.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out},vec2.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out},vec2.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out},vec2.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return Math.sqrt(x*x+y*y)},vec2.dist=vec2.distance,vec2.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1];return x*x+y*y},vec2.sqrDist=vec2.squaredDistance,vec2.length=function(a){var x=a[0],y=a[1];return Math.sqrt(x*x+y*y)},vec2.len=vec2.length,vec2.squaredLength=function(a){var x=a[0],y=a[1];return x*x+y*y},vec2.sqrLen=vec2.squaredLength,vec2.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out},vec2.normalize=function(out,a){var x=a[0],y=a[1],len=x*x+y*y;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len),out},vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2.cross=function(out,a,b){var z=a[0]*b[1]-a[1]*b[0];return out[0]=out[1]=0,out[2]=z,out},vec2.lerp=function(out,a,b,t){var ax=a[0],ay=a[1];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out},vec2.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI;return out[0]=Math.cos(r)*scale,out[1]=Math.sin(r)*scale,out},vec2.transformMat2=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y,out[1]=m[1]*x+m[3]*y,out},vec2.transformMat2d=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[2]*y+m[4],out[1]=m[1]*x+m[3]*y+m[5],out},vec2.transformMat3=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[3]*y+m[6],out[1]=m[1]*x+m[4]*y+m[7],out},vec2.transformMat4=function(out,a,m){var x=a[0],y=a[1];return out[0]=m[0]*x+m[4]*y+m[12],out[1]=m[1]*x+m[5]*y+m[13],out},vec2.forEach=function(){var vec=vec2.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=2),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1];return a}}(),vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof exports&&(exports.vec2=vec2);var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=0,out[1]=0,out[2]=0,out},vec3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);return out[0]=x,out[1]=y,out[2]=z,out},vec3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out},vec3.set=function(out,x,y,z){return out[0]=x,out[1]=y,out[2]=z,out },vec3.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out},vec3.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out},vec3.sub=vec3.subtract,vec3.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out},vec3.mul=vec3.multiply,vec3.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out},vec3.div=vec3.divide,vec3.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out},vec3.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out},vec3.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out},vec3.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out},vec3.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.dist=vec3.distance,vec3.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2];return x*x+y*y+z*z},vec3.sqrDist=vec3.squaredDistance,vec3.length=function(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)},vec3.len=vec3.length,vec3.squaredLength=function(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z},vec3.sqrLen=vec3.squaredLength,vec3.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out},vec3.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],len=x*x+y*y+z*z;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len),out},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.cross=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2];return out[0]=ay*bz-az*by,out[1]=az*bx-ax*bz,out[2]=ax*by-ay*bx,out},vec3.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out},vec3.random=function(out,scale){scale=scale||1;var r=2*GLMAT_RANDOM()*Math.PI,z=2*GLMAT_RANDOM()-1,zScale=Math.sqrt(1-z*z)*scale;return out[0]=Math.cos(r)*zScale,out[1]=Math.sin(r)*zScale,out[2]=z*scale,out},vec3.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12],out[1]=m[1]*x+m[5]*y+m[9]*z+m[13],out[2]=m[2]*x+m[6]*y+m[10]*z+m[14],out},vec3.transformMat3=function(out,a,m){var x=a[0],y=a[1],z=a[2];return out[0]=x*m[0]+y*m[3]+z*m[6],out[1]=x*m[1]+y*m[4]+z*m[7],out[2]=x*m[2]+y*m[5]+z*m[8],out},vec3.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec3.rotateX=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0],r[1]=p[1]*Math.cos(c)-p[2]*Math.sin(c),r[2]=p[1]*Math.sin(c)+p[2]*Math.cos(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateY=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[2]*Math.sin(c)+p[0]*Math.cos(c),r[1]=p[1],r[2]=p[2]*Math.cos(c)-p[0]*Math.sin(c),out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.rotateZ=function(out,a,b,c){var p=[],r=[];return p[0]=a[0]-b[0],p[1]=a[1]-b[1],p[2]=a[2]-b[2],r[0]=p[0]*Math.cos(c)-p[1]*Math.sin(c),r[1]=p[0]*Math.sin(c)+p[1]*Math.cos(c),r[2]=p[2],out[0]=r[0]+b[0],out[1]=r[1]+b[1],out[2]=r[2]+b[2],out},vec3.forEach=function(){var vec=vec3.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=3),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2];return a}}(),vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof exports&&(exports.vec3=vec3);var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out},vec4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.fromValues=function(x,y,z,w){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},vec4.set=function(out,x,y,z,w){return out[0]=x,out[1]=y,out[2]=z,out[3]=w,out},vec4.add=function(out,a,b){return out[0]=a[0]+b[0],out[1]=a[1]+b[1],out[2]=a[2]+b[2],out[3]=a[3]+b[3],out},vec4.subtract=function(out,a,b){return out[0]=a[0]-b[0],out[1]=a[1]-b[1],out[2]=a[2]-b[2],out[3]=a[3]-b[3],out},vec4.sub=vec4.subtract,vec4.multiply=function(out,a,b){return out[0]=a[0]*b[0],out[1]=a[1]*b[1],out[2]=a[2]*b[2],out[3]=a[3]*b[3],out},vec4.mul=vec4.multiply,vec4.divide=function(out,a,b){return out[0]=a[0]/b[0],out[1]=a[1]/b[1],out[2]=a[2]/b[2],out[3]=a[3]/b[3],out},vec4.div=vec4.divide,vec4.min=function(out,a,b){return out[0]=Math.min(a[0],b[0]),out[1]=Math.min(a[1],b[1]),out[2]=Math.min(a[2],b[2]),out[3]=Math.min(a[3],b[3]),out},vec4.max=function(out,a,b){return out[0]=Math.max(a[0],b[0]),out[1]=Math.max(a[1],b[1]),out[2]=Math.max(a[2],b[2]),out[3]=Math.max(a[3],b[3]),out},vec4.scale=function(out,a,b){return out[0]=a[0]*b,out[1]=a[1]*b,out[2]=a[2]*b,out[3]=a[3]*b,out},vec4.scaleAndAdd=function(out,a,b,scale){return out[0]=a[0]+b[0]*scale,out[1]=a[1]+b[1]*scale,out[2]=a[2]+b[2]*scale,out[3]=a[3]+b[3]*scale,out},vec4.distance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.dist=vec4.distance,vec4.squaredDistance=function(a,b){var x=b[0]-a[0],y=b[1]-a[1],z=b[2]-a[2],w=b[3]-a[3];return x*x+y*y+z*z+w*w},vec4.sqrDist=vec4.squaredDistance,vec4.length=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return Math.sqrt(x*x+y*y+z*z+w*w)},vec4.len=vec4.length,vec4.squaredLength=function(a){var x=a[0],y=a[1],z=a[2],w=a[3];return x*x+y*y+z*z+w*w},vec4.sqrLen=vec4.squaredLength,vec4.negate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=-a[3],out},vec4.normalize=function(out,a){var x=a[0],y=a[1],z=a[2],w=a[3],len=x*x+y*y+z*z+w*w;return len>0&&(len=1/Math.sqrt(len),out[0]=a[0]*len,out[1]=a[1]*len,out[2]=a[2]*len,out[3]=a[3]*len),out},vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4.lerp=function(out,a,b,t){var ax=a[0],ay=a[1],az=a[2],aw=a[3];return out[0]=ax+t*(b[0]-ax),out[1]=ay+t*(b[1]-ay),out[2]=az+t*(b[2]-az),out[3]=aw+t*(b[3]-aw),out},vec4.random=function(out,scale){return scale=scale||1,out[0]=GLMAT_RANDOM(),out[1]=GLMAT_RANDOM(),out[2]=GLMAT_RANDOM(),out[3]=GLMAT_RANDOM(),vec4.normalize(out,out),vec4.scale(out,out,scale),out},vec4.transformMat4=function(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];return out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w,out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w,out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w,out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w,out},vec4.transformQuat=function(out,a,q){var x=a[0],y=a[1],z=a[2],qx=q[0],qy=q[1],qz=q[2],qw=q[3],ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy,out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz,out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx,out},vec4.forEach=function(){var vec=vec4.create();return function(a,stride,offset,count,fn,arg){var i,l;for(stride||(stride=4),offset||(offset=0),l=count?Math.min(count*stride+offset,a.length):a.length,i=offset;l>i;i+=stride)vec[0]=a[i],vec[1]=a[i+1],vec[2]=a[i+2],vec[3]=a[i+3],fn(vec,vec,arg),a[i]=vec[0],a[i+1]=vec[1],a[i+2]=vec[2],a[i+3]=vec[3];return a}}(),vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.vec4=vec4);var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(4);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out},mat2.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out},mat2.transpose=function(out,a){if(out===a){var a1=a[1];out[1]=a[2],out[2]=a1}else out[0]=a[0],out[1]=a[2],out[2]=a[1],out[3]=a[3];return out},mat2.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],det=a0*a3-a2*a1;return det?(det=1/det,out[0]=a3*det,out[1]=-a1*det,out[2]=-a2*det,out[3]=a0*det,out):null},mat2.adjoint=function(out,a){var a0=a[0];return out[0]=a[3],out[1]=-a[1],out[2]=-a[2],out[3]=a0,out},mat2.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},mat2.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out},mat2.mul=mat2.multiply,mat2.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out},mat2.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out},mat2.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},mat2.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2))},mat2.LDU=function(L,D,U,a){return L[2]=a[2]/a[0],U[0]=a[0],U[1]=a[1],U[3]=a[3]-L[2]*U[1],[L,D,U]},"undefined"!=typeof exports&&(exports.mat2=mat2);var mat2d={};mat2d.create=function(){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.clone=function(a){var out=new GLMAT_ARRAY_TYPE(6);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out},mat2d.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out},mat2d.invert=function(out,a){var aa=a[0],ab=a[1],ac=a[2],ad=a[3],atx=a[4],aty=a[5],det=aa*ad-ab*ac;return det?(det=1/det,out[0]=ad*det,out[1]=-ab*det,out[2]=-ac*det,out[3]=aa*det,out[4]=(ac*aty-ad*atx)*det,out[5]=(ab*atx-aa*aty)*det,out):null},mat2d.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},mat2d.multiply=function(out,a,b){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],b0=b[0],b1=b[1],b2=b[2],b3=b[3],b4=b[4],b5=b[5];return out[0]=a0*b0+a2*b1,out[1]=a1*b0+a3*b1,out[2]=a0*b2+a2*b3,out[3]=a1*b2+a3*b3,out[4]=a0*b4+a2*b5+a4,out[5]=a1*b4+a3*b5+a5,out},mat2d.mul=mat2d.multiply,mat2d.rotate=function(out,a,rad){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],s=Math.sin(rad),c=Math.cos(rad);return out[0]=a0*c+a2*s,out[1]=a1*c+a3*s,out[2]=a0*-s+a2*c,out[3]=a1*-s+a3*c,out[4]=a4,out[5]=a5,out},mat2d.scale=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0*v0,out[1]=a1*v0,out[2]=a2*v1,out[3]=a3*v1,out[4]=a4,out[5]=a5,out},mat2d.translate=function(out,a,v){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],a4=a[4],a5=a[5],v0=v[0],v1=v[1];return out[0]=a0,out[1]=a1,out[2]=a2,out[3]=a3,out[4]=a0*v0+a2*v1+a4,out[5]=a1*v0+a3*v1+a5,out},mat2d.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},mat2d.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+1)},"undefined"!=typeof exports&&(exports.mat2d=mat2d);var mat3={};mat3.create=function(){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.fromMat4=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[4],out[4]=a[5],out[5]=a[6],out[6]=a[8],out[7]=a[9],out[8]=a[10],out},mat3.clone=function(a){var out=new GLMAT_ARRAY_TYPE(9);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out},mat3.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3],out[2]=a[6],out[3]=a01,out[5]=a[7],out[6]=a02,out[7]=a12}else out[0]=a[0],out[1]=a[3],out[2]=a[6],out[3]=a[1],out[4]=a[4],out[5]=a[7],out[6]=a[2],out[7]=a[5],out[8]=a[8];return out},mat3.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b01=a22*a11-a12*a21,b11=-a22*a10+a12*a20,b21=a21*a10-a11*a20,det=a00*b01+a01*b11+a02*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a02*a21)*det,out[2]=(a12*a01-a02*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a02*a20)*det,out[5]=(-a12*a00+a02*a10)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a10)*det,out):null},mat3.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return out[0]=a11*a22-a12*a21,out[1]=a02*a21-a01*a22,out[2]=a01*a12-a02*a11,out[3]=a12*a20-a10*a22,out[4]=a00*a22-a02*a20,out[5]=a02*a10-a00*a12,out[6]=a10*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a10,out},mat3.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20)},mat3.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],b00=b[0],b01=b[1],b02=b[2],b10=b[3],b11=b[4],b12=b[5],b20=b[6],b21=b[7],b22=b[8];return out[0]=b00*a00+b01*a10+b02*a20,out[1]=b00*a01+b01*a11+b02*a21,out[2]=b00*a02+b01*a12+b02*a22,out[3]=b10*a00+b11*a10+b12*a20,out[4]=b10*a01+b11*a11+b12*a21,out[5]=b10*a02+b11*a12+b12*a22,out[6]=b20*a00+b21*a10+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a02+b21*a12+b22*a22,out},mat3.mul=mat3.multiply,mat3.translate=function(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];return out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a10,out[4]=a11,out[5]=a12,out[6]=x*a00+y*a10+a20,out[7]=x*a01+y*a11+a21,out[8]=x*a02+y*a12+a22,out},mat3.rotate=function(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);return out[0]=c*a00+s*a10,out[1]=c*a01+s*a11,out[2]=c*a02+s*a12,out[3]=c*a10-s*a00,out[4]=c*a11-s*a01,out[5]=c*a12-s*a02,out[6]=a20,out[7]=a21,out[8]=a22,out},mat3.scale=function(out,a,v){var x=v[0],y=v[1];return out[0]=x*a[0],out[1]=x*a[1],out[2]=x*a[2],out[3]=y*a[3],out[4]=y*a[4],out[5]=y*a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out},mat3.fromMat2d=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=0,out[3]=a[2],out[4]=a[3],out[5]=0,out[6]=a[4],out[7]=a[5],out[8]=1,out},mat3.fromQuat=function(out,q){var x=q[0],y=q[1],z=q[2],w=q[3],x2=x+x,y2=y+y,z2=z+z,xx=x*x2,yx=y*x2,yy=y*y2,zx=z*x2,zy=z*y2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2;return out[0]=1-yy-zz,out[3]=yx-wz,out[6]=zx+wy,out[1]=yx+wz,out[4]=1-xx-zz,out[7]=zy-wx,out[2]=zx-wy,out[5]=zy+wx,out[8]=1-xx-yy,out},mat3.normalFromMat4=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a10*b11-a13*b07)*det,out[2]=(a10*b10-a11*b08+a13*b06)*det,out[3]=(a02*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a02*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b02-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b02+a33*b00)*det,out):null},mat3.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},mat3.frob=function(a){return Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)+Math.pow(a[2],2)+Math.pow(a[3],2)+Math.pow(a[4],2)+Math.pow(a[5],2)+Math.pow(a[6],2)+Math.pow(a[7],2)+Math.pow(a[8],2))},"undefined"!=typeof exports&&(exports.mat3=mat3);var mat4={};mat4.create=function(){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.clone=function(a){var out=new GLMAT_ARRAY_TYPE(16);return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.copy=function(out,a){return out[0]=a[0],out[1]=a[1],out[2]=a[2],out[3]=a[3],out[4]=a[4],out[5]=a[5],out[6]=a[6],out[7]=a[7],out[8]=a[8],out[9]=a[9],out[10]=a[10],out[11]=a[11],out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.identity=function(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out},mat4.transpose=function(out,a){if(out===a){var a01=a[1],a02=a[2],a03=a[3],a12=a[6],a13=a[7],a23=a[11];out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a01,out[6]=a[9],out[7]=a[13],out[8]=a02,out[9]=a12,out[11]=a[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a[0],out[1]=a[4],out[2]=a[8],out[3]=a[12],out[4]=a[1],out[5]=a[5],out[6]=a[9],out[7]=a[13],out[8]=a[2],out[9]=a[6],out[10]=a[10],out[11]=a[14],out[12]=a[3],out[13]=a[7],out[14]=a[11],out[15]=a[15];return out},mat4.invert=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a02*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a10*b11-a13*b07)*det,out[5]=(a00*b11-a02*b08+a03*b07)*det,out[6]=(a32*b02-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b02+a23*b01)*det,out[8]=(a10*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b02+a33*b00)*det,out[11]=(a21*b02-a20*b04-a23*b00)*det,out[12]=(a11*b07-a10*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a02*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null},mat4.adjoint=function(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15];return out[0]=a11*(a22*a33-a23*a32)-a21*(a12*a33-a13*a32)+a31*(a12*a23-a13*a22),out[1]=-(a01*(a22*a33-a23*a32)-a21*(a02*a33-a03*a32)+a31*(a02*a23-a03*a22)),out[2]=a01*(a12*a33-a13*a32)-a11*(a02*a33-a03*a32)+a31*(a02*a13-a03*a12),out[3]=-(a01*(a12*a23-a13*a22)-a11*(a02*a23-a03*a22)+a21*(a02*a13-a03*a12)),out[4]=-(a10*(a22*a33-a23*a32)-a20*(a12*a33-a13*a32)+a30*(a12*a23-a13*a22)),out[5]=a00*(a22*a33-a23*a32)-a20*(a02*a33-a03*a32)+a30*(a02*a23-a03*a22),out[6]=-(a00*(a12*a33-a13*a32)-a10*(a02*a33-a03*a32)+a30*(a02*a13-a03*a12)),out[7]=a00*(a12*a23-a13*a22)-a10*(a02*a23-a03*a22)+a20*(a02*a13-a03*a12),out[8]=a10*(a21*a33-a23*a31)-a20*(a11*a33-a13*a31)+a30*(a11*a23-a13*a21),out[9]=-(a00*(a21*a33-a23*a31)-a20*(a01*a33-a03*a31)+a30*(a01*a23-a03*a21)),out[10]=a00*(a11*a33-a13*a31)-a10*(a01*a33-a03*a31)+a30*(a01*a13-a03*a11),out[11]=-(a00*(a11*a23-a13*a21)-a10*(a01*a23-a03*a21)+a20*(a01*a13-a03*a11)),out[12]=-(a10*(a21*a32-a22*a31)-a20*(a11*a32-a12*a31)+a30*(a11*a22-a12*a21)),out[13]=a00*(a21*a32-a22*a31)-a20*(a01*a32-a02*a31)+a30*(a01*a22-a02*a21),out[14]=-(a00*(a11*a32-a12*a31)-a10*(a01*a32-a02*a31)+a30*(a01*a12-a02*a11)),out[15]=a00*(a11*a22-a12*a21)-a10*(a01*a22-a02*a21)+a20*(a01*a12-a02*a11),out},mat4.determinant=function(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06},mat4.multiply=function(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],a30=a[12],a31=a[13],a32=a[14],a33=a[15],b0=b[0],b1=b[1],b2=b[2],b3=b[3];return out[0]=b0*a00+b1*a10+b2*a20+b3*a30,out[1]=b0*a01+b1*a11+b2*a21+b3*a31,out[2]=b0*a02+b1*a12+b2*a22+b3*a32,out[3]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[4],b1=b[5],b2=b[6],b3=b[7],out[4]=b0*a00+b1*a10+b2*a20+b3*a30,out[5]=b0*a01+b1*a11+b2*a21+b3*a31,out[6]=b0*a02+b1*a12+b2*a22+b3*a32,out[7]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[8],b1=b[9],b2=b[10],b3=b[11],out[8]=b0*a00+b1*a10+b2*a20+b3*a30,out[9]=b0*a01+b1*a11+b2*a21+b3*a31,out[10]=b0*a02+b1*a12+b2*a22+b3*a32,out[11]=b0*a03+b1*a13+b2*a23+b3*a33,b0=b[12],b1=b[13],b2=b[14],b3=b[15],out[12]=b0*a00+b1*a10+b2*a20+b3*a30,out[13]=b0*a01+b1*a11+b2*a21+b3*a31,out[14]=b0*a02+b1*a12+b2*a22+b3*a32,out[15]=b0*a03+b1*a13+b2*a23+b3*a33,out},mat4.mul=mat4.multiply,mat4.translate=function(out,a,v){var a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,x=v[0],y=v[1],z=v[2];return a===out?(out[12]=a[0]*x+a[4]*y+a[8]*z+a[12],out[13]=a[1]*x+a[5]*y+a[9]*z+a[13],out[14]=a[2]*x+a[6]*y+a[10]*z+a[14],out[15]=a[3]*x+a[7]*y+a[11]*z+a[15]):(a00=a[0],a01=a[1],a02=a[2],a03=a[3],a10=a[4],a11=a[5],a12=a[6],a13=a[7],a20=a[8],a21=a[9],a22=a[10],a23=a[11],out[0]=a00,out[1]=a01,out[2]=a02,out[3]=a03,out[4]=a10,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x+a10*y+a20*z+a[12],out[13]=a01*x+a11*y+a21*z+a[13],out[14]=a02*x+a12*y+a22*z+a[14],out[15]=a03*x+a13*y+a23*z+a[15]),out},mat4.scale=function(out,a,v){var x=v[0],y=v[1],z=v[2];return out[0]=a[0]*x,out[1]=a[1]*x,out[2]=a[2]*x,out[3]=a[3]*x,out[4]=a[4]*y,out[5]=a[5]*y,out[6]=a[6]*y,out[7]=a[7]*y,out[8]=a[8]*z,out[9]=a[9]*z,out[10]=a[10]*z,out[11]=a[11]*z,out[12]=a[12],out[13]=a[13],out[14]=a[14],out[15]=a[15],out},mat4.rotate=function(out,a,rad,axis){var s,c,t,a00,a01,a02,a03,a10,a11,a12,a13,a20,a21,a22,a23,b00,b01,b02,b10,b11,b12,b20,b21,b22,x=axis[0],y=axis[1],z=axis[2],len=Math.sqrt(x*x+y*y+z*z);return Math.abs(len)dot?(vec3.cross(tmpvec3,xUnitVec3,a),vec3.length(tmpvec3)<1e-6&&vec3.cross(tmpvec3,yUnitVec3,a),vec3.normalize(tmpvec3,tmpvec3),quat.setAxisAngle(out,tmpvec3,Math.PI),out):dot>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(vec3.cross(tmpvec3,a,b),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot,quat.normalize(out,out))}}(),quat.setAxes=function(){var matr=mat3.create();return function(out,view,right,up){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up[0],matr[4]=up[1],matr[7]=up[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],quat.normalize(out,quat.fromMat3(out,matr))}}(),quat.clone=vec4.clone,quat.fromValues=vec4.fromValues,quat.copy=vec4.copy,quat.set=vec4.set,quat.identity=function(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out},quat.setAxisAngle=function(out,axis,rad){rad=.5*rad;var s=Math.sin(rad);return out[0]=s*axis[0],out[1]=s*axis[1],out[2]=s*axis[2],out[3]=Math.cos(rad),out},quat.add=vec4.add,quat.multiply=function(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return out[0]=ax*bw+aw*bx+ay*bz-az*by,out[1]=ay*bw+aw*by+az*bx-ax*bz,out[2]=az*bw+aw*bz+ax*by-ay*bx,out[3]=aw*bw-ax*bx-ay*by-az*bz,out},quat.mul=quat.multiply,quat.scale=vec4.scale,quat.rotateX=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+aw*bx,out[1]=ay*bw+az*bx,out[2]=az*bw-ay*bx,out[3]=aw*bw-ax*bx,out},quat.rotateY=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],by=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw-az*by,out[1]=ay*bw+aw*by,out[2]=az*bw+ax*by,out[3]=aw*bw-ay*by,out},quat.rotateZ=function(out,a,rad){rad*=.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3],bz=Math.sin(rad),bw=Math.cos(rad);return out[0]=ax*bw+ay*bz,out[1]=ay*bw-ax*bz,out[2]=az*bw+aw*bz,out[3]=aw*bw-az*bz,out},quat.calculateW=function(out,a){var x=a[0],y=a[1],z=a[2];return out[0]=x,out[1]=y,out[2]=z,out[3]=-Math.sqrt(Math.abs(1-x*x-y*y-z*z)),out},quat.dot=vec4.dot,quat.lerp=vec4.lerp,quat.slerp=function(out,a,b,t){var omega,cosom,sinom,scale0,scale1,ax=a[0],ay=a[1],az=a[2],aw=a[3],bx=b[0],by=b[1],bz=b[2],bw=b[3];return cosom=ax*bx+ay*by+az*bz+aw*bw,0>cosom&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),out[0]=scale0*ax+scale1*bx,out[1]=scale0*ay+scale1*by,out[2]=scale0*az+scale1*bz,out[3]=scale0*aw+scale1*bw,out},quat.invert=function(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3],dot=a0*a0+a1*a1+a2*a2+a3*a3,invDot=dot?1/dot:0;return out[0]=-a0*invDot,out[1]=-a1*invDot,out[2]=-a2*invDot,out[3]=a3*invDot,out},quat.conjugate=function(out,a){return out[0]=-a[0],out[1]=-a[1],out[2]=-a[2],out[3]=a[3],out},quat.length=vec4.length,quat.len=quat.length,quat.squaredLength=vec4.squaredLength,quat.sqrLen=quat.squaredLength,quat.normalize=vec4.normalize,quat.fromMat3=function(out,m){var fRoot,fTrace=m[0]+m[4]+m[8];if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m[7]-m[5])*fRoot,out[1]=(m[2]-m[6])*fRoot,out[2]=(m[3]-m[1])*fRoot;else{var i=0;m[4]>m[0]&&(i=1),m[8]>m[3*i+i]&&(i=2);var j=(i+1)%3,k=(i+2)%3;fRoot=Math.sqrt(m[3*i+i]-m[3*j+j]-m[3*k+k]+1),out[i]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m[3*k+j]-m[3*j+k])*fRoot,out[j]=(m[3*j+i]+m[3*i+j])*fRoot,out[k]=(m[3*k+i]+m[3*i+k])*fRoot}return out},quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof exports&&(exports.quat=quat)}(shim.exports)}(this)},{}],108:[function(require,module){"use strict";function OrbitCamera(rotation,center,distance){this.rotation=rotation,this.center=center,this.distance=distance }function quatFromVec(out,da){var x=da[0],y=da[1],s=(da[2],x*x+y*y);s>1&&(s=1),out[0]=-da[0],out[1]=da[1],out[2]=da[2]||Math.sqrt(1-s),out[3]=0}function createOrbitCamera(eye,target,up){eye=eye||[0,0,-1],target=target||[0,0,0],up=up||[0,1,0];var camera=new OrbitCamera(quat.create(),vec3.create(),1);return camera.lookAt(eye,target,up),camera}var glm=require("gl-matrix"),vec3=glm.vec3,mat3=glm.mat3,mat4=glm.mat4,quat=glm.quat,scratch0=new Float32Array(16),scratch1=new Float32Array(16),proto=OrbitCamera.prototype;proto.view=function(out){return out||(out=mat4.create()),scratch1[0]=scratch1[1]=0,scratch1[2]=-this.distance,mat4.fromRotationTranslation(out,quat.conjugate(scratch0,this.rotation),scratch1),mat4.translate(out,out,vec3.negate(scratch0,this.center)),out},proto.lookAt=function(eye,center,up){mat4.lookAt(scratch0,eye,center,up),mat3.fromMat4(scratch0,scratch0),quat.fromMat3(this.rotation,scratch0),vec3.copy(this.center,center),this.distance=vec3.distance(eye,center)},proto.pan=function(dpan){var d=this.distance;scratch0[0]=-d*(dpan[0]||0),scratch0[1]=d*(dpan[1]||0),scratch0[2]=d*(dpan[2]||0),vec3.transformQuat(scratch0,scratch0,this.rotation),vec3.add(this.center,this.center,scratch0)},proto.zoom=function(d){this.distance+=d,this.distance<0&&(this.distance=0)},proto.rotate=function(da,db){quatFromVec(scratch0,da),quatFromVec(scratch1,db),quat.invert(scratch1,scratch1),quat.multiply(scratch0,scratch0,scratch1),quat.length(scratch0)<1e-6||(quat.multiply(this.rotation,this.rotation,scratch0),quat.normalize(this.rotation,this.rotation))},module.exports=createOrbitCamera},{"gl-matrix":107}],109:[function(require,module){(function(global){module.exports=global.performance&&global.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],110:[function(require,module){function unindex(positions,cells,out){positions.positions&&positions.cells&&(out=cells,cells=positions.cells,positions=positions.positions),out=out||new Float32Array(9*cells.length);for(var i=0,n=0,l=cells.length;l>i;i+=1)out[n++]=positions[cells[i][0]][0],out[n++]=positions[cells[i][0]][1],out[n++]=positions[cells[i][0]][2],out[n++]=positions[cells[i][1]][0],out[n++]=positions[cells[i][1]][1],out[n++]=positions[cells[i][1]][2],out[n++]=positions[cells[i][2]][0],out[n++]=positions[cells[i][2]][1],out[n++]=positions[cells[i][2]][2];return out}module.exports=unindex},{}],111:[function(require,module,exports){function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var length,type=typeof subject;if("number"===type)length=subject>0?subject>>>0:0;else if("string"===type)length=Buffer.byteLength(subject,encoding);else{if("object"!==type||null===subject)throw new TypeError("must start with number, buffer, array or string");"Buffer"===subject.type&&isArray(subject.data)&&(subject=subject.data),length=+subject.length>0?Math.floor(+subject.length):0}if(length>kMaxLength)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+kMaxLength.toString(16)+" bytes");var buf;Buffer.TYPED_ARRAY_SUPPORT?buf=Buffer._augment(new Uint8Array(length)):(buf=this,buf.length=length,buf._isBuffer=!0);var i;if(Buffer.TYPED_ARRAY_SUPPORT&&"number"==typeof subject.byteLength)buf._set(subject);else if(isArrayish(subject))if(Buffer.isBuffer(subject))for(i=0;length>i;i++)buf[i]=subject.readUInt8(i);else for(i=0;length>i;i++)buf[i]=(subject[i]%256+256)%256;else if("string"===type)buf.write(subject,0,encoding);else if("number"===type&&!Buffer.TYPED_ARRAY_SUPPORT&&!noZero)for(i=0;length>i;i++)buf[i]=0;return length>0&&length<=Buffer.poolSize&&(buf.parent=rootParent),buf}function SlowBuffer(subject,encoding,noZero){if(!(this instanceof SlowBuffer))return new SlowBuffer(subject,encoding,noZero);var buf=new Buffer(subject,encoding,noZero);return delete buf.parent,buf}function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining;var strLen=string.length;if(strLen%2!==0)throw new Error("Invalid hex string");length>strLen/2&&(length=strLen/2);for(var i=0;length>i;i++){var byte=parseInt(string.substr(2*i,2),16);if(isNaN(byte))throw new Error("Invalid hex string");buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string,buf.length-offset),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string,buf.length-offset),buf,offset,length,2);return charsWritten}function base64Slice(buf,start,end){return base64.fromByteArray(0===start&&end===buf.length?buf:buf.slice(start,end))}function utf8Slice(buf,start,end){var res="",tmp="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)buf[i]<=127?(res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]),tmp=""):tmp+="%"+buf[i].toString(16);return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(127&buf[i]);return ret}function binarySlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;end>i;i++)ret+=String.fromCharCode(buf[i]);return ret}function hexSlice(buf,start,end){var len=buf.length;(!start||0>start)&&(start=0),(!end||0>end||end>len)&&(end=len);for(var out="",i=start;end>i;i++)out+=toHex(buf[i]);return out}function utf16leSlice(buf,start,end){for(var bytes=buf.slice(start,end),res="",i=0;ioffset)throw new RangeError("offset is not uint");if(offset+ext>length)throw new RangeError("Trying to access beyond buffer length")}function checkInt(buf,value,offset,ext,max,min){if(!Buffer.isBuffer(buf))throw new TypeError("buffer must be a Buffer instance");if(value>max||min>value)throw new RangeError("value is out of bounds");if(offset+ext>buf.length)throw new RangeError("index out of range")}function objectWriteUInt16(buf,value,offset,littleEndian){0>value&&(value=65535+value+1);for(var i=0,j=Math.min(buf.length-offset,2);j>i;i++)buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>8*(littleEndian?i:1-i)}function objectWriteUInt32(buf,value,offset,littleEndian){0>value&&(value=4294967295+value+1);for(var i=0,j=Math.min(buf.length-offset,4);j>i;i++)buf[offset+i]=value>>>8*(littleEndian?i:3-i)&255}function checkIEEE754(buf,value,offset,ext,max,min){if(value>max||min>value)throw new RangeError("value is out of bounds");if(offset+ext>buf.length)throw new RangeError("index out of range");if(0>offset)throw new RangeError("index out of range")}function writeFloat(buf,value,offset,littleEndian,noAssert){return noAssert||checkIEEE754(buf,value,offset,4,3.4028234663852886e38,-3.4028234663852886e38),ieee754.write(buf,value,offset,littleEndian,23,4),offset+4}function writeDouble(buf,value,offset,littleEndian,noAssert){return noAssert||checkIEEE754(buf,value,offset,8,1.7976931348623157e308,-1.7976931348623157e308),ieee754.write(buf,value,offset,littleEndian,52,8),offset+8}function base64clean(str){if(str=stringtrim(str).replace(INVALID_BASE64_RE,""),str.length<2)return"";for(;str.length%4!==0;)str+="=";return str}function stringtrim(str){return str.trim?str.trim():str.replace(/^\s+|\s+$/g,"")}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&"object"==typeof subject&&"number"==typeof subject.length}function toHex(n){return 16>n?"0"+n.toString(16):n.toString(16)}function utf8ToBytes(string,units){var codePoint,length=string.length,leadSurrogate=null;units=units||1/0;for(var bytes=[],i=0;length>i;i++){if(codePoint=string.charCodeAt(i),codePoint>55295&&57344>codePoint){if(!leadSurrogate){if(codePoint>56319){(units-=3)>-1&&bytes.push(239,191,189);continue}if(i+1===length){(units-=3)>-1&&bytes.push(239,191,189);continue}leadSurrogate=codePoint;continue}if(56320>codePoint){(units-=3)>-1&&bytes.push(239,191,189),leadSurrogate=codePoint;continue}codePoint=leadSurrogate-55296<<10|codePoint-56320|65536,leadSurrogate=null}else leadSurrogate&&((units-=3)>-1&&bytes.push(239,191,189),leadSurrogate=null);if(128>codePoint){if((units-=1)<0)break;bytes.push(codePoint)}else if(2048>codePoint){if((units-=2)<0)break;bytes.push(codePoint>>6|192,63&codePoint|128)}else if(65536>codePoint){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,63&codePoint|128)}else{if(!(2097152>codePoint))throw new Error("Invalid code point");if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,63&codePoint|128)}}return bytes}function asciiToBytes(str){for(var byteArray=[],i=0;i>8,lo=c%256,byteArray.push(lo),byteArray.push(hi);return byteArray}function base64ToBytes(str){return base64.toByteArray(base64clean(str))}function blitBuffer(src,dst,offset,length,unitSize){unitSize&&(length-=length%unitSize);for(var i=0;length>i&&!(i+offset>=dst.length||i>=src.length);i++)dst[i+offset]=src[i];return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533)}}var base64=require("base64-js"),ieee754=require("ieee754"),isArray=require("is-array");exports.Buffer=Buffer,exports.SlowBuffer=SlowBuffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var kMaxLength=1073741823,rootParent={};Buffer.TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0),arr=new Uint8Array(buf);return arr.foo=function(){return 42},42===arr.foo()&&"function"==typeof arr.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(e){return!1}}(),Buffer.isBuffer=function(b){return!(null==b||!b._isBuffer)},Buffer.compare=function(a,b){if(!Buffer.isBuffer(a)||!Buffer.isBuffer(b))throw new TypeError("Arguments must be Buffers");for(var x=a.length,y=b.length,i=0,len=Math.min(x,y);len>i&&a[i]===b[i];i++);return i!==len&&(x=a[i],y=b[i]),y>x?-1:x>y?1:0},Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.concat=function(list,totalLength){if(!isArray(list))throw new TypeError("Usage: Buffer.concat(list[, length])");if(0===list.length)return new Buffer(0);if(1===list.length)return list[0];var i;if(void 0===totalLength)for(totalLength=0,i=0;i>>1;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"base64":ret=base64ToBytes(str).length;break;default:ret=str.length}return ret},Buffer.prototype.length=void 0,Buffer.prototype.parent=void 0,Buffer.prototype.toString=function(encoding,start,end){var loweredCase=!1;if(start>>>=0,end=void 0===end||1/0===end?this.length:end>>>0,encoding||(encoding="utf8"),0>start&&(start=0),end>this.length&&(end=this.length),start>=end)return"";for(;;)switch(encoding){case"hex":return hexSlice(this,start,end);case"utf8":case"utf-8":return utf8Slice(this,start,end);case"ascii":return asciiSlice(this,start,end);case"binary":return binarySlice(this,start,end);case"base64":return base64Slice(this,start,end);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,start,end);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(encoding+"").toLowerCase(),loweredCase=!0}},Buffer.prototype.equals=function(b){if(!Buffer.isBuffer(b))throw new TypeError("Argument must be a Buffer");return 0===Buffer.compare(this,b)},Buffer.prototype.inspect=function(){var str="",max=exports.INSPECT_MAX_BYTES;return this.length>0&&(str=this.toString("hex",0,max).match(/.{2}/g).join(" "),this.length>max&&(str+=" ... ")),""},Buffer.prototype.compare=function(b){if(!Buffer.isBuffer(b))throw new TypeError("Argument must be a Buffer");return Buffer.compare(this,b)},Buffer.prototype.get=function(offset){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(offset)},Buffer.prototype.set=function(v,offset){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(v,offset)},Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset))isFinite(length)||(encoding=length,length=void 0);else{var swap=encoding;encoding=offset,offset=length,length=swap}if(offset=Number(offset)||0,0>length||0>offset||offset>this.length)throw new RangeError("attempt to write outside buffer bounds");var remaining=this.length-offset;length?(length=Number(length),length>remaining&&(length=remaining)):length=remaining,encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new TypeError("Unknown encoding: "+encoding)}return ret},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},Buffer.prototype.slice=function(start,end){var len=this.length;start=~~start,end=void 0===end?len:~~end,0>start?(start+=len,0>start&&(start=0)):start>len&&(start=len),0>end?(end+=len,0>end&&(end=0)):end>len&&(end=len),start>end&&(end=start);var newBuf;if(Buffer.TYPED_ARRAY_SUPPORT)newBuf=Buffer._augment(this.subarray(start,end));else{var sliceLen=end-start;newBuf=new Buffer(sliceLen,void 0,!0);for(var i=0;sliceLen>i;i++)newBuf[i]=this[i+start]}return newBuf.length&&(newBuf.parent=this.parent||this),newBuf},Buffer.prototype.readUIntLE=function(offset,byteLength,noAssert){offset>>>=0,byteLength>>>=0,noAssert||checkOffset(offset,byteLength,this.length);for(var val=this[offset],mul=1,i=0;++i>>=0,byteLength>>>=0,noAssert||checkOffset(offset,byteLength,this.length);for(var val=this[offset+--byteLength],mul=1;byteLength>0&&(mul*=256);)val+=this[offset+--byteLength]*mul;return val},Buffer.prototype.readUInt8=function(offset,noAssert){return noAssert||checkOffset(offset,1,this.length),this[offset]},Buffer.prototype.readUInt16LE=function(offset,noAssert){return noAssert||checkOffset(offset,2,this.length),this[offset]|this[offset+1]<<8},Buffer.prototype.readUInt16BE=function(offset,noAssert){return noAssert||checkOffset(offset,2,this.length),this[offset]<<8|this[offset+1]},Buffer.prototype.readUInt32LE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),(this[offset]|this[offset+1]<<8|this[offset+2]<<16)+16777216*this[offset+3]},Buffer.prototype.readUInt32BE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),16777216*this[offset]+(this[offset+1]<<16|this[offset+2]<<8|this[offset+3])},Buffer.prototype.readIntLE=function(offset,byteLength,noAssert){offset>>>=0,byteLength>>>=0,noAssert||checkOffset(offset,byteLength,this.length);for(var val=this[offset],mul=1,i=0;++i=mul&&(val-=Math.pow(2,8*byteLength)),val},Buffer.prototype.readIntBE=function(offset,byteLength,noAssert){offset>>>=0,byteLength>>>=0,noAssert||checkOffset(offset,byteLength,this.length);for(var i=byteLength,mul=1,val=this[offset+--i];i>0&&(mul*=256);)val+=this[offset+--i]*mul;return mul*=128,val>=mul&&(val-=Math.pow(2,8*byteLength)),val},Buffer.prototype.readInt8=function(offset,noAssert){return noAssert||checkOffset(offset,1,this.length),128&this[offset]?-1*(255-this[offset]+1):this[offset]},Buffer.prototype.readInt16LE=function(offset,noAssert){noAssert||checkOffset(offset,2,this.length);var val=this[offset]|this[offset+1]<<8;return 32768&val?4294901760|val:val},Buffer.prototype.readInt16BE=function(offset,noAssert){noAssert||checkOffset(offset,2,this.length);var val=this[offset+1]|this[offset]<<8;return 32768&val?4294901760|val:val},Buffer.prototype.readInt32LE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),this[offset]|this[offset+1]<<8|this[offset+2]<<16|this[offset+3]<<24},Buffer.prototype.readInt32BE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),this[offset]<<24|this[offset+1]<<16|this[offset+2]<<8|this[offset+3]},Buffer.prototype.readFloatLE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),ieee754.read(this,offset,!0,23,4)},Buffer.prototype.readFloatBE=function(offset,noAssert){return noAssert||checkOffset(offset,4,this.length),ieee754.read(this,offset,!1,23,4)},Buffer.prototype.readDoubleLE=function(offset,noAssert){return noAssert||checkOffset(offset,8,this.length),ieee754.read(this,offset,!0,52,8)},Buffer.prototype.readDoubleBE=function(offset,noAssert){return noAssert||checkOffset(offset,8,this.length),ieee754.read(this,offset,!1,52,8)},Buffer.prototype.writeUIntLE=function(value,offset,byteLength,noAssert){value=+value,offset>>>=0,byteLength>>>=0,noAssert||checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength),0);var mul=1,i=0;for(this[offset]=255&value;++i>>0&255;return offset+byteLength},Buffer.prototype.writeUIntBE=function(value,offset,byteLength,noAssert){value=+value,offset>>>=0,byteLength>>>=0,noAssert||checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength),0);var i=byteLength-1,mul=1;for(this[offset+i]=255&value;--i>=0&&(mul*=256);)this[offset+i]=value/mul>>>0&255;return offset+byteLength},Buffer.prototype.writeUInt8=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,1,255,0),Buffer.TYPED_ARRAY_SUPPORT||(value=Math.floor(value)),this[offset]=value,offset+1},Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value,this[offset+1]=value>>>8):objectWriteUInt16(this,value,offset,!0),offset+2},Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value>>>8,this[offset+1]=value):objectWriteUInt16(this,value,offset,!1),offset+2},Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[offset+3]=value>>>24,this[offset+2]=value>>>16,this[offset+1]=value>>>8,this[offset]=value):objectWriteUInt32(this,value,offset,!0),offset+4},Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value>>>24,this[offset+1]=value>>>16,this[offset+2]=value>>>8,this[offset+3]=value):objectWriteUInt32(this,value,offset,!1),offset+4},Buffer.prototype.writeIntLE=function(value,offset,byteLength,noAssert){value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength-1)-1,-Math.pow(2,8*byteLength-1));var i=0,mul=1,sub=0>value?1:0;for(this[offset]=255&value;++i>0)-sub&255;return offset+byteLength},Buffer.prototype.writeIntBE=function(value,offset,byteLength,noAssert){value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength-1)-1,-Math.pow(2,8*byteLength-1));var i=byteLength-1,mul=1,sub=0>value?1:0;for(this[offset+i]=255&value;--i>=0&&(mul*=256);)this[offset+i]=(value/mul>>0)-sub&255;return offset+byteLength},Buffer.prototype.writeInt8=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,1,127,-128),Buffer.TYPED_ARRAY_SUPPORT||(value=Math.floor(value)),0>value&&(value=255+value+1),this[offset]=value,offset+1},Buffer.prototype.writeInt16LE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value,this[offset+1]=value>>>8):objectWriteUInt16(this,value,offset,!0),offset+2},Buffer.prototype.writeInt16BE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value>>>8,this[offset+1]=value):objectWriteUInt16(this,value,offset,!1),offset+2},Buffer.prototype.writeInt32LE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,4,2147483647,-2147483648),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value,this[offset+1]=value>>>8,this[offset+2]=value>>>16,this[offset+3]=value>>>24):objectWriteUInt32(this,value,offset,!0),offset+4},Buffer.prototype.writeInt32BE=function(value,offset,noAssert){return value=+value,offset>>>=0,noAssert||checkInt(this,value,offset,4,2147483647,-2147483648),0>value&&(value=4294967295+value+1),Buffer.TYPED_ARRAY_SUPPORT?(this[offset]=value>>>24,this[offset+1]=value>>>16,this[offset+2]=value>>>8,this[offset+3]=value):objectWriteUInt32(this,value,offset,!1),offset+4},Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,!0,noAssert)},Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,!1,noAssert)},Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,!0,noAssert)},Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,!1,noAssert)},Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(start||(start=0),end||0===end||(end=this.length),target_start>=target.length&&(target_start=target.length),target_start||(target_start=0),end>0&&start>end&&(end=start),end===start)return 0;if(0===target.length||0===source.length)return 0;if(0>target_start)throw new RangeError("targetStart out of bounds");if(0>start||start>=source.length)throw new RangeError("sourceStart out of bounds");if(0>end)throw new RangeError("sourceEnd out of bounds");end>this.length&&(end=this.length),target.length-target_startlen||!Buffer.TYPED_ARRAY_SUPPORT)for(var i=0;len>i;i++)target[i+target_start]=this[i+start];else target._set(this.subarray(start,start+len),target_start);return len},Buffer.prototype.fill=function(value,start,end){if(value||(value=0),start||(start=0),end||(end=this.length),start>end)throw new RangeError("end < start");if(end!==start&&0!==this.length){if(0>start||start>=this.length)throw new RangeError("start out of bounds");if(0>end||end>this.length)throw new RangeError("end out of bounds");var i;if("number"==typeof value)for(i=start;end>i;i++)this[i]=value;else{var bytes=utf8ToBytes(value.toString()),len=bytes.length;for(i=start;end>i;i++)this[i]=bytes[i%len]}return this}},Buffer.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(Buffer.TYPED_ARRAY_SUPPORT)return new Buffer(this).buffer;for(var buf=new Uint8Array(this.length),i=0,len=buf.length;len>i;i+=1)buf[i]=this[i];return buf.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var BP=Buffer.prototype;Buffer._augment=function(arr){return arr.constructor=Buffer,arr._isBuffer=!0,arr._get=arr.get,arr._set=arr.set,arr.get=BP.get,arr.set=BP.set,arr.write=BP.write,arr.toString=BP.toString,arr.toLocaleString=BP.toString,arr.toJSON=BP.toJSON,arr.equals=BP.equals,arr.compare=BP.compare,arr.copy=BP.copy,arr.slice=BP.slice,arr.readUIntLE=BP.readUIntLE,arr.readUIntBE=BP.readUIntBE,arr.readUInt8=BP.readUInt8,arr.readUInt16LE=BP.readUInt16LE,arr.readUInt16BE=BP.readUInt16BE,arr.readUInt32LE=BP.readUInt32LE,arr.readUInt32BE=BP.readUInt32BE,arr.readIntLE=BP.readIntLE,arr.readIntBE=BP.readIntBE,arr.readInt8=BP.readInt8,arr.readInt16LE=BP.readInt16LE,arr.readInt16BE=BP.readInt16BE,arr.readInt32LE=BP.readInt32LE,arr.readInt32BE=BP.readInt32BE,arr.readFloatLE=BP.readFloatLE,arr.readFloatBE=BP.readFloatBE,arr.readDoubleLE=BP.readDoubleLE,arr.readDoubleBE=BP.readDoubleBE,arr.writeUInt8=BP.writeUInt8,arr.writeUIntLE=BP.writeUIntLE,arr.writeUIntBE=BP.writeUIntBE,arr.writeUInt16LE=BP.writeUInt16LE,arr.writeUInt16BE=BP.writeUInt16BE,arr.writeUInt32LE=BP.writeUInt32LE,arr.writeUInt32BE=BP.writeUInt32BE,arr.writeIntLE=BP.writeIntLE,arr.writeIntBE=BP.writeIntBE,arr.writeInt8=BP.writeInt8,arr.writeInt16LE=BP.writeInt16LE,arr.writeInt16BE=BP.writeInt16BE,arr.writeInt32LE=BP.writeInt32LE,arr.writeInt32BE=BP.writeInt32BE,arr.writeFloatLE=BP.writeFloatLE,arr.writeFloatBE=BP.writeFloatBE,arr.writeDoubleLE=BP.writeDoubleLE,arr.writeDoubleBE=BP.writeDoubleBE,arr.fill=BP.fill,arr.inspect=BP.inspect,arr.toArrayBuffer=BP.toArrayBuffer,arr};var INVALID_BASE64_RE=/[^+\/0-9A-z\-]/g},{"base64-js":112,ieee754:113,"is-array":114}],112:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(exports){"use strict";function decode(elt){var code=elt.charCodeAt(0);return code===PLUS||code===PLUS_URL_SAFE?62:code===SLASH||code===SLASH_URL_SAFE?63:NUMBER>code?-1:NUMBER+10>code?code-NUMBER+26+26:UPPER+26>code?code-UPPER:LOWER+26>code?code-LOWER+26:void 0}function b64ToByteArray(b64){function push(v){arr[L++]=v}var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0,arr=new Arr(3*b64.length/4-placeHolders),l=placeHolders>0?b64.length-4:b64.length;var L=0;for(i=0,j=0;l>i;i+=4,j+=3)tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3)),push((16711680&tmp)>>16),push((65280&tmp)>>8),push(255&tmp);return 2===placeHolders?(tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4,push(255&tmp)):1===placeHolders&&(tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2,push(tmp>>8&255),push(255&tmp)),arr}function uint8ToBase64(uint8){function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(63&num)}var i,temp,length,extraBytes=uint8.length%3,output="";for(i=0,length=uint8.length-extraBytes;length>i;i+=3)temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2],output+=tripletToBase64(temp);switch(extraBytes){case 1:temp=uint8[uint8.length-1],output+=encode(temp>>2),output+=encode(temp<<4&63),output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1],output+=encode(temp>>10),output+=encode(temp>>4&63),output+=encode(temp<<2&63),output+="="}return output}var Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,PLUS="+".charCodeAt(0),SLASH="/".charCodeAt(0),NUMBER="0".charCodeAt(0),LOWER="a".charCodeAt(0),UPPER="A".charCodeAt(0),PLUS_URL_SAFE="-".charCodeAt(0),SLASH_URL_SAFE="_".charCodeAt(0);exports.toByteArray=b64ToByteArray,exports.fromByteArray=uint8ToBase64}("undefined"==typeof exports?this.base64js={}:exports)},{}],113:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=8*nBytes-mLen-1,eMax=(1<>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];for(i+=d,e=s&(1<<-nBits)-1,s>>=-nBits,nBits+=eLen;nBits>0;e=256*e+buffer[offset+i],i+=d,nBits-=8);for(m=e&(1<<-nBits)-1,e>>=-nBits,nBits+=mLen;nBits>0;m=256*m+buffer[offset+i],i+=d,nBits-=8);if(0===e)e=1-eBias;else{if(e===eMax)return m?0/0:1/0*(s?-1:1);m+=Math.pow(2,mLen),e-=eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)},exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=8*nBytes-mLen-1,eMax=(1<>1,rt=23===mLen?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=0>value||0===value&&0>1/value?1:0;for(value=Math.abs(value),isNaN(value)||1/0===value?(m=isNaN(value)?1:0,e=eMax):(e=Math.floor(Math.log(value)/Math.LN2),value*(c=Math.pow(2,-e))<1&&(e--,c*=2),value+=e+eBias>=1?rt/c:rt*Math.pow(2,1-eBias),value*c>=2&&(e++,c/=2),e+eBias>=eMax?(m=0,e=eMax):e+eBias>=1?(m=(value*c-1)*Math.pow(2,mLen),e+=eBias):(m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen),e=0));mLen>=8;buffer[offset+i]=255&m,i+=d,m/=256,mLen-=8);for(e=e<0;buffer[offset+i]=255&e,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=128*s}},{}],114:[function(require,module){var isArray=Array.isArray,str=Object.prototype.toString;module.exports=isArray||function(val){return!!val&&"[object Array]"==str.call(val)}},{}],115:[function(require,module){function drainQueue(){if(!draining){draining=!0;for(var currentQueue,len=queue.length;len;){currentQueue=queue,queue=[];for(var i=-1;++i-1||(list.push(token),setTokens(list))}function remove(token){var list=getTokens(),index=indexof(list,token);-1!==index&&(list.splice(index,1),setTokens(list))}function contains(token){return indexof(getTokens(),token)>-1}function toggle(token){return contains(token)?(remove(token),!1):(add(token),!0)}function $toString(){return elem.className}function item(index){var tokens=getTokens();return tokens[index]||null}function getTokens(){var className=elem.className;return filter(className.split(" "),isTruthy)}function setTokens(list){var length=list.length;elem.className=list.join(" "),classList.length=length;for(var i=0;i li { +.topnav ul > li { display: inline-block; } -#splash canvas { - z-index: 1; +/** + * Thumbnails + */ +.thumbs { + list-style-type: none; + margin-right: 0; + margin-left: -1em; + margin-bottom: 2em; + margin-top: -1em; +} + +.thumbs:before, +.thumbs:after { + content: ' '; + display: table; +} + +.thumbs:after { + clear: both; +} + +.thumbs li { + position: relative; + box-sizing: border-box; + padding-top: 2em; + padding-left: 1em; + width: 33.3%; + float: left; +} + +.thumbs.thumbs-pair li { + width: 50%; +} + +.thumbs.thumbs-trio li { + font-size: 0.95em; +} + +.thumbs li .image { + background-image: url(default.jpg); + background-position: 50% 50%; + background-size: cover; + width: 100%; + height: 140px; + box-sizing: border-box; + border: 1px solid #DEE7FF; + border-radius: 4px; +} + +.thumbs li h3 { + font-family: 'Fantasque Sans Mono', 'Ubuntu Mono', 'Helvetica Neue', Helvetica, Arial, sans-serif; + white-space: nowrap; + margin-top: 0.5rem; + color: #4A4F5E; + opacity: 0.8; +} + +/** + * Intro + */ +#intro { + position: absolute; + top: 0; + left: 0; + z-index: 2; + background: rgba(255,255,255,0.75); + padding: 2em; +} + +#intro aside, +#community-content aside { + max-width: 400px; + color: #4A4F5E; + font-size: 0.9em; } #community { @@ -89,10 +184,6 @@ h1 .lighter { z-index: 2; } -#community-canvas { - z-index: 1; -} - .no-webgl #grid { background-image: url(bg.jpg); background-size: cover; diff --git a/index.html b/index.html index 2f1729b..e5be612 100644 --- a/index.html +++ b/index.html @@ -8,74 +8,99 @@ -
            -
            -
            -

            #stackgl

            +
            +

            #stackgl

            + -
            - -
            - - - -
            - - +
            + stackgl is an open software ecosystem for WebGL, built on top of + browserify and + npm. Inspired by the + Unix philosophy, + stackgl modules "do one thing, and do it well". It is + easy to use parts of stackgl à la carte, and because it is written from the + bottom up, you can always drill down a layer. Unlike many 3D engines, + stackgl emphasizes writing shader code, and provides powerful tools like + glslify which bring the + modularity and productivity of npm to GLSL!
            -
            +

            examples & demos

            -
              +
                -
                -
                -

                community

                +
                +

                learning

                + - -
                +

                + Before getting started with stackgl, you'll want to get familiar with + the basics of WebGL and GLSL. One place to start would be by trying out + one of our graphics-themed NodeSchool + workshops. Shader School and + WebGL Workshop are interactive and may be taken in any + order. +

                + +

                + Some other good learning resources include + Learning WebGL, + WebGL Academy, and + GLSL Sandbox. + + If you're particularly interested in shaders, you might want to out + An Introduction to Shaders or + Primer: Shaders. +

                +
                - +
                +

                community

                +

                + Not sure where to start? Here's some links that should help you + learn more and/or get involved yourself. Feel free to get in touch + if you have any questions! +

                + +

                + stack.gl contributors: +

                +
                -
                + +