Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Created January 11, 2015 01:40
Show Gist options
  • Save tmpvar/8e2456cf2841d7fe6f23 to your computer and use it in GitHub Desktop.
Save tmpvar/8e2456cf2841d7fe6f23 to your computer and use it in GitHub Desktop.
requirebin sketch
var createContext = require('fc');
var extractMesh = require('isosurface').surfaceNets;
var createVAO = require('gl-vao');
var createCamera = require('orbit-camera');
var createShader = require('simple-3d-shader');
var createMesh = require('gl-mesh');
var createNormals = require('normals').vertexNormals;
var vec3 = require('gl-vec3');
var mat4 = require('gl-mat4');
var view = mat4.create();
var projection = mat4.create();
var model = mat4.create();
var mouse = {
down: false,
pos: [0, 0]
};
var gl = createContext(frame, true, 3);
var camera = createCamera(
[0, 0, 20],
[0, 0, 0],
[0, 1, 0]
);
var shader = createShader(gl);
var v3pos = [0, 0, 0];
var v3abs = [0, 0, 0];
var temp = [0, 0, 0];
var zero = [0, 0, 0];
var max = Math.max;
var min = Math.min;
var extracted = extractMesh([64,64,64], function(x,y,z) {
v3pos[0] = x;
v3pos[1] = y;
v3pos[2] = z;
// sphere
var sphere = vec3.length(v3pos) - 6;
var dims = [5, 5, 5];
v3abs[0] = Math.abs(v3pos[0]);
v3abs[1] = Math.abs(v3pos[1]);
v3abs[2] = Math.abs(v3pos[2]);
vec3.subtract(v3pos, v3abs, dims);
vec3.max(temp, v3pos, zero);
var cube = min(
max(
v3pos[0], max(
v3pos[1],
v3pos[2]
)
), 0.0) + vec3.distance(temp, zero);
return max(cube, -sphere);
}, [[-11,-11,-11], [11,11,11]])
extracted.color = createNormals(extracted.cells, extracted.positions);
var mesh = createMesh(gl, extracted);
// createNormals
function frame() {
var w = gl.canvas.width
var h = gl.canvas.height;
gl.viewport(0, 0, w, h);
gl.enable(gl.DEPTH_TEST);
mat4.identity(model);
mat4.perspective(
projection,
Math.PI/4.0,
w/h,
0.1,
1000.0
);
//Calculate camera matrices
camera.view(view);
shader.uniforms.projection = projection;
shader.uniforms.view = view;
shader.uniforms.model = model;
shader.bind();
mesh.bind(shader);
mesh.draw();
mesh.unbind();
}
function handleMouse(e) {
gl.start();
switch (e.type) {
case 'mousedown':
mouse.down = true;
break;
case 'mouseup':
mouse.down = false;
break;
case 'mousemove':
var x = e.clientX;
var y = e.clientY;
if (mouse.down) {
// fc ensures that the canvas is fullscreen
// you'll want to get the offset of the canvas
// element if you don't use fc.
var w = gl.canvas.width;
var h = gl.canvas.height;
var l = mouse.pos;
// TODO: pre-allocate these vectors to avoid gc hickups
camera.rotate(
[x/w - .5, y/h - .5],
[l[0]/w - .5, l[1]/h - .5]
)
}
mouse.pos[0] = x;
mouse.pos[1] = y;
break;
case 'mousewheel':
camera.zoom(e.wheelDeltaY * -.001);
e.preventDefault();
break;
// TODO: eliminate new array creation below
case 'keydown' :
var panSpeed = .01;
switch (e.keyCode) {
case 37:
camera.pan([-panSpeed, 0, 0]);
break;
case 38:
camera.pan([0, -panSpeed, 0]);
break;
case 39:
camera.pan([panSpeed, 0, 0]);
break;
case 40:
camera.pan([0, panSpeed, 0]);
break;
}
break;
}
}
['mousedown', 'mouseup', 'mousemove', 'mousewheel', 'keydown'].forEach(function(name) {
document.addEventListener(name, handleMouse);
});
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&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}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({fc:[function(require,module,exports){(function(){var performance=window.performance||{};var performanceNow=performance.now||performance.now||performance.mozNow||performance.msNow||performance.oNow||performance.webkitNow||function(){return(new Date).getTime()};performanceNow=performanceNow.bind(performance);function fc(fn,autorun,dimensions){document.body.style.margin="0px";document.body.style.padding="0px";var canvas=document.createElement("canvas");document.body.appendChild(canvas);canvas.style.position="absolute";canvas.style.left="0px";canvas.style.top="0px";var ctx;dimensions=dimensions||2;if(dimensions===2){ctx=canvas.getContext("2d")}else if(dimensions===3){ctx=canvas.getContext("webgl")||canvas.getContext("experimental-webgl")}if(!ctx){return}var last=performanceNow(),request;function requestFrame(){if(request===null){request=requestAnimationFrame(tick)}}function tick(){request=null;var time=performanceNow();var delta=time-last;last=time;ctx.reset();dimensions===2&&ctx.save();fn&&fn.call(ctx,delta);dimensions===2&&ctx.restore();if(autorun){requestFrame()}}if(dimensions===2){ctx.reset=function fc_reset(){canvas.width=0;canvas.width=window.innerWidth;canvas.height=window.innerHeight};ctx.clear=function fc_clear(color){var orig=ctx.fillStyle;ctx.fillStyle=color||"#223";ctx.fillRect(0,0,canvas.width,canvas.height);ctx.fillStyle=orig}}else{ctx.reset=function fc_reset(){if(canvas.width!==window.innerWidth){canvas.width=window.innerWidth}if(canvas.height!==window.innerHeight){canvas.height=window.innerHeight}}}setTimeout(tick,0);ctx.dirty=function fc_dirty(){last=performanceNow();requestFrame()};ctx.stop=function fc_stop(){autorun=false;request&&cancelAnimationFrame(request);request=null};ctx.start=function fc_start(){autorun=true;requestFrame()};(window.attachEvent||window.addEventListener)("resize",ctx.dirty);ctx.reset();ctx.canvas=canvas;return ctx}if(typeof module!=="undefined"&&typeof module.exports!=="undefined"){module.exports=fc}if(typeof window!=="undefined"){window.fc=window.fc||fc}})()},{}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&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}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var edgeTable=new Uint32Array([0,265,515,778,1030,1295,1541,1804,2060,2309,2575,2822,3082,3331,3593,3840,400,153,915,666,1430,1183,1941,1692,2460,2197,2975,2710,3482,3219,3993,3728,560,825,51,314,1590,1855,1077,1340,2620,2869,2111,2358,3642,3891,3129,3376,928,681,419,170,1958,1711,1445,1196,2988,2725,2479,2214,4010,3747,3497,3232,1120,1385,1635,1898,102,367,613,876,3180,3429,3695,3942,2154,2403,2665,2912,1520,1273,2035,1786,502,255,1013,764,3580,3317,4095,3830,2554,2291,3065,2800,1616,1881,1107,1370,598,863,85,348,3676,3925,3167,3414,2650,2899,2137,2384,1984,1737,1475,1226,966,719,453,204,4044,3781,3535,3270,3018,2755,2505,2240,2240,2505,2755,3018,3270,3535,3781,4044,204,453,719,966,1226,1475,1737,1984,2384,2137,2899,2650,3414,3167,3925,3676,348,85,863,598,1370,1107,1881,1616,2800,3065,2291,2554,3830,4095,3317,3580,764,1013,255,502,1786,2035,1273,1520,2912,2665,2403,2154,3942,3695,3429,3180,876,613,367,102,1898,1635,1385,1120,3232,3497,3747,4010,2214,2479,2725,2988,1196,1445,1711,1958,170,419,681,928,3376,3129,3891,3642,2358,2111,2869,2620,1340,1077,1855,1590,314,51,825,560,3728,3993,3219,3482,2710,2975,2197,2460,1692,1941,1183,1430,666,915,153,400,3840,3593,3331,3082,2822,2575,2309,2060,1804,1541,1295,1030,778,515,265,0]),triTable=[[],[0,8,3],[0,1,9],[1,8,3,9,8,1],[1,2,10],[0,8,3,1,2,10],[9,2,10,0,2,9],[2,8,3,2,10,8,10,9,8],[3,11,2],[0,11,2,8,11,0],[1,9,0,2,3,11],[1,11,2,1,9,11,9,8,11],[3,10,1,11,10,3],[0,10,1,0,8,10,8,11,10],[3,9,0,3,11,9,11,10,9],[9,8,10,10,8,11],[4,7,8],[4,3,0,7,3,4],[0,1,9,8,4,7],[4,1,9,4,7,1,7,3,1],[1,2,10,8,4,7],[3,4,7,3,0,4,1,2,10],[9,2,10,9,0,2,8,4,7],[2,10,9,2,9,7,2,7,3,7,9,4],[8,4,7,3,11,2],[11,4,7,11,2,4,2,0,4],[9,0,1,8,4,7,2,3,11],[4,7,11,9,4,11,9,11,2,9,2,1],[3,10,1,3,11,10,7,8,4],[1,11,10,1,4,11,1,0,4,7,11,4],[4,7,8,9,0,11,9,11,10,11,0,3],[4,7,11,4,11,9,9,11,10],[9,5,4],[9,5,4,0,8,3],[0,5,4,1,5,0],[8,5,4,8,3,5,3,1,5],[1,2,10,9,5,4],[3,0,8,1,2,10,4,9,5],[5,2,10,5,4,2,4,0,2],[2,10,5,3,2,5,3,5,4,3,4,8],[9,5,4,2,3,11],[0,11,2,0,8,11,4,9,5],[0,5,4,0,1,5,2,3,11],[2,1,5,2,5,8,2,8,11,4,8,5],[10,3,11,10,1,3,9,5,4],[4,9,5,0,8,1,8,10,1,8,11,10],[5,4,0,5,0,11,5,11,10,11,0,3],[5,4,8,5,8,10,10,8,11],[9,7,8,5,7,9],[9,3,0,9,5,3,5,7,3],[0,7,8,0,1,7,1,5,7],[1,5,3,3,5,7],[9,7,8,9,5,7,10,1,2],[10,1,2,9,5,0,5,3,0,5,7,3],[8,0,2,8,2,5,8,5,7,10,5,2],[2,10,5,2,5,3,3,5,7],[7,9,5,7,8,9,3,11,2],[9,5,7,9,7,2,9,2,0,2,7,11],[2,3,11,0,1,8,1,7,8,1,5,7],[11,2,1,11,1,7,7,1,5],[9,5,8,8,5,7,10,1,3,10,3,11],[5,7,0,5,0,9,7,11,0,1,0,10,11,10,0],[11,10,0,11,0,3,10,5,0,8,0,7,5,7,0],[11,10,5,7,11,5],[10,6,5],[0,8,3,5,10,6],[9,0,1,5,10,6],[1,8,3,1,9,8,5,10,6],[1,6,5,2,6,1],[1,6,5,1,2,6,3,0,8],[9,6,5,9,0,6,0,2,6],[5,9,8,5,8,2,5,2,6,3,2,8],[2,3,11,10,6,5],[11,0,8,11,2,0,10,6,5],[0,1,9,2,3,11,5,10,6],[5,10,6,1,9,2,9,11,2,9,8,11],[6,3,11,6,5,3,5,1,3],[0,8,11,0,11,5,0,5,1,5,11,6],[3,11,6,0,3,6,0,6,5,0,5,9],[6,5,9,6,9,11,11,9,8],[5,10,6,4,7,8],[4,3,0,4,7,3,6,5,10],[1,9,0,5,10,6,8,4,7],[10,6,5,1,9,7,1,7,3,7,9,4],[6,1,2,6,5,1,4,7,8],[1,2,5,5,2,6,3,0,4,3,4,7],[8,4,7,9,0,5,0,6,5,0,2,6],[7,3,9,7,9,4,3,2,9,5,9,6,2,6,9],[3,11,2,7,8,4,10,6,5],[5,10,6,4,7,2,4,2,0,2,7,11],[0,1,9,4,7,8,2,3,11,5,10,6],[9,2,1,9,11,2,9,4,11,7,11,4,5,10,6],[8,4,7,3,11,5,3,5,1,5,11,6],[5,1,11,5,11,6,1,0,11,7,11,4,0,4,11],[0,5,9,0,6,5,0,3,6,11,6,3,8,4,7],[6,5,9,6,9,11,4,7,9,7,11,9],[10,4,9,6,4,10],[4,10,6,4,9,10,0,8,3],[10,0,1,10,6,0,6,4,0],[8,3,1,8,1,6,8,6,4,6,1,10],[1,4,9,1,2,4,2,6,4],[3,0,8,1,2,9,2,4,9,2,6,4],[0,2,4,4,2,6],[8,3,2,8,2,4,4,2,6],[10,4,9,10,6,4,11,2,3],[0,8,2,2,8,11,4,9,10,4,10,6],[3,11,2,0,1,6,0,6,4,6,1,10],[6,4,1,6,1,10,4,8,1,2,1,11,8,11,1],[9,6,4,9,3,6,9,1,3,11,6,3],[8,11,1,8,1,0,11,6,1,9,1,4,6,4,1],[3,11,6,3,6,0,0,6,4],[6,4,8,11,6,8],[7,10,6,7,8,10,8,9,10],[0,7,3,0,10,7,0,9,10,6,7,10],[10,6,7,1,10,7,1,7,8,1,8,0],[10,6,7,10,7,1,1,7,3],[1,2,6,1,6,8,1,8,9,8,6,7],[2,6,9,2,9,1,6,7,9,0,9,3,7,3,9],[7,8,0,7,0,6,6,0,2],[7,3,2,6,7,2],[2,3,11,10,6,8,10,8,9,8,6,7],[2,0,7,2,7,11,0,9,7,6,7,10,9,10,7],[1,8,0,1,7,8,1,10,7,6,7,10,2,3,11],[11,2,1,11,1,7,10,6,1,6,7,1],[8,9,6,8,6,7,9,1,6,11,6,3,1,3,6],[0,9,1,11,6,7],[7,8,0,7,0,6,3,11,0,11,6,0],[7,11,6],[7,6,11],[3,0,8,11,7,6],[0,1,9,11,7,6],[8,1,9,8,3,1,11,7,6],[10,1,2,6,11,7],[1,2,10,3,0,8,6,11,7],[2,9,0,2,10,9,6,11,7],[6,11,7,2,10,3,10,8,3,10,9,8],[7,2,3,6,2,7],[7,0,8,7,6,0,6,2,0],[2,7,6,2,3,7,0,1,9],[1,6,2,1,8,6,1,9,8,8,7,6],[10,7,6,10,1,7,1,3,7],[10,7,6,1,7,10,1,8,7,1,0,8],[0,3,7,0,7,10,0,10,9,6,10,7],[7,6,10,7,10,8,8,10,9],[6,8,4,11,8,6],[3,6,11,3,0,6,0,4,6],[8,6,11,8,4,6,9,0,1],[9,4,6,9,6,3,9,3,1,11,3,6],[6,8,4,6,11,8,2,10,1],[1,2,10,3,0,11,0,6,11,0,4,6],[4,11,8,4,6,11,0,2,9,2,10,9],[10,9,3,10,3,2,9,4,3,11,3,6,4,6,3],[8,2,3,8,4,2,4,6,2],[0,4,2,4,6,2],[1,9,0,2,3,4,2,4,6,4,3,8],[1,9,4,1,4,2,2,4,6],[8,1,3,8,6,1,8,4,6,6,10,1],[10,1,0,10,0,6,6,0,4],[4,6,3,4,3,8,6,10,3,0,3,9,10,9,3],[10,9,4,6,10,4],[4,9,5,7,6,11],[0,8,3,4,9,5,11,7,6],[5,0,1,5,4,0,7,6,11],[11,7,6,8,3,4,3,5,4,3,1,5],[9,5,4,10,1,2,7,6,11],[6,11,7,1,2,10,0,8,3,4,9,5],[7,6,11,5,4,10,4,2,10,4,0,2],[3,4,8,3,5,4,3,2,5,10,5,2,11,7,6],[7,2,3,7,6,2,5,4,9],[9,5,4,0,8,6,0,6,2,6,8,7],[3,6,2,3,7,6,1,5,0,5,4,0],[6,2,8,6,8,7,2,1,8,4,8,5,1,5,8],[9,5,4,10,1,6,1,7,6,1,3,7],[1,6,10,1,7,6,1,0,7,8,7,0,9,5,4],[4,0,10,4,10,5,0,3,10,6,10,7,3,7,10],[7,6,10,7,10,8,5,4,10,4,8,10],[6,9,5,6,11,9,11,8,9],[3,6,11,0,6,3,0,5,6,0,9,5],[0,11,8,0,5,11,0,1,5,5,6,11],[6,11,3,6,3,5,5,3,1],[1,2,10,9,5,11,9,11,8,11,5,6],[0,11,3,0,6,11,0,9,6,5,6,9,1,2,10],[11,8,5,11,5,6,8,0,5,10,5,2,0,2,5],[6,11,3,6,3,5,2,10,3,10,5,3],[5,8,9,5,2,8,5,6,2,3,8,2],[9,5,6,9,6,0,0,6,2],[1,5,8,1,8,0,5,6,8,3,8,2,6,2,8],[1,5,6,2,1,6],[1,3,6,1,6,10,3,8,6,5,6,9,8,9,6],[10,1,0,10,0,6,9,5,0,5,6,0],[0,3,8,5,6,10],[10,5,6],[11,5,10,7,5,11],[11,5,10,11,7,5,8,3,0],[5,11,7,5,10,11,1,9,0],[10,7,5,10,11,7,9,8,1,8,3,1],[11,1,2,11,7,1,7,5,1],[0,8,3,1,2,7,1,7,5,7,2,11],[9,7,5,9,2,7,9,0,2,2,11,7],[7,5,2,7,2,11,5,9,2,3,2,8,9,8,2],[2,5,10,2,3,5,3,7,5],[8,2,0,8,5,2,8,7,5,10,2,5],[9,0,1,5,10,3,5,3,7,3,10,2],[9,8,2,9,2,1,8,7,2,10,2,5,7,5,2],[1,3,5,3,7,5],[0,8,7,0,7,1,1,7,5],[9,0,3,9,3,5,5,3,7],[9,8,7,5,9,7],[5,8,4,5,10,8,10,11,8],[5,0,4,5,11,0,5,10,11,11,3,0],[0,1,9,8,4,10,8,10,11,10,4,5],[10,11,4,10,4,5,11,3,4,9,4,1,3,1,4],[2,5,1,2,8,5,2,11,8,4,5,8],[0,4,11,0,11,3,4,5,11,2,11,1,5,1,11],[0,2,5,0,5,9,2,11,5,4,5,8,11,8,5],[9,4,5,2,11,3],[2,5,10,3,5,2,3,4,5,3,8,4],[5,10,2,5,2,4,4,2,0],[3,10,2,3,5,10,3,8,5,4,5,8,0,1,9],[5,10,2,5,2,4,1,9,2,9,4,2],[8,4,5,8,5,3,3,5,1],[0,4,5,1,0,5],[8,4,5,8,5,3,9,0,5,0,3,5],[9,4,5],[4,11,7,4,9,11,9,10,11],[0,8,3,4,9,7,9,11,7,9,10,11],[1,10,11,1,11,4,1,4,0,7,4,11],[3,1,4,3,4,8,1,10,4,7,4,11,10,11,4],[4,11,7,9,11,4,9,2,11,9,1,2],[9,7,4,9,11,7,9,1,11,2,11,1,0,8,3],[11,7,4,11,4,2,2,4,0],[11,7,4,11,4,2,8,3,4,3,2,4],[2,9,10,2,7,9,2,3,7,7,4,9],[9,10,7,9,7,4,10,2,7,8,7,0,2,0,7],[3,7,10,3,10,2,7,4,10,1,10,0,4,0,10],[1,10,2,8,7,4],[4,9,1,4,1,7,7,1,3],[4,9,1,4,1,7,0,8,1,8,7,1],[4,0,3,7,4,3],[4,8,7],[9,10,8,10,11,8],[3,0,9,3,9,11,11,9,10],[0,1,10,0,10,8,8,10,11],[3,1,10,11,3,10],[1,2,11,1,11,9,9,11,8],[3,0,9,3,9,11,1,2,9,2,11,9],[0,2,11,8,0,11],[3,2,11],[2,3,8,2,8,10,10,8,9],[9,10,2,0,9,2],[2,3,8,2,8,10,0,1,8,1,10,8],[1,10,2],[1,3,8,9,1,8],[0,9,1],[0,3,8],[]],cubeVerts=[[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]],edgeIndex=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]];exports.marchingCubes=function(dims,potential,bounds){if(!bounds){bounds=[[0,0,0],dims]}var scale=[0,0,0];var shift=[0,0,0];for(var i=0;i<3;++i){scale[i]=(bounds[1][i]-bounds[0][i])/dims[i];shift[i]=bounds[0][i]}var vertices=[],faces=[],n=0,grid=new Array(8),edges=new Array(12),x=[0,0,0];for(x[2]=0;x[2]<dims[2]-1;++x[2],n+=dims[0])for(x[1]=0;x[1]<dims[1]-1;++x[1],++n)for(x[0]=0;x[0]<dims[0]-1;++x[0],++n){var cube_index=0;for(var i=0;i<8;++i){var v=cubeVerts[i],s=potential(scale[0]*(x[0]+v[0])+shift[0],scale[1]*(x[1]+v[1])+shift[1],scale[2]*(x[2]+v[2])+shift[2]);grid[i]=s;cube_index|=s>0?1<<i:0}var edge_mask=edgeTable[cube_index];if(edge_mask===0){continue}for(var i=0;i<12;++i){if((edge_mask&1<<i)===0){continue}edges[i]=vertices.length;var nv=[0,0,0],e=edgeIndex[i],p0=cubeVerts[e[0]],p1=cubeVerts[e[1]],a=grid[e[0]],b=grid[e[1]],d=a-b,t=0;if(Math.abs(d)>1e-6){t=a/d}for(var j=0;j<3;++j){nv[j]=scale[j]*(x[j]+p0[j]+t*(p1[j]-p0[j]))+shift[j]}vertices.push(nv)}var f=triTable[cube_index];for(var i=0;i<f.length;i+=3){faces.push([edges[f[i]],edges[f[i+1]],edges[f[i+2]]])}}return{positions:vertices,cells:faces}}},{}],2:[function(require,module,exports){var cube_vertices=[[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]],tetra_list=[[0,2,3,7],[0,6,2,7],[0,4,6,7],[0,6,1,2],[0,1,6,4],[5,6,1,4]];exports.marchingTetrahedra=function(dims,potential,bounds){if(!bounds){bounds=[[0,0,0],dims]}var scale=[0,0,0];var shift=[0,0,0];for(var i=0;i<3;++i){scale[i]=(bounds[1][i]-bounds[0][i])/dims[i];shift[i]=bounds[0][i]}var vertices=[],faces=[],n=0,grid=new Float32Array(8),edges=new Int32Array(12),x=[0,0,0];function interp(i0,i1){var g0=grid[i0],g1=grid[i1],p0=cube_vertices[i0],p1=cube_vertices[i1],v=[x[0],x[1],x[2]],t=g0-g1;if(Math.abs(t)>1e-6){t=g0/t}for(var i=0;i<3;++i){v[i]=scale[i]*(v[i]+p0[i]+t*(p1[i]-p0[i]))+shift[i]}vertices.push(v);return vertices.length-1}for(x[2]=0;x[2]<dims[2]-1;++x[2],n+=dims[0])for(x[1]=0;x[1]<dims[1]-1;++x[1],++n)for(x[0]=0;x[0]<dims[0]-1;++x[0],++n){for(var i=0;i<8;++i){var cube_vert=cube_vertices[i];grid[i]=potential(scale[0]*(x[0]+cube_vert[0])+shift[0],scale[1]*(x[1]+cube_vert[1])+shift[1],scale[2]*(x[2]+cube_vert[2])+shift[2])}for(var i=0;i<tetra_list.length;++i){var T=tetra_list[i],triindex=0;if(grid[T[0]]<0)triindex|=1;if(grid[T[1]]<0)triindex|=2;if(grid[T[2]]<0)triindex|=4;if(grid[T[3]]<0)triindex|=8;switch(triindex){case 0:case 15:break;case 14:faces.push([interp(T[0],T[1]),interp(T[0],T[3]),interp(T[0],T[2])]);break;case 1:faces.push([interp(T[0],T[1]),interp(T[0],T[2]),interp(T[0],T[3])]);break;case 13:faces.push([interp(T[1],T[0]),interp(T[1],T[2]),interp(T[1],T[3])]);break;case 2:faces.push([interp(T[1],T[0]),interp(T[1],T[3]),interp(T[1],T[2])]);break;case 12:faces.push([interp(T[1],T[2]),interp(T[1],T[3]),interp(T[0],T[3]),interp(T[0],T[2])]);break;case 3:faces.push([interp(T[1],T[2]),interp(T[0],T[2]),interp(T[0],T[3]),interp(T[1],T[3])]);break;case 4:faces.push([interp(T[2],T[0]),interp(T[2],T[1]),interp(T[2],T[3])]);break;case 11:faces.push([interp(T[2],T[0]),interp(T[2],T[3]),interp(T[2],T[1])]);break;case 5:faces.push([interp(T[0],T[1]),interp(T[1],T[2]),interp(T[2],T[3]),interp(T[0],T[3])]);break;case 10:faces.push([interp(T[0],T[1]),interp(T[0],T[3]),interp(T[2],T[3]),interp(T[1],T[2])]);break;case 6:faces.push([interp(T[2],T[3]),interp(T[0],T[2]),interp(T[0],T[1]),interp(T[1],T[3])]);break;case 9:faces.push([interp(T[2],T[3]),interp(T[1],T[3]),interp(T[0],T[1]),interp(T[0],T[2])]);break;case 7:faces.push([interp(T[3],T[0]),interp(T[3],T[1]),interp(T[3],T[2])]);break;case 8:faces.push([interp(T[3],T[0]),interp(T[3],T[2]),interp(T[3],T[1])]);break}}}return{positions:vertices,cells:faces}}},{}],3:[function(require,module,exports){"use strict";var cube_edges=new Int32Array(24),edge_table=new Int32Array(256);(function(){var k=0;for(var i=0;i<8;++i){for(var j=1;j<=4;j<<=1){var p=i^j;if(i<=p){cube_edges[k++]=i;cube_edges[k++]=p}}}for(var i=0;i<256;++i){var em=0;for(var j=0;j<24;j+=2){var a=!!(i&1<<cube_edges[j]),b=!!(i&1<<cube_edges[j+1]);em|=a!==b?1<<(j>>1):0}edge_table[i]=em}})();var buffer=new Array(4096);(function(){for(var i=0;i<buffer.length;++i){buffer[i]=0}})();exports.surfaceNets=function(dims,potential,bounds){if(!bounds){bounds=[[0,0,0],dims]}var scale=[0,0,0];var shift=[0,0,0];for(var i=0;i<3;++i){scale[i]=(bounds[1][i]-bounds[0][i])/dims[i];shift[i]=bounds[0][i]}var vertices=[],faces=[],n=0,x=[0,0,0],R=[1,dims[0]+1,(dims[0]+1)*(dims[1]+1)],grid=[0,0,0,0,0,0,0,0],buf_no=1;if(R[2]*2>buffer.length){var ol=buffer.length;buffer.length=R[2]*2;while(ol<buffer.length){buffer[ol++]=0}}for(x[2]=0;x[2]<dims[2]-1;++x[2],n+=dims[0],buf_no^=1,R[2]=-R[2]){var m=1+(dims[0]+1)*(1+buf_no*(dims[1]+1));for(x[1]=0;x[1]<dims[1]-1;++x[1],++n,m+=2)for(x[0]=0;x[0]<dims[0]-1;++x[0],++n,++m){var mask=0,g=0;for(var k=0;k<2;++k)for(var j=0;j<2;++j)for(var i=0;i<2;++i,++g){var p=potential(scale[0]*(x[0]+i)+shift[0],scale[1]*(x[1]+j)+shift[1],scale[2]*(x[2]+k)+shift[2]);grid[g]=p;mask|=p<0?1<<g:0}if(mask===0||mask===255){continue}var edge_mask=edge_table[mask],v=[0,0,0],e_count=0;for(var i=0;i<12;++i){if(!(edge_mask&1<<i)){continue}++e_count;var e0=cube_edges[i<<1],e1=cube_edges[(i<<1)+1],g0=grid[e0],g1=grid[e1],t=g0-g1;if(Math.abs(t)>1e-6){t=g0/t}else{continue}for(var j=0,k=1;j<3;++j,k<<=1){var a=e0&k,b=e1&k;if(a!==b){v[j]+=a?1-t:t}else{v[j]+=a?1:0}}}var s=1/e_count;for(var i=0;i<3;++i){v[i]=scale[i]*(x[i]+s*v[i])+shift[i]}buffer[m]=vertices.length;vertices.push(v);for(var i=0;i<3;++i){if(!(edge_mask&1<<i)){continue}var iu=(i+1)%3,iv=(i+2)%3;if(x[iu]===0||x[iv]===0){continue}var du=R[iu],dv=R[iv];if(mask&1){faces.push([buffer[m],buffer[m-du],buffer[m-dv]]);faces.push([buffer[m-dv],buffer[m-du],buffer[m-du-dv]])}else{faces.push([buffer[m],buffer[m-dv],buffer[m-du]]);faces.push([buffer[m-du],buffer[m-dv],buffer[m-du-dv]])}}}}return{positions:vertices,cells:faces}}},{}],isosurface:[function(require,module,exports){exports.surfaceNets=require("./lib/surfacenets.js").surfaceNets;exports.marchingCubes=require("./lib/marchingcubes.js").marchingCubes;exports.marchingTetrahedra=require("./lib/marchingtetrahedra.js").marchingTetrahedra},{"./lib/marchingcubes.js":1,"./lib/marchingtetrahedra.js":2,"./lib/surfacenets.js":3}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&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}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[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<attributes.length;++i){var attrib=attributes[i];if(attrib.buffer){var buffer=attrib.buffer;var size=attrib.size||4;var type=attrib.type||gl.FLOAT;var normalized=!!attrib.normalized;var stride=attrib.stride||0;var offset=attrib.offset||0;buffer.bind();gl.enableVertexAttribArray(i);gl.vertexAttribPointer(i,size,type,normalized,stride,offset)}else{if(typeof attrib==="number"){gl.vertexAttrib1f(i,attrib)}else if(attrib.length===1){gl.vertexAttrib1f(i,attrib[0])}else if(attrib.length===2){gl.vertexAttrib2f(i,attrib[0],attrib[1])}else if(attrib.length===3){gl.vertexAttrib3f(i,attrib[0],attrib[1],attrib[2])}else if(attrib.length===4){gl.vertexAttrib4f(i,attrib[0],attrib[1],attrib[2],attrib[3])}else{throw new Error("gl-vao: Invalid vertex attribute")}gl.disableVertexAttribArray(i)}}for(;i<nattribs;++i){gl.disableVertexAttribArray(i)}}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;i<nattribs;++i){gl.disableVertexAttribArray(i)}}}module.exports=doBind},{}],2:[function(require,module,exports){"use strict";var bindAttribs=require("./do-bind.js");function VAOEmulated(gl){this.gl=gl;this._elements=null;this._attributes=null;this._elementsType=gl.UNSIGNED_SHORT}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;if(this._elements){gl.drawElements(mode,count,this._elementsType,offset)}else{gl.drawArrays(mode,offset,count)}};function createVAOEmulated(gl){return new VAOEmulated(gl)}module.exports=createVAOEmulated},{"./do-bind.js":1}],3:[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;this._elementsType=gl.UNSIGNED_SHORT}VAONative.prototype.bind=function(){this._ext.bindVertexArrayOES(this.handle);for(var i=0;i<this._attribs.length;++i){this._attribs[i].bind(this.gl)}};VAONative.prototype.unbind=function(){this._ext.bindVertexArrayOES(null)};VAONative.prototype.dispose=function(){this._ext.deleteVertexArrayOES(this.handle)};VAONative.prototype.update=function(attributes,elements,elementsType){this.bind();bindAttribs(this.gl,elements,attributes);this.unbind();this._attribs.length=0;if(attributes)for(var i=0;i<attributes.length;++i){var a=attributes[i];if(typeof a==="number"){this._attribs.push(new VertexAttribute(i,1,a))}else if(Array.isArray(a)){this._attribs.push(new VertexAttribute(i,a.length,a[0],a[1],a[2],a[3]))}}this._useElements=!!elements;this._elementsType=elementsType||this.gl.UNSIGNED_SHORT};VAONative.prototype.draw=function(mode,count,offset){offset=offset||0;var gl=this.gl;if(this._useElements){gl.drawElements(mode,count,this._elementsType,offset)}else{gl.drawArrays(mode,offset,count)}};function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}module.exports=createVAONative},{"./do-bind.js":1}],4:[function(require,module,exports){(function WeakMapModule(){"use strict";if(typeof ses!=="undefined"&&ses.ok&&!ses.ok()){return}function weakMapPermitHostObjects(map){if(map.permitHostObjects___){map.permitHostObjects___(weakMapPermitHostObjects)}}if(typeof ses!=="undefined"){ses.weakMapPermitHostObjects=weakMapPermitHostObjects}var doubleWeakMapCheckSilentFailure=false;if(typeof WeakMap==="function"){var HostWeakMap=WeakMap;if(typeof navigator!=="undefined"&&/Firefox/.test(navigator.userAgent)){}else{var testMap=new HostWeakMap;var testObject=Object.freeze({});testMap.set(testObject,1);if(testMap.get(testObject)!==1){doubleWeakMapCheckSilentFailure=true}else{module.exports=WeakMap;return}}}var hop=Object.prototype.hasOwnProperty;var gopn=Object.getOwnPropertyNames;var defProp=Object.defineProperty;var isExtensible=Object.isExtensible;var HIDDEN_NAME_PREFIX="weakmap:";var HIDDEN_NAME=HIDDEN_NAME_PREFIX+"ident:"+Math.random()+"___";if(typeof crypto!=="undefined"&&typeof crypto.getRandomValues==="function"&&typeof ArrayBuffer==="function"&&typeof Uint8Array==="function"){var ab=new ArrayBuffer(25);var u8s=new Uint8Array(ab);crypto.getRandomValues(u8s);HIDDEN_NAME=HIDDEN_NAME_PREFIX+"rand:"+Array.prototype.map.call(u8s,function(u8){return(u8%36).toString(36)}).join("")+"___"}function isNotHiddenName(name){return!(name.substr(0,HIDDEN_NAME_PREFIX.length)==HIDDEN_NAME_PREFIX&&name.substr(name.length-3)==="___")}defProp(Object,"getOwnPropertyNames",{value:function fakeGetOwnPropertyNames(obj){return gopn(obj).filter(isNotHiddenName)}});if("getPropertyNames"in Object){var originalGetPropertyNames=Object.getPropertyNames;defProp(Object,"getPropertyNames",{value:function fakeGetPropertyNames(obj){return originalGetPropertyNames(obj).filter(isNotHiddenName)}})}function getHiddenRecord(key){if(key!==Object(key)){throw new TypeError("Not an object: "+key)}var hiddenRecord=key[HIDDEN_NAME];if(hiddenRecord&&hiddenRecord.key===key){return hiddenRecord}if(!isExtensible(key)){return void 0}hiddenRecord={key:key};try{defProp(key,HIDDEN_NAME,{value:hiddenRecord,writable:false,enumerable:false,configurable:false});return hiddenRecord}catch(error){return void 0}}(function(){var oldFreeze=Object.freeze;defProp(Object,"freeze",{value:function identifyingFreeze(obj){getHiddenRecord(obj);return oldFreeze(obj)}});var oldSeal=Object.seal;defProp(Object,"seal",{value:function identifyingSeal(obj){getHiddenRecord(obj);return oldSeal(obj)}});var oldPreventExtensions=Object.preventExtensions;defProp(Object,"preventExtensions",{value:function identifyingPreventExtensions(obj){getHiddenRecord(obj);return oldPreventExtensions(obj)}})})();function constFunc(func){func.prototype=null;return Object.freeze(func)}var calledAsFunctionWarningDone=false;function calledAsFunctionWarning(){if(!calledAsFunctionWarningDone&&typeof console!=="undefined"){calledAsFunctionWarningDone=true;console.warn("WeakMap should be invoked as new WeakMap(), not "+"WeakMap(). This will be an error in the future.")}}var nextId=0;var OurWeakMap=function(){if(!(this instanceof OurWeakMap)){calledAsFunctionWarning()}var keys=[];var values=[];var id=nextId++;function get___(key,opt_default){var index;var hiddenRecord=getHiddenRecord(key);if(hiddenRecord){return id in hiddenRecord?hiddenRecord[id]:opt_default}else{index=keys.indexOf(key);return index>=0?values[index]:opt_default}}function has___(key){var hiddenRecord=getHiddenRecord(key);if(hiddenRecord){return id in hiddenRecord}else{return keys.indexOf(key)>=0}}function set___(key,value){var index;var hiddenRecord=getHiddenRecord(key);if(hiddenRecord){hiddenRecord[id]=value}else{index=keys.indexOf(key);if(index>=0){values[index]=value}else{index=keys.length;values[index]=value;keys[index]=key}}return this}function delete___(key){var hiddenRecord=getHiddenRecord(key);var index,lastIndex;if(hiddenRecord){return id in hiddenRecord&&delete hiddenRecord[id]}else{index=keys.indexOf(key);if(index<0){return false}lastIndex=keys.length-1;keys[index]=void 0;values[index]=values[lastIndex];keys[index]=keys[lastIndex];keys.length=lastIndex;values.length=lastIndex;return true}}return Object.create(OurWeakMap.prototype,{get___:{value:constFunc(get___)},has___:{value:constFunc(has___)},set___:{value:constFunc(set___)},delete___:{value:constFunc(delete___)}})};OurWeakMap.prototype=Object.create(Object.prototype,{get:{value:function get(key,opt_default){return this.get___(key,opt_default)},writable:true,configurable:true},has:{value:function has(key){return this.has___(key)},writable:true,configurable:true},set:{value:function set(key,value){return this.set___(key,value)},writable:true,configurable:true},"delete":{value:function remove(key){return this.delete___(key)},writable:true,configurable:true}});if(typeof HostWeakMap==="function"){(function(){if(doubleWeakMapCheckSilentFailure&&typeof Proxy!=="undefined"){Proxy=undefined}function DoubleWeakMap(){if(!(this instanceof OurWeakMap)){calledAsFunctionWarning()}var hmap=new HostWeakMap;var omap=undefined;var enableSwitching=false;function dget(key,opt_default){if(omap){return hmap.has(key)?hmap.get(key):omap.get___(key,opt_default)}else{return hmap.get(key,opt_default)}}function dhas(key){return hmap.has(key)||(omap?omap.has___(key):false)}var dset;if(doubleWeakMapCheckSilentFailure){dset=function(key,value){hmap.set(key,value);if(!hmap.has(key)){if(!omap){omap=new OurWeakMap}omap.set(key,value)}return this}}else{dset=function(key,value){if(enableSwitching){try{hmap.set(key,value)}catch(e){if(!omap){omap=new OurWeakMap}omap.set___(key,value)}}else{hmap.set(key,value)}return this}}function ddelete(key){var result=!!hmap["delete"](key);if(omap){return omap.delete___(key)||result}return result}return Object.create(OurWeakMap.prototype,{get___:{value:constFunc(dget)},has___:{value:constFunc(dhas)},set___:{value:constFunc(dset)},delete___:{value:constFunc(ddelete)},permitHostObjects___:{value:constFunc(function(token){if(token===weakMapPermitHostObjects){enableSwitching=true}else{throw new Error("bogus call to permitHostObjects___")}})}})}DoubleWeakMap.prototype=OurWeakMap.prototype;module.exports=DoubleWeakMap;Object.defineProperty(WeakMap.prototype,"constructor",{value:WeakMap,enumerable:false,configurable:true,writable:true})})()}else{if(typeof Proxy!=="undefined"){Proxy=undefined}module.exports=OurWeakMap}})()},{}],5:[function(require,module,exports){"use strict";var weakMap=typeof WeakMap==="undefined"?require("weak-map"):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<supported.length;++i){var extName=supported[i];if(extName.indexOf("MOZ_")===0){continue}var ext=gl.getExtension(supported[i]);if(!ext){continue}while(true){extensions[extName]=ext;var base=baseName(extName);if(base===extName){break}extName=base}}WebGLEWStruct.set(gl,extensions);return extensions}module.exports=initWebGLEW},{"weak-map":4}],"gl-vao":[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,elementsType){var ext=webglew(gl).OES_vertex_array_object;var vao;if(ext){vao=createVAONative(gl,ext)}else{vao=createVAOEmulated(gl)}vao.update(attributes,elements,elementsType);return vao}module.exports=createVAO},{"./lib/vao-emulated.js":2,"./lib/vao-native.js":3,webglew:5}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&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}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){(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{shim.exports=typeof window!=="undefined"?window:_global}}else{shim.exports=exports}(function(exports){if(!GLMAT_EPSILON){var GLMAT_EPSILON=1e-6}if(!GLMAT_ARRAY_TYPE){var GLMAT_ARRAY_TYPE=typeof Float32Array!=="undefined"?Float32Array:Array}if(!GLMAT_RANDOM){var GLMAT_RANDOM=Math.random}var glMatrix={};glMatrix.setMatrixArrayType=function(type){GLMAT_ARRAY_TYPE=type};if(typeof exports!=="undefined"){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);out[0]=0;out[1]=0;return out};vec2.clone=function(a){var out=new GLMAT_ARRAY_TYPE(2);out[0]=a[0];out[1]=a[1];return out};vec2.fromValues=function(x,y){var out=new GLMAT_ARRAY_TYPE(2);out[0]=x;out[1]=y;return out};vec2.copy=function(out,a){out[0]=a[0];out[1]=a[1];return out};vec2.set=function(out,x,y){out[0]=x;out[1]=y;return out};vec2.add=function(out,a,b){out[0]=a[0]+b[0];out[1]=a[1]+b[1];return out};vec2.subtract=function(out,a,b){out[0]=a[0]-b[0];out[1]=a[1]-b[1];return out};vec2.sub=vec2.subtract;vec2.multiply=function(out,a,b){out[0]=a[0]*b[0];out[1]=a[1]*b[1];return out};vec2.mul=vec2.multiply;vec2.divide=function(out,a,b){out[0]=a[0]/b[0];out[1]=a[1]/b[1];return out};vec2.div=vec2.divide;vec2.min=function(out,a,b){out[0]=Math.min(a[0],b[0]);out[1]=Math.min(a[1],b[1]);return 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};vec2.scale=function(out,a,b){out[0]=a[0]*b;out[1]=a[1]*b;return out};vec2.scaleAndAdd=function(out,a,b,scale){out[0]=a[0]+b[0]*scale;out[1]=a[1]+b[1]*scale;return 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){out[0]=-a[0];out[1]=-a[1];return out};vec2.normalize=function(out,a){var x=a[0],y=a[1];var len=x*x+y*y;if(len>0){len=1/Math.sqrt(len);out[0]=a[0]*len;out[1]=a[1]*len}return 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];out[0]=out[1]=0;out[2]=z;return 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};vec2.random=function(out,scale){scale=scale||1;var r=GLMAT_RANDOM()*2*Math.PI;out[0]=Math.cos(r)*scale;out[1]=Math.sin(r)*scale;return 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};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};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};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};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}}();vec2.str=function(a){return"vec2("+a[0]+", "+a[1]+")"};if(typeof exports!=="undefined"){exports.vec2=vec2}var vec3={};vec3.create=function(){var out=new GLMAT_ARRAY_TYPE(3);out[0]=0;out[1]=0;out[2]=0;return out};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};vec3.fromValues=function(x,y,z){var out=new GLMAT_ARRAY_TYPE(3);out[0]=x;out[1]=y;out[2]=z;return out};vec3.copy=function(out,a){out[0]=a[0];out[1]=a[1];out[2]=a[2];return out};vec3.set=function(out,x,y,z){out[0]=x;out[1]=y;out[2]=z;return 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};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};vec3.sub=vec3.subtract;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};vec3.mul=vec3.multiply;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};vec3.div=vec3.divide;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};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};vec3.scale=function(out,a,b){out[0]=a[0]*b;out[1]=a[1]*b;out[2]=a[2]*b;return 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};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){out[0]=-a[0];out[1]=-a[1];out[2]=-a[2];return 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){len=1/Math.sqrt(len);out[0]=a[0]*len;out[1]=a[1]*len;out[2]=a[2]*len}return 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];out[0]=ay*bz-az*by;out[1]=az*bx-ax*bz;out[2]=ax*by-ay*bx;return 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};vec3.random=function(out,scale){scale=scale||1;var r=GLMAT_RANDOM()*2*Math.PI;var z=GLMAT_RANDOM()*2-1;var zScale=Math.sqrt(1-z*z)*scale;out[0]=Math.cos(r)*zScale;out[1]=Math.sin(r)*zScale;out[2]=z*scale;return 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};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};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;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};vec3.rotateX=function(out,a,b,c){var p=[],r=[];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];return out};vec3.rotateY=function(out,a,b,c){var p=[],r=[];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];return out};vec3.rotateZ=function(out,a,b,c){var p=[],r=[];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];return out};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}}();vec3.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"};if(typeof exports!=="undefined"){exports.vec3=vec3}var vec4={};vec4.create=function(){var out=new GLMAT_ARRAY_TYPE(4);out[0]=0;out[1]=0;out[2]=0;out[3]=0;return out};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};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};vec4.copy=function(out,a){out[0]=a[0];out[1]=a[1];out[2]=a[2];out[3]=a[3];return out};vec4.set=function(out,x,y,z,w){out[0]=x;out[1]=y;out[2]=z;out[3]=w;return 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};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};vec4.sub=vec4.subtract;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};vec4.mul=vec4.multiply;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};vec4.div=vec4.divide;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};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};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};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};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){out[0]=-a[0];out[1]=-a[1];out[2]=-a[2];out[3]=-a[3];return 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};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];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};vec4.random=function(out,scale){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);return 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};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;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};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}}();vec4.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"};if(typeof exports!=="undefined"){exports.vec4=vec4}var mat2={};mat2.create=function(){var out=new GLMAT_ARRAY_TYPE(4);out[0]=1;out[1]=0;out[2]=0;out[3]=1;return out};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};mat2.copy=function(out,a){out[0]=a[0];out[1]=a[1];out[2]=a[2];out[3]=a[3];return out};mat2.identity=function(out){out[0]=1;out[1]=0;out[2]=0;out[3]=1;return 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;if(!det){return null}det=1/det;out[0]=a3*det;out[1]=-a1*det;out[2]=-a2*det;out[3]=a0*det;return out};mat2.adjoint=function(out,a){var a0=a[0];out[0]=a[3];out[1]=-a[1];out[2]=-a[2];out[3]=a0;return 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];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};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);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};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};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){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}var mat2d={};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};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};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};mat2d.identity=function(out){out[0]=1;out[1]=0;out[2]=0;out[3]=1;out[4]=0;out[5]=0;return 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/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};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];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};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);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};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};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};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)};if(typeof exports!=="undefined"){exports.mat2d=mat2d}var mat3={};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};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};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};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};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};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;if(!det){return null}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;return 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};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];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};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];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};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};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};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};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};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;if(!det){return null}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;return 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]+")"};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}var mat4={};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};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};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};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};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;if(!det){return null}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;return 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};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];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};mat4.mul=mat4.multiply;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};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};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];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;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){out[12]=a[12];out[13]=a[13];out[14]=a[14];out[15]=a[15]}return 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){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]}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};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){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]}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};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){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[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};mat4.fromRotationTranslation=function(out,q,v){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};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};mat4.perspective=function(out,fovy,aspect,near,far){var f=1/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};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};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};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]+")"};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}var quat={};quat.create=function(){var out=new GLMAT_ARRAY_TYPE(4);out[0]=0;out[1]=0;out[2]=0;out[3]=1;return 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<-.999999){vec3.cross(tmpvec3,xUnitVec3,a);if(vec3.length(tmpvec3)<1e-6)vec3.cross(tmpvec3,yUnitVec3,a);vec3.normalize(tmpvec3,tmpvec3);quat.setAxisAngle(out,tmpvec3,Math.PI);return out}else if(dot>.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)}}}();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))}}();quat.clone=vec4.clone;quat.fromValues=vec4.fromValues;quat.copy=vec4.copy;quat.set=vec4.set;quat.identity=function(out){out[0]=0;out[1]=0;out[2]=0;out[3]=1;return out};quat.setAxisAngle=function(out,axis,rad){rad=rad*.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};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];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};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);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};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);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};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);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};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-x*x-y*y-z*z));return out};quat.dot=vec4.dot;quat.lerp=vec4.lerp;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 omega,cosom,sinom,scale0,scale1;cosom=ax*bx+ay*by+az*bz+aw*bw;if(cosom<0){cosom=-cosom;bx=-bx;by=-by;bz=-bz;bw=-bw}if(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}else{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;return 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;out[0]=-a0*invDot;out[1]=-a1*invDot;out[2]=-a2*invDot;out[3]=a3*invDot;return out};quat.conjugate=function(out,a){out[0]=-a[0];out[1]=-a[1];out[2]=-a[2];out[3]=a[3];return 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 fTrace=m[0]+m[4]+m[8];var fRoot;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;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);out[i]=.5*fRoot;fRoot=.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};quat.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"};if(typeof exports!=="undefined"){exports.quat=quat}})(shim.exports)})(this)},{}],"orbit-camera":[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;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;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){this.distance=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){s=1}out[0]=-da[0];out[1]=da[1];out[2]=da[2]||Math.sqrt(1-s);out[3]=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);camera.lookAt(eye,target,up);return camera}module.exports=createOrbitCamera},{"gl-matrix":1}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&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}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var base64=require("base64-js");var ieee754=require("ieee754");var isArray=require("is-array");exports.Buffer=Buffer;exports.SlowBuffer=SlowBuffer;exports.INSPECT_MAX_BYTES=50;Buffer.poolSize=8192;var kMaxLength=1073741823;var rootParent={};Buffer.TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0);var arr=new Uint8Array(buf);arr.foo=function(){return 42};return 42===arr.foo()&&typeof arr.subarray==="function"&&new Uint8Array(1).subarray(1,1).byteLength===0}catch(e){return false}}();function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var type=typeof subject;var length;if(type==="number")length=subject>0?subject>>>0:0;else if(type==="string"){length=Buffer.byteLength(subject,encoding)}else if(type==="object"&&subject!==null){if(subject.type==="Buffer"&&isArray(subject.data))subject=subject.data;length=+subject.length>0?Math.floor(+subject.length):0}else throw new TypeError("must start with number, buffer, array or string");if(length>kMaxLength)throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+kMaxLength.toString(16)+" bytes");var buf;if(Buffer.TYPED_ARRAY_SUPPORT){buf=Buffer._augment(new Uint8Array(length))}else{buf=this;buf.length=length;buf._isBuffer=true}var i;if(Buffer.TYPED_ARRAY_SUPPORT&&typeof subject.byteLength==="number"){buf._set(subject)}else if(isArrayish(subject)){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"&&!Buffer.TYPED_ARRAY_SUPPORT&&!noZero){for(i=0;i<length;i++){buf[i]=0}}if(length>0&&length<=Buffer.poolSize)buf.parent=rootParent;return buf}function SlowBuffer(subject,encoding,noZero){if(!(this instanceof SlowBuffer))return new SlowBuffer(subject,encoding,noZero);var buf=new Buffer(subject,encoding,noZero);delete buf.parent;return buf}Buffer.isBuffer=function(b){return!!(b!=null&&b._isBuffer)};Buffer.compare=function(a,b){if(!Buffer.isBuffer(a)||!Buffer.isBuffer(b))throw new TypeError("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.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.concat=function(list,totalLength){if(!isArray(list))throw new TypeError("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.byteLength=function(str,encoding){var ret;str=str+"";switch(encoding||"utf8"){case"ascii":case"binary":case"raw":ret=str.length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=str.length*2;break;case"hex":ret=str.length>>>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=undefined;Buffer.prototype.parent=undefined;Buffer.prototype.toString=function(encoding,start,end){var loweredCase=false;start=start>>>0;end=end===undefined||end===Infinity?this.length:end>>>0;if(!encoding)encoding="utf8";if(start<0)start=0;if(end>this.length)end=this.length;if(end<=start)return"";while(true){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=true}}};Buffer.prototype.equals=function(b){if(!Buffer.isBuffer(b))throw new TypeError("Argument must be a Buffer");return Buffer.compare(this,b)===0};Buffer.prototype.inspect=function(){var str="";var max=exports.INSPECT_MAX_BYTES;if(this.length>0){str=this.toString("hex",0,max).match(/.{2}/g).join(" ");if(this.length>max)str+=" ... "}return"<Buffer "+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){console.log(".get() is deprecated. Access using array indexes instead.");return this.readUInt8(offset)};Buffer.prototype.set=function(v,offset){console.log(".set() is deprecated. Access using array indexes instead.");return this.writeUInt8(v,offset)};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}}var strLen=string.length;if(strLen%2!==0)throw new Error("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);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}Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset)){if(!isFinite(length)){encoding=length;length=undefined}}else{var swap=encoding;encoding=offset;offset=length;length=swap}offset=Number(offset)||0;if(length<0||offset<0||offset>this.length)throw new RangeError("attempt to write outside buffer bounds");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 TypeError("Unknown encoding: "+encoding)}return ret};Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};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]<=127){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]&127)}return ret}function binarySlice(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 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;var newBuf;if(Buffer.TYPED_ARRAY_SUPPORT){newBuf=Buffer._augment(this.subarray(start,end))}else{var sliceLen=end-start;newBuf=new Buffer(sliceLen,undefined,true);for(var i=0;i<sliceLen;i++){newBuf[i]=this[i+start]}}if(newBuf.length)newBuf.parent=this.parent||this;return newBuf};function checkOffset(offset,ext,length){if(offset%1!==0||offset<0)throw new RangeError("offset is not uint");if(offset+ext>length)throw new RangeError("Trying to access beyond buffer length")}Buffer.prototype.readUIntLE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i<byteLength&&(mul*=256))val+=this[offset+i]*mul;return val};Buffer.prototype.readUIntBE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset+--byteLength];var mul=1;while(byteLength>0&&(mul*=256))val+=this[offset+--byteLength]*mul;return val};Buffer.prototype.readUInt8=function(offset,noAssert){if(!noAssert)checkOffset(offset,1,this.length);return this[offset]};Buffer.prototype.readUInt16LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);return this[offset]|this[offset+1]<<8};Buffer.prototype.readUInt16BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);return this[offset]<<8|this[offset+1]};Buffer.prototype.readUInt32LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return(this[offset]|this[offset+1]<<8|this[offset+2]<<16)+this[offset+3]*16777216};Buffer.prototype.readUInt32BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]*16777216+(this[offset+1]<<16|this[offset+2]<<8|this[offset+3])};Buffer.prototype.readIntLE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i<byteLength&&(mul*=256))val+=this[offset+i]*mul;mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readIntBE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var i=byteLength;var mul=1;var val=this[offset+--i];while(i>0&&(mul*=256))val+=this[offset+--i]*mul;mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readInt8=function(offset,noAssert){if(!noAssert)checkOffset(offset,1,this.length);if(!(this[offset]&128))return this[offset];return(255-this[offset]+1)*-1};Buffer.prototype.readInt16LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset]|this[offset+1]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt16BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset+1]|this[offset]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt32LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]|this[offset+1]<<8|this[offset+2]<<16|this[offset+3]<<24};Buffer.prototype.readInt32BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]<<24|this[offset+1]<<16|this[offset+2]<<8|this[offset+3]};Buffer.prototype.readFloatLE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,true,23,4)};Buffer.prototype.readFloatBE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,false,23,4)};Buffer.prototype.readDoubleLE=function(offset,noAssert){if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,true,52,8)};Buffer.prototype.readDoubleBE=function(offset,noAssert){if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,false,52,8)};function checkInt(buf,value,offset,ext,max,min){if(!Buffer.isBuffer(buf))throw new TypeError("buffer must be a Buffer instance");if(value>max||value<min)throw new RangeError("value is out of bounds");if(offset+ext>buf.length)throw new RangeError("index out of range")}Buffer.prototype.writeUIntLE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength),0);var mul=1;var i=0;this[offset]=value&255;while(++i<byteLength&&(mul*=256))this[offset+i]=value/mul>>>0&255;return offset+byteLength};Buffer.prototype.writeUIntBE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength),0);var i=byteLength-1;var mul=1;this[offset+i]=value&255;while(--i>=0&&(mul*=256))this[offset+i]=value/mul>>>0&255;return offset+byteLength};Buffer.prototype.writeUInt8=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,255,0);if(!Buffer.TYPED_ARRAY_SUPPORT)value=Math.floor(value);this[offset]=value;return offset+1};function objectWriteUInt16(buf,value,offset,littleEndian){if(value<0)value=65535+value+1;for(var i=0,j=Math.min(buf.length-offset,2);i<j;i++){buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>(littleEndian?i:1-i)*8}}Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value;this[offset+1]=value>>>8}else objectWriteUInt16(this,value,offset,true);return offset+2};Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>8;this[offset+1]=value}else objectWriteUInt16(this,value,offset,false);return offset+2};function objectWriteUInt32(buf,value,offset,littleEndian){if(value<0)value=4294967295+value+1;for(var i=0,j=Math.min(buf.length-offset,4);i<j;i++){buf[offset+i]=value>>>(littleEndian?i:3-i)*8&255}}Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset+3]=value>>>24;this[offset+2]=value>>>16;this[offset+1]=value>>>8;this[offset]=value}else objectWriteUInt32(this,value,offset,true);return offset+4};Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value}else objectWriteUInt32(this,value,offset,false);return offset+4};Buffer.prototype.writeIntLE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength-1)-1,-Math.pow(2,8*byteLength-1))}var i=0;var mul=1;var sub=value<0?1:0;this[offset]=value&255;while(++i<byteLength&&(mul*=256))this[offset+i]=(value/mul>>0)-sub&255;return offset+byteLength};Buffer.prototype.writeIntBE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength-1)-1,-Math.pow(2,8*byteLength-1))}var i=byteLength-1;var mul=1;var sub=value<0?1:0;this[offset+i]=value&255;while(--i>=0&&(mul*=256))this[offset+i]=(value/mul>>0)-sub&255;return offset+byteLength};Buffer.prototype.writeInt8=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,127,-128);if(!Buffer.TYPED_ARRAY_SUPPORT)value=Math.floor(value);if(value<0)value=255+value+1;this[offset]=value;return offset+1};Buffer.prototype.writeInt16LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value;this[offset+1]=value>>>8}else objectWriteUInt16(this,value,offset,true);return offset+2};Buffer.prototype.writeInt16BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>8;this[offset+1]=value}else objectWriteUInt16(this,value,offset,false);return offset+2};Buffer.prototype.writeInt32LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value;this[offset+1]=value>>>8;this[offset+2]=value>>>16;this[offset+3]=value>>>24}else objectWriteUInt32(this,value,offset,true);return offset+4};Buffer.prototype.writeInt32BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(value<0)value=4294967295+value+1;if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value}else objectWriteUInt32(this,value,offset,false);return offset+4};function checkIEEE754(buf,value,offset,ext,max,min){if(value>max||value<min)throw new RangeError("value is out of bounds");if(offset+ext>buf.length)throw new RangeError("index out of range");if(offset<0)throw new RangeError("index out of range")}function writeFloat(buf,value,offset,littleEndian,noAssert){if(!noAssert)checkIEEE754(buf,value,offset,4,3.4028234663852886e38,-3.4028234663852886e38);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)checkIEEE754(buf,value,offset,8,1.7976931348623157e308,-1.7976931348623157e308);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)};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.length)target_start=target.length;if(!target_start)target_start=0;if(end>0&&end<start)end=start;if(end===start)return 0;if(target.length===0||source.length===0)return 0;if(target_start<0)throw new RangeError("targetStart out of bounds");if(start<0||start>=source.length)throw new RangeError("sourceStart out of bounds");if(end<0)throw new RangeError("sourceEnd out of bounds");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<1e3||!Buffer.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)}return len};Buffer.prototype.fill=function(value,start,end){if(!value)value=0;if(!start)start=0;if(!end)end=this.length;if(end<start)throw new RangeError("end < start");if(end===start)return;if(this.length===0)return;if(start<0||start>=this.length)throw new RangeError("start out of bounds");if(end<0||end>this.length)throw new RangeError("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.toArrayBuffer=function(){if(typeof Uint8Array!=="undefined"){if(Buffer.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 TypeError("Buffer.toArrayBuffer not supported in this browser")}};var BP=Buffer.prototype;Buffer._augment=function(arr){arr.constructor=Buffer;arr._isBuffer=true;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;return arr};var INVALID_BASE64_RE=/[^+\/0-9A-z\-]/g;function base64clean(str){str=stringtrim(str).replace(INVALID_BASE64_RE,"");if(str.length<2)return"";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 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(string,units){var codePoint,length=string.length;var leadSurrogate=null;units=units||Infinity;var bytes=[];var i=0;for(;i<length;i++){codePoint=string.charCodeAt(i);if(codePoint>55295&&codePoint<57344){if(leadSurrogate){if(codePoint<56320){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=codePoint;continue}else{codePoint=leadSurrogate-55296<<10|codePoint-56320|65536;leadSurrogate=null}}else{if(codePoint>56319){if((units-=3)>-1)bytes.push(239,191,189);continue}else if(i+1===length){if((units-=3)>-1)bytes.push(239,191,189);continue}else{leadSurrogate=codePoint;continue}}}else if(leadSurrogate){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=null}if(codePoint<128){if((units-=1)<0)break;bytes.push(codePoint)}else if(codePoint<2048){if((units-=2)<0)break;bytes.push(codePoint>>6|192,codePoint&63|128)}else if(codePoint<65536){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,codePoint&63|128)}else if(codePoint<2097152){if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,codePoint&63|128)}else{throw new Error("Invalid code point")}}return bytes}function asciiToBytes(str){var byteArray=[];for(var i=0;i<str.length;i++){byteArray.push(str.charCodeAt(i)&255)}return byteArray}function utf16leToBytes(str,units){var c,hi,lo;var byteArray=[];for(var i=0;i<str.length;i++){if((units-=2)<0)break;c=str.charCodeAt(i);hi=c>>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){if(unitSize)length-=length%unitSize;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(65533)}}},{"base64-js":2,ieee754:3,"is-array":4}],2:[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);var PLUS_URL_SAFE="-".charCodeAt(0);var SLASH_URL_SAFE="_".charCodeAt(0);function decode(elt){var code=elt.charCodeAt(0);if(code===PLUS||code===PLUS_URL_SAFE)return 62;if(code===SLASH||code===SLASH_URL_SAFE)return 63;if(code<NUMBER)return-1;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")}var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0;arr=new Arr(b64.length*3/4-placeHolders);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&16711680)>>16);push((tmp&65280)>>8);push(tmp&255)}if(placeHolders===2){tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4;push(tmp&255)}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&255);push(tmp&255)}return arr}function uint8ToBase64(uint8){var i,extraBytes=uint8.length%3,output="",temp,length;function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(num&63)}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)}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+="=";break}return output}exports.toByteArray=b64ToByteArray;exports.fromByteArray=uint8ToBase64})(typeof exports==="undefined"?this.base64js={}:exports)},{}],3:[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&255,i+=d,m/=256,mLen-=8);e=e<<mLen|m;eLen+=mLen;for(;eLen>0;buffer[offset+i]=e&255,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=s*128}},{}],4:[function(require,module,exports){var isArray=Array.isArray;var str=Object.prototype.toString;module.exports=isArray||function(val){return!!val&&"[object Array]"==str.call(val)}},{}],5:[function(require,module,exports){function EventEmitter(){this._events=this._events||{};this._maxListeners=this._maxListeners||undefined
}module.exports=EventEmitter;EventEmitter.EventEmitter=EventEmitter;EventEmitter.prototype._events=undefined;EventEmitter.prototype._maxListeners=undefined;EventEmitter.defaultMaxListeners=10;EventEmitter.prototype.setMaxListeners=function(n){if(!isNumber(n)||n<0||isNaN(n))throw TypeError("n must be a positive number");this._maxListeners=n;return this};EventEmitter.prototype.emit=function(type){var er,handler,len,args,i,listeners;if(!this._events)this._events={};if(type==="error"){if(!this._events.error||isObject(this._events.error)&&!this._events.error.length){er=arguments[1];if(er instanceof Error){throw er}throw TypeError('Uncaught, unspecified "error" event.')}}handler=this._events[type];if(isUndefined(handler))return false;if(isFunction(handler)){switch(arguments.length){case 1:handler.call(this);break;case 2:handler.call(this,arguments[1]);break;case 3:handler.call(this,arguments[1],arguments[2]);break;default:len=arguments.length;args=new Array(len-1);for(i=1;i<len;i++)args[i-1]=arguments[i];handler.apply(this,args)}}else if(isObject(handler)){len=arguments.length;args=new Array(len-1);for(i=1;i<len;i++)args[i-1]=arguments[i];listeners=handler.slice();len=listeners.length;for(i=0;i<len;i++)listeners[i].apply(this,args)}return true};EventEmitter.prototype.addListener=function(type,listener){var m;if(!isFunction(listener))throw TypeError("listener must be a function");if(!this._events)this._events={};if(this._events.newListener)this.emit("newListener",type,isFunction(listener.listener)?listener.listener:listener);if(!this._events[type])this._events[type]=listener;else if(isObject(this._events[type]))this._events[type].push(listener);else this._events[type]=[this._events[type],listener];if(isObject(this._events[type])&&!this._events[type].warned){var m;if(!isUndefined(this._maxListeners)){m=this._maxListeners}else{m=EventEmitter.defaultMaxListeners}if(m&&m>0&&this._events[type].length>m){this._events[type].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[type].length);if(typeof console.trace==="function"){console.trace()}}}return this};EventEmitter.prototype.on=EventEmitter.prototype.addListener;EventEmitter.prototype.once=function(type,listener){if(!isFunction(listener))throw TypeError("listener must be a function");var fired=false;function g(){this.removeListener(type,g);if(!fired){fired=true;listener.apply(this,arguments)}}g.listener=listener;this.on(type,g);return this};EventEmitter.prototype.removeListener=function(type,listener){var list,position,length,i;if(!isFunction(listener))throw TypeError("listener must be a function");if(!this._events||!this._events[type])return this;list=this._events[type];length=list.length;position=-1;if(list===listener||isFunction(list.listener)&&list.listener===listener){delete this._events[type];if(this._events.removeListener)this.emit("removeListener",type,listener)}else if(isObject(list)){for(i=length;i-->0;){if(list[i]===listener||list[i].listener&&list[i].listener===listener){position=i;break}}if(position<0)return this;if(list.length===1){list.length=0;delete this._events[type]}else{list.splice(position,1)}if(this._events.removeListener)this.emit("removeListener",type,listener)}return this};EventEmitter.prototype.removeAllListeners=function(type){var key,listeners;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[type])delete this._events[type];return this}if(arguments.length===0){for(key in this._events){if(key==="removeListener")continue;this.removeAllListeners(key)}this.removeAllListeners("removeListener");this._events={};return this}listeners=this._events[type];if(isFunction(listeners)){this.removeListener(type,listeners)}else{while(listeners.length)this.removeListener(type,listeners[listeners.length-1])}delete this._events[type];return this};EventEmitter.prototype.listeners=function(type){var ret;if(!this._events||!this._events[type])ret=[];else if(isFunction(this._events[type]))ret=[this._events[type]];else ret=this._events[type].slice();return ret};EventEmitter.listenerCount=function(emitter,type){var ret;if(!emitter._events||!emitter._events[type])ret=0;else if(isFunction(emitter._events[type]))ret=1;else ret=emitter._events[type].length;return ret};function isFunction(arg){return typeof arg==="function"}function isNumber(arg){return typeof arg==="number"}function isObject(arg){return typeof arg==="object"&&arg!==null}function isUndefined(arg){return arg===void 0}},{}],6:[function(require,module,exports){if(typeof Object.create==="function"){module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}})}}else{module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}}},{}],7:[function(require,module,exports){module.exports=Array.isArray||function(arr){return Object.prototype.toString.call(arr)=="[object Array]"}},{}],8:[function(require,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canMutationObserver=typeof window!=="undefined"&&window.MutationObserver;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}var queue=[];if(canMutationObserver){var hiddenDiv=document.createElement("div");var observer=new MutationObserver(function(){var queueList=queue.slice();queue.length=0;queueList.forEach(function(fn){fn()})});observer.observe(hiddenDiv,{attributes:true});return function nextTick(fn){if(!queue.length){hiddenDiv.setAttribute("yes","no")}queue.push(fn)}}if(canPost){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")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}],9:[function(require,module,exports){module.exports=require("./lib/_stream_duplex.js")},{"./lib/_stream_duplex.js":10}],10:[function(require,module,exports){(function(process){module.exports=Duplex;var objectKeys=Object.keys||function(obj){var keys=[];for(var key in obj)keys.push(key);return keys};var util=require("core-util-is");util.inherits=require("inherits");var Readable=require("./_stream_readable");var Writable=require("./_stream_writable");util.inherits(Duplex,Readable);forEach(objectKeys(Writable.prototype),function(method){if(!Duplex.prototype[method])Duplex.prototype[method]=Writable.prototype[method]});function Duplex(options){if(!(this instanceof Duplex))return new Duplex(options);Readable.call(this,options);Writable.call(this,options);if(options&&options.readable===false)this.readable=false;if(options&&options.writable===false)this.writable=false;this.allowHalfOpen=true;if(options&&options.allowHalfOpen===false)this.allowHalfOpen=false;this.once("end",onend)}function onend(){if(this.allowHalfOpen||this._writableState.ended)return;process.nextTick(this.end.bind(this))}function forEach(xs,f){for(var i=0,l=xs.length;i<l;i++){f(xs[i],i)}}}).call(this,require("_process"))},{"./_stream_readable":12,"./_stream_writable":14,_process:8,"core-util-is":15,inherits:6}],11:[function(require,module,exports){module.exports=PassThrough;var Transform=require("./_stream_transform");var util=require("core-util-is");util.inherits=require("inherits");util.inherits(PassThrough,Transform);function PassThrough(options){if(!(this instanceof PassThrough))return new PassThrough(options);Transform.call(this,options)}PassThrough.prototype._transform=function(chunk,encoding,cb){cb(null,chunk)}},{"./_stream_transform":13,"core-util-is":15,inherits:6}],12:[function(require,module,exports){(function(process){module.exports=Readable;var isArray=require("isarray");var Buffer=require("buffer").Buffer;Readable.ReadableState=ReadableState;var EE=require("events").EventEmitter;if(!EE.listenerCount)EE.listenerCount=function(emitter,type){return emitter.listeners(type).length};var Stream=require("stream");var util=require("core-util-is");util.inherits=require("inherits");var StringDecoder;util.inherits(Readable,Stream);function ReadableState(options,stream){options=options||{};var hwm=options.highWaterMark;this.highWaterMark=hwm||hwm===0?hwm:16*1024;this.highWaterMark=~~this.highWaterMark;this.buffer=[];this.length=0;this.pipes=null;this.pipesCount=0;this.flowing=false;this.ended=false;this.endEmitted=false;this.reading=false;this.calledRead=false;this.sync=true;this.needReadable=false;this.emittedReadable=false;this.readableListening=false;this.objectMode=!!options.objectMode;this.defaultEncoding=options.defaultEncoding||"utf8";this.ranOut=false;this.awaitDrain=0;this.readingMore=false;this.decoder=null;this.encoding=null;if(options.encoding){if(!StringDecoder)StringDecoder=require("string_decoder/").StringDecoder;this.decoder=new StringDecoder(options.encoding);this.encoding=options.encoding}}function Readable(options){if(!(this instanceof Readable))return new Readable(options);this._readableState=new ReadableState(options,this);this.readable=true;Stream.call(this)}Readable.prototype.push=function(chunk,encoding){var state=this._readableState;if(typeof chunk==="string"&&!state.objectMode){encoding=encoding||state.defaultEncoding;if(encoding!==state.encoding){chunk=new Buffer(chunk,encoding);encoding=""}}return readableAddChunk(this,state,chunk,encoding,false)};Readable.prototype.unshift=function(chunk){var state=this._readableState;return readableAddChunk(this,state,chunk,"",true)};function readableAddChunk(stream,state,chunk,encoding,addToFront){var er=chunkInvalid(state,chunk);if(er){stream.emit("error",er)}else if(chunk===null||chunk===undefined){state.reading=false;if(!state.ended)onEofChunk(stream,state)}else if(state.objectMode||chunk&&chunk.length>0){if(state.ended&&!addToFront){var e=new Error("stream.push() after EOF");stream.emit("error",e)}else if(state.endEmitted&&addToFront){var e=new Error("stream.unshift() after end event");stream.emit("error",e)}else{if(state.decoder&&!addToFront&&!encoding)chunk=state.decoder.write(chunk);state.length+=state.objectMode?1:chunk.length;if(addToFront){state.buffer.unshift(chunk)}else{state.reading=false;state.buffer.push(chunk)}if(state.needReadable)emitReadable(stream);maybeReadMore(stream,state)}}else if(!addToFront){state.reading=false}return needMoreData(state)}function needMoreData(state){return!state.ended&&(state.needReadable||state.length<state.highWaterMark||state.length===0)}Readable.prototype.setEncoding=function(enc){if(!StringDecoder)StringDecoder=require("string_decoder/").StringDecoder;this._readableState.decoder=new StringDecoder(enc);this._readableState.encoding=enc};var MAX_HWM=8388608;function roundUpToNextPowerOf2(n){if(n>=MAX_HWM){n=MAX_HWM}else{n--;for(var p=1;p<32;p<<=1)n|=n>>p;n++}return n}function howMuchToRead(n,state){if(state.length===0&&state.ended)return 0;if(state.objectMode)return n===0?0:1;if(n===null||isNaN(n)){if(state.flowing&&state.buffer.length)return state.buffer[0].length;else return state.length}if(n<=0)return 0;if(n>state.highWaterMark)state.highWaterMark=roundUpToNextPowerOf2(n);if(n>state.length){if(!state.ended){state.needReadable=true;return 0}else return state.length}return n}Readable.prototype.read=function(n){var state=this._readableState;state.calledRead=true;var nOrig=n;var ret;if(typeof n!=="number"||n>0)state.emittedReadable=false;if(n===0&&state.needReadable&&(state.length>=state.highWaterMark||state.ended)){emitReadable(this);return null}n=howMuchToRead(n,state);if(n===0&&state.ended){ret=null;if(state.length>0&&state.decoder){ret=fromList(n,state);state.length-=ret.length}if(state.length===0)endReadable(this);return ret}var doRead=state.needReadable;if(state.length-n<=state.highWaterMark)doRead=true;if(state.ended||state.reading)doRead=false;if(doRead){state.reading=true;state.sync=true;if(state.length===0)state.needReadable=true;this._read(state.highWaterMark);state.sync=false}if(doRead&&!state.reading)n=howMuchToRead(nOrig,state);if(n>0)ret=fromList(n,state);else ret=null;if(ret===null){state.needReadable=true;n=0}state.length-=n;if(state.length===0&&!state.ended)state.needReadable=true;if(state.ended&&!state.endEmitted&&state.length===0)endReadable(this);return ret};function chunkInvalid(state,chunk){var er=null;if(!Buffer.isBuffer(chunk)&&"string"!==typeof chunk&&chunk!==null&&chunk!==undefined&&!state.objectMode){er=new TypeError("Invalid non-string/buffer chunk")}return er}function onEofChunk(stream,state){if(state.decoder&&!state.ended){var chunk=state.decoder.end();if(chunk&&chunk.length){state.buffer.push(chunk);state.length+=state.objectMode?1:chunk.length}}state.ended=true;if(state.length>0)emitReadable(stream);else endReadable(stream)}function emitReadable(stream){var state=stream._readableState;state.needReadable=false;if(state.emittedReadable)return;state.emittedReadable=true;if(state.sync)process.nextTick(function(){emitReadable_(stream)});else emitReadable_(stream)}function emitReadable_(stream){stream.emit("readable")}function maybeReadMore(stream,state){if(!state.readingMore){state.readingMore=true;process.nextTick(function(){maybeReadMore_(stream,state)})}}function maybeReadMore_(stream,state){var len=state.length;while(!state.reading&&!state.flowing&&!state.ended&&state.length<state.highWaterMark){stream.read(0);if(len===state.length)break;else len=state.length}state.readingMore=false}Readable.prototype._read=function(n){this.emit("error",new Error("not implemented"))};Readable.prototype.pipe=function(dest,pipeOpts){var src=this;var state=this._readableState;switch(state.pipesCount){case 0:state.pipes=dest;break;case 1:state.pipes=[state.pipes,dest];break;default:state.pipes.push(dest);break}state.pipesCount+=1;var doEnd=(!pipeOpts||pipeOpts.end!==false)&&dest!==process.stdout&&dest!==process.stderr;var endFn=doEnd?onend:cleanup;if(state.endEmitted)process.nextTick(endFn);else src.once("end",endFn);dest.on("unpipe",onunpipe);function onunpipe(readable){if(readable!==src)return;cleanup()}function onend(){dest.end()}var ondrain=pipeOnDrain(src);dest.on("drain",ondrain);function cleanup(){dest.removeListener("close",onclose);dest.removeListener("finish",onfinish);dest.removeListener("drain",ondrain);dest.removeListener("error",onerror);dest.removeListener("unpipe",onunpipe);src.removeListener("end",onend);src.removeListener("end",cleanup);if(!dest._writableState||dest._writableState.needDrain)ondrain()}function onerror(er){unpipe();dest.removeListener("error",onerror);if(EE.listenerCount(dest,"error")===0)dest.emit("error",er)}if(!dest._events||!dest._events.error)dest.on("error",onerror);else if(isArray(dest._events.error))dest._events.error.unshift(onerror);else dest._events.error=[onerror,dest._events.error];function onclose(){dest.removeListener("finish",onfinish);unpipe()}dest.once("close",onclose);function onfinish(){dest.removeListener("close",onclose);unpipe()}dest.once("finish",onfinish);function unpipe(){src.unpipe(dest)}dest.emit("pipe",src);if(!state.flowing){this.on("readable",pipeOnReadable);state.flowing=true;process.nextTick(function(){flow(src)})}return dest};function pipeOnDrain(src){return function(){var dest=this;var state=src._readableState;state.awaitDrain--;if(state.awaitDrain===0)flow(src)}}function flow(src){var state=src._readableState;var chunk;state.awaitDrain=0;function write(dest,i,list){var written=dest.write(chunk);if(false===written){state.awaitDrain++}}while(state.pipesCount&&null!==(chunk=src.read())){if(state.pipesCount===1)write(state.pipes,0,null);else forEach(state.pipes,write);src.emit("data",chunk);if(state.awaitDrain>0)return}if(state.pipesCount===0){state.flowing=false;if(EE.listenerCount(src,"data")>0)emitDataEvents(src);return}state.ranOut=true}function pipeOnReadable(){if(this._readableState.ranOut){this._readableState.ranOut=false;flow(this)}}Readable.prototype.unpipe=function(dest){var state=this._readableState;if(state.pipesCount===0)return this;if(state.pipesCount===1){if(dest&&dest!==state.pipes)return this;if(!dest)dest=state.pipes;state.pipes=null;state.pipesCount=0;this.removeListener("readable",pipeOnReadable);state.flowing=false;if(dest)dest.emit("unpipe",this);return this}if(!dest){var dests=state.pipes;var len=state.pipesCount;state.pipes=null;state.pipesCount=0;this.removeListener("readable",pipeOnReadable);state.flowing=false;for(var i=0;i<len;i++)dests[i].emit("unpipe",this);return this}var i=indexOf(state.pipes,dest);if(i===-1)return this;state.pipes.splice(i,1);state.pipesCount-=1;if(state.pipesCount===1)state.pipes=state.pipes[0];dest.emit("unpipe",this);return this};Readable.prototype.on=function(ev,fn){var res=Stream.prototype.on.call(this,ev,fn);if(ev==="data"&&!this._readableState.flowing)emitDataEvents(this);if(ev==="readable"&&this.readable){var state=this._readableState;if(!state.readableListening){state.readableListening=true;state.emittedReadable=false;state.needReadable=true;if(!state.reading){this.read(0)}else if(state.length){emitReadable(this,state)}}}return res};Readable.prototype.addListener=Readable.prototype.on;Readable.prototype.resume=function(){emitDataEvents(this);this.read(0);this.emit("resume")};Readable.prototype.pause=function(){emitDataEvents(this,true);this.emit("pause")};function emitDataEvents(stream,startPaused){var state=stream._readableState;if(state.flowing){throw new Error("Cannot switch to old mode now.")}var paused=startPaused||false;var readable=false;stream.readable=true;stream.pipe=Stream.prototype.pipe;stream.on=stream.addListener=Stream.prototype.on;stream.on("readable",function(){readable=true;var c;while(!paused&&null!==(c=stream.read()))stream.emit("data",c);if(c===null){readable=false;stream._readableState.needReadable=true}});stream.pause=function(){paused=true;this.emit("pause")};stream.resume=function(){paused=false;if(readable)process.nextTick(function(){stream.emit("readable")});else this.read(0);this.emit("resume")};stream.emit("readable")}Readable.prototype.wrap=function(stream){var state=this._readableState;var paused=false;var self=this;stream.on("end",function(){if(state.decoder&&!state.ended){var chunk=state.decoder.end();if(chunk&&chunk.length)self.push(chunk)}self.push(null)});stream.on("data",function(chunk){if(state.decoder)chunk=state.decoder.write(chunk);if(state.objectMode&&(chunk===null||chunk===undefined))return;else if(!state.objectMode&&(!chunk||!chunk.length))return;var ret=self.push(chunk);if(!ret){paused=true;stream.pause()}});for(var i in stream){if(typeof stream[i]==="function"&&typeof this[i]==="undefined"){this[i]=function(method){return function(){return stream[method].apply(stream,arguments)}}(i)}}var events=["error","close","destroy","pause","resume"];forEach(events,function(ev){stream.on(ev,self.emit.bind(self,ev))});self._read=function(n){if(paused){paused=false;stream.resume()}};return self};Readable._fromList=fromList;function fromList(n,state){var list=state.buffer;var length=state.length;var stringMode=!!state.decoder;var objectMode=!!state.objectMode;var ret;if(list.length===0)return null;if(length===0)ret=null;else if(objectMode)ret=list.shift();else if(!n||n>=length){if(stringMode)ret=list.join("");else ret=Buffer.concat(list,length);list.length=0}else{if(n<list[0].length){var buf=list[0];ret=buf.slice(0,n);list[0]=buf.slice(n)}else if(n===list[0].length){ret=list.shift()}else{if(stringMode)ret="";else ret=new Buffer(n);var c=0;for(var i=0,l=list.length;i<l&&c<n;i++){var buf=list[0];var cpy=Math.min(n-c,buf.length);if(stringMode)ret+=buf.slice(0,cpy);else buf.copy(ret,c,0,cpy);if(cpy<buf.length)list[0]=buf.slice(cpy);else list.shift();c+=cpy}}}return ret}function endReadable(stream){var state=stream._readableState;if(state.length>0)throw new Error("endReadable called on non-empty stream");if(!state.endEmitted&&state.calledRead){state.ended=true;process.nextTick(function(){if(!state.endEmitted&&state.length===0){state.endEmitted=true;stream.readable=false;stream.emit("end")}})}}function forEach(xs,f){for(var i=0,l=xs.length;i<l;i++){f(xs[i],i)}}function indexOf(xs,x){for(var i=0,l=xs.length;i<l;i++){if(xs[i]===x)return i}return-1}}).call(this,require("_process"))},{_process:8,buffer:1,"core-util-is":15,events:5,inherits:6,isarray:7,stream:20,"string_decoder/":21}],13:[function(require,module,exports){module.exports=Transform;var Duplex=require("./_stream_duplex");var util=require("core-util-is");util.inherits=require("inherits");util.inherits(Transform,Duplex);function TransformState(options,stream){this.afterTransform=function(er,data){return afterTransform(stream,er,data)};this.needTransform=false;this.transforming=false;this.writecb=null;this.writechunk=null}function afterTransform(stream,er,data){var ts=stream._transformState;ts.transforming=false;var cb=ts.writecb;if(!cb)return stream.emit("error",new Error("no writecb in Transform class"));ts.writechunk=null;ts.writecb=null;if(data!==null&&data!==undefined)stream.push(data);if(cb)cb(er);var rs=stream._readableState;rs.reading=false;if(rs.needReadable||rs.length<rs.highWaterMark){stream._read(rs.highWaterMark)}}function Transform(options){if(!(this instanceof Transform))return new Transform(options);Duplex.call(this,options);var ts=this._transformState=new TransformState(options,this);var stream=this;this._readableState.needReadable=true;this._readableState.sync=false;this.once("finish",function(){if("function"===typeof this._flush)this._flush(function(er){done(stream,er)});else done(stream)})}Transform.prototype.push=function(chunk,encoding){this._transformState.needTransform=false;return Duplex.prototype.push.call(this,chunk,encoding)};Transform.prototype._transform=function(chunk,encoding,cb){throw new Error("not implemented")};Transform.prototype._write=function(chunk,encoding,cb){var ts=this._transformState;ts.writecb=cb;ts.writechunk=chunk;ts.writeencoding=encoding;if(!ts.transforming){var rs=this._readableState;if(ts.needTransform||rs.needReadable||rs.length<rs.highWaterMark)this._read(rs.highWaterMark)}};Transform.prototype._read=function(n){var ts=this._transformState;if(ts.writechunk!==null&&ts.writecb&&!ts.transforming){ts.transforming=true;this._transform(ts.writechunk,ts.writeencoding,ts.afterTransform)}else{ts.needTransform=true}};function done(stream,er){if(er)return stream.emit("error",er);var ws=stream._writableState;var rs=stream._readableState;var ts=stream._transformState;if(ws.length)throw new Error("calling transform done when ws.length != 0");if(ts.transforming)throw new Error("calling transform done when still transforming");return stream.push(null)}},{"./_stream_duplex":10,"core-util-is":15,inherits:6}],14:[function(require,module,exports){(function(process){module.exports=Writable;var Buffer=require("buffer").Buffer;Writable.WritableState=WritableState;var util=require("core-util-is");util.inherits=require("inherits");var Stream=require("stream");util.inherits(Writable,Stream);function WriteReq(chunk,encoding,cb){this.chunk=chunk;this.encoding=encoding;this.callback=cb}function WritableState(options,stream){options=options||{};var hwm=options.highWaterMark;this.highWaterMark=hwm||hwm===0?hwm:16*1024;this.objectMode=!!options.objectMode;this.highWaterMark=~~this.highWaterMark;this.needDrain=false;this.ending=false;this.ended=false;this.finished=false;var noDecode=options.decodeStrings===false;this.decodeStrings=!noDecode;this.defaultEncoding=options.defaultEncoding||"utf8";this.length=0;this.writing=false;this.sync=true;this.bufferProcessing=false;this.onwrite=function(er){onwrite(stream,er)};this.writecb=null;this.writelen=0;this.buffer=[];this.errorEmitted=false}function Writable(options){var Duplex=require("./_stream_duplex");if(!(this instanceof Writable)&&!(this instanceof Duplex))return new Writable(options);this._writableState=new WritableState(options,this);this.writable=true;Stream.call(this)}Writable.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe. Not readable."))};function writeAfterEnd(stream,state,cb){var er=new Error("write after end");stream.emit("error",er);process.nextTick(function(){cb(er)})}function validChunk(stream,state,chunk,cb){var valid=true;if(!Buffer.isBuffer(chunk)&&"string"!==typeof chunk&&chunk!==null&&chunk!==undefined&&!state.objectMode){var er=new TypeError("Invalid non-string/buffer chunk");stream.emit("error",er);process.nextTick(function(){cb(er)});valid=false}return valid}Writable.prototype.write=function(chunk,encoding,cb){var state=this._writableState;var ret=false;if(typeof encoding==="function"){cb=encoding;encoding=null}if(Buffer.isBuffer(chunk))encoding="buffer";else if(!encoding)encoding=state.defaultEncoding;if(typeof cb!=="function")cb=function(){};if(state.ended)writeAfterEnd(this,state,cb);else if(validChunk(this,state,chunk,cb))ret=writeOrBuffer(this,state,chunk,encoding,cb);return ret};function decodeChunk(state,chunk,encoding){if(!state.objectMode&&state.decodeStrings!==false&&typeof chunk==="string"){chunk=new Buffer(chunk,encoding)}return chunk}function writeOrBuffer(stream,state,chunk,encoding,cb){chunk=decodeChunk(state,chunk,encoding);if(Buffer.isBuffer(chunk))encoding="buffer";var len=state.objectMode?1:chunk.length;state.length+=len;var ret=state.length<state.highWaterMark;if(!ret)state.needDrain=true;if(state.writing)state.buffer.push(new WriteReq(chunk,encoding,cb));else doWrite(stream,state,len,chunk,encoding,cb);return ret}function doWrite(stream,state,len,chunk,encoding,cb){state.writelen=len;state.writecb=cb;state.writing=true;state.sync=true;stream._write(chunk,encoding,state.onwrite);state.sync=false}function onwriteError(stream,state,sync,er,cb){if(sync)process.nextTick(function(){cb(er)});else cb(er);stream._writableState.errorEmitted=true;stream.emit("error",er)}function onwriteStateUpdate(state){state.writing=false;state.writecb=null;state.length-=state.writelen;state.writelen=0}function onwrite(stream,er){var state=stream._writableState;var sync=state.sync;var cb=state.writecb;onwriteStateUpdate(state);if(er)onwriteError(stream,state,sync,er,cb);else{var finished=needFinish(stream,state);if(!finished&&!state.bufferProcessing&&state.buffer.length)clearBuffer(stream,state);if(sync){process.nextTick(function(){afterWrite(stream,state,finished,cb)})}else{afterWrite(stream,state,finished,cb)}}}function afterWrite(stream,state,finished,cb){if(!finished)onwriteDrain(stream,state);cb();if(finished)finishMaybe(stream,state)}function onwriteDrain(stream,state){if(state.length===0&&state.needDrain){state.needDrain=false;stream.emit("drain")}}function clearBuffer(stream,state){state.bufferProcessing=true;for(var c=0;c<state.buffer.length;c++){var entry=state.buffer[c];var chunk=entry.chunk;var encoding=entry.encoding;var cb=entry.callback;var len=state.objectMode?1:chunk.length;doWrite(stream,state,len,chunk,encoding,cb);if(state.writing){c++;break}}state.bufferProcessing=false;if(c<state.buffer.length)state.buffer=state.buffer.slice(c);else state.buffer.length=0}Writable.prototype._write=function(chunk,encoding,cb){cb(new Error("not implemented"))};Writable.prototype.end=function(chunk,encoding,cb){var state=this._writableState;if(typeof chunk==="function"){cb=chunk;chunk=null;encoding=null}else if(typeof encoding==="function"){cb=encoding;encoding=null}if(typeof chunk!=="undefined"&&chunk!==null)this.write(chunk,encoding);if(!state.ending&&!state.finished)endWritable(this,state,cb)};function needFinish(stream,state){return state.ending&&state.length===0&&!state.finished&&!state.writing}function finishMaybe(stream,state){var need=needFinish(stream,state);if(need){state.finished=true;stream.emit("finish")}return need}function endWritable(stream,state,cb){state.ending=true;finishMaybe(stream,state);if(cb){if(state.finished)process.nextTick(cb);else stream.once("finish",cb)}state.ended=true}}).call(this,require("_process"))},{"./_stream_duplex":10,_process:8,buffer:1,"core-util-is":15,inherits:6,stream:20}],15:[function(require,module,exports){(function(Buffer){function isArray(ar){return Array.isArray(ar)}exports.isArray=isArray;function isBoolean(arg){return typeof arg==="boolean"}exports.isBoolean=isBoolean;function isNull(arg){return arg===null}exports.isNull=isNull;function isNullOrUndefined(arg){return arg==null}exports.isNullOrUndefined=isNullOrUndefined;function isNumber(arg){return typeof arg==="number"}exports.isNumber=isNumber;function isString(arg){return typeof arg==="string"}exports.isString=isString;function isSymbol(arg){return typeof arg==="symbol"}exports.isSymbol=isSymbol;function isUndefined(arg){return arg===void 0}exports.isUndefined=isUndefined;function isRegExp(re){return isObject(re)&&objectToString(re)==="[object RegExp]"}exports.isRegExp=isRegExp;function isObject(arg){return typeof arg==="object"&&arg!==null}exports.isObject=isObject;function isDate(d){return isObject(d)&&objectToString(d)==="[object Date]"}exports.isDate=isDate;function isError(e){return isObject(e)&&(objectToString(e)==="[object Error]"||e instanceof Error)}exports.isError=isError;function isFunction(arg){return typeof arg==="function"}exports.isFunction=isFunction;function isPrimitive(arg){return arg===null||typeof arg==="boolean"||typeof arg==="number"||typeof arg==="string"||typeof arg==="symbol"||typeof arg==="undefined"}exports.isPrimitive=isPrimitive;function isBuffer(arg){return Buffer.isBuffer(arg)}exports.isBuffer=isBuffer;function objectToString(o){return Object.prototype.toString.call(o)}}).call(this,require("buffer").Buffer)},{buffer:1}],16:[function(require,module,exports){module.exports=require("./lib/_stream_passthrough.js")},{"./lib/_stream_passthrough.js":11}],17:[function(require,module,exports){var Stream=require("stream");exports=module.exports=require("./lib/_stream_readable.js");exports.Stream=Stream;exports.Readable=exports;exports.Writable=require("./lib/_stream_writable.js");exports.Duplex=require("./lib/_stream_duplex.js");exports.Transform=require("./lib/_stream_transform.js");exports.PassThrough=require("./lib/_stream_passthrough.js")},{"./lib/_stream_duplex.js":10,"./lib/_stream_passthrough.js":11,"./lib/_stream_readable.js":12,"./lib/_stream_transform.js":13,"./lib/_stream_writable.js":14,stream:20}],18:[function(require,module,exports){module.exports=require("./lib/_stream_transform.js")},{"./lib/_stream_transform.js":13}],19:[function(require,module,exports){module.exports=require("./lib/_stream_writable.js")},{"./lib/_stream_writable.js":14}],20:[function(require,module,exports){module.exports=Stream;var EE=require("events").EventEmitter;var inherits=require("inherits");inherits(Stream,EE);Stream.Readable=require("readable-stream/readable.js");Stream.Writable=require("readable-stream/writable.js");Stream.Duplex=require("readable-stream/duplex.js");Stream.Transform=require("readable-stream/transform.js");Stream.PassThrough=require("readable-stream/passthrough.js");Stream.Stream=Stream;function Stream(){EE.call(this)}Stream.prototype.pipe=function(dest,options){var source=this;function ondata(chunk){if(dest.writable){if(false===dest.write(chunk)&&source.pause){source.pause()}}}source.on("data",ondata);function ondrain(){if(source.readable&&source.resume){source.resume()
}}dest.on("drain",ondrain);if(!dest._isStdio&&(!options||options.end!==false)){source.on("end",onend);source.on("close",onclose)}var didOnEnd=false;function onend(){if(didOnEnd)return;didOnEnd=true;dest.end()}function onclose(){if(didOnEnd)return;didOnEnd=true;if(typeof dest.destroy==="function")dest.destroy()}function onerror(er){cleanup();if(EE.listenerCount(this,"error")===0){throw er}}source.on("error",onerror);dest.on("error",onerror);function cleanup(){source.removeListener("data",ondata);dest.removeListener("drain",ondrain);source.removeListener("end",onend);source.removeListener("close",onclose);source.removeListener("error",onerror);dest.removeListener("error",onerror);source.removeListener("end",cleanup);source.removeListener("close",cleanup);dest.removeListener("close",cleanup)}source.on("end",cleanup);source.on("close",cleanup);dest.on("close",cleanup);dest.emit("pipe",source);return dest}},{events:5,inherits:6,"readable-stream/duplex.js":9,"readable-stream/passthrough.js":16,"readable-stream/readable.js":17,"readable-stream/transform.js":18,"readable-stream/writable.js":19}],21:[function(require,module,exports){var Buffer=require("buffer").Buffer;var isBufferEncoding=Buffer.isEncoding||function(encoding){switch(encoding&&encoding.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return true;default:return false}};function assertEncoding(encoding){if(encoding&&!isBufferEncoding(encoding)){throw new Error("Unknown encoding: "+encoding)}}var StringDecoder=exports.StringDecoder=function(encoding){this.encoding=(encoding||"utf8").toLowerCase().replace(/[-_]/,"");assertEncoding(encoding);switch(this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2;this.detectIncompleteChar=utf16DetectIncompleteChar;break;case"base64":this.surrogateSize=3;this.detectIncompleteChar=base64DetectIncompleteChar;break;default:this.write=passThroughWrite;return}this.charBuffer=new Buffer(6);this.charReceived=0;this.charLength=0};StringDecoder.prototype.write=function(buffer){var charStr="";while(this.charLength){var available=buffer.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:buffer.length;buffer.copy(this.charBuffer,this.charReceived,0,available);this.charReceived+=available;if(this.charReceived<this.charLength){return""}buffer=buffer.slice(available,buffer.length);charStr=this.charBuffer.slice(0,this.charLength).toString(this.encoding);var charCode=charStr.charCodeAt(charStr.length-1);if(charCode>=55296&&charCode<=56319){this.charLength+=this.surrogateSize;charStr="";continue}this.charReceived=this.charLength=0;if(buffer.length===0){return charStr}break}this.detectIncompleteChar(buffer);var end=buffer.length;if(this.charLength){buffer.copy(this.charBuffer,0,buffer.length-this.charReceived,end);end-=this.charReceived}charStr+=buffer.toString(this.encoding,0,end);var end=charStr.length-1;var charCode=charStr.charCodeAt(end);if(charCode>=55296&&charCode<=56319){var size=this.surrogateSize;this.charLength+=size;this.charReceived+=size;this.charBuffer.copy(this.charBuffer,size,0,size);buffer.copy(this.charBuffer,0,0,size);return charStr.substring(0,end)}return charStr};StringDecoder.prototype.detectIncompleteChar=function(buffer){var i=buffer.length>=3?3:buffer.length;for(;i>0;i--){var c=buffer[buffer.length-i];if(i==1&&c>>5==6){this.charLength=2;break}if(i<=2&&c>>4==14){this.charLength=3;break}if(i<=3&&c>>3==30){this.charLength=4;break}}this.charReceived=i};StringDecoder.prototype.end=function(buffer){var res="";if(buffer&&buffer.length)res=this.write(buffer);if(this.charReceived){var cr=this.charReceived;var buf=this.charBuffer;var enc=this.encoding;res+=buf.slice(0,cr).toString(enc)}return res};function passThroughWrite(buffer){return buffer.toString(this.encoding)}function utf16DetectIncompleteChar(buffer){this.charReceived=buffer.length%2;this.charLength=this.charReceived?2:0}function base64DetectIncompleteChar(buffer){this.charReceived=buffer.length%3;this.charLength=this.charReceived?3:0}},{buffer:1}],22:[function(require,module,exports){"use strict";var glslExports=require("glsl-exports");var uniq=require("uniq");function Shader(gl,prog,uniforms,attributes){this.gl=gl;this.program=prog;this.uniforms=uniforms;this.attributes=attributes}Shader.prototype.bind=function(){this.gl.useProgram(this.program)};function kvPairs(obj){return Object.keys(obj).map(function(x){return[x,obj[x]]})}function makeVectorUniform(gl,prog,location,obj,type,d,name){if(d>1){type+="v"}var setter=new Function("gl","prog","v","gl.uniform"+d+type+"(gl.getUniformLocation(prog,'"+name+"'), v)");var getter=new Function("gl","prog","return gl.getUniform(prog, gl.getUniformLocation(prog,'"+name+"'))");Object.defineProperty(obj,name,{set:setter.bind(undefined,gl,prog),get:getter.bind(undefined,gl,prog),enumerable:true})}function makeMatrixUniform(gl,prog,location,obj,d,name){var setter=new Function("gl","prog","v","gl.uniformMatrix"+d+"fv(gl.getUniformLocation(prog,'"+name+"'), false, v)");var getter=new Function("gl","prog","return gl.getUniform(prog, gl.getUniformLocation(prog,'"+name+"'))");Object.defineProperty(obj,name,{set:setter.bind(undefined,gl,prog),get:getter.bind(undefined,gl,prog),enumerable:true})}function makeVectorAttrib(gl,prog,location,obj,d,name){var out={};out.pointer=function attribPointer(type,normalized,stride,offset){gl.vertexAttribPointer(location,d,type||gl.FLOAT,normalized?gl.TRUE:gl.FALSE,stride||0,offset||0)};out.enable=function enableAttrib(){gl.enableVertexAttribArray(location)};out.disable=function disableAttrib(){gl.disableVertexAttribArray(location)};Object.defineProperty(out,"location",{get:function(){return location},set:function(v){if(v!==location){location=v;gl.bindAttribLocation(prog,v,name);gl.linkProgram(prog)}return v}});var constFuncArgs=["gl","v"];var var_names=[];for(var i=0;i<d;++i){constFuncArgs.push("x"+i);var_names.push("x"+i)}constFuncArgs.push(["if(x0.length === undefined) {","return gl.vertexAttrib"+d+"f(v,"+var_names.join(",")+")","} else {","return gl.vertexAttrib"+d+"fv(v,x0)","}"].join("\n"));var constFunc=Function.apply(undefined,constFuncArgs);out.set=function setAttrib(x,y,z,w){return constFunc(gl,location,x,y,z,w)};Object.defineProperty(obj,name,{set:function(x){out.isArray=false;constFunc(gl,location,x);return x},get:function(){return out},enumerable:true})}function makeShader(gl,vert_source,frag_source){var vert_shader=gl.createShader(gl.VERTEX_SHADER);gl.shaderSource(vert_shader,vert_source);gl.compileShader(vert_shader);if(!gl.getShaderParameter(vert_shader,gl.COMPILE_STATUS)){throw new Error("Error compiling vertex shader: "+gl.getShaderInfoLog(vert_shader))}var frag_shader=gl.createShader(gl.FRAGMENT_SHADER);gl.shaderSource(frag_shader,frag_source);gl.compileShader(frag_shader);if(!gl.getShaderParameter(frag_shader,gl.COMPILE_STATUS)){throw new Error("Error compiling fragment shader: "+gl.getShaderInfoLog(frag_shader))}var program=gl.createProgram();gl.attachShader(program,frag_shader);gl.attachShader(program,vert_shader);gl.linkProgram(program);if(!gl.getProgramParameter(program,gl.LINK_STATUS)){throw new Error("Error linking shader program: "+gl.getProgramInfoLog(program))}var frag_exports=glslExports(frag_source);var vert_exports=glslExports(vert_source);var uniforms=uniq(kvPairs(frag_exports.uniforms).concat(kvPairs(vert_exports.uniforms)),function compare(a,b){return a[0]<b[0]?-1:a[0]===b[0]?0:1});var uniform_fields={};for(var i=0;i<uniforms.length;++i){var u=uniforms[i];var name=u[0];var type=u[1];var x=gl.getUniformLocation(program,name);if(!x){Object.defineProperty(uniform_fields,name,{get:function(){},set:function(){}});continue}switch(type){case"bool":case"int":case"sampler2D":case"samplerCube":makeVectorUniform(gl,program,x,uniform_fields,"i",1,name);break;case"float":makeVectorUniform(gl,program,x,uniform_fields,"f",1,name);break;default:if(type.indexOf("vec")>=0){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":makeVectorUniform(gl,program,x,uniform_fields,"i",d,name);break;case"v":makeVectorUniform(gl,program,x,uniform_fields,"f",d,name);break;default:throw new Error("Unrecognized data type")}}else if(type.charAt(0)==="m"){var d=type.charCodeAt(type.length-1)-48;if(d<2||d>4){throw new Error("Invalid data type")}makeMatrixUniform(gl,program,x,uniform_fields,d,name)}else{throw new Error("Invalid data type")}break}}var attributes=kvPairs(vert_exports.attributes);var attribute_fields={};for(var i=0;i<attributes.length;++i){var u=attributes[i];var name=u[0];var type=u[1];var x=gl.getAttribLocation(program,name);switch(type){case"bool":case"int":case"float":makeVectorAttrib(gl,program,x,attribute_fields,1,name);break;default:if(type.indexOf("vec")>=0){var d=type.charCodeAt(type.length-1)-48;if(d<2||d>4){throw new Error("Invalid data type")}makeVectorAttrib(gl,program,x,attribute_fields,d,name)}else{throw new Error("Invalid data type")}break}}return new Shader(gl,program,uniform_fields,attribute_fields)}module.exports=makeShader},{"glsl-exports":23,uniq:34}],23:[function(require,module,exports){"use strict";var glslTokenizer=require("glsl-tokenizer");var glslParser=require("glsl-parser");var through=require("through");function parseDeclaration(x){var type,identifiers=[],i;for(var i=0;i<x.children.length;++i){var c=x.children[i];if(c.type==="placeholder"){continue}else if(c.type==="keyword"){if(c.token.data==="uniform"||c.token.data==="attribute"){continue}type=c.token.data}else if(c.type==="decllist"){for(var j=0;j<c.children.length;++j){var d=c.children[j];if(d.type==="ident"){identifiers.push(d.token.data)}}}}return{type:type,vars:identifiers}}function glslGlobals(src){var uniforms={};var attributes={};var strm=through();strm.pipe(glslTokenizer()).pipe(glslParser()).on("data",function(x){if(x.type==="decl"&&x.token.type==="keyword"){if(x.token.data==="uniform"){var result=parseDeclaration(x);for(var i=0;i<result.vars.length;++i){uniforms[result.vars[i]]=result.type}}else if(x.token.data==="attribute"){var result=parseDeclaration(x);for(var i=0;i<result.vars.length;++i){attributes[result.vars[i]]=result.type}}}});strm.write(src);return{uniforms:uniforms,attributes:attributes}}module.exports=glslGlobals},{"glsl-parser":24,"glsl-tokenizer":29,through:33}],24:[function(require,module,exports){module.exports=require("./lib/index")},{"./lib/index":26}],25:[function(require,module,exports){var state,token,tokens,idx;var original_symbol={nud:function(){return this.children&&this.children.length?this:fail("unexpected")()},led:fail("missing operator")};var symbol_table={};function itself(){return this}symbol("(ident)").nud=itself;symbol("(keyword)").nud=itself;symbol("(builtin)").nud=itself;symbol("(literal)").nud=itself;symbol("(end)");symbol(":");symbol(";");symbol(",");symbol(")");symbol("]");symbol("}");infixr("&&",30);infixr("||",30);infix("|",43);infix("^",44);infix("&",45);infix("==",46);infix("!=",46);infix("<",47);infix("<=",47);infix(">",47);infix(">=",47);infix(">>",48);infix("<<",48);infix("+",50);infix("-",50);infix("*",60);infix("/",60);infix("%",60);infix("?",20,function(left){this.children=[left,expression(0),(advance(":"),expression(0))];this.type="ternary";return this});infix(".",80,function(left){token.type="literal";state.fake(token);this.children=[left,token];advance();return this});infix("[",80,function(left){this.children=[left,expression(0)];this.type="binary";advance("]");return this});infix("(",80,function(left){this.children=[left];this.type="call";if(token.data!==")")while(1){this.children.push(expression(0));if(token.data!==",")break;advance(",")}advance(")");return this});prefix("-");prefix("+");prefix("!");prefix("~");prefix("defined");prefix("(",function(){this.type="group";this.children=[expression(0)];advance(")");return this});prefix("++");prefix("--");suffix("++");suffix("--");assignment("=");assignment("+=");assignment("-=");assignment("*=");assignment("/=");assignment("%=");assignment("&=");assignment("|=");assignment("^=");assignment(">>=");assignment("<<=");module.exports=function(incoming_state,incoming_tokens){state=incoming_state;tokens=incoming_tokens;idx=0;var result;if(!tokens.length)return;advance();result=expression(0);result.parent=state[0];emit(result);if(idx<tokens.length){throw new Error("did not use all tokens")}result.parent.children=[result];function emit(node){state.unshift(node,false);for(var i=0,len=node.children.length;i<len;++i){emit(node.children[i])}state.shift()}};function symbol(id,binding_power){var sym=symbol_table[id];binding_power=binding_power||0;if(sym){if(binding_power>sym.lbp){sym.lbp=binding_power}}else{sym=Object.create(original_symbol);sym.id=id;sym.lbp=binding_power;symbol_table[id]=sym}return sym}function expression(rbp){var left,t=token;advance();left=t.nud();while(rbp<token.lbp){t=token;advance();left=t.led(left)}return left}function infix(id,bp,led){var sym=symbol(id,bp);sym.led=led||function(left){this.children=[left,expression(bp)];this.type="binary";return this}}function infixr(id,bp,led){var sym=symbol(id,bp);sym.led=led||function(left){this.children=[left,expression(bp-1)];this.type="binary";return this};return sym}function prefix(id,nud){var sym=symbol(id);sym.nud=nud||function(){this.children=[expression(70)];this.type="unary";return this};return sym}function suffix(id){var sym=symbol(id,150);sym.led=function(left){this.children=[left];this.type="suffix";return this}}function assignment(id){return infixr(id,10,function(left){this.children=[left,expression(9)];this.assignment=true;this.type="assign";return this})}function advance(id){var next,value,type,output;if(id&&token.data!==id){return state.unexpected("expected `"+id+"`, got `"+token.data+"`")}if(idx>=tokens.length){token=symbol_table["(end)"];return}next=tokens[idx++];value=next.data;type=next.type;if(type==="ident"){output=state.scope.find(value)||state.create_node();type=output.type}else if(type==="builtin"){output=symbol_table["(builtin)"]}else if(type==="keyword"){output=symbol_table["(keyword)"]}else if(type==="operator"){output=symbol_table[value];if(!output){return state.unexpected("unknown operator `"+value+"`")}}else if(type==="float"||type==="integer"){type="literal";output=symbol_table["(literal)"]}else{return state.unexpected("unexpected token.")}if(output){if(!output.nud){output.nud=itself}if(!output.children){output.children=[]}}output=Object.create(output);output.token=next;output.type=type;if(!output.data)output.data=value;return token=output}function fail(message){return function(){return state.unexpected(message)}}},{}],26:[function(require,module,exports){module.exports=parser;var through=require("through"),full_parse_expr=require("./expr"),Scope=require("./scope");var Advance=new Object;var DEBUG=false;var _=0,IDENT=_++,STMT=_++,STMTLIST=_++,STRUCT=_++,FUNCTION=_++,FUNCTIONARGS=_++,DECL=_++,DECLLIST=_++,FORLOOP=_++,WHILELOOP=_++,IF=_++,EXPR=_++,PRECISION=_++,COMMENT=_++,PREPROCESSOR=_++,KEYWORD=_++,KEYWORD_OR_IDENT=_++,RETURN=_++,BREAK=_++,CONTINUE=_++,DISCARD=_++,DOWHILELOOP=_++,PLACEHOLDER=_++,QUANTIFIER=_++;var DECL_ALLOW_ASSIGN=1,DECL_ALLOW_COMMA=2,DECL_REQUIRE_NAME=4,DECL_ALLOW_INVARIANT=8,DECL_ALLOW_STORAGE=16,DECL_NO_INOUT=32,DECL_ALLOW_STRUCT=64,DECL_STATEMENT=255,DECL_FUNCTION=DECL_STATEMENT&~(DECL_ALLOW_ASSIGN|DECL_ALLOW_COMMA|DECL_NO_INOUT|DECL_ALLOW_INVARIANT|DECL_REQUIRE_NAME),DECL_STRUCT=DECL_STATEMENT&~(DECL_ALLOW_ASSIGN|DECL_ALLOW_INVARIANT|DECL_ALLOW_STORAGE|DECL_ALLOW_STRUCT);var QUALIFIERS=["const","attribute","uniform","varying"];var NO_ASSIGN_ALLOWED=false,NO_COMMA_ALLOWED=false;var token_map={"block-comment":COMMENT,"line-comment":COMMENT,preprocessor:PREPROCESSOR};var stmt_type=_=["ident","stmt","stmtlist","struct","function","functionargs","decl","decllist","forloop","whileloop","if","expr","precision","comment","preprocessor","keyword","keyword_or_ident","return","break","continue","discard","do-while","placeholder","quantifier"];function parser(){var stmtlist=n(STMTLIST),stmt=n(STMT),decllist=n(DECLLIST),precision=n(PRECISION),ident=n(IDENT),keyword_or_ident=n(KEYWORD_OR_IDENT),fn=n(FUNCTION),fnargs=n(FUNCTIONARGS),forstmt=n(FORLOOP),ifstmt=n(IF),whilestmt=n(WHILELOOP),returnstmt=n(RETURN),dowhilestmt=n(DOWHILELOOP),quantifier=n(QUANTIFIER);var parse_struct,parse_precision,parse_quantifier,parse_forloop,parse_if,parse_return,parse_whileloop,parse_dowhileloop,parse_function,parse_function_args;var stream=through(write,end),check=arguments.length?[].slice.call(arguments):[],depth=0,state=[],tokens=[],whitespace=[],errored=false,program,token,node;state.shift=special_shift;state.unshift=special_unshift;state.fake=special_fake;state.unexpected=unexpected;state.scope=new Scope(state);state.create_node=function(){var n=mknode(IDENT,token);n.parent=stream.program;return n};setup_stative_parsers();node=stmtlist();node.expecting="(eof)";node.mode=STMTLIST;node.token={type:"(program)",data:"(program)"};program=node;stream.program=program;stream.scope=function(scope){if(arguments.length===1){state.scope=scope}return state.scope};state.unshift(node);return stream;function write(input){if(input.type==="whitespace"||input.type==="line-comment"||input.type==="block-comment"){whitespace.push(input);return}tokens.push(input);token=token||tokens[0];if(token&&whitespace.length){token.preceding=token.preceding||[];token.preceding=token.preceding.concat(whitespace);whitespace=[]}while(take())switch(state[0].mode){case STMT:parse_stmt();break;case STMTLIST:parse_stmtlist();break;case DECL:parse_decl();break;case DECLLIST:parse_decllist();break;case EXPR:parse_expr();break;case STRUCT:parse_struct(true,true);break;case PRECISION:parse_precision();break;case IDENT:parse_ident();break;case KEYWORD:parse_keyword();break;case KEYWORD_OR_IDENT:parse_keyword_or_ident();break;case FUNCTION:parse_function();break;case FUNCTIONARGS:parse_function_args();break;case FORLOOP:parse_forloop();break;case WHILELOOP:parse_whileloop();break;case DOWHILELOOP:parse_dowhileloop();break;case RETURN:parse_return();break;case IF:parse_if();break;case QUANTIFIER:parse_quantifier();break}}function end(tokens){if(arguments.length){write(tokens)}if(state.length>1){unexpected("unexpected EOF");return}stream.emit("end")}function take(){if(errored||!state.length)return false;return(token=tokens[0])&&!stream.paused}function special_fake(x){state.unshift(x);state.shift()}function special_unshift(_node,add_child){_node.parent=state[0];var ret=[].unshift.call(this,_node);add_child=add_child===undefined?true:add_child;if(DEBUG){var pad="";for(var i=0,len=this.length-1;i<len;++i){pad+=" |"}console.log(pad,"\\"+_node.type,_node.token.data)}if(add_child&&node!==_node)node.children.push(_node);node=_node;return ret}function special_shift(){var _node=[].shift.call(this),okay=check[this.length],emit=false;if(DEBUG){var pad="";for(var i=0,len=this.length;i<len;++i){pad+=" |"}console.log(pad,"/"+_node.type)}if(check.length){if(typeof check[0]==="function"){emit=check[0](_node)}else if(okay!==undefined){emit=okay.test?okay.test(_node.type):okay===_node.type}}else{emit=true}if(emit)stream.emit("data",_node);node=_node.parent;return _node}function parse_stmtlist(){return stative(function(){state.scope.enter();return Advance},normal_mode)();function normal_mode(){if(token.data===state[0].expecting){return state.scope.exit(),state.shift()}switch(token.type){case"preprocessor":state.fake(adhoc());tokens.shift();return;default:state.unshift(stmt());return}}}function parse_stmt(){if(state[0].brace){if(token.data!=="}"){return unexpected("expected `}`, got "+token.data)}state[0].brace=false;return tokens.shift(),state.shift()}switch(token.type){case"eof":return state.shift();case"keyword":switch(token.data){case"for":return state.unshift(forstmt());case"if":return state.unshift(ifstmt());case"while":return state.unshift(whilestmt());case"do":return state.unshift(dowhilestmt());case"break":return state.fake(mknode(BREAK,token)),tokens.shift();case"continue":return state.fake(mknode(CONTINUE,token)),tokens.shift();case"discard":return state.fake(mknode(DISCARD,token)),tokens.shift();case"return":return state.unshift(returnstmt());case"precision":return state.unshift(precision())}return state.unshift(decl(DECL_STATEMENT));case"ident":var lookup;if(lookup=state.scope.find(token.data)){if(lookup.parent.type==="struct"){return state.unshift(decl(DECL_STATEMENT))}return state.unshift(expr(";"))}case"operator":if(token.data==="{"){state[0].brace=true;var n=stmtlist();n.expecting="}";return tokens.shift(),state.unshift(n)}if(token.data===";"){return tokens.shift(),state.shift()}default:return state.unshift(expr(";"))}}function parse_decl(){var stmt=state[0];return stative(invariant_or_not,storage_or_not,parameter_or_not,precision_or_not,struct_or_type,maybe_name,maybe_lparen,is_decllist,done)();function invariant_or_not(){if(token.data==="invariant"){if(stmt.flags&DECL_ALLOW_INVARIANT){state.unshift(keyword());return Advance}else{return unexpected("`invariant` is not allowed here")}}else{state.fake(mknode(PLACEHOLDER,{data:"",position:token.position}));return Advance}}function storage_or_not(){if(is_storage(token)){if(stmt.flags&DECL_ALLOW_STORAGE){state.unshift(keyword());return Advance}else{return unexpected("storage is not allowed here")}}else{state.fake(mknode(PLACEHOLDER,{data:"",position:token.position}));return Advance}}function parameter_or_not(){if(is_parameter(token)){if(!(stmt.flags&DECL_NO_INOUT)){state.unshift(keyword());return Advance}else{return unexpected("parameter is not allowed here")}}else{state.fake(mknode(PLACEHOLDER,{data:"",position:token.position}));return Advance}}function precision_or_not(){if(is_precision(token)){state.unshift(keyword());return Advance}else{state.fake(mknode(PLACEHOLDER,{data:"",position:token.position}));return Advance}}function struct_or_type(){if(token.data==="struct"){if(!(stmt.flags&DECL_ALLOW_STRUCT)){return unexpected("cannot nest structs")}state.unshift(struct());return Advance}if(token.type==="keyword"){state.unshift(keyword());return Advance}var lookup=state.scope.find(token.data);if(lookup){state.fake(Object.create(lookup));tokens.shift();return Advance}return unexpected("expected user defined type, struct or keyword, got "+token.data)}function maybe_name(){if(token.data===","&&!(stmt.flags&DECL_ALLOW_COMMA)){return state.shift()}if(token.data==="["){state.unshift(quantifier());return}if(token.data===")")return state.shift();if(token.data===";"){return stmt.stage+3}if(token.type!=="ident"&&token.type!=="builtin"){return unexpected("expected identifier, got "+token.data)}stmt.collected_name=tokens.shift();return Advance}function maybe_lparen(){if(token.data==="("){tokens.unshift(stmt.collected_name);delete stmt.collected_name;state.unshift(fn());return stmt.stage+2}return Advance}function is_decllist(){tokens.unshift(stmt.collected_name);delete stmt.collected_name;state.unshift(decllist());return Advance}function done(){return state.shift()}}function parse_decllist(){if(token.type==="ident"){var name=token.data;state.unshift(ident());state.scope.define(name);return}if(token.type==="operator"){if(token.data===","){if(!(state[1].flags&DECL_ALLOW_COMMA)){return state.shift()}return tokens.shift()}else if(token.data==="="){if(!(state[1].flags&DECL_ALLOW_ASSIGN))return unexpected("`=` is not allowed here.");tokens.shift();state.unshift(expr(",",";"));return}else if(token.data==="["){state.unshift(quantifier());return}}return state.shift()}function parse_keyword_or_ident(){if(token.type==="keyword"){state[0].type="keyword";state[0].mode=KEYWORD;return}if(token.type==="ident"){state[0].type="ident";state[0].mode=IDENT;return}return unexpected("expected keyword or user-defined name, got "+token.data)}function parse_keyword(){if(token.type!=="keyword"){return unexpected("expected keyword, got "+token.data)}return state.shift(),tokens.shift()}function parse_ident(){if(token.type!=="ident"){return unexpected("expected user-defined name, got "+token.data)}state[0].data=token.data;return state.shift(),tokens.shift()}function parse_expr(){var expecting=state[0].expecting;state[0].tokens=state[0].tokens||[];if(state[0].parenlevel===undefined){state[0].parenlevel=0;state[0].bracelevel=0}if(state[0].parenlevel<1&&expecting.indexOf(token.data)>-1){return parseexpr(state[0].tokens)}if(token.data==="("){++state[0].parenlevel}else if(token.data===")"){--state[0].parenlevel}switch(token.data){case"{":++state[0].bracelevel;break;case"}":--state[0].bracelevel;break;case"(":++state[0].parenlevel;break;case")":--state[0].parenlevel;break}if(state[0].parenlevel<0)return unexpected("unexpected `)`");if(state[0].bracelevel<0)return unexpected("unexpected `}`");state[0].tokens.push(tokens.shift());return;function parseexpr(tokens){return full_parse_expr(state,tokens),state.shift()}}function n(type){return function(){return mknode(type,token)}}function adhoc(){return mknode(token_map[token.type],token,node)}function decl(flags){var _=mknode(DECL,token,node);_.flags=flags;return _}function struct(allow_assign,allow_comma){var _=mknode(STRUCT,token,node);_.allow_assign=allow_assign===undefined?true:allow_assign;_.allow_comma=allow_comma===undefined?true:allow_comma;return _}function expr(){var n=mknode(EXPR,token,node);n.expecting=[].slice.call(arguments);return n}function keyword(default_value){var t=token;if(default_value){t={type:"(implied)",data:"(default)",position:t.position}}return mknode(KEYWORD,t,node)}function unexpected(str){errored=true;stream.emit("error",new Error((str||"unexpected "+state)+" at line "+state[0].token.line))}function assert(type,data){return 1,assert_null_string_or_array(type,token.type)&&assert_null_string_or_array(data,token.data)}function assert_null_string_or_array(x,y){switch(typeof x){case"string":if(y!==x){unexpected("expected `"+x+"`, got "+y+"\n"+token.data)}return!errored;case"object":if(x&&x.indexOf(y)===-1){unexpected("expected one of `"+x.join("`, `")+"`, got "+y)}return!errored}return true}function stative(){var steps=[].slice.call(arguments),step,result;return function(){var current=state[0];current.stage||(current.stage=0);step=steps[current.stage];if(!step)return unexpected("parser in undefined state!");result=step();if(result===Advance)return++current.stage;if(result===undefined)return;current.stage=result}}function advance(op,t){t=t||"operator";return function(){if(!assert(t,op))return;var last=tokens.shift(),children=state[0].children,last_node=children[children.length-1];if(last_node&&last_node.token&&last.preceding){last_node.token.succeeding=last_node.token.succeeding||[];last_node.token.succeeding=last_node.token.succeeding.concat(last.preceding)}return Advance}}function advance_expr(until){return function(){return state.unshift(expr(until)),Advance}}function advance_ident(declare){return declare?function(){var name=token.data;return assert("ident")&&(state.unshift(ident()),state.scope.define(name),Advance)}:function(){if(!assert("ident"))return;var s=Object.create(state.scope.find(token.data));s.token=token;return tokens.shift(),Advance}}function advance_stmtlist(){return function(){var n=stmtlist();n.expecting="}";return state.unshift(n),Advance}}function maybe_stmtlist(skip){return function(){var current=state[0].stage;if(token.data!=="{"){return state.unshift(stmt()),current+skip}return tokens.shift(),Advance}}function popstmt(){return function(){return state.shift(),state.shift()}}function setup_stative_parsers(){parse_struct=stative(advance("struct","keyword"),function(){if(token.data==="{"){state.fake(mknode(IDENT,{data:"",position:token.position,type:"ident"}));return Advance}return advance_ident(true)()},function(){state.scope.enter();return Advance},advance("{"),function(){if(token.type==="preprocessor"){state.fake(adhoc());tokens.shift();return}if(token.data==="}"){state.scope.exit();tokens.shift();return state.shift()}if(token.data===";"){tokens.shift();return}state.unshift(decl(DECL_STRUCT))});parse_precision=stative(function(){return tokens.shift(),Advance},function(){return assert("keyword",["lowp","mediump","highp"])&&(state.unshift(keyword()),Advance)},function(){return state.unshift(keyword()),Advance},function(){return state.shift()});parse_quantifier=stative(advance("["),advance_expr("]"),advance("]"),function(){return state.shift()});parse_forloop=stative(advance("for","keyword"),advance("("),function(){var lookup;if(token.type==="ident"){if(!(lookup=state.scope.find(token.data))){lookup=state.create_node()}if(lookup.parent.type==="struct"){return state.unshift(decl(DECL_STATEMENT)),Advance}}else if(token.type==="builtin"||token.type==="keyword"){return state.unshift(decl(DECL_STATEMENT)),Advance}return advance_expr(";")()},advance(";"),advance_expr(";"),advance(";"),advance_expr(")"),advance(")"),maybe_stmtlist(3),advance_stmtlist(),advance("}"),popstmt());parse_if=stative(advance("if","keyword"),advance("("),advance_expr(")"),advance(")"),maybe_stmtlist(3),advance_stmtlist(),advance("}"),function(){if(token.data==="else"){return tokens.shift(),state.unshift(stmt()),Advance}return popstmt()()},popstmt());parse_return=stative(advance("return","keyword"),function(){if(token.data===";")return Advance;return state.unshift(expr(";")),Advance},function(){tokens.shift(),popstmt()()});parse_whileloop=stative(advance("while","keyword"),advance("("),advance_expr(")"),advance(")"),maybe_stmtlist(3),advance_stmtlist(),advance("}"),popstmt());parse_dowhileloop=stative(advance("do","keyword"),maybe_stmtlist(3),advance_stmtlist(),advance("}"),advance("while","keyword"),advance("("),advance_expr(")"),advance(")"),popstmt());parse_function=stative(function(){for(var i=1,len=state.length;i<len;++i)if(state[i].mode===FUNCTION){return unexpected("function definition is not allowed within another function")}return Advance},function(){if(!assert("ident"))return;var name=token.data,lookup=state.scope.find(name);state.unshift(ident());state.scope.define(name);state.scope.enter(lookup?lookup.scope:null);return Advance},advance("("),function(){return state.unshift(fnargs()),Advance},advance(")"),function(){if(token.data===";"){return state.scope.exit(),state.shift(),state.shift()}return Advance},advance("{"),advance_stmtlist(),advance("}"),function(){state.scope.exit();return Advance},function(){return state.shift(),state.shift(),state.shift()});parse_function_args=stative(function(){if(token.data==="void"){state.fake(keyword());tokens.shift();return Advance}if(token.data===")"){state.shift();return}if(token.data==="struct"){state.unshift(struct(NO_ASSIGN_ALLOWED,NO_COMMA_ALLOWED));return Advance}state.unshift(decl(DECL_FUNCTION));return Advance},function(){if(token.data===","){tokens.shift();return 0}if(token.data===")"){state.shift();return}unexpected("expected one of `,` or `)`, got "+token.data)})}}function mknode(mode,sourcetoken){return{mode:mode,token:sourcetoken,children:[],type:stmt_type[mode],id:(Math.random()*4294967295).toString(16)}}function is_storage(token){return token.data==="const"||token.data==="attribute"||token.data==="uniform"||token.data==="varying"}function is_parameter(token){return token.data==="in"||token.data==="inout"||token.data==="out"}function is_precision(token){return token.data==="highp"||token.data==="mediump"||token.data==="lowp"}},{"./expr":25,"./scope":27,through:28}],27:[function(require,module,exports){module.exports=scope;function scope(state){if(this.constructor!==scope)return new scope(state);this.state=state;this.scopes=[];this.current=null}var cons=scope,proto=cons.prototype;proto.enter=function(s){this.scopes.push(this.current=this.state[0].scope=s||{})};proto.exit=function(){this.scopes.pop();this.current=this.scopes[this.scopes.length-1]};proto.define=function(str){this.current[str]=this.state[0]};proto.find=function(name,fail){for(var i=this.scopes.length-1;i>-1;--i){if(this.scopes[i].hasOwnProperty(name)){return this.scopes[i][name]
}}return null}},{}],28:[function(require,module,exports){(function(process){var Stream=require("stream");exports=module.exports=through;through.through=through;function through(write,end){write=write||function(data){this.emit("data",data)};end=end||function(){this.emit("end")};var ended=false,destroyed=false;var stream=new Stream,buffer=[];stream.buffer=buffer;stream.readable=stream.writable=true;stream.paused=false;stream.write=function(data){write.call(this,data);return!stream.paused};function drain(){while(buffer.length&&!stream.paused){var data=buffer.shift();if(null===data)return stream.emit("end");else stream.emit("data",data)}}stream.queue=function(data){buffer.push(data);drain()};stream.on("end",function(){stream.readable=false;if(!stream.writable)process.nextTick(function(){stream.destroy()})});function _end(){stream.writable=false;end.call(stream);if(!stream.readable)stream.destroy()}stream.end=function(data){if(ended)return;ended=true;if(arguments.length)stream.write(data);_end()};stream.destroy=function(){if(destroyed)return;destroyed=true;ended=true;buffer.length=0;stream.writable=stream.readable=false;stream.emit("close")};stream.pause=function(){if(stream.paused)return;stream.paused=true;stream.emit("pause")};stream.resume=function(){if(stream.paused){stream.paused=false}drain();if(!stream.paused)stream.emit("drain")};return stream}}).call(this,require("_process"))},{_process:8,stream:20}],29:[function(require,module,exports){module.exports=tokenize;var through=require("through");var literals=require("./lib/literals"),operators=require("./lib/operators"),builtins=require("./lib/builtins");var NORMAL=999,TOKEN=9999,BLOCK_COMMENT=0,LINE_COMMENT=1,PREPROCESSOR=2,OPERATOR=3,INTEGER=4,FLOAT=5,IDENT=6,BUILTIN=7,KEYWORD=8,WHITESPACE=9,EOF=10,HEX=11;var map=["block-comment","line-comment","preprocessor","operator","integer","float","ident","builtin","keyword","whitespace","eof","integer"];function tokenize(){var stream=through(write,end);var i=0,total=0,mode=NORMAL,c,last,content=[],token_idx=0,token_offs=0,line=1,start=0,isnum=false,isoperator=false,input="",len;return stream;function token(data){if(data.length){stream.queue({type:map[mode],data:data,position:start,line:line})}}function write(chunk){i=0;input+=chunk.toString();len=input.length;while(c=input[i],i<len)switch(mode){case BLOCK_COMMENT:i=block_comment();break;case LINE_COMMENT:i=line_comment();break;case PREPROCESSOR:i=preprocessor();break;case OPERATOR:i=operator();break;case INTEGER:i=integer();break;case HEX:i=hex();break;case FLOAT:i=decimal();break;case TOKEN:i=readtoken();break;case WHITESPACE:i=whitespace();break;case NORMAL:i=normal();break}total+=i;input=input.slice(i)}function end(chunk){if(content.length){token(content.join(""))}mode=EOF;token("(eof)");stream.queue(null)}function normal(){content=content.length?[]:content;if(last==="/"&&c==="*"){start=total+i-1;mode=BLOCK_COMMENT;last=c;return i+1}if(last==="/"&&c==="/"){start=total+i-1;mode=LINE_COMMENT;last=c;return i+1}if(c==="#"){mode=PREPROCESSOR;start=total+i;return i}if(/\s/.test(c)){mode=WHITESPACE;start=total+i;return i}isnum=/\d/.test(c);isoperator=/[^\w_]/.test(c);start=total+i;mode=isnum?INTEGER:isoperator?OPERATOR:TOKEN;return i}function whitespace(){if(c==="\n")++line;if(/[^\s]/g.test(c)){token(content.join(""));mode=NORMAL;return i}content.push(c);last=c;return i+1}function preprocessor(){if(c==="\n")++line;if(c==="\n"&&last!=="\\"){token(content.join(""));mode=NORMAL;return i}content.push(c);last=c;return i+1}function line_comment(){return preprocessor()}function block_comment(){if(c==="/"&&last==="*"){content.push(c);token(content.join(""));mode=NORMAL;return i+1}if(c==="\n")++line;content.push(c);last=c;return i+1}function operator(){if(last==="."&&/\d/.test(c)){mode=FLOAT;return i}if(last==="/"&&c==="*"){mode=BLOCK_COMMENT;return i}if(last==="/"&&c==="/"){mode=LINE_COMMENT;return i}if(c==="."&&content.length){while(determine_operator(content));mode=FLOAT;return i}if(c===";"||c===")"||c==="("){if(content.length)while(determine_operator(content));token(c);mode=NORMAL;return i+1}var is_composite_operator=content.length===2&&c!=="=";if(/[\w_\d\s]/.test(c)||is_composite_operator){while(determine_operator(content));mode=NORMAL;return i}content.push(c);last=c;return i+1}function determine_operator(buf){var j=0,idx;do{idx=operators.indexOf(buf.slice(0,buf.length+j).join(""));if(idx===-1){j-=1;continue}token(operators[idx]);start+=operators[idx].length;content=content.slice(operators[idx].length);return content.length}while(1)}function hex(){if(/[^a-fA-F0-9]/.test(c)){token(content.join(""));mode=NORMAL;return i}content.push(c);last=c;return i+1}function integer(){if(c==="."){content.push(c);mode=FLOAT;last=c;return i+1}if(/[eE]/.test(c)){content.push(c);mode=FLOAT;last=c;return i+1}if(c==="x"&&content.length===1&&content[0]==="0"){mode=HEX;content.push(c);last=c;return i+1}if(/[^\d]/.test(c)){token(content.join(""));mode=NORMAL;return i}content.push(c);last=c;return i+1}function decimal(){if(c==="f"){content.push(c);last=c;i+=1}if(/[eE]/.test(c)){content.push(c);last=c;return i+1}if(/[^\d]/.test(c)){token(content.join(""));mode=NORMAL;return i}content.push(c);last=c;return i+1}function readtoken(){if(/[^\d\w_]/.test(c)){var contentstr=content.join("");if(literals.indexOf(contentstr)>-1){mode=KEYWORD}else if(builtins.indexOf(contentstr)>-1){mode=BUILTIN}else{mode=IDENT}token(content.join(""));mode=NORMAL;return i}content.push(c);last=c;return i+1}}},{"./lib/builtins":30,"./lib/literals":31,"./lib/operators":32,through:33}],30:[function(require,module,exports){module.exports=["gl_Position","gl_PointSize","gl_ClipVertex","gl_FragCoord","gl_FrontFacing","gl_FragColor","gl_FragData","gl_FragDepth","gl_Color","gl_SecondaryColor","gl_Normal","gl_Vertex","gl_MultiTexCoord0","gl_MultiTexCoord1","gl_MultiTexCoord2","gl_MultiTexCoord3","gl_MultiTexCoord4","gl_MultiTexCoord5","gl_MultiTexCoord6","gl_MultiTexCoord7","gl_FogCoord","gl_MaxLights","gl_MaxClipPlanes","gl_MaxTextureUnits","gl_MaxTextureCoords","gl_MaxVertexAttribs","gl_MaxVertexUniformComponents","gl_MaxVaryingFloats","gl_MaxVertexTextureImageUnits","gl_MaxCombinedTextureImageUnits","gl_MaxTextureImageUnits","gl_MaxFragmentUniformComponents","gl_MaxDrawBuffers","gl_ModelViewMatrix","gl_ProjectionMatrix","gl_ModelViewProjectionMatrix","gl_TextureMatrix","gl_NormalMatrix","gl_ModelViewMatrixInverse","gl_ProjectionMatrixInverse","gl_ModelViewProjectionMatrixInverse","gl_TextureMatrixInverse","gl_ModelViewMatrixTranspose","gl_ProjectionMatrixTranspose","gl_ModelViewProjectionMatrixTranspose","gl_TextureMatrixTranspose","gl_ModelViewMatrixInverseTranspose","gl_ProjectionMatrixInverseTranspose","gl_ModelViewProjectionMatrixInverseTranspose","gl_TextureMatrixInverseTranspose","gl_NormalScale","gl_DepthRangeParameters","gl_DepthRange","gl_ClipPlane","gl_PointParameters","gl_Point","gl_MaterialParameters","gl_FrontMaterial","gl_BackMaterial","gl_LightSourceParameters","gl_LightSource","gl_LightModelParameters","gl_LightModel","gl_LightModelProducts","gl_FrontLightModelProduct","gl_BackLightModelProduct","gl_LightProducts","gl_FrontLightProduct","gl_BackLightProduct","gl_FogParameters","gl_Fog","gl_TextureEnvColor","gl_EyePlaneS","gl_EyePlaneT","gl_EyePlaneR","gl_EyePlaneQ","gl_ObjectPlaneS","gl_ObjectPlaneT","gl_ObjectPlaneR","gl_ObjectPlaneQ","gl_FrontColor","gl_BackColor","gl_FrontSecondaryColor","gl_BackSecondaryColor","gl_TexCoord","gl_FogFragCoord","gl_Color","gl_SecondaryColor","gl_TexCoord","gl_FogFragCoord","gl_PointCoord","radians","degrees","sin","cos","tan","asin","acos","atan","pow","exp","log","exp2","log2","sqrt","inversesqrt","abs","sign","floor","ceil","fract","mod","min","max","clamp","mix","step","smoothstep","length","distance","dot","cross","normalize","faceforward","reflect","refract","matrixCompMult","lessThan","lessThanEqual","greaterThan","greaterThanEqual","equal","notEqual","any","all","not","texture2D","texture2DProj","texture2DLod","texture2DProjLod","textureCube","textureCubeLod"]},{}],31:[function(require,module,exports){module.exports=["precision","highp","mediump","lowp","attribute","const","uniform","varying","break","continue","do","for","while","if","else","in","out","inout","float","int","void","bool","true","false","discard","return","mat2","mat3","mat4","vec2","vec3","vec4","ivec2","ivec3","ivec4","bvec2","bvec3","bvec4","sampler1D","sampler2D","sampler3D","samplerCube","sampler1DShadow","sampler2DShadow","struct","asm","class","union","enum","typedef","template","this","packed","goto","switch","default","inline","noinline","volatile","public","static","extern","external","interface","long","short","double","half","fixed","unsigned","input","output","hvec2","hvec3","hvec4","dvec2","dvec3","dvec4","fvec2","fvec3","fvec4","sampler2DRect","sampler3DRect","sampler2DRectShadow","sizeof","cast","namespace","using"]},{}],32:[function(require,module,exports){module.exports=["<<=",">>=","++","--","<<",">>","<=",">=","==","!=","&&","||","+=","-=","*=","/=","%=","&=","^=","|=","(",")","[","]",".","!","~","*","/","%","+","-","<",">","&","^","|","?",":","=",",",";","{","}"]},{}],33:[function(require,module,exports){(function(process){var Stream=require("stream");exports=module.exports=through;through.through=through;function through(write,end,opts){write=write||function(data){this.queue(data)};end=end||function(){this.queue(null)};var ended=false,destroyed=false,buffer=[],_ended=false;var stream=new Stream;stream.readable=stream.writable=true;stream.paused=false;stream.autoDestroy=!(opts&&opts.autoDestroy===false);stream.write=function(data){write.call(this,data);return!stream.paused};function drain(){while(buffer.length&&!stream.paused){var data=buffer.shift();if(null===data)return stream.emit("end");else stream.emit("data",data)}}stream.queue=stream.push=function(data){if(_ended)return stream;if(data==null)_ended=true;buffer.push(data);drain();return stream};stream.on("end",function(){stream.readable=false;if(!stream.writable&&stream.autoDestroy)process.nextTick(function(){stream.destroy()})});function _end(){stream.writable=false;end.call(stream);if(!stream.readable&&stream.autoDestroy)stream.destroy()}stream.end=function(data){if(ended)return;ended=true;if(arguments.length)stream.write(data);_end();return stream};stream.destroy=function(){if(destroyed)return;destroyed=true;ended=true;buffer.length=0;stream.writable=stream.readable=false;stream.emit("close");return stream};stream.pause=function(){if(stream.paused)return;stream.paused=true;return stream};stream.resume=function(){if(stream.paused){stream.paused=false;stream.emit("resume")}drain();if(!stream.paused)stream.emit("drain");return stream};return stream}}).call(this,require("_process"))},{_process:8,stream:20}],34:[function(require,module,exports){"use strict";function unique_pred(list,compare){var ptr=1,len=list.length,a=list[0],b=list[0];for(var i=1;i<len;++i){b=a;a=list[i];if(compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}}list.length=ptr;return list}function unique_eq(list){var ptr=1,len=list.length,a=list[0],b=list[0];for(var i=1;i<len;++i,b=a){b=a;a=list[i];if(a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}}list.length=ptr;return list}function unique(list,compare,sorted){if(list.length===0){return[]}if(compare){if(!sorted){list.sort(compare)}return unique_pred(list,compare)}if(!sorted){list.sort()}return unique_eq(list)}module.exports=unique},{}],"simple-3d-shader":[function(require,module,exports){"use strict";var createShader=require("gl-shader");module.exports=function createSimple3DShader(gl){return createShader(gl,"attribute vec3 position;attribute vec3 color;uniform mat4 model;uniform mat4 view;uniform mat4 projection;varying vec3 fragColor;void main() { gl_Position = projection * view * model * vec4(position,1); fragColor = color;}","precision highp float;varying vec3 fragColor;void main() { gl_FragColor = vec4(fragColor, 1.0);}")}},{"gl-shader":22}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&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}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var base64=require("base64-js");var ieee754=require("ieee754");var isArray=require("is-array");exports.Buffer=Buffer;exports.SlowBuffer=SlowBuffer;exports.INSPECT_MAX_BYTES=50;Buffer.poolSize=8192;var kMaxLength=1073741823;var rootParent={};Buffer.TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0);var arr=new Uint8Array(buf);arr.foo=function(){return 42};return 42===arr.foo()&&typeof arr.subarray==="function"&&new Uint8Array(1).subarray(1,1).byteLength===0}catch(e){return false}}();function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var type=typeof subject;var length;if(type==="number")length=subject>0?subject>>>0:0;else if(type==="string"){length=Buffer.byteLength(subject,encoding)}else if(type==="object"&&subject!==null){if(subject.type==="Buffer"&&isArray(subject.data))subject=subject.data;length=+subject.length>0?Math.floor(+subject.length):0}else throw new TypeError("must start with number, buffer, array or string");if(length>kMaxLength)throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+kMaxLength.toString(16)+" bytes");var buf;if(Buffer.TYPED_ARRAY_SUPPORT){buf=Buffer._augment(new Uint8Array(length))}else{buf=this;buf.length=length;buf._isBuffer=true}var i;if(Buffer.TYPED_ARRAY_SUPPORT&&typeof subject.byteLength==="number"){buf._set(subject)}else if(isArrayish(subject)){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"&&!Buffer.TYPED_ARRAY_SUPPORT&&!noZero){for(i=0;i<length;i++){buf[i]=0}}if(length>0&&length<=Buffer.poolSize)buf.parent=rootParent;return buf}function SlowBuffer(subject,encoding,noZero){if(!(this instanceof SlowBuffer))return new SlowBuffer(subject,encoding,noZero);var buf=new Buffer(subject,encoding,noZero);delete buf.parent;return buf}Buffer.isBuffer=function(b){return!!(b!=null&&b._isBuffer)};Buffer.compare=function(a,b){if(!Buffer.isBuffer(a)||!Buffer.isBuffer(b))throw new TypeError("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.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.concat=function(list,totalLength){if(!isArray(list))throw new TypeError("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.byteLength=function(str,encoding){var ret;str=str+"";switch(encoding||"utf8"){case"ascii":case"binary":case"raw":ret=str.length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=str.length*2;break;case"hex":ret=str.length>>>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=undefined;Buffer.prototype.parent=undefined;Buffer.prototype.toString=function(encoding,start,end){var loweredCase=false;start=start>>>0;end=end===undefined||end===Infinity?this.length:end>>>0;if(!encoding)encoding="utf8";if(start<0)start=0;if(end>this.length)end=this.length;if(end<=start)return"";while(true){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=true}}};Buffer.prototype.equals=function(b){if(!Buffer.isBuffer(b))throw new TypeError("Argument must be a Buffer");return Buffer.compare(this,b)===0};Buffer.prototype.inspect=function(){var str="";var max=exports.INSPECT_MAX_BYTES;if(this.length>0){str=this.toString("hex",0,max).match(/.{2}/g).join(" ");if(this.length>max)str+=" ... "}return"<Buffer "+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){console.log(".get() is deprecated. Access using array indexes instead.");return this.readUInt8(offset)};Buffer.prototype.set=function(v,offset){console.log(".set() is deprecated. Access using array indexes instead.");return this.writeUInt8(v,offset)};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}}var strLen=string.length;if(strLen%2!==0)throw new Error("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);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}Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset)){if(!isFinite(length)){encoding=length;length=undefined}}else{var swap=encoding;encoding=offset;offset=length;length=swap}offset=Number(offset)||0;if(length<0||offset<0||offset>this.length)throw new RangeError("attempt to write outside buffer bounds");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 TypeError("Unknown encoding: "+encoding)}return ret};Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};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]<=127){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]&127)}return ret}function binarySlice(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 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;var newBuf;if(Buffer.TYPED_ARRAY_SUPPORT){newBuf=Buffer._augment(this.subarray(start,end))}else{var sliceLen=end-start;newBuf=new Buffer(sliceLen,undefined,true);for(var i=0;i<sliceLen;i++){newBuf[i]=this[i+start]}}if(newBuf.length)newBuf.parent=this.parent||this;return newBuf};function checkOffset(offset,ext,length){if(offset%1!==0||offset<0)throw new RangeError("offset is not uint");if(offset+ext>length)throw new RangeError("Trying to access beyond buffer length")}Buffer.prototype.readUIntLE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i<byteLength&&(mul*=256))val+=this[offset+i]*mul;return val};Buffer.prototype.readUIntBE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset+--byteLength];var mul=1;while(byteLength>0&&(mul*=256))val+=this[offset+--byteLength]*mul;return val};Buffer.prototype.readUInt8=function(offset,noAssert){if(!noAssert)checkOffset(offset,1,this.length);return this[offset]};Buffer.prototype.readUInt16LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);return this[offset]|this[offset+1]<<8};Buffer.prototype.readUInt16BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);return this[offset]<<8|this[offset+1]};Buffer.prototype.readUInt32LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return(this[offset]|this[offset+1]<<8|this[offset+2]<<16)+this[offset+3]*16777216};Buffer.prototype.readUInt32BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]*16777216+(this[offset+1]<<16|this[offset+2]<<8|this[offset+3])};Buffer.prototype.readIntLE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i<byteLength&&(mul*=256))val+=this[offset+i]*mul;mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readIntBE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var i=byteLength;var mul=1;var val=this[offset+--i];while(i>0&&(mul*=256))val+=this[offset+--i]*mul;mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readInt8=function(offset,noAssert){if(!noAssert)checkOffset(offset,1,this.length);if(!(this[offset]&128))return this[offset];return(255-this[offset]+1)*-1};Buffer.prototype.readInt16LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset]|this[offset+1]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt16BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset+1]|this[offset]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt32LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]|this[offset+1]<<8|this[offset+2]<<16|this[offset+3]<<24};Buffer.prototype.readInt32BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]<<24|this[offset+1]<<16|this[offset+2]<<8|this[offset+3]};Buffer.prototype.readFloatLE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,true,23,4)};Buffer.prototype.readFloatBE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,false,23,4)};Buffer.prototype.readDoubleLE=function(offset,noAssert){if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,true,52,8)};Buffer.prototype.readDoubleBE=function(offset,noAssert){if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,false,52,8)};function checkInt(buf,value,offset,ext,max,min){if(!Buffer.isBuffer(buf))throw new TypeError("buffer must be a Buffer instance");if(value>max||value<min)throw new RangeError("value is out of bounds");if(offset+ext>buf.length)throw new RangeError("index out of range")}Buffer.prototype.writeUIntLE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength),0);var mul=1;var i=0;this[offset]=value&255;while(++i<byteLength&&(mul*=256))this[offset+i]=value/mul>>>0&255;return offset+byteLength};Buffer.prototype.writeUIntBE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength),0);var i=byteLength-1;var mul=1;this[offset+i]=value&255;while(--i>=0&&(mul*=256))this[offset+i]=value/mul>>>0&255;return offset+byteLength};Buffer.prototype.writeUInt8=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,255,0);if(!Buffer.TYPED_ARRAY_SUPPORT)value=Math.floor(value);this[offset]=value;return offset+1};function objectWriteUInt16(buf,value,offset,littleEndian){if(value<0)value=65535+value+1;for(var i=0,j=Math.min(buf.length-offset,2);i<j;i++){buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>(littleEndian?i:1-i)*8}}Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value;this[offset+1]=value>>>8}else objectWriteUInt16(this,value,offset,true);return offset+2};Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>8;this[offset+1]=value}else objectWriteUInt16(this,value,offset,false);return offset+2};function objectWriteUInt32(buf,value,offset,littleEndian){if(value<0)value=4294967295+value+1;for(var i=0,j=Math.min(buf.length-offset,4);i<j;i++){buf[offset+i]=value>>>(littleEndian?i:3-i)*8&255}}Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset+3]=value>>>24;this[offset+2]=value>>>16;this[offset+1]=value>>>8;this[offset]=value}else objectWriteUInt32(this,value,offset,true);return offset+4};Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value}else objectWriteUInt32(this,value,offset,false);return offset+4};Buffer.prototype.writeIntLE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength-1)-1,-Math.pow(2,8*byteLength-1))}var i=0;var mul=1;var sub=value<0?1:0;this[offset]=value&255;while(++i<byteLength&&(mul*=256))this[offset+i]=(value/mul>>0)-sub&255;return offset+byteLength};Buffer.prototype.writeIntBE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength-1)-1,-Math.pow(2,8*byteLength-1))}var i=byteLength-1;var mul=1;var sub=value<0?1:0;this[offset+i]=value&255;while(--i>=0&&(mul*=256))this[offset+i]=(value/mul>>0)-sub&255;return offset+byteLength};Buffer.prototype.writeInt8=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,127,-128);if(!Buffer.TYPED_ARRAY_SUPPORT)value=Math.floor(value);if(value<0)value=255+value+1;this[offset]=value;return offset+1};Buffer.prototype.writeInt16LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value;this[offset+1]=value>>>8}else objectWriteUInt16(this,value,offset,true);return offset+2};Buffer.prototype.writeInt16BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>8;this[offset+1]=value}else objectWriteUInt16(this,value,offset,false);return offset+2};Buffer.prototype.writeInt32LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value;this[offset+1]=value>>>8;this[offset+2]=value>>>16;this[offset+3]=value>>>24}else objectWriteUInt32(this,value,offset,true);return offset+4};Buffer.prototype.writeInt32BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(value<0)value=4294967295+value+1;if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value}else objectWriteUInt32(this,value,offset,false);return offset+4};function checkIEEE754(buf,value,offset,ext,max,min){if(value>max||value<min)throw new RangeError("value is out of bounds");if(offset+ext>buf.length)throw new RangeError("index out of range");if(offset<0)throw new RangeError("index out of range")}function writeFloat(buf,value,offset,littleEndian,noAssert){if(!noAssert)checkIEEE754(buf,value,offset,4,3.4028234663852886e38,-3.4028234663852886e38);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)checkIEEE754(buf,value,offset,8,1.7976931348623157e308,-1.7976931348623157e308);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)};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.length)target_start=target.length;if(!target_start)target_start=0;if(end>0&&end<start)end=start;if(end===start)return 0;if(target.length===0||source.length===0)return 0;if(target_start<0)throw new RangeError("targetStart out of bounds");if(start<0||start>=source.length)throw new RangeError("sourceStart out of bounds");if(end<0)throw new RangeError("sourceEnd out of bounds");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<1e3||!Buffer.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)}return len};Buffer.prototype.fill=function(value,start,end){if(!value)value=0;if(!start)start=0;if(!end)end=this.length;if(end<start)throw new RangeError("end < start");if(end===start)return;if(this.length===0)return;if(start<0||start>=this.length)throw new RangeError("start out of bounds");if(end<0||end>this.length)throw new RangeError("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.toArrayBuffer=function(){if(typeof Uint8Array!=="undefined"){if(Buffer.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 TypeError("Buffer.toArrayBuffer not supported in this browser")}};var BP=Buffer.prototype;Buffer._augment=function(arr){arr.constructor=Buffer;arr._isBuffer=true;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;return arr};var INVALID_BASE64_RE=/[^+\/0-9A-z\-]/g;function base64clean(str){str=stringtrim(str).replace(INVALID_BASE64_RE,"");if(str.length<2)return"";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 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(string,units){var codePoint,length=string.length;var leadSurrogate=null;units=units||Infinity;var bytes=[];var i=0;for(;i<length;i++){codePoint=string.charCodeAt(i);if(codePoint>55295&&codePoint<57344){if(leadSurrogate){if(codePoint<56320){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=codePoint;continue}else{codePoint=leadSurrogate-55296<<10|codePoint-56320|65536;leadSurrogate=null}}else{if(codePoint>56319){if((units-=3)>-1)bytes.push(239,191,189);continue}else if(i+1===length){if((units-=3)>-1)bytes.push(239,191,189);continue}else{leadSurrogate=codePoint;continue}}}else if(leadSurrogate){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=null}if(codePoint<128){if((units-=1)<0)break;bytes.push(codePoint)}else if(codePoint<2048){if((units-=2)<0)break;bytes.push(codePoint>>6|192,codePoint&63|128)}else if(codePoint<65536){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,codePoint&63|128)}else if(codePoint<2097152){if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,codePoint&63|128)}else{throw new Error("Invalid code point")}}return bytes}function asciiToBytes(str){var byteArray=[];for(var i=0;i<str.length;i++){byteArray.push(str.charCodeAt(i)&255)}return byteArray}function utf16leToBytes(str,units){var c,hi,lo;var byteArray=[];for(var i=0;i<str.length;i++){if((units-=2)<0)break;c=str.charCodeAt(i);hi=c>>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){if(unitSize)length-=length%unitSize;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(65533)}}},{"base64-js":2,ieee754:3,"is-array":4}],2:[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);var PLUS_URL_SAFE="-".charCodeAt(0);var SLASH_URL_SAFE="_".charCodeAt(0);function decode(elt){var code=elt.charCodeAt(0);if(code===PLUS||code===PLUS_URL_SAFE)return 62;if(code===SLASH||code===SLASH_URL_SAFE)return 63;if(code<NUMBER)return-1;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")}var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0;arr=new Arr(b64.length*3/4-placeHolders);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&16711680)>>16);push((tmp&65280)>>8);push(tmp&255)}if(placeHolders===2){tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4;push(tmp&255)}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&255);push(tmp&255)}return arr}function uint8ToBase64(uint8){var i,extraBytes=uint8.length%3,output="",temp,length;function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(num&63)}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)}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+="=";break}return output}exports.toByteArray=b64ToByteArray;exports.fromByteArray=uint8ToBase64})(typeof exports==="undefined"?this.base64js={}:exports)},{}],3:[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&255,i+=d,m/=256,mLen-=8);e=e<<mLen|m;eLen+=mLen;for(;eLen>0;buffer[offset+i]=e&255,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=s*128}},{}],4:[function(require,module,exports){var isArray=Array.isArray;var str=Object.prototype.toString;module.exports=isArray||function(val){return!!val&&"[object Array]"==str.call(val)}},{}],5:[function(require,module,exports){"use strict";function Mesh(gl,mode,numElements,vao,elements,attributes,attributeNames){this.gl=gl;this.mode=mode;this.numElements=numElements;this.vao=vao;this.elements=elements;this.attributes=attributes;this.attributeNames=attributeNames}Mesh.prototype.bind=function(shader){this.vao.bind();var attributeNames=this.attributeNames;var nattribs=attributeNames.length;for(var i=0;i<nattribs;++i){var sattrib=shader.attributes[attributeNames[i]];if(sattrib){sattrib.location=i}}};Mesh.prototype.unbind=function(){this.vao.unbind()};Mesh.prototype.dispose=function(){this.vao.dispose();if(this.elements){this.elements.dispose()}var attributes=this.attributes;var n=attributes.length;for(var i=0;i<n;++i){var attrib=attributes[i];if(attrib.buffer){attrib.buffer.dispose()}}};Mesh.prototype.draw=function(){if(this.elements){this.elements.draw(this.mode,this.numElements)}else{this.gl.drawArrays(this.mode,0,this.numElements)}};module.exports=Mesh},{}],6:[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<n;++i){res[i]=array[i]}return res}GLBuffer.prototype.update=function(array,offset){if(!offset){offset=0}this.bind();if(typeof array==="number"){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(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:16,"ndarray-ops":11,"typedarray-pool":20}],7:[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<attributes.length;++i){var attrib=attributes[i];if(attrib.buffer){var buffer=attrib.buffer;var size=attrib.size||4;var type=attrib.type||gl.FLOAT;var normalized=!!attrib.normalized;var stride=attrib.stride||0;var offset=attrib.offset||0;buffer.bind();gl.vertexAttribPointer(i,size,type,normalized,stride,offset);gl.enableVertexAttribArray(i)}else{if(typeof attrib==="number"){gl.vertexAttrib1f(i,attrib)}else if(attrib.length===1){gl.vertexAttrib1f(i,attrib[0])}else if(attrib.length===2){gl.vertexAttrib2f(i,attrib[0],attrib[1])}else if(attrib.length===3){gl.vertexAttrib3f(i,attrib[0],attrib[1],attrib[2])}else if(attrib.length===4){gl.vertexAttrib4f(i,attrib[0],attrib[1],attrib[2],attrib[3])}else{throw new Error("Invalid vertex attribute")}gl.disableVertexAttribArray(i)}}for(;i<nattribs;++i){gl.disableVertexAttribArray(i)}}else{gl.bindBuffer(gl.ARRAY_BUFFER,null);for(var i=0;i<nattribs;++i){gl.disableVertexAttribArray(i)}}}module.exports=doBind},{}],8:[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(elements,attributes){this.elements=elements;this.attributes=attributes};VAOEmulated.prototype.dispose=function(){};VAOEmulated.prototype.unbind=function(){};function createVAOEmulated(gl){return new VAOEmulated(gl)}module.exports=createVAOEmulated},{"./do-bind.js":7}],9:[function(require,module,exports){"use strict";var bindAttribs=require("./do-bind.js");function VAONative(gl,ext,handle){this.gl=gl;this.ext=ext;this.handle=handle}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()};function createVAONative(gl,ext){return new VAONative(gl,ext,ext.createVertexArrayOES())}module.exports=createVAONative},{"./do-bind.js":7}],10:[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,elements,attributes){var ext=webglew(gl).OES_vertex_array_object;var vao;if(ext){vao=createVAONative(gl,ext)}else{vao=createVAOEmulated(gl)}vao.update(elements,attributes);return vao}module.exports=createVAO},{"./lib/vao-emulated.js":8,"./lib/vao-native.js":9,webglew:21}],11:[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<x.args.length;++i){var a=x.args[i];if(i===0){x.args[i]={name:a,lvalue:true,rvalue:!!x.rvalue,count:x.count||1}}else{x.args[i]={name:a,lvalue:false,rvalue:true,count:1}}}if(!x.thisVars){x.thisVars=[]}if(!x.localVars){x.localVars=[]}return x}function pcompile(user_args){return compile({args:user_args.args,pre:fixup(user_args.pre),body:fixup(user_args.body),post:fixup(user_args.proc),funcName:user_args.funcName})}function makeOp(user_args){var args=[];for(var i=0;i<user_args.args.length;++i){args.push("a"+i)}var wrapper=new Function("P",["return function ",user_args.funcName,"_ndarrayops(",args.join(","),") {P(",args.join(","),");return a0}"].join(""));return wrapper(pcompile(user_args))}var assign_ops={add:"+",sub:"-",mul:"*",div:"/",mod:"%",band:"&",bor:"|",bxor:"^",lshift:"<<",rshift:">>",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;i<math_unary.length;++i){var f=math_unary[i];exports[f]=makeOp({args:["array","array"],pre:{args:[],body:"this_f=Math."+f,thisVars:["this_f"]},body:{args:["a","b"],body:"a=this_f(b)",thisVars:["this_f"]},funcName:f});exports[f+"eq"]=makeOp({args:["array"],pre:{args:[],body:"this_f=Math."+f,thisVars:["this_f"]},body:{args:["a"],body:"a=this_f(a)",thisVars:["this_f"]},rvalue:true,count:2,funcName:f+"eq"})}})();var math_comm=["max","min","atan2","pow"];(function(){for(var i=0;i<math_comm.length;++i){var f=math_comm[i];exports[f]=makeOp({args:["array","array","array"],pre:{args:[],body:"this_f=Math."+f,thisVars:["this_f"]},body:{args:["a","b","c"],body:"a=this_f(b,c)",thisVars:["this_f"]},funcName:f});exports[f+"s"]=makeOp({args:["array","array","scalar"],pre:{args:[],body:"this_f=Math."+f,thisVars:["this_f"]},body:{args:["a","b","c"],body:"a=this_f(b,c)",thisVars:["this_f"]},funcName:f+"s"});exports[f+"eq"]=makeOp({args:["array","array"],pre:{args:[],body:"this_f=Math."+f,thisVars:["this_f"]},body:{args:["a","b"],body:"a=this_f(a,b)",thisVars:["this_f"]},rvalue:true,count:2,funcName:f+"eq"});exports[f+"seq"]=makeOp({args:["array","scalar"],pre:{args:[],body:"this_f=Math."+f,thisVars:["this_f"]},body:{args:["a","b"],body:"a=this_f(a,b)",thisVars:["this_f"]},rvalue:true,count:2,funcName:f+"seq"})}})();var math_noncomm=["atan2","pow"];(function(){for(var i=0;i<math_noncomm.length;++i){var f=math_noncomm[i];exports[f+"op"]=makeOp({args:["array","array","array"],pre:{args:[],body:"this_f=Math."+f,thisVars:["this_f"]},body:{args:["a","b","c"],body:"a=this_f(c,b)",thisVars:["this_f"]},funcName:f+"op"});exports[f+"ops"]=makeOp({args:["array","array","scalar"],pre:{args:[],body:"this_f=Math."+f,thisVars:["this_f"]},body:{args:["a","b","c"],body:"a=this_f(c,b)",thisVars:["this_f"]},funcName:f+"ops"});exports[f+"opeq"]=makeOp({args:["array","array"],pre:{args:[],body:"this_f=Math."+f,thisVars:["this_f"]},body:{args:["a","b"],body:"a=this_f(b,a)",thisVars:["this_f"]},rvalue:true,count:2,funcName:f+"opeq"});exports[f+"opseq"]=makeOp({args:["array","scalar"],pre:{args:[],body:"this_f=Math."+f,thisVars:["this_f"]},body:{args:["a","b"],body:"a=this_f(b,a)",thisVars:["this_f"]},rvalue:true,count:2,funcName:f+"opseq"})}})();exports.any=compile({args:["array"],pre:EmptyProc,body:{args:[{name:"a",lvalue:false,rvalue:true,count:1}],body:"if(a){return true}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return false"},funcName:"any"});exports.all=compile({args:["array"],pre:EmptyProc,body:{args:[{name:"x",lvalue:false,rvalue:true,count:1}],body:"if(!x){return false}",localVars:[],thisVars:[]},post:{args:[],localVars:[],thisVars:[],body:"return true"},funcName:"all"});exports.sum=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:false,rvalue:true,count:1}],body:"this_s+=a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"sum"});exports.prod=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=1"},body:{args:[{name:"a",lvalue:false,rvalue:true,count:1}],body:"this_s*=a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"prod"});exports.norm2squared=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:false,rvalue:true,count:2}],body:"this_s+=a*a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return this_s"},funcName:"norm2squared"});exports.norm2=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:false,rvalue:true,count:2}],body:"this_s+=a*a",localVars:[],thisVars:["this_s"]},post:{args:[],localVars:[],thisVars:["this_s"],body:"return Math.sqrt(this_s)"},funcName:"norm2"});exports.norminf=compile({args:["array"],pre:{args:[],localVars:[],thisVars:["this_s"],body:"this_s=0"},body:{args:[{name:"a",lvalue:false,rvalue:true,count:4}],body:"if(-a>this_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_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.argmin=compile({args:["index","array","shape"],pre:{body:"{this_v=Infinity;this_i=_inline_0_arg2_.slice(0)}",args:[{name:"_inline_0_arg0_",lvalue:false,rvalue:false,count:0},{name:"_inline_0_arg1_",lvalue:false,rvalue:false,count:0},{name:"_inline_0_arg2_",lvalue:false,rvalue:true,count:1}],thisVars:["this_i","this_v"],localVars:[]},body:{body:"{if(_inline_1_arg1_<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.argmax=compile({args:["index","array","shape"],pre:{body:"{this_v=-Infinity;this_i=_inline_0_arg2_.slice(0)}",args:[{name:"_inline_0_arg0_",lvalue:false,rvalue:false,count:0},{name:"_inline_0_arg1_",lvalue:false,rvalue:false,count:0},{name:"_inline_0_arg2_",lvalue:false,rvalue:true,count:1}],thisVars:["this_i","this_v"],localVars:[]},body:{body:"{if(_inline_1_arg1_>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"})},{"cwise-compiler":12}],12:[function(require,module,exports){"use strict";var createThunk=require("./lib/thunk.js");function Procedure(){this.argTypes=[];this.shimArgs=[];this.arrayArgs=[];this.scalarArgs=[];this.indexArgs=[];this.shapeArgs=[];this.funcName="";this.pre=null;this.body=null;this.post=null;this.debug=false}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;i<proc_args.length;++i){switch(proc_args[i]){case"array":proc.arrayArgs.push(i);proc.shimArgs.push("array"+i);if(i<proc.pre.args.length&&proc.pre.args[i].count>0){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")}break;case"scalar":proc.scalarArgs.push(i);proc.shimArgs.push("scalar"+i);break;case"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")}break;case"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")}break;default:throw new Error("cwise: Unknown argument type "+proc_args[i])}}if(proc.arrayArgs.length<=0){throw new Error("cwise: No array arguments specified")}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")}proc.debug=!!user_args.printCode||!!user_args.debug;proc.funcName=user_args.funcName||"cwise";proc.blockSize=user_args.blockSize||64;return createThunk(proc)}module.exports=compileCwise},{"./lib/thunk.js":14}],13:[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<dimension;++i){vars.push(["i",i,"=0"].join(""))}for(j=0;j<nargs;++j){for(i=0;i<dimension;++i){pidx=idx;idx=order[i];if(i===0){vars.push(["d",j,"s",i,"=t",j,"[",idx,"]"].join(""))}else{vars.push(["d",j,"s",i,"=(t",j,"[",idx,"]-s",pidx,"*t",j,"[",pidx,"])"].join(""))}}}code.push("var "+vars.join(","));for(i=dimension-1;i>=0;--i){idx=order[i];code.push(["for(i",i,"=0;i",i,"<s",idx,";++i",i,"){"].join(""))}code.push(body);for(i=0;i<dimension;++i){pidx=idx;idx=order[i];for(j=0;j<nargs;++j){code.push(["p",j,"+=d",j,"s",i].join(""))}if(has_index){if(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;i<nargs;++i){code.push(["var offset",i,"=p",i].join(""))}for(var i=matched;i<dimension;++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(""));if(has_index){code.push(["index[",order[i],"]=j",i].join(""))}}for(var i=0;i<nargs;++i){var indexStr=["offset"+i];for(var j=matched;j<dimension;++j){indexStr.push(["j",j,"*t",i,"[",order[j],"]"].join(""))}code.push(["p",i,"=(",indexStr.join("+"),")"].join(""))}code.push(innerFill(order,proc,body));for(var i=matched;i<dimension;++i){code.push("}")}return code.join("\n")}function countMatches(orders){var matched=0,dimension=orders[0].length;while(matched<dimension){for(var j=1;j<orders.length;++j){if(orders[j][matched]!==orders[0][matched]){return matched}}++matched}return matched}function processBlock(block,proc,dtypes){var code=block.body;var pre=[];var post=[];for(var i=0;i<block.args.length;++i){var carg=block.args[i];if(carg.count<=0){continue}var re=new RegExp(carg.name,"g");switch(proc.argTypes[i]){case"array":var arrNum=proc.arrayArgs.indexOf(i);if(carg.count===1){if(dtypes[arrNum]==="generic"){if(carg.lvalue){pre.push(["var l",arrNum,"=a",arrNum,".get(p",arrNum,")"].join(""));code=code.replace(re,"l"+arrNum);post.push(["a",arrNum,".set(p",arrNum,",l",arrNum,")"].join(""))}else{code=code.replace(re,["a",arrNum,".get(p",arrNum,")"].join(""))}}else{code=code.replace(re,["a",arrNum,"[p",arrNum,"]"].join(""))}}else if(dtypes[arrNum]==="generic"){pre.push(["var l",arrNum,"=a",arrNum,".get(p",arrNum,")"].join(""));code=code.replace(re,"l"+arrNum);
if(carg.lvalue){post.push(["a",arrNum,".set(p",arrNum,",l",arrNum,")"].join(""))}}else{pre.push(["var l",arrNum,"=a",arrNum,"[p",arrNum,"]"].join(""));code=code.replace(re,"l"+arrNum);if(carg.lvalue){post.push(["a",arrNum,"[p",arrNum,"]=l",arrNum].join(""))}}break;case"scalar":code=code.replace(re,"Y"+proc.scalarArgs.indexOf(i));break;case"index":code=code.replace(re,"index");break;case"shape":code=code.replace(re,"shape");break}}return[pre.join("\n"),code,post.join("\n")].join("\n").trim()}function typeSummary(dtypes){var summary=new Array(dtypes.length);var allEqual=true;for(var i=0;i<dtypes.length;++i){var t=dtypes[i];var digits=t.match(/\d+/);if(!digits){digits=""}else{digits=digits[0]}if(t.charAt(0)===0){summary[i]="u"+t.charAt(1)+digits}else{summary[i]=t.charAt(0)+digits}if(i>0){allEqual=allEqual&&summary[i]===summary[i-1]}}if(allEqual){return summary[0]}return summary.join("")}function generateCWiseOp(proc,typesig){var dimension=typesig[1].length|0;var orders=new Array(proc.arrayArgs.length);var dtypes=new Array(proc.arrayArgs.length);var arglist=["SS"];var code=["'use strict'"];var vars=[];for(var j=0;j<dimension;++j){vars.push(["s",j,"=SS[",j,"]"].join(""))}for(var i=0;i<proc.arrayArgs.length;++i){arglist.push("a"+i);arglist.push("t"+i);arglist.push("p"+i);dtypes[i]=typesig[2*i];orders[i]=typesig[2*i+1]}for(var i=0;i<proc.scalarArgs.length;++i){arglist.push("Y"+i)}if(proc.shapeArgs.length>0){vars.push("shape=SS.slice(0)")}if(proc.indexArgs.length>0){var zeros=new Array(dimension);for(var i=0;i<dimension;++i){zeros[i]="0"}vars.push(["index=[",zeros.join(","),"]"].join(""))}var thisVars=uniq([].concat(proc.pre.thisVars).concat(proc.body.thisVars).concat(proc.post.thisVars));vars=vars.concat(thisVars);code.push("var "+vars.join(","));for(var i=0;i<proc.arrayArgs.length;++i){code.push("p"+i+"|=0")}if(proc.pre.body.length>3){code.push(processBlock(proc.pre,proc,dtypes))}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))}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:15}],14:[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";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;i<proc.arrayArgs.length;++i){var j=proc.arrayArgs[i];vars.push(["t",j,"=array",j,".dtype,","r",j,"=array",j,".order"].join(""));typesig.push("t"+j);typesig.push("r"+j);string_typesig.push("t"+j);string_typesig.push("r"+j+".join()");proc_args.push("array"+j+".data");proc_args.push("array"+j+".stride");proc_args.push("array"+j+".offset|0")}for(var i=0;i<proc.scalarArgs.length;++i){proc_args.push("scalar"+proc.scalarArgs[i])}vars.push(["type=[",string_typesig.join(","),"].join()"].join(""));vars.push("proc=CACHED[type]");code.push("var "+vars.join(","));code.push(["if(!proc){","CACHED[type]=proc=compile([",typesig.join(","),"])}","return proc(",proc_args.join(","),")}"].join(""));if(proc.debug){console.log("Generated thunk:",code.join("\n"))}var thunk=new Function("compile",code.join("\n"));return thunk(compile.bind(undefined,proc))}module.exports=createThunk},{"./compile.js":13}],15:[function(require,module,exports){"use strict";function unique_pred(list,compare){var ptr=1,len=list.length,a=list[0],b=list[0];for(var i=1;i<len;++i){b=a;a=list[i];if(compare(a,b)){if(i===ptr){ptr++;continue}list[ptr++]=a}}list.length=ptr;return list}function unique_eq(list){var ptr=1,len=list.length,a=list[0],b=list[0];for(var i=1;i<len;++i,b=a){b=a;a=list[i];if(a!==b){if(i===ptr){ptr++;continue}list[ptr++]=a}}list.length=ptr;return list}function unique(list,compare,sorted){if(list.length===0){return[]}if(compare){if(!sorted){list.sort(compare)}return unique_pred(list,compare)}if(!sorted){list.sort()}return unique_eq(list)}module.exports=unique},{}],16:[function(require,module,exports){(function(Buffer){var iota=require("iota-array");var hasTypedArrays=typeof Float64Array!=="undefined";var hasBuffer=typeof Buffer!=="undefined";function compare1st(a,b){return a[0]-b[0]}function order(){var stride=this.stride;var terms=new Array(stride.length);var i;for(i=0;i<terms.length;++i){terms[i]=[Math.abs(stride[i]),i]}terms.sort(compare1st);var result=new Array(terms.length);for(i=0;i<result.length;++i){result[i]=terms[i][1]}return result}function compileConstructor(dtype,dimension){var className=["View",dimension,"d",dtype].join("");if(dimension<0){className="View_Nil"+dtype}var useGetters=dtype==="generic";if(dimension===-1){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);}";var procedure=new Function(code);return procedure()}else if(dimension===0){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)}";var procedure=new Function("TrivialArray",code);return procedure(CACHED_CONSTRUCTORS[dtype][0])}var code=["'use strict'"];var indices=iota(dimension);var args=indices.map(function(i){return"i"+i});var index_str="this.offset+"+indices.map(function(i){return"this.stride["+i+"]*i"+i}).join("+");var shapeArg=indices.map(function(i){return"b"+i}).join(",");var strideArg=indices.map(function(i){return"c"+i}).join(",");code.push("function "+className+"(a,"+shapeArg+","+strideArg+",d){this.data=a","this.shape=["+shapeArg+"]","this.stride=["+strideArg+"]","this.offset=d|0}","var proto="+className+".prototype","proto.dtype='"+dtype+"'","proto.dimension="+dimension);code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){return "+indices.map(function(i){return"this.shape["+i+"]"}).join("*"),"}})");if(dimension===1){code.push("proto.order=[0]")}else{code.push("Object.defineProperty(proto,'order',{get:");if(dimension<4){code.push("function "+className+"_order(){");if(dimension===2){code.push("return (Math.abs(this.stride[0])>Math.abs(this.stride[1]))?[1,0]:[0,1]}})")}else if(dimension===3){code.push("var s0=Math.abs(this.stride[0]),s1=Math.abs(this.stride[1]),s2=Math.abs(this.stride[2]);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})")}}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}")}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+"]}")}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+"]"});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<dimension;++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;i<dimension;++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)}");var tShape=new Array(dimension);var tStride=new Array(dimension);for(var i=0;i<dimension;++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;i<dimension;++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){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<d;++i){if(stride[i]<0){offset-=(shape[i]-1)*stride[i]}}}var dtype=arrayDType(data);var ctor_list=CACHED_CONSTRUCTORS[dtype];while(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)}module.exports=wrappedNDArrayCtor}).call(this,require("buffer").Buffer)},{buffer:1,"iota-array":17}],17:[function(require,module,exports){"use strict";function iota(n){var result=new Array(n);for(var i=0;i<n;++i){result[i]=i}return result}module.exports=iota},{}],18:[function(require,module,exports){"use strict";"use restrict";var INT_BITS=32;exports.INT_BITS=INT_BITS;exports.INT_MAX=2147483647;exports.INT_MIN=-1<<INT_BITS-1;exports.sign=function(v){return(v>0)-(v<0)};exports.abs=function(v){var mask=v>>INT_BITS-1;return(v^mask)-mask};exports.min=function(x,y){return y^(x^y)&-(x<y)};exports.max=function(x,y){return x^(x^y)&-(x<y)};exports.isPow2=function(v){return!(v&v-1)&&!!v};exports.log2=function(v){var r,shift;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;return 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){v=v-(v>>>1&1431655765);v=(v&858993459)+(v>>>2&858993459);return(v+(v>>>4)&252645135)*16843009>>>24};function countTrailingZeros(v){var c=32;v&=-v;if(v)c--;if(v&65535)c-=16;if(v&16711935)c-=8;if(v&252645135)c-=4;if(v&858993459)c-=2;if(v&1431655765)c-=1;return c}exports.countTrailingZeros=countTrailingZeros;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};exports.prevPow2=function(v){v|=v>>>1;v|=v>>>2;v|=v>>>4;v|=v>>>8;v|=v>>>16;return v-(v>>>1)};exports.parity=function(v){v^=v>>>16;v^=v>>>8;v^=v>>>4;v&=15;return 27030>>>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&255}})(REVERSE_TABLE);exports.reverse=function(v){return REVERSE_TABLE[v&255]<<24|REVERSE_TABLE[v>>>8&255]<<16|REVERSE_TABLE[v>>>16&255]<<8|REVERSE_TABLE[v>>>24&255]};exports.interleave2=function(x,y){x&=65535;x=(x|x<<8)&16711935;x=(x|x<<4)&252645135;x=(x|x<<2)&858993459;x=(x|x<<1)&1431655765;y&=65535;y=(y|y<<8)&16711935;y=(y|y<<4)&252645135;y=(y|y<<2)&858993459;y=(y|y<<1)&1431655765;return x|y<<1};exports.deinterleave2=function(v,n){v=v>>>n&1431655765;v=(v|v>>>1)&858993459;v=(v|v>>>2)&252645135;v=(v|v>>>4)&16711935;v=(v|v>>>16)&65535;return v<<16>>16};exports.interleave3=function(x,y,z){x&=1023;x=(x|x<<16)&4278190335;x=(x|x<<8)&251719695;x=(x|x<<4)&3272356035;x=(x|x<<2)&1227133513;y&=1023;y=(y|y<<16)&4278190335;y=(y|y<<8)&251719695;y=(y|y<<4)&3272356035;y=(y|y<<2)&1227133513;x|=y<<1;z&=1023;z=(z|z<<16)&4278190335;z=(z|z<<8)&251719695;z=(z|z<<4)&3272356035;z=(z|z<<2)&1227133513;return x|z<<2};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)&1023;return v<<22>>22};exports.nextCombination=function(v){var t=v|v-1;return t+1|(~t&-~t)-1>>>countTrailingZeros(v)+1}},{}],19:[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<c;++j){result[j]=value}}else{for(j=0;j<c;++j){result[j]=dupe_array(count,value,i+1)}}return result}function dupe_number(count,value){var result,i;result=new Array(count);for(i=0;i<count;++i){result[i]=value}return result}function dupe(count,value){if(typeof value==="undefined"){value=0}switch(typeof count){case"number":if(count>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},{}],20:[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":18,dup:19}],21:[function(require,module,exports){"use strict";var VENDOR_PREFIX=["WEBKIT_","MOZ_"];function baseName(ext_name){for(var i=0;i<VENDOR_PREFIX.length;++i){var prefix=VENDOR_PREFIX[i];if(ext_name.indexOf(prefix)===0){return ext_name.slice(prefix.length)}}return ext_name}function initWebGLEW(gl){if(gl._webglew_struct){return gl._webglew_struct}var extensions={};var supported=gl.getSupportedExtensions();for(var i=0;i<supported.length;++i){var ext=gl.getExtension(supported[i]);if(!ext){continue}extensions[supported[i]]=ext;extensions[baseName(supported[i])]=ext}gl._webglew_struct=extensions;return extensions}module.exports=initWebGLEW},{}],"gl-mesh":[function(require,module,exports){"use strict";var webglew=require("webglew");var createBuffer=require("gl-buffer");var createVAO=require("gl-vao");var ndarray=require("ndarray");var ops=require("ndarray-ops");var pool=require("typedarray-pool");var Mesh=require("./lib/mesh.js");function EmptyMesh(gl){this.gl=gl;this.mode=gl.POINTS;this.numElements=0;this.elements=null;this.attributes={}}EmptyMesh.prototype.dispose=function(){};EmptyMesh.prototype.bind=function(){};EmptyMesh.prototype.unbind=function(){};EmptyMesh.prototype.draw=function(){};function MeshAttribute(buffer,size,type,normalized){this.buffer=buffer;this.size=size;this.type=type;this.normalized=normalized}function getGLType(gl,array){if(array instanceof Uint8Array||array instanceof Uint8ClampedArray){return gl.UNSIGNED_BYTE}else if(array instanceof Int8Array){return gl.BYTE}else if(array instanceof Uint16Array){return gl.UNSIGNED_SHORT}else if(array instanceof Int16Array){return gl.SHORT}else if(array instanceof Uint32Array){return gl.UNSIGNED_INT}else if(array instanceof Int32Array){return gl.INT}else if(array instanceof Float32Array){return gl.FLOAT}return 0}function createTmpArray(gl,type,n){if(type===gl.UNSIGNED_BYTE){return pool.mallocUint8(n)}else if(type===gl.BYTE){return pool.mallocInt8(n)}else if(type===gl.UNSIGNED_SHORT){return pool.mallocUint16(n)}else if(type===gl.SHORT){return pool.mallocInt16(n)}else if(type===gl.UNSIGNED_INT){return pool.mallocUint32(n)}else if(type===gl.INT){return pool.mallocInt32(n)}return pool.mallocFloat32(n)}function packAttributes(gl,numVertices,attributes){var attrNames=[];var attrVals=[];for(var name in attributes){var attr=attributes[name];var buffer,type,normalized,size;if(typeof attr.length==="number"){if(attr.length!==numVertices){throw new Error("Incorrect vertex count for attribute "+name)}if(typeof attr[0]==="number"){var gltype=getGLType(attr);if(gltype){size=1;type=gltype;normalized=gltype===gl.BYTE||gltype===gl.UNSIGNED_BYTE;buffer=createBuffer(gl,attr)}else{var tmp_buf=pool.mallocFloat32(numVertices);for(var i=0;i<numVertices;++i){tmp_buf[i]=attr[i]}size=1;type=gl.FLOAT;normalized=false;buffer=createBuffer(gl,tmp_buf.subarray(0,numVertices));pool.freeUint32(tmp_buf)}}else if(attr[0].length){size=attr[0].length|0;var ptr=0;var tmp_buf=pool.mallocFloat32(size*numVertices);for(var i=0;i<numVertices;++i){var vert=attr[i];for(var j=0;j<size;++j){tmp_buf[ptr++]=vert[j]}}type=gl.FLOAT;normalized=false;buffer=createBuffer(gl,tmp_buf.subarray(0,ptr));pool.freeFloat32(tmp_buf)}}else if(attr.shape){if(attr.shape[0]!==numVertices){throw new Error("Invalid shape for attribute "+name)}if(attr.shape.length===1){attr=ndarray(attr.data,[attr.shape[0],1],[attr.stride[0],1],attr.offset)}var packed=true;type=getGLType(gl,attr.data);if(!type){packed=false;type=gl.FLOAT}if(stride[0]!==1||shape[1]>1&&stride[1]!==1){packed=false}normalized=type===gl.BYTE||type===gl.UNSIGNED_BYTE;size=attr.shape[1];if(packed){if(attr.offset===0&&attr.data.length===size*numVertices){buffer=createBuffer(gl,attr.data)}else{buffer=createBuffer(gl,attr.data.subarray(0,size*numVertices))}}else{var tmp_buf=createTmpArray(gl,type,size*numVertices);var tmp=ndarray(tmp_buf,attr.shape);ops.assign(tmp,attr);buffer=createBuffer(gl,tmp.data.subarray(0,size*numVertices));pool.free(tmp_buf)}}else{throw new Error("Invalid vertex attribute "+name)}attrNames.push(name);attrVals.push(new MeshAttribute(buffer,size,type,normalized))}return{names:attrNames,values:attrVals}}function packAttributesFromNDArray(gl,numVertices,attributes,elements){var n=elements.shape[0]|0;var d=elements.shape[1]|0;var numElements=n*d|0;var attrNames=[],attrVals=[];for(var name in attributes){var attr=attributes[name];var type,size,normalized,buffer;if(typeof attr.length==="number"){if(attr.length!==numVertices){throw new Error("Invalid attribute size for attribute "+name)}if(typeof attr[0]==="number"){size=1;type=getGLType(gl,attr);var pack_buf;if(!type){type=gl.FLOAT}normalized=type===gl.BYTE||gl.UNSIGNED_BYTE;pack_buf=createTmpArray(gl,type,numElements);var ptr=0;for(var i=0;i<n;++i){for(var j=0;j<d;++j){pack_buf[ptr++]=attr[elements.get(i,j)]}}buffer=createBuffer(gl,pack_buf.subarray(0,ptr));pool.free(pack_buf)}else{size=attr[0].length|0;if(size<1||size>4){throw new Error("Invalid attribute size for attribute "+name)}type=gl.FLOAT;normalized=false;var pack_buf=pool.mallocFloat32(numElements*size);var ptr=0;for(var i=0;i<n;++i){for(var j=0;j<d;++j){var vert=attr[elements.get(i,j)];for(var k=0;k<size;++k){pack_buf[ptr++]=vert[k]}}}buffer=createBuffer(gl,pack_buf.subarray(0,numElements*size));pool.freeFloat32(pack_buf)}}else if(attr.shape){if(attr.shape[0]!==numVertices){throw new Error("Invalid number of vertices for attribute "+name)}if(attr.shape.length===1){size=1;type=getGLType(gl,array.data);if(!type){type=gl.FLOAT}normalized=type===gl.BYTE||type===gl.UNSIGNED_BYTE;var pack_buf=createTmpArray(gl,type,numElements);var ptr=0;for(var i=0;i<n;++i){for(var j=0;j<d;++j){pack_buf[ptr++]=attr.get(elements.get(i,j))}}buffer=createBuffer(gl,pack_buf.subarray(0,ptr));pool.free(pack_buf)}else if(attr.shape.length===2){size=attr.shape[1]|0;if(size<1||size>4){throw new Error("Invalid attribute size for attribute "+name)}type=getGLType(gl,array.data);if(!type){type=gl.FLOAT}normalized=type===gl.BYTE||gl.UNSIGNED_BYTE;var pack_buf=createTmpArray(gl,type,numElements*size);var ptr=0;for(var i=0;i<n;++i){for(var j=0;j<d;++j){var vert_num=elements.get(i,j);for(var k=0;k<size;++k){pack_buf[ptr++]=attr.get(vert_num,k)}}}buffer=createBuffer(gl,pack_buf.subarray(0,ptr));pool.free(pack_buf)}else{throw new Error("Invalid attribute "+name+", shape is too big")}}else{throw new Error("Invalid attribute "+name+", unrecognized type")}attrNames.push(name);attrVals.push(new MeshAttribute(buffer,size,type,normalized))}return{names:attrNames,values:attrVals}}function packAttributesFrom1DArray(gl,numVertices,attributes,elements){var n=elements.length|0;var buf=pool.mallocUint32(n);for(var i=0;i<n;++i){buf[i]=elements[i]}var result=packAttributesFromNDArray(gl,numVertices,attributes,ndarray(buf,[n,1]));pool.freeUint32(buf);return result}function packAttributesFromArray(gl,numVertices,attributes,elements){var n=elements.length|0;var d=elements[0].length|0;var ptr=0;var buf=pool.mallocUint32(n*d);for(var i=0;i<n;++i){var list=elements[i];for(var j=0;j<d;++j){buf[ptr++]=list[j]}}var result=packAttributesFromNDArray(gl,numVertices,attributes,ndarray(buf,[n,d]));pool.freeUint32(buf);return result}function buildMeshObject(gl,mode,numElements,elements,attributes){if(numElements===0){return new EmptyMesh(gl)}var vao=createVAO(gl,elements,attributes.values);return new Mesh(gl,mode,numElements,vao,elements,attributes.values,attributes.names)}function createMesh(gl,elements,attributes){if(arguments.length===2){if(elements.cells){attributes={};for(var id in elements){if(id==="cells"){continue}attributes[id]=elements[id]}elements=elements.cells}}var mode;if(attributes===undefined){attributes=elements;elements=undefined;mode=gl.POINTS}else if(elements instanceof Array){if(elements.length===0){return buildMeshObject(gl,gl.POINTS,0,null,[])}else if(typeof elements[0]==="number"||elements[0].length===1){mode=gl.POINTS}else if(elements[0].length===2){mode=gl.LINES}else if(elements[0].length===3){mode=gl.TRIANGLES}else{throw new Error("Invalid shape for element array")}}else if(elements.shape){if(elements.shape.length===1){mode=gl.POINTS;elements=ndarray(elements.data,[elements.shape[0],1],[elements.stride[0],1],elements.offset)}else if(elements.shape.length!==2){throw new Error("Invalid shape for element array")}else if(elements.shape[1]===1){mode=gl.POINTS}else if(elements.shape[1]===2){mode=gl.LINES}else if(elements.shape[1]===3){mode=gl.TRIANGLES}else{throw new Error("Invalid shape for elment array")}if(elements.shape[0]===0){return buildMeshObject(gl,mode,0,null,[])}}else{throw new Error("Invalid data type for element array")}var attr_names=Object.keys(attributes);if(attr_names.length<1){throw new Error("Invalid number of vertex attributes")}var numVertices,attr0=attributes[attr_names[0]];if(attr0.length){numVertices=attr0.length}else if(attr0.shape){numVertices=attr0.shape[0]}else{throw new Error("Invalid vertex attribute: "+attr_names[0])}if(elements===undefined){return buildMeshObject(gl,gl.POINTS,numVertices,null,packAttributes(gl,numVertices,attributes))}else if(numVertices<=1<<16&&mode!==gl.POINTS){var element_buffer,element_count;if(elements instanceof Array){if(typeof elements[0]==="number"){element_count=elements.length|0;var point_buf=pool.mallocUint16(element_count);for(var i=0;i<element_count;++i){point_buf[i]=elements[i]}element_buffer=createBuffer(gl,gl.ELEMENT_ARRAY_BUFFER,point_buf.subarray(0,element_count));pool.freeUint16(point_buf)}else{var n=elements.length|0;var d=elements[0].length|0;var ptr=0;element_count=n*d|0;var packed_buf=pool.mallocUint16(element_count);for(var i=0;i<n;++i){var prim=elements[i];for(var j=0;j<d;++j){packed_buf[ptr++]=prim[j]}}element_buffer=createBuffer(gl,gl.ELEMENT_ARRAY_BUFFER,packed_buf.subarray(0,element_count));pool.freeUint16(packed_buf)}}else{element_count=elements.shape[0]*elements.shape[1];if(elements.stride[1]===1&&elements.stride[0]===elements.shape[1]&&elements.data instanceof Uint16Array){if(elements.offset===0&&elements.data.length===element_count){element_buffer=createBuffer(gl,gl.ELEMENT_ARRAY_BUFFER,elements.data)}else{element_buffer=createBuffer(gl,gl.ELEMENT_ARRAY_BUFFER,elements.data.subarray(elements.offset,elements.offset+element_count))}}else{var packed_buf=pool.mallocUint16(element_count);var packed_view=ndarray(packed_buf,elements.shape);ops.assign(packed_view,elements);element_buffer=createBuffer(gl,gl.ELEMENT_ARRAY_BUFFER,packed_buf.subarray(0,element_count));pool.freeUint16(packed_buf)}}return buildMeshObject(gl,mode,element_count,element_buffer,packAttributes(gl,numVertices,attributes))}else{if(elements instanceof Array){if(typeof elements[0]==="number"){return buildMeshObject(gl,mode,elements.length,null,packAttributesFrom1DArray(gl,numVertices,attributes,elements))}else{return buildMeshObject(gl,mode,elements.length*elements[0].length,null,packAttributesFromArray(gl,numVertices,attributes,elements))
}}else{return buildMeshObject(gl,mode,elements.shape[0]*elements.shape[1],null,packAttributesFromNDArray(gl,numVertices,attributes,elements))}}throw new Error("Error building mesh object")}module.exports=createMesh},{"./lib/mesh.js":5,"gl-buffer":6,"gl-vao":10,ndarray:16,"ndarray-ops":11,"typedarray-pool":20,webglew:21}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&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}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({normals:[function(require,module,exports){var EPSILON=1e-6;exports.vertexNormals=function(faces,positions){var N=positions.length;var normals=new Array(N);for(var i=0;i<N;++i){normals[i]=[0,0,0]}for(var i=0;i<faces.length;++i){var f=faces[i];var p=0;var c=f[f.length-1];var n=f[0];for(var j=0;j<f.length;++j){p=c;c=n;n=f[(j+1)%f.length];var v0=positions[p];var v1=positions[c];var v2=positions[n];var d01=new Array(3);var m01=0;var d21=new Array(3);var m21=0;for(var k=0;k<3;++k){d01[k]=v0[k]-v1[k];m01+=d01[k]*d01[k];d21[k]=v2[k]-v1[k];m21+=d21[k]*d21[k]}if(m01*m21>EPSILON){var norm=normals[c];var w=1/Math.sqrt(m01*m21);for(var k=0;k<3;++k){var u=(k+1)%3;var v=(k+2)%3;norm[k]+=w*(d21[u]*d01[v]-d21[v]*d01[u])}}}}for(var i=0;i<N;++i){var norm=normals[i];var m=0;for(var k=0;k<3;++k){m+=norm[k]*norm[k]}if(m>EPSILON){var w=1/Math.sqrt(m);for(var k=0;k<3;++k){norm[k]*=w}}else{for(var k=0;k<3;++k){norm[k]=0}}}return normals};exports.faceNormals=function(faces,positions){var N=faces.length;var normals=new Array(N);for(var i=0;i<N;++i){var f=faces[i];var pos=new Array(3);for(var j=0;j<3;++j){pos[j]=positions[f[j]]}var d01=new Array(3);var d21=new Array(3);for(var j=0;j<3;++j){d01[j]=pos[1][j]-pos[0][j];d21[j]=pos[2][j]-pos[0][j]}var n=new Array(3);var l=0;for(var j=0;j<3;++j){var u=(j+1)%3;var v=(j+2)%3;n[j]=d01[u]*d21[v]-d01[v]*d21[u];l+=n[j]*n[j]}if(l>EPSILON){l=1/Math.sqrt(l)}else{l=0}for(var j=0;j<3;++j){n[j]*=l}normals[i]=n}return normals}},{}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&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}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){module.exports=add;function add(out,a,b){out[0]=a[0]+b[0];out[1]=a[1]+b[1];out[2]=a[2]+b[2];return out}},{}],2:[function(require,module,exports){module.exports=angle;var fromValues=require("./fromValues");var normalize=require("./normalize");var dot=require("./dot");function angle(a,b){var tempA=fromValues(a[0],a[1],a[2]);var tempB=fromValues(b[0],b[1],b[2]);normalize(tempA,tempA);normalize(tempB,tempB);var cosine=dot(tempA,tempB);if(cosine>1){return 0}else{return Math.acos(cosine)}}},{"./dot":9,"./fromValues":11,"./normalize":19}],3:[function(require,module,exports){module.exports=clone;function clone(a){var out=new Float32Array(3);out[0]=a[0];out[1]=a[1];out[2]=a[2];return out}},{}],4:[function(require,module,exports){module.exports=copy;function copy(out,a){out[0]=a[0];out[1]=a[1];out[2]=a[2];return out}},{}],5:[function(require,module,exports){module.exports=create;function create(){var out=new Float32Array(3);out[0]=0;out[1]=0;out[2]=0;return out}},{}],6:[function(require,module,exports){module.exports=cross;function cross(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}},{}],7:[function(require,module,exports){module.exports=distance;function distance(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)}},{}],8:[function(require,module,exports){module.exports=divide;function divide(out,a,b){out[0]=a[0]/b[0];out[1]=a[1]/b[1];out[2]=a[2]/b[2];return out}},{}],9:[function(require,module,exports){module.exports=dot;function dot(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]}},{}],10:[function(require,module,exports){module.exports=forEach;var vec=require("./create")();function forEach(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}},{"./create":5}],11:[function(require,module,exports){module.exports=fromValues;function fromValues(x,y,z){var out=new Float32Array(3);out[0]=x;out[1]=y;out[2]=z;return out}},{}],12:[function(require,module,exports){module.exports=inverse;function inverse(out,a){out[0]=1/a[0];out[1]=1/a[1];out[2]=1/a[2];return out}},{}],13:[function(require,module,exports){module.exports=length;function length(a){var x=a[0],y=a[1],z=a[2];return Math.sqrt(x*x+y*y+z*z)}},{}],14:[function(require,module,exports){module.exports=lerp;function lerp(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}},{}],15:[function(require,module,exports){module.exports=max;function max(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}},{}],16:[function(require,module,exports){module.exports=min;function min(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}},{}],17:[function(require,module,exports){module.exports=multiply;function multiply(out,a,b){out[0]=a[0]*b[0];out[1]=a[1]*b[1];out[2]=a[2]*b[2];return out}},{}],18:[function(require,module,exports){module.exports=negate;function negate(out,a){out[0]=-a[0];out[1]=-a[1];out[2]=-a[2];return out}},{}],19:[function(require,module,exports){module.exports=normalize;function normalize(out,a){var x=a[0],y=a[1],z=a[2];var len=x*x+y*y+z*z;if(len>0){len=1/Math.sqrt(len);out[0]=a[0]*len;out[1]=a[1]*len;out[2]=a[2]*len}return out}},{}],20:[function(require,module,exports){module.exports=random;function random(out,scale){scale=scale||1;var r=Math.random()*2*Math.PI;var z=Math.random()*2-1;var zScale=Math.sqrt(1-z*z)*scale;out[0]=Math.cos(r)*zScale;out[1]=Math.sin(r)*zScale;out[2]=z*scale;return out}},{}],21:[function(require,module,exports){module.exports=rotateX;function rotateX(out,a,b,c){var p=[],r=[];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];return out}},{}],22:[function(require,module,exports){module.exports=rotateY;function rotateY(out,a,b,c){var p=[],r=[];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];return out}},{}],23:[function(require,module,exports){module.exports=rotateZ;function rotateZ(out,a,b,c){var p=[],r=[];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];return out}},{}],24:[function(require,module,exports){module.exports=scale;function scale(out,a,b){out[0]=a[0]*b;out[1]=a[1]*b;out[2]=a[2]*b;return out}},{}],25:[function(require,module,exports){module.exports=scaleAndAdd;function scaleAndAdd(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}},{}],26:[function(require,module,exports){module.exports=set;function set(out,x,y,z){out[0]=x;out[1]=y;out[2]=z;return out}},{}],27:[function(require,module,exports){module.exports=squaredDistance;function squaredDistance(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}},{}],28:[function(require,module,exports){module.exports=squaredLength;function squaredLength(a){var x=a[0],y=a[1],z=a[2];return x*x+y*y+z*z}},{}],29:[function(require,module,exports){module.exports=subtract;function subtract(out,a,b){out[0]=a[0]-b[0];out[1]=a[1]-b[1];out[2]=a[2]-b[2];return out}},{}],30:[function(require,module,exports){module.exports=transformMat3;function transformMat3(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}},{}],31:[function(require,module,exports){module.exports=transformMat4;function transformMat4(out,a,m){var x=a[0],y=a[1],z=a[2],w=m[3]*x+m[7]*y+m[11]*z+m[15];w=w||1;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;return out}},{}],32:[function(require,module,exports){module.exports=transformQuat;function transformQuat(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;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}},{}],"gl-vec3":[function(require,module,exports){module.exports={create:require("./create"),clone:require("./clone"),angle:require("./angle"),fromValues:require("./fromValues"),copy:require("./copy"),set:require("./set"),add:require("./add"),subtract:require("./subtract"),multiply:require("./multiply"),divide:require("./divide"),min:require("./min"),max:require("./max"),scale:require("./scale"),scaleAndAdd:require("./scaleAndAdd"),distance:require("./distance"),squaredDistance:require("./squaredDistance"),length:require("./length"),squaredLength:require("./squaredLength"),negate:require("./negate"),inverse:require("./inverse"),normalize:require("./normalize"),dot:require("./dot"),cross:require("./cross"),lerp:require("./lerp"),random:require("./random"),transformMat4:require("./transformMat4"),transformMat3:require("./transformMat3"),transformQuat:require("./transformQuat"),rotateX:require("./rotateX"),rotateY:require("./rotateY"),rotateZ:require("./rotateZ"),forEach:require("./forEach")}},{"./add":1,"./angle":2,"./clone":3,"./copy":4,"./create":5,"./cross":6,"./distance":7,"./divide":8,"./dot":9,"./forEach":10,"./fromValues":11,"./inverse":12,"./length":13,"./lerp":14,"./max":15,"./min":16,"./multiply":17,"./negate":18,"./normalize":19,"./random":20,"./rotateX":21,"./rotateY":22,"./rotateZ":23,"./scale":24,"./scaleAndAdd":25,"./set":26,"./squaredDistance":27,"./squaredLength":28,"./subtract":29,"./transformMat3":30,"./transformMat4":31,"./transformQuat":32}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&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}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){module.exports=adjoint;function adjoint(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}},{}],2:[function(require,module,exports){module.exports=clone;function clone(a){var out=new Float32Array(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}},{}],3:[function(require,module,exports){module.exports=copy;function copy(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}},{}],4:[function(require,module,exports){module.exports=create;function create(){var out=new Float32Array(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}},{}],5:[function(require,module,exports){module.exports=determinant;function determinant(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}},{}],6:[function(require,module,exports){module.exports=fromQuat;function fromQuat(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}},{}],7:[function(require,module,exports){module.exports=fromRotationTranslation;function fromRotationTranslation(out,q,v){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}},{}],8:[function(require,module,exports){module.exports=frustum;function frustum(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}},{}],9:[function(require,module,exports){module.exports=identity;function identity(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}},{}],10:[function(require,module,exports){module.exports=invert;function invert(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;if(!det){return null}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;return out}},{}],11:[function(require,module,exports){module.exports=lookAt;function lookAt(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)<1e-6&&Math.abs(eyey-centery)<1e-6&&Math.abs(eyez-centerz)<1e-6){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}},{}],12:[function(require,module,exports){module.exports=multiply;function multiply(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];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}},{}],13:[function(require,module,exports){module.exports=ortho;function ortho(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}},{}],14:[function(require,module,exports){module.exports=perspective;function perspective(out,fovy,aspect,near,far){var f=1/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}},{}],15:[function(require,module,exports){module.exports=rotate;function rotate(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)<1e-6){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];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;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){out[12]=a[12];out[13]=a[13];out[14]=a[14];out[15]=a[15]}return out}},{}],16:[function(require,module,exports){module.exports=rotateX;function rotateX(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){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]}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}},{}],17:[function(require,module,exports){module.exports=rotateY;function rotateY(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){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]}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}},{}],18:[function(require,module,exports){module.exports=rotateZ;function rotateZ(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){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[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}},{}],19:[function(require,module,exports){module.exports=scale;function scale(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}},{}],20:[function(require,module,exports){module.exports=str;function str(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]+")"}},{}],21:[function(require,module,exports){module.exports=translate;function translate(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}},{}],22:[function(require,module,exports){module.exports=transpose;function transpose(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}},{}],"gl-mat4":[function(require,module,exports){module.exports={create:require("./create"),clone:require("./clone"),copy:require("./copy"),identity:require("./identity"),transpose:require("./transpose"),invert:require("./invert"),adjoint:require("./adjoint"),determinant:require("./determinant"),multiply:require("./multiply"),translate:require("./translate"),scale:require("./scale"),rotate:require("./rotate"),rotateX:require("./rotateX"),rotateY:require("./rotateY"),rotateZ:require("./rotateZ"),fromRotationTranslation:require("./fromRotationTranslation"),fromQuat:require("./fromQuat"),frustum:require("./frustum"),perspective:require("./perspective"),ortho:require("./ortho"),lookAt:require("./lookAt"),str:require("./str")}},{"./adjoint":1,"./clone":2,"./copy":3,"./create":4,"./determinant":5,"./fromQuat":6,"./fromRotationTranslation":7,"./frustum":8,"./identity":9,"./invert":10,"./lookAt":11,"./multiply":12,"./ortho":13,"./perspective":14,"./rotate":15,"./rotateX":16,"./rotateY":17,"./rotateZ":18,"./scale":19,"./str":20,"./translate":21,"./transpose":22}]},{},[]);var createContext=require("fc");var extractMesh=require("isosurface").surfaceNets;var createVAO=require("gl-vao");var createCamera=require("orbit-camera");var createShader=require("simple-3d-shader");var createMesh=require("gl-mesh");var createNormals=require("normals").vertexNormals;var vec3=require("gl-vec3");var mat4=require("gl-mat4");var view=mat4.create();var projection=mat4.create();var model=mat4.create();var mouse={down:false,pos:[0,0]};var gl=createContext(frame,true,3);var camera=createCamera([0,0,20],[0,0,0],[0,1,0]);var shader=createShader(gl);var v3pos=[0,0,0];var v3abs=[0,0,0];var temp=[0,0,0];var zero=[0,0,0];var max=Math.max;var min=Math.min;var extracted=extractMesh([64,64,64],function(x,y,z){v3pos[0]=x;v3pos[1]=y;v3pos[2]=z;var sphere=vec3.length(v3pos)-6;var dims=[5,5,5];v3abs[0]=Math.abs(v3pos[0]);v3abs[1]=Math.abs(v3pos[1]);v3abs[2]=Math.abs(v3pos[2]);vec3.subtract(v3pos,v3abs,dims);vec3.max(temp,v3pos,zero);var cube=min(max(v3pos[0],max(v3pos[1],v3pos[2])),0)+vec3.distance(temp,zero);return max(cube,-sphere)},[[-11,-11,-11],[11,11,11]]);extracted.color=createNormals(extracted.cells,extracted.positions);var mesh=createMesh(gl,extracted);function frame(){var w=gl.canvas.width;var h=gl.canvas.height;gl.viewport(0,0,w,h);gl.enable(gl.DEPTH_TEST);mat4.identity(model);mat4.perspective(projection,Math.PI/4,w/h,.1,1e3);camera.view(view);shader.uniforms.projection=projection;shader.uniforms.view=view;shader.uniforms.model=model;shader.bind();mesh.bind(shader);mesh.draw();mesh.unbind()}function handleMouse(e){gl.start();switch(e.type){case"mousedown":mouse.down=true;break;case"mouseup":mouse.down=false;break;case"mousemove":var x=e.clientX;var y=e.clientY;if(mouse.down){var w=gl.canvas.width;var h=gl.canvas.height;var l=mouse.pos;camera.rotate([x/w-.5,y/h-.5],[l[0]/w-.5,l[1]/h-.5])}mouse.pos[0]=x;mouse.pos[1]=y;break;case"mousewheel":camera.zoom(e.wheelDeltaY*-.001);e.preventDefault();break;case"keydown":var panSpeed=.01;switch(e.keyCode){case 37:camera.pan([-panSpeed,0,0]);break;case 38:camera.pan([0,-panSpeed,0]);break;case 39:camera.pan([panSpeed,0,0]);break;case 40:camera.pan([0,panSpeed,0]);break}break}}["mousedown","mouseup","mousemove","mousewheel","keydown"].forEach(function(name){document.addEventListener(name,handleMouse)});
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"fc": "1.4.3",
"isosurface": "1.0.0",
"gl-vao": "1.2.0",
"orbit-camera": "1.0.0",
"simple-3d-shader": "0.0.0",
"gl-mesh": "0.1.0",
"normals": "1.0.1",
"gl-vec3": "1.0.2",
"gl-mat4": "1.0.1"
}
}
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment