Skip to content

Instantly share code, notes, and snippets.

@tatarize
Created February 11, 2013 18:15
Show Gist options
  • Save tatarize/4756319 to your computer and use it in GitHub Desktop.
Save tatarize/4756319 to your computer and use it in GitHub Desktop.
voxel.js game
// Voxel Tetris by @tatarize
// Click the board side to make the piece go that way.
// Click something on the board (eg, the falling piece) to make it turn.
// Turns are currently logged counter clockwise/counter-clockwise depending on the height you clicked at.
var createGame = require('voxel-engine')
var chunkSize = 32
var chunkDistance = 3
var game = createGame({
texturePath: '/textures/',
materials: [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt', 'obsidian', 'whitewool', 'cobblestone'],
generate: function(x,y,z) {
return (y < -2 && Math.abs(x) < 100 && Math.abs(z) < 100) ? 1 : 0
},
controlOptions: {
jump: 0,
move: 0,
fall: 0
},
startingPosition:[161,322,500]
})
var container = document.body
game.appendTo(container)
window.game = game
var tetris = require('voxel-tetris')(game)
game.on('mousedown', function (pos) {
tetris.touch(pos)
})
game.on('tick', function() {
tetris.tick()
})
game.controls.on('command', function(cmd,up) {
if (!up) return;
switch(cmd) {
case 'moveForward':
tetris.command(0);
break;
case 'moveLeft':
tetris.command(3);
break;
case 'moveRight':
tetris.command(2);
break;
case 'moveBackward':
tetris.command(4);
break;
case 'wantsJump':
tetris.command(5);
break;
}
});
var audio = require('voxel-audio')
audio.initGameAudio(game)
var tetrisTheme = new audio.PositionAudio({
url : 'http://commondatastorage.googleapis.com/maxomusic/tetris-gameboy-02.mp3',
startingPosition:[161,322,500],
coneOuterAngle : 360,
coneInnerAngle : 360,
refDistance : 2.0,
loop: true
});
tetrisTheme.load(function(err){
console.log('playing')
tetrisTheme.play()
})
// obtain pointer lock
game.setupPointerLock(container)
(function(){var n=function(e,t){var a=n.resolve(e,t||"/"),r=n.modules[a];if(!r)throw Error("Failed to resolve module "+e+", tried "+a);var o=n.cache[a],i=o?o.exports:r();return i};n.paths=[],n.modules={},n.cache={},n.extensions=[".js",".coffee",".json"],n._core={assert:!0,events:!0,fs:!0,path:!0,vm:!0},n.resolve=function(){return function(e,t){function a(e){if(e=s.normalize(e),n.modules[e])return e;for(var t=0;n.extensions.length>t;t++){var a=n.extensions[t];if(n.modules[e+a])return e+a}}function r(e){e=e.replace(/\/+$/,"");var t=s.normalize(e+"/package.json");if(n.modules[t]){var r=n.modules[t](),o=r.browserify;if("object"==typeof o&&o.main){var i=a(s.resolve(e,o.main));if(i)return i}else if("string"==typeof o){var i=a(s.resolve(e,o));if(i)return i}else if(r.main){var i=a(s.resolve(e,r.main));if(i)return i}}return a(e+"/index")}function o(n,e){for(var t=i(e),o=0;t.length>o;o++){var s=t[o],u=a(s+"/"+n);if(u)return u;var c=r(s+"/"+n);if(c)return c}var u=a(n);return u?u:void 0}function i(n){var e;e="/"===n?[""]:s.normalize(n).split("/");for(var t=[],a=e.length-1;a>=0;a--)if("node_modules"!==e[a]){var r=e.slice(0,a+1).join("/")+"/node_modules";t.push(r)}return t}if(t||(t="/"),n._core[e])return e;var s=n.modules.path();t=s.resolve("/",t);var u=t||"/";if(e.match(/^(?:\.\.?\/|\/)/)){var c=a(s.resolve(u,e))||r(s.resolve(u,e));if(c)return c}var l=o(e,u);if(l)return l;throw Error("Cannot find module '"+e+"'")}}(),n.alias=function(e,t){var a=n.modules.path(),r=null;try{r=n.resolve(e+"/package.json","/")}catch(o){r=n.resolve(e,"/")}for(var i=a.dirname(r),s=(Object.keys||function(n){var e=[];for(var t in n)e.push(t);return e})(n.modules),u=0;s.length>u;u++){var c=s[u];if(c.slice(0,i.length+1)===i+"/"){var l=c.slice(i.length);n.modules[t+l]=n.modules[i+l]}else c===i&&(n.modules[t]=n.modules[i])}},function(){var e={},t="undefined"!=typeof window?window:{},a=!1;n.define=function(r,o){!a&&n.modules.__browserify_process&&(e=n.modules.__browserify_process(),a=!0);var i=n._core[r]?"":n.modules.path().dirname(r),s=function(e){var t=n(e,i),a=n.cache[n.resolve(e,i)];return a&&null===a.parent&&(a.parent=u),t};s.resolve=function(e){return n.resolve(e,i)},s.modules=n.modules,s.define=n.define,s.cache=n.cache;var u={id:r,filename:r,exports:{},loaded:!1,parent:null};n.modules[r]=function(){return n.cache[r]=u,o.call(u.exports,s,u,u.exports,i,r,e,t),u.loaded=!0,u.exports}}}(),n.define("path",Function(["require","module","exports","__dirname","__filename","process","global"],"function filter (xs, fn) {\n var res = [];\n for (var i = 0; i < xs.length; i++) {\n if (fn(xs[i], i, xs)) res.push(xs[i]);\n }\n return res;\n}\n\n// resolves . and .. elements in a path array with directory names there\n// must be no slashes, empty elements, or device names (c:\\) in the array\n// (so also no leading and trailing slashes - it does not distinguish\n// relative and absolute paths)\nfunction normalizeArray(parts, allowAboveRoot) {\n // if the path tries to go above the root, `up` ends up > 0\n var up = 0;\n for (var i = parts.length; i >= 0; i--) {\n var last = parts[i];\n if (last == '.') {\n parts.splice(i, 1);\n } else if (last === '..') {\n parts.splice(i, 1);\n up++;\n } else if (up) {\n parts.splice(i, 1);\n up--;\n }\n }\n\n // if the path is allowed to go above the root, restore leading ..s\n if (allowAboveRoot) {\n for (; up--; up) {\n parts.unshift('..');\n }\n }\n\n return parts;\n}\n\n// Regex to split a filename into [*, dir, basename, ext]\n// posix version\nvar splitPathRe = /^(.+\\/(?!$)|\\/)?((?:.+?)?(\\.[^.]*)?)$/;\n\n// path.resolve([from ...], to)\n// posix version\nexports.resolve = function() {\nvar resolvedPath = '',\n resolvedAbsolute = false;\n\nfor (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {\n var path = (i >= 0)\n ? arguments[i]\n : process.cwd();\n\n // Skip empty and invalid entries\n if (typeof path !== 'string' || !path) {\n continue;\n }\n\n resolvedPath = path + '/' + resolvedPath;\n resolvedAbsolute = path.charAt(0) === '/';\n}\n\n// At this point the path should be resolved to a full absolute path, but\n// handle relative paths to be safe (might happen when process.cwd() fails)\n\n// Normalize the path\nresolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {\n return !!p;\n }), !resolvedAbsolute).join('/');\n\n return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';\n};\n\n// path.normalize(path)\n// posix version\nexports.normalize = function(path) {\nvar isAbsolute = path.charAt(0) === '/',\n trailingSlash = path.slice(-1) === '/';\n\n// Normalize the path\npath = normalizeArray(filter(path.split('/'), function(p) {\n return !!p;\n }), !isAbsolute).join('/');\n\n if (!path && !isAbsolute) {\n path = '.';\n }\n if (path && trailingSlash) {\n path += '/';\n }\n \n return (isAbsolute ? '/' : '') + path;\n};\n\n\n// posix version\nexports.join = function() {\n var paths = Array.prototype.slice.call(arguments, 0);\n return exports.normalize(filter(paths, function(p, index) {\n return p && typeof p === 'string';\n }).join('/'));\n};\n\n\nexports.dirname = function(path) {\n var dir = splitPathRe.exec(path)[1] || '';\n var isWindows = false;\n if (!dir) {\n // No dirname\n return '.';\n } else if (dir.length === 1 ||\n (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {\n // It is just a slash or a drive letter with a slash\n return dir;\n } else {\n // It is a full dirname, strip trailing slash\n return dir.substring(0, dir.length - 1);\n }\n};\n\n\nexports.basename = function(path, ext) {\n var f = splitPathRe.exec(path)[2] || '';\n // TODO: make this comparison case-insensitive on windows?\n if (ext && f.substr(-1 * ext.length) === ext) {\n f = f.substr(0, f.length - ext.length);\n }\n return f;\n};\n\n\nexports.extname = function(path) {\n return splitPathRe.exec(path)[3] || '';\n};\n\nexports.relative = function(from, to) {\n from = exports.resolve(from).substr(1);\n to = exports.resolve(to).substr(1);\n\n function trim(arr) {\n var start = 0;\n for (; start < arr.length; start++) {\n if (arr[start] !== '') break;\n }\n\n var end = arr.length - 1;\n for (; end >= 0; end--) {\n if (arr[end] !== '') break;\n }\n\n if (start > end) return [];\n return arr.slice(start, end - start + 1);\n }\n\n var fromParts = trim(from.split('/'));\n var toParts = trim(to.split('/'));\n\n var length = Math.min(fromParts.length, toParts.length);\n var samePartsLength = length;\n for (var i = 0; i < length; i++) {\n if (fromParts[i] !== toParts[i]) {\n samePartsLength = i;\n break;\n }\n }\n\n var outputParts = [];\n for (var i = samePartsLength; i < fromParts.length; i++) {\n outputParts.push('..');\n }\n\n outputParts = outputParts.concat(toParts.slice(samePartsLength));\n\n return outputParts.join('/');\n};\n\n//@ sourceURL=path")),n.define("__browserify_process",Function(["require","module","exports","__dirname","__filename","process","global"],"var process = module.exports = {};\n\nprocess.nextTick = (function () {\n var canSetImmediate = typeof window !== 'undefined'\n && window.setImmediate;\n var canPost = typeof window !== 'undefined'\n && window.postMessage && window.addEventListener\n ;\n\n if (canSetImmediate) {\n return function (f) { return window.setImmediate(f) };\n }\n\n if (canPost) {\n var queue = [];\n window.addEventListener('message', function (ev) {\n if (ev.source === window && ev.data === 'browserify-tick') {\n ev.stopPropagation();\n if (queue.length > 0) {\n var fn = queue.shift();\n fn();\n }\n }\n }, true);\n\n return function nextTick(fn) {\n queue.push(fn);\n window.postMessage('browserify-tick', '*');\n };\n }\n\n return function nextTick(fn) {\n setTimeout(fn, 0);\n };\n})();\n\nprocess.title = 'browser';\nprocess.browser = true;\nprocess.env = {};\nprocess.argv = [];\n\nprocess.binding = function (name) {\n if (name === 'evals') return (require)('vm')\n else throw new Error('No such module. (Possibly not yet loaded)')\n};\n\n(function () {\n var cwd = '/';\n var path;\n process.cwd = function () { return cwd };\n process.chdir = function (dir) {\n if (!path) path = require('path');\n cwd = path.resolve(dir, cwd);\n };\n})();\n\n//@ sourceURL=__browserify_process")),n.define("/node_modules/voxel-engine/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = {}\n//@ sourceURL=/node_modules/voxel-engine/package.json")),n.define("/node_modules/voxel-engine/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var voxel = require('voxel')\nvar voxelMesh = require('voxel-mesh')\nvar voxelChunks = require('voxel-chunks')\nvar THREE = require('three')\nvar Stats = require('./lib/stats')\nvar Detector = require('./lib/detector')\nvar inherits = require('inherits')\nvar path = require('path')\nvar EventEmitter = require('events').EventEmitter\nif (process.browser) var interact = require('interact')\nvar playerPhysics = require('player-physics')\nvar requestAnimationFrame = require('raf')\nvar collisions = require('collide-3d-tilemap')\nvar aabb = require('aabb-3d')\nvar SpatialEventEmitter = require('spatial-events')\nvar regionChange = require('voxel-region-change')\nvar AXISES = ['x', 'y', 'z']\n\nmodule.exports = Game\n\nfunction Game(opts) {\n if (!(this instanceof Game)) return new Game(opts)\n var self = this\n if (!opts) opts = {}\n if (process.browser && this.notCapable()) return\n if (!('generateChunks' in opts)) opts.generateChunks = true\n this.generateChunks = opts.generateChunks\n this.setConfigurablePositions(opts)\n this.configureChunkLoading(opts)\n this.THREE = THREE\n this.cubeSize = opts.cubeSize || 25\n this.chunkSize = opts.chunkSize || 32\n // chunkDistance and removeDistance should not be set to the same thing\n // as it causes lag when you go back and forth on a chunk boundary\n this.chunkDistance = opts.chunkDistance || 2\n this.removeDistance = opts.removeDistance || this.chunkDistance + 1\n this.playerHeight = opts.playerHeight || 1.62 // gets multiplied by cubeSize\n this.meshType = opts.meshType || 'surfaceMesh'\n this.controlOptions = opts.controlOptions || {}\n this.mesher = opts.mesher || voxel.meshers.greedy\n this.items = []\n this.voxels = voxel(this)\n this.chunkGroups = voxelChunks(this) \n this.height = typeof window === \"undefined\" ? 1 : window.innerHeight\n this.width = typeof window === \"undefined\" ? 1 : window.innerWidth\n this.scene = new THREE.Scene()\n this.camera = this.createCamera(this.scene)\n this.controls = this.createControls()\n if (!opts.lightsDisabled) this.addLights(this.scene)\n this.controlLayouts = {\n qwerty: {\n 87: 'moveForward', //w\n 65: 'moveLeft', //a\n 83: 'moveBackward', //s\n 68: 'moveRight', //d\n 32: 'wantsJump', //space\n },\n azerty: {\n 90: 'moveForward', //z\n 81: 'moveLeft', //q\n 83: 'moveBackward', //s\n 68: 'moveRight', //d\n 32: 'wantsJump', //space\n },\n dvorak: {\n 188: 'moveForward', //comma\n 65: 'moveLeft', //a\n 79: 'moveBackward', //o\n 69: 'moveRight', //e\n 32: 'wantsJump', //space\n }\n }\n this.playerControls = opts.controlLayout ? this.controlLayouts[opts.controlLayout] : this.controlLayouts.qwerty\n this.skyColor = opts.skyColor || 0xBFD1E5\n this.fogScale = opts.fogScale || 1\n if (!opts.controlsDisabled) this.bindControls(this.controls)\n if (!opts.fogDisabled) this.scene.fog = new THREE.Fog( this.skyColor, 0.00025, this.worldWidth() * this.fogScale )\n this.moveToPosition(this.startingPosition)\n this.collideVoxels = collisions(\n this.getTileAtIJK.bind(this),\n this.cubeSize,\n [Infinity, Infinity, Infinity],\n [-Infinity, -Infinity, -Infinity]\n )\n this.spatial = new SpatialEventEmitter()\n this.voxelRegion = regionChange(this.spatial, this.cubeSize)\n this.chunkRegion = regionChange(this.spatial, this.cubeSize * this.chunkSize)\n \n // contains chunks that has had an update this tick. Will be generated right before redrawing the frame\n this.chunksNeedsUpdate = {}\n\n // client side only\n if (process.browser) {\n this.materials = require('voxel-texture')({\n THREE: THREE,\n texturePath: opts.texturePath || './textures/',\n materialType: opts.materialType || THREE.MeshLambertMaterial,\n materialParams: opts.materialParams || {}\n })\n this.materials.load(opts.materials || [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'])\n this.initializeRendering()\n }\n \n if (this.generateChunks) {\n self.voxels.on('missingChunk', function(chunkPos) {\n var chunk = self.voxels.generateChunk(chunkPos[0], chunkPos[1], chunkPos[2])\n if (process.browser) self.showChunk(chunk)\n })\n this.voxels.requestMissingChunks(this.worldOrigin)\n }\n}\n\ninherits(Game, EventEmitter)\n\nGame.prototype.configureChunkLoading = function(opts) {\n var self = this\n if (!opts.generateChunks) return\n if (!opts.generate) {\n this.generate = function(x,y,z) {\n return x*x+y*y+z*z <= 15*15 ? 1 : 0 // sphere world\n }\n } else {\n this.generate = opts.generate\n }\n if (opts.generateVoxelChunk) {\n this.generateVoxelChunk = opts.generateVoxelChunk\n } else {\n this.generateVoxelChunk = function(low, high) {\n return voxel.generate(low, high, self.generate)\n }\n }\n}\n\nGame.prototype.worldWidth = function() {\n return this.chunkSize * 2 * this.chunkDistance * this.cubeSize\n}\n\nGame.prototype.getTileAtIJK = function(i, j, k) {\n var pos = this.tilespaceToWorldspace(i, j, k)\n // TODO: @chrisdickinson: cache the chunk lookup by `i|j|k`\n // since we'll be seeing the same chunk so often\n var chunk = this.getChunkAtPosition(pos)\n\n if(!chunk) {\n return\n }\n\n var chunkPosition = this.chunkspaceToTilespace(chunk.position)\n var chunkID = this.voxels.chunkAtPosition(pos).join('|') \n var chunk = this.voxels.chunks[chunkID]\n \n i -= chunkPosition.i\n j -= chunkPosition.j\n k -= chunkPosition.k\n\n var tileOffset = \n i +\n j * this.chunkSize +\n k * this.chunkSize * this.chunkSize\n\n return chunk.voxels[tileOffset] \n}\n\nGame.prototype.tilespaceToWorldspace = function(i, j, k) {\n return {\n x: i * this.cubeSize,\n y: j * this.cubeSize,\n z: k * this.cubeSize\n }\n}\n\nGame.prototype.chunkspaceToTilespace = function(pos) {\n return {\n i: pos[0] * this.chunkSize,\n j: pos[1] * this.chunkSize,\n k: pos[2] * this.chunkSize\n }\n}\n\nGame.prototype.getChunkAtPosition = function(pos) {\n var chunkID = this.voxels.chunkAtPosition(pos).join('|') \n\n var chunk = this.voxels.chunks[chunkID]\n return chunk\n}\n\nGame.prototype.initializeRendering = function() {\n var self = this\n this.renderer = this.createRenderer()\n if (!this.statsDisabled) this.addStats()\n window.addEventListener('resize', this.onWindowResize.bind(this), false)\n window.addEventListener('mousedown', this.onMouseDown.bind(this), false)\n window.addEventListener('mouseup', this.onMouseUp.bind(this), false)\n requestAnimationFrame(window).on('data', this.tick.bind(this))\n this.chunkRegion.on('change', function(newChunk) {\n self.removeFarChunks()\n })\n}\n\nGame.prototype.removeFarChunks = function(playerPosition) {\n var self = this\n playerPosition = playerPosition || this.controls.yawObject.position\n var nearbyChunks = this.voxels.nearbyChunks(playerPosition, this.removeDistance).map(function(chunkPos) {\n return chunkPos.join('|')\n })\n Object.keys(self.voxels.chunks).map(function(chunkIndex) {\n if (nearbyChunks.indexOf(chunkIndex) > -1) return\n self.scene.remove(self.voxels.meshes[chunkIndex][self.meshType])\n delete self.voxels.chunks[chunkIndex]\n })\n self.voxels.requestMissingChunks(playerPosition)\n}\n\nGame.prototype.parseVectorOption = function(vector) {\n if (!vector) return\n if (vector.length && typeof vector.length === 'number') return new THREE.Vector3(vector[0], vector[1], vector[2])\n if (typeof vector === 'object') return new THREE.Vector3(vector.x, vector.y, vector.z)\n}\n\nGame.prototype.setConfigurablePositions = function(opts) {\n var sp = opts.startingPosition\n if (sp) sp = this.parseVectorOption(sp)\n this.startingPosition = sp || new THREE.Vector3(35,1024,35)\n var wo = opts.worldOrigin\n if (wo) wo = this.parseVectorOption(wo)\n this.worldOrigin = wo || new THREE.Vector3(0,0,0)\n}\n\nGame.prototype.notCapable = function() {\n if( !Detector().webgl ) {\n var wrapper = document.createElement('div')\n wrapper.className = \"errorMessage\"\n var a = document.createElement('a')\n a.title = \"You need WebGL and Pointer Lock (Chrome 23/Firefox 14) to play this game. Click here for more information.\"\n a.innerHTML = a.title\n a.href = \"http://get.webgl.org\"\n wrapper.appendChild(a)\n this.element = wrapper\n return true\n }\n return false\n}\n\nGame.prototype.setupPointerLock = function(element) {\n var self = this\n element = element || document.body\n if (typeof element !== 'object') element = document.querySelector(element)\n var pointer = this.pointer = interact(element)\n if (!pointer.pointerAvailable()) this.pointerLockDisabled = true\n pointer.on('attain', function(movements) {\n self.controls.enabled = true\n movements.pipe(self.controls)\n })\n pointer.on('release', function() {\n self.controls.enabled = false\n })\n pointer.on('error', function() {\n // user denied pointer lock OR it's not available\n self.pointerLockDisabled = true\n console.error('pointerlock error')\n })\n}\n\nGame.prototype.requestPointerLock = function(element) {\n if (!this.pointer) this.setupPointerLock(element)\n this.pointer.request()\n}\n\nGame.prototype.moveToPosition = function(position) {\n var pos = this.controls.yawObject.position\n pos.x = position.x\n pos.y = position.y\n pos.z = position.z\n}\n\nGame.prototype.onWindowResize = function() {\n this.camera.aspect = window.innerWidth / window.innerHeight\n this.camera.updateProjectionMatrix()\n this.renderer.setSize( window.innerWidth, window.innerHeight )\n}\n\nGame.prototype.addMarker = function(position) {\n var geometry = new THREE.SphereGeometry( 1, 4, 4 );\n var material = new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading } );\n var mesh = new THREE.Mesh( geometry, material );\n mesh.position.copy(position)\n this.scene.add(mesh)\n}\n\nGame.prototype.addAABBMarker = function(aabb, color) {\n var geometry = new THREE.CubeGeometry(aabb.width(), aabb.height(), aabb.depth())\n var material = new THREE.MeshBasicMaterial({ color: color || 0xffffff, wireframe: true, transparent: true, opacity: 0.5, side: THREE.DoubleSide })\n var mesh = new THREE.Mesh(geometry, material)\n mesh.position.set(aabb.x0() + aabb.width() / 2, aabb.y0() + aabb.height() / 2, aabb.z0() + aabb.depth() / 2)\n this.scene.add(mesh)\n}\n\nGame.prototype.addItem = function(item) {\n var self = this\n self.items.push(item)\n item.velocity = item.velocity || { x: 0, y: 0, z: 0 }\n item.collisionRadius = item.collisionRadius || item.size\n if (!item.width) item.width = item.size\n if (!item.height) item.height = item.size\n if (!item.depth) item.depth = item.width\n\n var ticker = item.tick\n item.tick = function (dt) {\n if (item.collisionRadius) {\n var p0 = self.controls.yawObject.position.clone()\n var p1 = self.controls.yawObject.position.clone()\n p1.y -= 25\n var d0 = distance(item.mesh.position, p0)\n var d1 = distance(item.mesh.position, p1)\n if (Math.min(d0, d1) <= item.collisionRadius) {\n self.emit('collision', item)\n }\n }\n\n if (!item.resting) {\n var c = self.getCollisions(item.mesh.position, item)\n if (c.bottom.length > 0) {\n if (item.velocity.y <= 0) {\n item.mesh.position.y -= item.velocity.y\n item.velocity.y = 0\n item.resting = true\n }\n item.velocity.x = 0\n item.velocity.z = 0\n } else if (c.middle.length || c.top.length) {\n item.velocity.x *= -1\n item.velocity.z *= -1\n }\n\n item.velocity.y -= 0.003\n item.mesh.position.x += item.velocity.x * dt\n item.mesh.position.y += item.velocity.y * dt\n item.mesh.position.z += item.velocity.z * dt\n }\n\n if (ticker) ticker(item)\n }\n self.scene.add(item.mesh)\n}\n\nGame.prototype.removeItem = function(item) {\n var ix = this.items.indexOf(item)\n if (ix < 0) return\n this.items.splice(ix, 1)\n this.scene.remove(item.mesh)\n}\n\nGame.prototype.onMouseDown = function(e) {\n if (!this.controls.enabled) return\n var intersection = this.raycast()\n if (intersection) this.emit('mousedown', intersection, e)\n}\n\nGame.prototype.onMouseUp = function(e) {\n if (!this.controls.enabled) return\n var intersection = this.raycast()\n if (intersection) this.emit('mouseup', intersection, e)\n}\n\nGame.prototype.intersectAllMeshes = function(start, direction, maxDistance) {\n var self = this\n var meshes = Object.keys(self.voxels.meshes).map(function(key) {\n return self.voxels.meshes[key][self.meshType]\n }).concat(self.chunkGroups.meshes)\n \n var d = direction.subSelf(start).normalize()\n var ray = new THREE.Raycaster(start, d, 0, maxDistance)\n var intersections = ray.intersectObjects(meshes)\n if (intersections.length === 0) return false\n \n var dists = intersections.map(function (i) { return i.distance })\n var inter = intersections[dists.indexOf(Math.min.apply(null, dists))]\n \n var p = new THREE.Vector3()\n p.copy(inter.point)\n p.intersection = inter\n p.direction = d\n \n var cm = self.chunkGroups.chunkMatricies[inter.object.id]\n if (cm) p.chunkMatrix = cm\n \n p.x += d.x\n p.y += d.y\n p.z += d.z\n return p\n}\n\nGame.prototype.raycast = function(maxDistance) {\n var start = this.controls.yawObject.position.clone()\n var direction = this.camera.matrixWorld.multiplyVector3(new THREE.Vector3(0,0,-1))\n var intersects = this.intersectAllMeshes(start, direction, maxDistance)\n return intersects\n}\n\nGame.prototype.createCamera = function() {\n var camera;\n camera = new THREE.PerspectiveCamera(60, this.width / this.height, 1, 10000)\n camera.lookAt(new THREE.Vector3(0, 0, 0))\n this.scene.add(camera)\n return camera\n}\n\nGame.prototype.createControls = function(camera) {\n var controls = playerPhysics(this.camera, this.controlOptions)\n this.scene.add( controls.yawObject )\n return controls\n}\n\nGame.prototype.createRenderer = function() {\n this.renderer = new THREE.WebGLRenderer({\n antialias: true\n })\n this.renderer.setSize(this.width, this.height)\n this.renderer.setClearColorHex(this.skyColor, 1.0)\n this.renderer.clear()\n this.element = this.renderer.domElement\n return this.renderer\n}\n\nGame.prototype.appendTo = function (element) {\n if (typeof element === 'object') {\n element.appendChild(this.element)\n }\n else {\n document.querySelector(element).appendChild(this.element)\n }\n}\n\nGame.prototype.addStats = function() {\n stats = new Stats()\n stats.domElement.style.position = 'absolute'\n stats.domElement.style.bottom = '0px'\n document.body.appendChild( stats.domElement )\n}\n\nGame.prototype.cameraRotation = function() {\n var xAngle = this.controls.pitchObject.rotation.x\n var yAngle = this.controls.yawObject.rotation.y\n return {x: xAngle, y: yAngle}\n}\n\nGame.prototype.getCollisions = function(position, dims, checker, controls) {\n var self = this\n var p = position.clone()\n var w = dims.width / 2\n var h = dims.height / 2\n var d = dims.depth / 2\n\n controls = controls || this.controls\n var rx = controls.pitchObject.rotation.x\n var ry = controls.yawObject.rotation.y\n\n var vertices = {\n bottom: [\n new THREE.Vector3(p.x - w, p.y - h, p.z - d),\n new THREE.Vector3(p.x - w, p.y - h, p.z + d),\n new THREE.Vector3(p.x + w, p.y - h, p.z - d),\n new THREE.Vector3(p.x + w, p.y - h, p.z + d)\n ],\n middle: [\n new THREE.Vector3(p.x - w, p.y, p.z - d),\n new THREE.Vector3(p.x - w, p.y, p.z + d),\n new THREE.Vector3(p.x + w, p.y, p.z - d),\n new THREE.Vector3(p.x + w, p.y, p.z + d)\n ],\n top: [\n new THREE.Vector3(p.x - w, p.y + h, p.z - d),\n new THREE.Vector3(p.x - w, p.y + h, p.z + d),\n new THREE.Vector3(p.x + w, p.y + h, p.z - d),\n new THREE.Vector3(p.x + w, p.y + h, p.z + d)\n ],\n // -------------------------------\n up: [ new THREE.Vector3(p.x, p.y + h, p.z) ],\n down: [ new THREE.Vector3(p.x, p.y - h, p.z) ],\n left: [\n new THREE.Vector3(\n p.x + w * Math.cos(ry + Math.PI / 2),\n p.y,\n p.z + d * Math.sin(ry + Math.PI / 2)\n ) ,\n new THREE.Vector3(\n p.x + w * Math.cos(ry + Math.PI / 2),\n p.y + h * 1.5,\n p.z + d * Math.sin(ry + Math.PI / 2)\n )\n ],\n right: [\n new THREE.Vector3(\n p.x + w * Math.cos(ry - Math.PI / 2),\n p.y,\n p.z + d * Math.sin(ry - Math.PI / 2)\n ),\n new THREE.Vector3(\n p.x + w * Math.cos(ry - Math.PI / 2),\n p.y + h * 1.5,\n p.z + d * Math.sin(ry - Math.PI / 2)\n )\n ],\n back: [\n new THREE.Vector3(\n p.x + w * Math.cos(ry),\n p.y,\n p.z + d * Math.sin(ry)\n ),\n new THREE.Vector3(\n p.x + w * Math.cos(ry),\n p.y + h * 1.5,\n p.z + d * Math.sin(ry)\n )\n ],\n forward: [\n new THREE.Vector3(\n p.x + w * Math.cos(ry + Math.PI),\n p.y,\n p.z + d * Math.sin(ry + Math.PI)\n ),\n new THREE.Vector3(\n p.x + w * Math.cos(ry + Math.PI),\n p.y + h * 1.5,\n p.z + d * Math.sin(ry + Math.PI)\n )\n ]\n }\n\n return {\n bottom: vertices.bottom.map(check).filter(Boolean),\n middle: vertices.middle.map(check).filter(Boolean),\n top: vertices.top.map(check).filter(Boolean),\n // ----\n up: vertices.up.map(check).filter(Boolean),\n down: vertices.down.map(check).filter(Boolean),\n left: vertices.left.map(check).filter(Boolean),\n right: vertices.right.map(check).filter(Boolean),\n forward: vertices.forward.map(check).filter(Boolean),\n back: vertices.back.map(check).filter(Boolean)\n }\n\n function check(vertex) {\n if (checker) return checker(vertex) && vertex\n var val = self.voxels.voxelAtPosition(vertex)\n return val && vertex\n }\n}\n\nGame.prototype.addLights = function(scene) {\n var ambientLight, directionalLight\n ambientLight = new THREE.AmbientLight(0xcccccc)\n scene.add(ambientLight)\n var light = new THREE.DirectionalLight( 0xffffff , 1)\n light.position.set( 1, 1, 0.5 ).normalize()\n scene.add( light )\n};\n\nGame.prototype.currentMesh = function() {\n var cid = this.voxels.chunkAtPosition(this.controls.yawObject.position).join('|')\n return this.voxels.meshes[cid]\n}\n\nGame.prototype.checkBlock = function(pos) {\n var self = this\n var direction = self.camera.matrixWorld.multiplyVector3(new THREE.Vector3(0,0,-1))\n var start = self.controls.yawObject.position.clone()\n var d = direction.subSelf(start).normalize()\n\n var p = new THREE.Vector3()\n p.copy(pos)\n p.x -= 1.1 * d.x\n p.y -= 1.1 * d.y\n p.z -= 1.1 * d.z\n var block = self.getBlock(p)\n if (block) return false\n\n var voxelVector = self.voxels.voxelVector(p)\n var vidx = self.voxels.voxelIndex(voxelVector)\n var c = self.voxels.chunkAtPosition(p)\n var ckey = c.join('|')\n var chunk = self.voxels.chunks[ckey]\n if (!chunk) return false\n\n var aabb = this.playerAABB()\n var bottom = {x: aabb.x0(), y: aabb.y0(), z: aabb.z0()}\n var playerVector = self.voxels.voxelVector(bottom)\n\n if ( playerVector.x === voxelVector.x\n && playerVector.y === voxelVector.y\n && playerVector.z === voxelVector.z) return false\n \n return {chunkIndex: ckey, voxelVector: voxelVector}\n}\n\nGame.prototype.addChunkToNextUpdate = function(chunk) {\n this.chunksNeedsUpdate[chunk.position.join('|')] = chunk\n}\n\nGame.prototype.updateDirtyChunks = function() {\n var self = this;\n Object.keys(this.chunksNeedsUpdate).forEach(function showChunkAtIndex(chunkIndex) {\n var chunk = self.chunksNeedsUpdate[chunkIndex];\n self.showChunk(chunk);\n })\n this.chunksNeedsUpdate = {}\n}\n\nGame.prototype.createBlock = function(pos, val) {\n if (pos.chunkMatrix) {\n return this.chunkGroups.createBlock(pos, val)\n }\n \n var newBlock = this.checkBlock(pos)\n if (!newBlock) return\n var chunk = this.voxels.chunks[newBlock.chunkIndex]\n var old = chunk.voxels[this.voxels.voxelIndex(newBlock.voxelVector)]\n chunk.voxels[this.voxels.voxelIndex(newBlock.voxelVector)] = val\n this.addChunkToNextUpdate(chunk)\n this.spatial.emit('change-block', [pos.x, pos.y, pos.z], pos, old, val)\n return true\n}\n\nGame.prototype.setBlock = function(pos, val) {\n if (pos.chunkMatrix) {\n return this.chunkGroups.setBlock(pos, val)\n }\n \n var hitVoxel = this.voxels.voxelAtPosition(pos, val)\n var c = this.voxels.chunkAtPosition(pos)\n this.addChunkToNextUpdate(this.voxels.chunks[c.join('|')])\n\n this.spatial.emit('change-block', [pos.x, pos.y, pos.z], pos, hitVoxel, val)\n}\n\nGame.prototype.getBlock = function(pos) {\n if (pos.chunkMatrix) {\n return this.chunkGroups.getBlock(pos)\n }\n return this.voxels.voxelAtPosition(pos)\n}\n\nGame.prototype.showChunk = function(chunk) {\n var chunkIndex = chunk.position.join('|')\n var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position)\n var cubeSize = this.cubeSize\n var scale = new THREE.Vector3(cubeSize, cubeSize, cubeSize)\n var mesh = voxelMesh(chunk, this.mesher, scale)\n this.voxels.chunks[chunkIndex] = chunk\n if (this.voxels.meshes[chunkIndex]) this.scene.remove(this.voxels.meshes[chunkIndex][this.meshType])\n this.voxels.meshes[chunkIndex] = mesh\n if (this.meshType === 'wireMesh') mesh.createWireMesh()\n else mesh.createSurfaceMesh(new THREE.MeshFaceMaterial(this.materials.get()))\n mesh.setPosition(bounds[0][0] * cubeSize, bounds[0][1] * cubeSize, bounds[0][2] * cubeSize)\n mesh.addToScene(this.scene)\n this.materials.paint(mesh.geometry)\n this.items.forEach(function (item) { item.resting = false })\n return mesh\n}\n\nGame.prototype.playerAABB = function(position) {\n var pos = position || this.controls.yawObject.position\n var size = this.cubeSize\n\n var bbox = aabb([\n pos.x - size / 4,\n pos.y - size * this.playerHeight,\n pos.z - size / 4\n ], [\n size / 2,\n size * this.playerHeight,\n size / 2\n ])\n return bbox\n}\n\nGame.prototype.updatePlayerPhysics = function(bbox, controls) {\n var self = this\n var pos = controls.yawObject.position\n var yaw = controls.yawObject\n var size = self.cubeSize\n\n var base = [ pos.x, pos.y, pos.z ]\n \n var velocity = [\n controls.velocity.x,\n controls.velocity.y,\n controls.velocity.z\n ]\n \n var worldVector\n\n yaw.translateX(velocity[0])\n yaw.translateY(velocity[1])\n yaw.translateZ(velocity[2])\n\n worldVector = [\n pos.x - base[0],\n pos.y - base[1],\n pos.z - base[2]\n ]\n\n yaw.translateX(-velocity[0])\n yaw.translateY(-velocity[1])\n yaw.translateZ(-velocity[2])\n\n controls.freedom['y-'] = true\n\n self.collideVoxels(bbox, worldVector, function(axis, tile, coords, dir, edgeVector) {\n if (tile) {\n worldVector[axis] = edgeVector\n if (axis === 1 && dir === -1) {\n controls.freedom['y-'] = false\n }\n self.spatial.emit(\n 'collide-'+AXISES[axis],\n [worldVector[0] + base[0], worldVector[1] + base[1], worldVector[2] + base[2]],\n tile, coords, dir\n )\n return true\n }\n }) \n \n var newLocation = new THREE.Vector3(\n worldVector[0] + base[0], worldVector[1] + base[1], worldVector[2] + base[2]\n )\n\n pos.copy(newLocation)\n\n self.spatial.emit('position', bbox, newLocation)\n\n}\n\nGame.prototype.bindControls = function (controls) {\n var self = this\n var onKeyDown = function ( event ) {\n var command = self.playerControls[event.keyCode];\n if (command) { controls.emit('command', command, true); }\n }\n\n var onKeyUp = function ( event ) {\n var command = self.playerControls[event.keyCode];\n if (command) { controls.emit('command', command, false); }\n }\n\n document.addEventListener( 'keydown', onKeyDown, false )\n document.addEventListener( 'keyup', onKeyUp, false )\n}\n\nGame.prototype.tick = function(delta) {\n var self = this\n this.controls.tick(delta, function(controls) {\n var bbox = self.playerAABB()\n self.updatePlayerPhysics(bbox, controls)\n })\n this.items.forEach(function (item) { item.tick(delta) })\n if (this.materials) this.materials.tick()\n if (Object.keys(this.chunksNeedsUpdate).length > 0) this.updateDirtyChunks();\n this.emit('tick', delta)\n this.render(delta)\n stats.update()\n}\n\nGame.prototype.render = function(delta) {\n this.renderer.render(this.scene, this.camera)\n}\n\nfunction distance (a, b) {\n var x = a.x - b.x\n var y = a.y - b.y\n var z = a.z - b.z\n return Math.sqrt(x*x + y*y + z*z)\n}\n\n//@ sourceURL=/node_modules/voxel-engine/index.js")),n.define("/node_modules/voxel/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel/package.json')),n.define("/node_modules/voxel/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var chunker = require('./chunker')\n\nmodule.exports = function(opts) {\n if (!opts.generateVoxelChunk) opts.generateVoxelChunk = function(low, high) {\n return generate(low, high, module.exports.generator['Valley'])\n }\n return chunker(opts)\n}\n\nmodule.exports.meshers = {\n culled: require('./meshers/culled').mesher,\n greedy: require('./meshers/greedy').mesher,\n monotone: require('./meshers/monotone').mesher,\n stupid: require('./meshers/stupid').mesher\n}\n\nmodule.exports.Chunker = chunker.Chunker\nmodule.exports.geometry = {}\nmodule.exports.generator = {}\nmodule.exports.generate = generate\n\n// from https://github.com/mikolalysenko/mikolalysenko.github.com/blob/master/MinecraftMeshes2/js/testdata.js#L4\nfunction generate(l, h, f) {\n var d = [ h[0]-l[0], h[1]-l[1], h[2]-l[2] ]\n var v = new Int8Array(d[0]*d[1]*d[2])\n var n = 0\n for(var k=l[2]; k<h[2]; ++k)\n for(var j=l[1]; j<h[1]; ++j)\n for(var i=l[0]; i<h[0]; ++i, ++n) {\n v[n] = f(i,j,k,n)\n }\n return {voxels:v, dims:d}\n}\n\n// shape and terrain generator functions\nmodule.exports.generator['Sphere'] = function(i,j,k) {\n return i*i+j*j+k*k <= 16*16 ? 1 : 0\n}\n\nmodule.exports.generator['Noise'] = function(i,j,k) {\n return Math.random() < 0.1 ? Math.random() * 0xffffff : 0;\n}\n\nmodule.exports.generator['Dense Noise'] = function(i,j,k) {\n return Math.round(Math.random() * 0xffffff);\n}\n\nmodule.exports.generator['Checker'] = function(i,j,k) {\n return !!((i+j+k)&1) ? (((i^j^k)&2) ? 1 : 0xffffff) : 0;\n}\n\nmodule.exports.generator['Hill'] = function(i,j,k) {\n return j <= 16 * Math.exp(-(i*i + k*k) / 64) ? 1 : 0;\n}\n\nmodule.exports.generator['Valley'] = function(i,j,k) {\n return j <= (i*i + k*k) * 31 / (32*32*2) + 1 ? 1 : 0;\n}\n\nmodule.exports.generator['Hilly Terrain'] = function(i,j,k) {\n var h0 = 3.0 * Math.sin(Math.PI * i / 12.0 - Math.PI * k * 0.1) + 27; \n if(j > h0+1) {\n return 0;\n }\n if(h0 <= j) {\n return 1;\n }\n var h1 = 2.0 * Math.sin(Math.PI * i * 0.25 - Math.PI * k * 0.3) + 20;\n if(h1 <= j) {\n return 2;\n }\n if(2 < j) {\n return Math.random() < 0.1 ? 0x222222 : 0xaaaaaa;\n }\n return 3;\n}\n\nmodule.exports.scale = function ( x, fromLow, fromHigh, toLow, toHigh ) {\n return ( x - fromLow ) * ( toHigh - toLow ) / ( fromHigh - fromLow ) + toLow\n}\n\n// convenience function that uses the above functions to prebake some simple voxel geometries\nmodule.exports.generateExamples = function() {\n return {\n 'Sphere': generate([-16,-16,-16], [16,16,16], module.exports.generator['Sphere']),\n 'Noise': generate([0,0,0], [16,16,16], module.exports.generator['Noise']),\n 'Dense Noise': generate([0,0,0], [16,16,16], module.exports.generator['Dense Noise']),\n 'Checker': generate([0,0,0], [8,8,8], module.exports.generator['Checker']),\n 'Hill': generate([-16, 0, -16], [16,16,16], module.exports.generator['Hill']),\n 'Valley': generate([0,0,0], [32,32,32], module.exports.generator['Valley']),\n 'Hilly Terrain': generate([0, 0, 0], [32,32,32], module.exports.generator['Hilly Terrain'])\n }\n}\n\n\n//@ sourceURL=/node_modules/voxel/index.js")),n.define("/node_modules/voxel/chunker.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var events = require('events')\nvar inherits = require('inherits')\n\nmodule.exports = function(opts) {\n return new Chunker(opts)\n}\n\nmodule.exports.Chunker = Chunker\n\nfunction Chunker(opts) {\n this.distance = opts.chunkDistance || 2\n this.chunkSize = opts.chunkSize || 32\n this.cubeSize = opts.cubeSize || 25\n this.generateVoxelChunk = opts.generateVoxelChunk\n this.chunks = {}\n this.meshes = {}\n}\n\ninherits(Chunker, events.EventEmitter)\n\nChunker.prototype.nearbyChunks = function(position, distance) {\n var current = this.chunkAtPosition(position)\n var x = current[0]\n var y = current[1]\n var z = current[2]\n var dist = distance || this.distance\n var nearby = []\n for (var cx = (x - dist); cx !== (x + dist); ++cx) {\n for (var cy = (y - dist); cy !== (y + dist); ++cy) {\n for (var cz = (z - dist); cz !== (z + dist); ++cz) {\n nearby.push([cx, cy, cz])\n }\n }\n }\n return nearby\n}\n\nChunker.prototype.requestMissingChunks = function(position) {\n var self = this\n this.nearbyChunks(position).map(function(chunk) {\n if (!self.chunks[chunk.join('|')]) {\n self.emit('missingChunk', chunk)\n }\n })\n}\n\nChunker.prototype.getBounds = function(x, y, z) {\n var size = this.chunkSize\n var low = [x * size, y * size, z * size]\n var high = [low[0] + size, low[1] + size, low[2] + size]\n return [low, high]\n}\n\nChunker.prototype.generateChunk = function(x, y, z) {\n var self = this\n var bounds = this.getBounds(x, y, z)\n var chunk = this.generateVoxelChunk(bounds[0], bounds[1], x, y, z)\n var position = [x, y, z]\n chunk.position = position\n this.chunks[position.join('|')] = chunk\n return chunk\n}\n\nChunker.prototype.chunkAtPosition = function(position) {\n var chunkSize = this.chunkSize\n var cubeSize = this.cubeSize\n var cx = position.x / cubeSize / chunkSize\n var cy = position.y / cubeSize / chunkSize\n var cz = position.z / cubeSize / chunkSize\n var chunkPos = [Math.floor(cx), Math.floor(cy), Math.floor(cz)]\n return chunkPos\n};\n\nChunker.prototype.voxelIndex = function(voxelVector) {\n var size = this.chunkSize\n var vidx = voxelVector.x + voxelVector.y*size + voxelVector.z*size*size\n return vidx\n}\n\nChunker.prototype.voxelIndexFromPosition = function(pos) {\n var v = this.voxelVector(pos)\n return this.voxelIndex(v)\n}\n\nChunker.prototype.voxelAtPosition = function(pos, val) {\n var ckey = this.chunkAtPosition(pos).join('|')\n var chunk = this.chunks[ckey]\n if (!chunk) return false\n var vector = this.voxelVector(pos)\n var vidx = this.voxelIndex(vector)\n if (!vidx && vidx !== 0) return false\n if (typeof val !== 'undefined') {\n chunk.voxels[vidx] = val\n }\n var v = chunk.voxels[vidx]\n return v\n}\n\nChunker.prototype.voxelVector = function(pos) {\n var size = this.chunkSize\n var cubeSize = this.cubeSize\n var vx = (size + Math.floor(pos.x / cubeSize) % size) % size\n var vy = (size + Math.floor(pos.y / cubeSize) % size) % size\n var vz = (size + Math.floor(pos.z / cubeSize) % size) % size\n return {x: Math.abs(vx), y: Math.abs(vy), z: Math.abs(vz)}\n};\n\n//@ sourceURL=/node_modules/voxel/chunker.js")),n.define("events",Function(["require","module","exports","__dirname","__filename","process","global"],"if (!process.EventEmitter) process.EventEmitter = function () {};\n\nvar EventEmitter = exports.EventEmitter = process.EventEmitter;\nvar isArray = typeof Array.isArray === 'function'\n ? Array.isArray\n : function (xs) {\n return Object.prototype.toString.call(xs) === '[object Array]'\n }\n;\nfunction indexOf (xs, x) {\n if (xs.indexOf) return xs.indexOf(x);\n for (var i = 0; i < xs.length; i++) {\n if (x === xs[i]) return i;\n }\n return -1;\n}\n\n// By default EventEmitters will print a warning if more than\n// 10 listeners are added to it. This is a useful default which\n// helps finding memory leaks.\n//\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nvar defaultMaxListeners = 10;\nEventEmitter.prototype.setMaxListeners = function(n) {\n if (!this._events) this._events = {};\n this._events.maxListeners = n;\n};\n\n\nEventEmitter.prototype.emit = function(type) {\n // If there is no 'error' event listener then throw.\n if (type === 'error') {\n if (!this._events || !this._events.error ||\n (isArray(this._events.error) && !this._events.error.length))\n {\n if (arguments[1] instanceof Error) {\n throw arguments[1]; // Unhandled 'error' event\n } else {\n throw new Error(\"Uncaught, unspecified 'error' event.\");\n }\n return false;\n }\n }\n\n if (!this._events) return false;\n var handler = this._events[type];\n if (!handler) return false;\n\n if (typeof handler == 'function') {\n switch (arguments.length) {\n // fast cases\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n // slower\n default:\n var args = Array.prototype.slice.call(arguments, 1);\n handler.apply(this, args);\n }\n return true;\n\n } else if (isArray(handler)) {\n var args = Array.prototype.slice.call(arguments, 1);\n\n var listeners = handler.slice();\n for (var i = 0, l = listeners.length; i < l; i++) {\n listeners[i].apply(this, args);\n }\n return true;\n\n } else {\n return false;\n }\n};\n\n// EventEmitter is defined in src/node_events.cc\n// EventEmitter.prototype.emit() is also defined there.\nEventEmitter.prototype.addListener = function(type, listener) {\n if ('function' !== typeof listener) {\n throw new Error('addListener only takes instances of Function');\n }\n\n if (!this._events) this._events = {};\n\n // To avoid recursion in the case that type == \"newListeners\"! Before\n // adding it to the listeners, first emit \"newListeners\".\n this.emit('newListener', type, listener);\n\n if (!this._events[type]) {\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n } else if (isArray(this._events[type])) {\n\n // Check for listener leak\n if (!this._events[type].warned) {\n var m;\n if (this._events.maxListeners !== undefined) {\n m = this._events.maxListeners;\n } else {\n m = defaultMaxListeners;\n }\n\n if (m && m > 0 && this._events[type].length > m) {\n this._events[type].warned = true;\n console.error('(node) warning: possible EventEmitter memory ' +\n 'leak detected. %d listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.',\n this._events[type].length);\n console.trace();\n }\n }\n\n // If we've already got an array, just append.\n this._events[type].push(listener);\n } else {\n // Adding the second element, need to change to array.\n this._events[type] = [this._events[type], listener];\n }\n\n return this;\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.once = function(type, listener) {\n var self = this;\n self.on(type, function g() {\n self.removeListener(type, g);\n listener.apply(this, arguments);\n });\n\n return this;\n};\n\nEventEmitter.prototype.removeListener = function(type, listener) {\n if ('function' !== typeof listener) {\n throw new Error('removeListener only takes instances of Function');\n }\n\n // does not use listeners(), so no side effect of creating _events[type]\n if (!this._events || !this._events[type]) return this;\n\n var list = this._events[type];\n\n if (isArray(list)) {\n var i = indexOf(list, listener);\n if (i < 0) return this;\n list.splice(i, 1);\n if (list.length == 0)\n delete this._events[type];\n } else if (this._events[type] === listener) {\n delete this._events[type];\n }\n\n return this;\n};\n\nEventEmitter.prototype.removeAllListeners = function(type) {\n // does not use listeners(), so no side effect of creating _events[type]\n if (type && this._events && this._events[type]) this._events[type] = null;\n return this;\n};\n\nEventEmitter.prototype.listeners = function(type) {\n if (!this._events) this._events = {};\n if (!this._events[type]) this._events[type] = [];\n if (!isArray(this._events[type])) {\n this._events[type] = [this._events[type]];\n }\n return this._events[type];\n};\n\n//@ sourceURL=events")),n.define("/node_modules/voxel/node_modules/inherits/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"./inherits.js"}\n//@ sourceURL=/node_modules/voxel/node_modules/inherits/package.json')),n.define("/node_modules/voxel/node_modules/inherits/inherits.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = inherits\n\nfunction inherits (c, p, proto) {\n proto = proto || {}\n var e = {}\n ;[c.prototype, proto].forEach(function (s) {\n Object.getOwnPropertyNames(s).forEach(function (k) {\n e[k] = Object.getOwnPropertyDescriptor(s, k)\n })\n })\n c.prototype = Object.create(p.prototype, e)\n c.super = p\n}\n\n//function Child () {\n// Child.super.call(this)\n// console.error([this\n// ,this.constructor\n// ,this.constructor === Child\n// ,this.constructor.super === Parent\n// ,Object.getPrototypeOf(this) === Child.prototype\n// ,Object.getPrototypeOf(Object.getPrototypeOf(this))\n// === Parent.prototype\n// ,this instanceof Child\n// ,this instanceof Parent])\n//}\n//function Parent () {}\n//inherits(Child, Parent)\n//new Child\n\n//@ sourceURL=/node_modules/voxel/node_modules/inherits/inherits.js")),n.define("/node_modules/voxel/meshers/culled.js",Function(["require","module","exports","__dirname","__filename","process","global"],"//Naive meshing (with face culling)\nfunction CulledMesh(volume, dims) {\n //Precalculate direction vectors for convenience\n var dir = new Array(3);\n for(var i=0; i<3; ++i) {\n dir[i] = [[0,0,0], [0,0,0]];\n dir[i][0][(i+1)%3] = 1;\n dir[i][1][(i+2)%3] = 1;\n }\n //March over the volume\n var vertices = []\n , faces = []\n , x = [0,0,0]\n , B = [[false,true] //Incrementally update bounds (this is a bit ugly)\n ,[false,true]\n ,[false,true]]\n , n = -dims[0]*dims[1];\n for( B[2]=[false,true],x[2]=-1; x[2]<dims[2]; B[2]=[true,(++x[2]<dims[2]-1)])\n for(n-=dims[0],B[1]=[false,true],x[1]=-1; x[1]<dims[1]; B[1]=[true,(++x[1]<dims[1]-1)])\n for(n-=1, B[0]=[false,true],x[0]=-1; x[0]<dims[0]; B[0]=[true,(++x[0]<dims[0]-1)], ++n) {\n //Read current voxel and 3 neighboring voxels using bounds check results\n var p = (B[0][0] && B[1][0] && B[2][0]) ? volume[n] : 0\n , b = [ (B[0][1] && B[1][0] && B[2][0]) ? volume[n+1] : 0\n , (B[0][0] && B[1][1] && B[2][0]) ? volume[n+dims[0]] : 0\n , (B[0][0] && B[1][0] && B[2][1]) ? volume[n+dims[0]*dims[1]] : 0\n ];\n //Generate faces\n for(var d=0; d<3; ++d)\n if((!!p) !== (!!b[d])) {\n var s = !p ? 1 : 0;\n var t = [x[0],x[1],x[2]]\n , u = dir[d][s]\n , v = dir[d][s^1];\n ++t[d];\n \n var vertex_count = vertices.length;\n vertices.push([t[0], t[1], t[2] ]);\n vertices.push([t[0]+u[0], t[1]+u[1], t[2]+u[2] ]);\n vertices.push([t[0]+u[0]+v[0], t[1]+u[1]+v[1], t[2]+u[2]+v[2]]);\n vertices.push([t[0] +v[0], t[1] +v[1], t[2] +v[2]]);\n faces.push([vertex_count, vertex_count+1, vertex_count+2, vertex_count+3, s ? b[d] : p]);\n }\n }\n return { vertices:vertices, faces:faces };\n}\n\n\nif(exports) {\n exports.mesher = CulledMesh;\n}\n\n//@ sourceURL=/node_modules/voxel/meshers/culled.js")),n.define("/node_modules/voxel/meshers/greedy.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var GreedyMesh = (function() {\n//Cache buffer internally\nvar mask = new Int32Array(4096);\n\nreturn function(volume, dims) {\n var vertices = [], faces = []\n , dimsX = dims[0]\n , dimsY = dims[1]\n , dimsXY = dimsX * dimsY;\n\n //Sweep over 3-axes\n for(var d=0; d<3; ++d) {\n var i, j, k, l, w, W, h, n, c\n , u = (d+1)%3\n , v = (d+2)%3\n , x = [0,0,0]\n , q = [0,0,0]\n , du = [0,0,0]\n , dv = [0,0,0]\n , dimsD = dims[d]\n , dimsU = dims[u]\n , dimsV = dims[v]\n , qdimsX, qdimsXY\n , xd\n\n if (mask.length < dimsU * dimsV) {\n mask = new Int32Array(dimsU * dimsV);\n }\n\n q[d] = 1;\n x[d] = -1;\n\n qdimsX = dimsX * q[1]\n qdimsXY = dimsXY * q[2]\n\n // Compute mask\n while (x[d] < dimsD) {\n xd = x[d]\n n = 0;\n\n for(x[v] = 0; x[v] < dimsV; ++x[v]) {\n for(x[u] = 0; x[u] < dimsU; ++x[u], ++n) {\n var a = xd >= 0 && volume[x[0] + dimsX * x[1] + dimsXY * x[2] ]\n , b = xd < dimsD-1 && volume[x[0]+q[0] + dimsX * x[1] + qdimsX + dimsXY * x[2] + qdimsXY]\n if (a ? b : !b) {\n mask[n] = 0; continue;\n }\n mask[n] = a ? a : -b;\n }\n }\n\n ++x[d];\n\n // Generate mesh for mask using lexicographic ordering\n n = 0;\n for (j=0; j < dimsV; ++j) {\n for (i=0; i < dimsU; ) {\n c = mask[n];\n if (!c) {\n i++; n++; continue;\n }\n\n //Compute width\n w = 1;\n while (c === mask[n+w] && i+w < dimsU) w++;\n\n //Compute height (this is slightly awkward)\n for (h=1; j+h < dimsV; ++h) {\n k = 0;\n while (k < w && c === mask[n+k+h*dimsU]) k++\n if (k < w) break;\n }\n\n // Add quad\n // The du/dv arrays are reused/reset\n // for each iteration.\n du[d] = 0; dv[d] = 0;\n x[u] = i; x[v] = j;\n\n if (c > 0) {\n dv[v] = h; dv[u] = 0;\n du[u] = w; du[v] = 0;\n } else {\n c = -c;\n du[v] = h; du[u] = 0;\n dv[u] = w; dv[v] = 0;\n }\n var vertex_count = vertices.length;\n vertices.push([x[0], x[1], x[2] ]);\n vertices.push([x[0]+du[0], x[1]+du[1], x[2]+du[2] ]);\n vertices.push([x[0]+du[0]+dv[0], x[1]+du[1]+dv[1], x[2]+du[2]+dv[2]]);\n vertices.push([x[0] +dv[0], x[1] +dv[1], x[2] +dv[2]]);\n faces.push([vertex_count, vertex_count+1, vertex_count+2, vertex_count+3, c]);\n\n //Zero-out mask\n W = n + w;\n for(l=0; l<h; ++l) {\n for(k=n; k<W; ++k) {\n mask[k+l*dimsU] = 0;\n }\n }\n\n //Increment counters and continue\n i += w; n += w;\n }\n }\n }\n }\n return { vertices:vertices, faces:faces };\n}\n})();\n\nif(exports) {\n exports.mesher = GreedyMesh;\n}\n\n//@ sourceURL=/node_modules/voxel/meshers/greedy.js")),n.define("/node_modules/voxel/meshers/monotone.js",Function(["require","module","exports","__dirname","__filename","process","global"],'"use strict";\n\nvar MonotoneMesh = (function(){\n\nfunction MonotonePolygon(c, v, ul, ur) {\n this.color = c;\n this.left = [[ul, v]];\n this.right = [[ur, v]];\n};\n\nMonotonePolygon.prototype.close_off = function(v) {\n this.left.push([ this.left[this.left.length-1][0], v ]);\n this.right.push([ this.right[this.right.length-1][0], v ]);\n};\n\nMonotonePolygon.prototype.merge_run = function(v, u_l, u_r) {\n var l = this.left[this.left.length-1][0]\n , r = this.right[this.right.length-1][0]; \n if(l !== u_l) {\n this.left.push([ l, v ]);\n this.left.push([ u_l, v ]);\n }\n if(r !== u_r) {\n this.right.push([ r, v ]);\n this.right.push([ u_r, v ]);\n }\n};\n\n\nreturn function(volume, dims) {\n function f(i,j,k) {\n return volume[i + dims[0] * (j + dims[1] * k)];\n }\n //Sweep over 3-axes\n var vertices = [], faces = [];\n for(var d=0; d<3; ++d) {\n var i, j, k\n , u = (d+1)%3 //u and v are orthogonal directions to d\n , v = (d+2)%3\n , x = new Int32Array(3)\n , q = new Int32Array(3)\n , runs = new Int32Array(2 * (dims[u]+1))\n , frontier = new Int32Array(dims[u]) //Frontier is list of pointers to polygons\n , next_frontier = new Int32Array(dims[u])\n , left_index = new Int32Array(2 * dims[v])\n , right_index = new Int32Array(2 * dims[v])\n , stack = new Int32Array(24 * dims[v])\n , delta = [[0,0], [0,0]];\n //q points along d-direction\n q[d] = 1;\n //Initialize sentinel\n for(x[d]=-1; x[d]<dims[d]; ) {\n // --- Perform monotone polygon subdivision ---\n var n = 0\n , polygons = []\n , nf = 0;\n for(x[v]=0; x[v]<dims[v]; ++x[v]) {\n //Make one pass over the u-scan line of the volume to run-length encode polygon\n var nr = 0, p = 0, c = 0;\n for(x[u]=0; x[u]<dims[u]; ++x[u], p = c) {\n //Compute the type for this face\n var a = (0 <= x[d] ? f(x[0], x[1], x[2]) : 0)\n , b = (x[d] < dims[d]-1 ? f(x[0]+q[0], x[1]+q[1], x[2]+q[2]) : 0);\n c = a;\n if((!a) === (!b)) {\n c = 0;\n } else if(!a) {\n c = -b;\n }\n //If cell type doesn\'t match, start a new run\n if(p !== c) {\n runs[nr++] = x[u];\n runs[nr++] = c;\n }\n }\n //Add sentinel run\n runs[nr++] = dims[u];\n runs[nr++] = 0;\n //Update frontier by merging runs\n var fp = 0;\n for(var i=0, j=0; i<nf && j<nr-2; ) {\n var p = polygons[frontier[i]]\n , p_l = p.left[p.left.length-1][0]\n , p_r = p.right[p.right.length-1][0]\n , p_c = p.color\n , r_l = runs[j] //Start of run\n , r_r = runs[j+2] //End of run\n , r_c = runs[j+1]; //Color of run\n //Check if we can merge run with polygon\n if(r_r > p_l && p_r > r_l && r_c === p_c) {\n //Merge run\n p.merge_run(x[v], r_l, r_r);\n //Insert polygon into frontier\n next_frontier[fp++] = frontier[i];\n ++i;\n j += 2;\n } else {\n //Check if we need to advance the run pointer\n if(r_r <= p_r) {\n if(!!r_c) {\n var n_poly = new MonotonePolygon(r_c, x[v], r_l, r_r);\n next_frontier[fp++] = polygons.length;\n polygons.push(n_poly);\n }\n j += 2;\n }\n //Check if we need to advance the frontier pointer\n if(p_r <= r_r) {\n p.close_off(x[v]);\n ++i;\n }\n }\n }\n //Close off any residual polygons\n for(; i<nf; ++i) {\n polygons[frontier[i]].close_off(x[v]);\n }\n //Add any extra runs to frontier\n for(; j<nr-2; j+=2) {\n var r_l = runs[j]\n , r_r = runs[j+2]\n , r_c = runs[j+1];\n if(!!r_c) {\n var n_poly = new MonotonePolygon(r_c, x[v], r_l, r_r);\n next_frontier[fp++] = polygons.length;\n polygons.push(n_poly);\n }\n }\n //Swap frontiers\n var tmp = next_frontier;\n next_frontier = frontier;\n frontier = tmp;\n nf = fp;\n }\n //Close off frontier\n for(var i=0; i<nf; ++i) {\n var p = polygons[frontier[i]];\n p.close_off(dims[v]);\n }\n // --- Monotone subdivision of polygon is complete at this point ---\n \n x[d]++;\n \n //Now we just need to triangulate each monotone polygon\n for(var i=0; i<polygons.length; ++i) {\n var p = polygons[i]\n , c = p.color\n , flipped = false;\n if(c < 0) {\n flipped = true;\n c = -c;\n }\n for(var j=0; j<p.left.length; ++j) {\n left_index[j] = vertices.length;\n var y = [0.0,0.0,0.0]\n , z = p.left[j];\n y[d] = x[d];\n y[u] = z[0];\n y[v] = z[1];\n vertices.push(y);\n }\n for(var j=0; j<p.right.length; ++j) {\n right_index[j] = vertices.length;\n var y = [0.0,0.0,0.0]\n , z = p.right[j];\n y[d] = x[d];\n y[u] = z[0];\n y[v] = z[1];\n vertices.push(y);\n }\n //Triangulate the monotone polygon\n var bottom = 0\n , top = 0\n , l_i = 1\n , r_i = 1\n , side = true; //true = right, false = left\n \n stack[top++] = left_index[0];\n stack[top++] = p.left[0][0];\n stack[top++] = p.left[0][1];\n \n stack[top++] = right_index[0];\n stack[top++] = p.right[0][0];\n stack[top++] = p.right[0][1];\n \n while(l_i < p.left.length || r_i < p.right.length) {\n //Compute next side\n var n_side = false;\n if(l_i === p.left.length) {\n n_side = true;\n } else if(r_i !== p.right.length) {\n var l = p.left[l_i]\n , r = p.right[r_i];\n n_side = l[1] > r[1];\n }\n var idx = n_side ? right_index[r_i] : left_index[l_i]\n , vert = n_side ? p.right[r_i] : p.left[l_i];\n if(n_side !== side) {\n //Opposite side\n while(bottom+3 < top) {\n if(flipped === n_side) {\n faces.push([ stack[bottom], stack[bottom+3], idx, c]);\n } else {\n faces.push([ stack[bottom+3], stack[bottom], idx, c]); \n }\n bottom += 3;\n }\n } else {\n //Same side\n while(bottom+3 < top) {\n //Compute convexity\n for(var j=0; j<2; ++j)\n for(var k=0; k<2; ++k) {\n delta[j][k] = stack[top-3*(j+1)+k+1] - vert[k];\n }\n var det = delta[0][0] * delta[1][1] - delta[1][0] * delta[0][1];\n if(n_side === (det > 0)) {\n break;\n }\n if(det !== 0) {\n if(flipped === n_side) {\n faces.push([ stack[top-3], stack[top-6], idx, c ]);\n } else {\n faces.push([ stack[top-6], stack[top-3], idx, c ]);\n }\n }\n top -= 3;\n }\n }\n //Push vertex\n stack[top++] = idx;\n stack[top++] = vert[0];\n stack[top++] = vert[1];\n //Update loop index\n if(n_side) {\n ++r_i;\n } else {\n ++l_i;\n }\n side = n_side;\n }\n }\n }\n }\n return { vertices:vertices, faces:faces };\n}\n})();\n\nif(exports) {\n exports.mesher = MonotoneMesh;\n}\n\n//@ sourceURL=/node_modules/voxel/meshers/monotone.js')),n.define("/node_modules/voxel/meshers/stupid.js",Function(["require","module","exports","__dirname","__filename","process","global"],"//The stupidest possible way to generate a Minecraft mesh (I think)\nfunction StupidMesh(volume, dims) {\n var vertices = [], faces = [], x = [0,0,0], n = 0;\n for(x[2]=0; x[2]<dims[2]; ++x[2])\n for(x[1]=0; x[1]<dims[1]; ++x[1])\n for(x[0]=0; x[0]<dims[0]; ++x[0], ++n)\n if(!!volume[n]) {\n for(var d=0; d<3; ++d) {\n var t = [x[0], x[1], x[2]]\n , u = [0,0,0]\n , v = [0,0,0];\n u[(d+1)%3] = 1;\n v[(d+2)%3] = 1;\n for(var s=0; s<2; ++s) {\n t[d] = x[d] + s;\n var tmp = u;\n u = v;\n v = tmp;\n var vertex_count = vertices.length;\n vertices.push([t[0], t[1], t[2] ]);\n vertices.push([t[0]+u[0], t[1]+u[1], t[2]+u[2] ]);\n vertices.push([t[0]+u[0]+v[0], t[1]+u[1]+v[1], t[2]+u[2]+v[2]]);\n vertices.push([t[0] +v[0], t[1] +v[1], t[2] +v[2]]);\n faces.push([vertex_count, vertex_count+1, vertex_count+2, vertex_count+3, volume[n]]);\n }\n }\n }\n return { vertices:vertices, faces:faces };\n}\n\n\nif(exports) {\n exports.mesher = StupidMesh;\n}\n\n//@ sourceURL=/node_modules/voxel/meshers/stupid.js")),n.define("/node_modules/voxel-mesh/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-mesh/package.json')),n.define("/node_modules/voxel-mesh/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var THREE = require('three')\n\nmodule.exports = function(data, scaleFactor, mesher) {\n return new Mesh(data, scaleFactor, mesher)\n}\n\nmodule.exports.Mesh = Mesh\n\nfunction Mesh(data, mesher, scaleFactor) {\n this.data = data\n var geometry = this.geometry = new THREE.Geometry()\n this.scale = scaleFactor || new THREE.Vector3(10, 10, 10)\n \n var result = mesher( data.voxels, data.dims )\n this.meshed = result\n\n geometry.vertices.length = 0\n geometry.faces.length = 0\n\n for (var i = 0; i < result.vertices.length; ++i) {\n var q = result.vertices[i]\n geometry.vertices.push(new THREE.Vector3(q[0], q[1], q[2]))\n } \n \n for (var i = 0; i < result.faces.length; ++i) {\n geometry.faceVertexUvs[0].push(this.faceVertexUv(i))\n \n var q = result.faces[i]\n if (q.length === 5) {\n var f = new THREE.Face4(q[0], q[1], q[2], q[3])\n f.color = new THREE.Color(q[4])\n f.vertexColors = [f.color,f.color,f.color,f.color]\n geometry.faces.push(f)\n } else if (q.length == 4) {\n var f = new THREE.Face3(q[0], q[1], q[2])\n f.color = new THREE.Color(q[3])\n f.vertexColors = [f.color,f.color,f.color]\n geometry.faces.push(f)\n }\n }\n \n geometry.computeFaceNormals()\n\n geometry.verticesNeedUpdate = true\n geometry.elementsNeedUpdate = true\n geometry.normalsNeedUpdate = true\n\n geometry.computeBoundingBox()\n geometry.computeBoundingSphere()\n\n}\n\nMesh.prototype.createWireMesh = function(hexColor) { \n var wireMaterial = new THREE.MeshBasicMaterial({\n color : hexColor || 0xffffff,\n wireframe : true\n })\n wireMesh = new THREE.Mesh(this.geometry, wireMaterial)\n wireMesh.scale = this.scale\n wireMesh.doubleSided = true\n this.wireMesh = wireMesh\n return wireMesh\n}\n\nMesh.prototype.createSurfaceMesh = function(material) {\n material = material || new THREE.MeshNormalMaterial()\n var surfaceMesh = new THREE.Mesh( this.geometry, material )\n surfaceMesh.scale = this.scale\n surfaceMesh.doubleSided = false\n this.surfaceMesh = surfaceMesh\n return surfaceMesh\n}\n\nMesh.prototype.addToScene = function(scene) {\n if (this.wireMesh) scene.add( this.wireMesh )\n if (this.surfaceMesh) scene.add( this.surfaceMesh )\n}\n\nMesh.prototype.setPosition = function(x, y, z) {\n if (this.wireMesh) this.wireMesh.position = new THREE.Vector3(x, y, z)\n if (this.surfaceMesh) this.surfaceMesh.position = new THREE.Vector3(x, y, z)\n}\n\nMesh.prototype.faceVertexUv = function(i) {\n var vs = [\n this.meshed.vertices[i*4+0],\n this.meshed.vertices[i*4+1],\n this.meshed.vertices[i*4+2],\n this.meshed.vertices[i*4+3]\n ]\n var spans = {\n x0: vs[0][0] - vs[1][0],\n x1: vs[1][0] - vs[2][0],\n y0: vs[0][1] - vs[1][1],\n y1: vs[1][1] - vs[2][1],\n z0: vs[0][2] - vs[1][2],\n z1: vs[1][2] - vs[2][2]\n }\n var size = {\n x: Math.max(Math.abs(spans.x0), Math.abs(spans.x1)),\n y: Math.max(Math.abs(spans.y0), Math.abs(spans.y1)),\n z: Math.max(Math.abs(spans.z0), Math.abs(spans.z1))\n }\n if (size.x === 0) {\n if (spans.y0 > spans.y1) {\n var width = size.y\n var height = size.z\n }\n else {\n var width = size.z\n var height = size.y\n }\n }\n if (size.y === 0) {\n if (spans.x0 > spans.x1) {\n var width = size.x\n var height = size.z\n }\n else {\n var width = size.z\n var height = size.x\n }\n }\n if (size.z === 0) {\n if (spans.x0 > spans.x1) {\n var width = size.x\n var height = size.y\n }\n else {\n var width = size.y\n var height = size.x\n }\n }\n if ((size.z === 0 && spans.x0 < spans.x1) || (size.x === 0 && spans.y0 > spans.y1)) {\n return [\n new THREE.Vector2(height, 0),\n new THREE.Vector2(0, 0),\n new THREE.Vector2(0, width),\n new THREE.Vector2(height, width)\n ]\n } else {\n return [\n new THREE.Vector2(0, 0),\n new THREE.Vector2(0, height),\n new THREE.Vector2(width, height),\n new THREE.Vector2(width, 0)\n ]\n }\n}\n;\n\n//@ sourceURL=/node_modules/voxel-mesh/index.js")),n.define("/node_modules/three/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"./three.js"}\n//@ sourceURL=/node_modules/three/package.json')),n.define("/node_modules/three/three.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = THREE\n//@ sourceURL=/node_modules/three/three.js")),n.define("/node_modules/voxel-chunks/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-chunks/package.json')),n.define("/node_modules/voxel-chunks/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var voxel = require('voxel');\nvar ChunkMatrix = require('./lib/chunk_matrix');\nvar indexer = require('./lib/indexer');\n\nmodule.exports = Group;\n\nfunction Group (game) {\n if (!(this instanceof Group)) return new Group(game);\n this.meshes = [];\n this.chunkMatricies = [];\n this.game = game;\n this.indexer = indexer(game);\n}\n\nGroup.prototype.create = function (generate) {\n var self = this;\n var cm = new ChunkMatrix(self.game, generate);\n cm.on('add', function (mesh) {\n self.chunkMatricies[mesh.id] = cm;\n self.meshes.push(mesh);\n });\n cm.on('remove', function (id) {\n delete self.chunkMatricies[id];\n });\n self.chunkMatricies.push(cm);\n return cm;\n};\n \nGroup.prototype.createBlock = function (pos, val) {\n var self = this;\n var T = self.game.THREE;\n var size = self.game.cubeSize;\n \n var cm = pos.chunkMatrix;\n var d = pos.direction;\n \n var mr = new T.Matrix4().getInverse(cm.rotationObject.matrix);\n var mt = new T.Matrix4().getInverse(cm.translationObject.matrix);\n var m = new T.Matrix4().multiply(mr, mt);\n \n \n return (function draw (offset) {\n var pt = new T.Vector3();\n pt.copy(pos);\n \n pt.x -= d.x * offset;\n pt.y -= d.y * offset;\n pt.z -= d.z * offset;\n offset += size / 8;\n \n var tr = m.multiplyVector3(pt);\n var ci = self.indexer.chunk(tr);\n var vi = self.indexer.voxel(tr);\n \n var value = cm.getByIndex(ci, vi);\n if (!value) {\n cm.setByIndex(ci, vi, 3);\n return true;\n }\n else draw(offset + 0.1)\n })(0)\n};\n\nGroup.prototype.setBlock = function (pos, val) {\n var ix = this.getIndex(pos);\n var cm = pos.chunkMatrix;\n return cm.setByIndex(ix.chunk, ix.voxel, val);\n};\n\nGroup.prototype.getBlock = function (pos) {\n var ix = this.getIndex(pos);\n var cm = pos.chunkMatrix;\n return cm.getByIndex(ix.chunk, ix.voxel);\n};\n\nGroup.prototype.getIndex = function (pos) {\n var T = this.game.THREE;\n var cm = pos.chunkMatrix;\n \n var mr = new T.Matrix4().getInverse(cm.rotationObject.matrix);\n var mt = new T.Matrix4().getInverse(cm.translationObject.matrix);\n var m = new T.Matrix4().multiply(mt, mr);\n \n var tr = m.multiplyVector3(pos);\n var ci = this.indexer.chunk(tr);\n var vi = this.indexer.voxel(tr);\n \n return { chunk: ci, voxel: vi };\n};\n\n//@ sourceURL=/node_modules/voxel-chunks/index.js")),n.define("/node_modules/voxel-chunks/lib/chunk_matrix.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var voxelMesh = require('voxel-mesh');\nvar voxel = require('voxel');\n\nvar EventEmitter = require('events').EventEmitter;\nvar inherits = require('inherits');\n\nvar indexer = require('./indexer');\n\nmodule.exports = ChunkMatrix;\ninherits(ChunkMatrix, EventEmitter);\n\nfunction ChunkMatrix (game, generator) {\n var T = game.THREE;\n var size = game.cubeSize;\n \n var r = this.rotationObject = new T.Object3D;\n var t = this.translationObject = new T.Object3D;\n var inner = new T.Object3D;\n \n inner.add(r);\n t.add(inner);\n game.scene.add(t);\n \n inner.position.x = size / 2;\n inner.position.z = size / 2;\n \n this.generator = generator || function (x,y,z) { return 0 };\n this.rotation = r.rotation;\n this.position = t.position;\n this.chunks = {};\n this.meshes = {};\n this.game = game;\n this.indexer = indexer(game);\n \n this._update('0|0|0');\n}\n\nChunkMatrix.prototype.generateChunk = function (ckey) {\n if (Array.isArray(ckey)) ckey = ckey.join('|');\n var xyz = ckey.split('|');\n \n var d = this.game.chunkSize;\n var low = [ xyz[0]*d, xyz[1]*d, xyz[2]*d ];\n var high = [ low[0]+d, low[1]+d, low[2]+d ];\n \n var chunk = voxel.generate(low, high, this.generator);\n this.chunks[ckey] = chunk;\n return chunk;\n};\n\nChunkMatrix.prototype.setBlock = function (pos, value) {\n var ci = this.indexer.chunk(pos);\n var vi = this.indexer.voxel(pos);\n return this.setByIndex(ci, vi, value);\n};\n\nChunkMatrix.prototype.getBlock = function (pos) {\n var ci = this.indexer.chunk(pos);\n var vi = this.indexer.voxel(pos);\n return this.getByIndex(ci, vi);\n};\n\nChunkMatrix.prototype.setByIndex = function (ci, vi, value) {\n var ckey = typeof ci === 'object' ? ci.join('|') : ci\n if (!this.chunks[ckey]) this.generateChunk(ckey);\n this.chunks[ckey].voxels[vi] = value;\n this._update(ckey);\n};\n\nChunkMatrix.prototype.getByIndex = function (ci, vi) {\n var ckey = typeof ci === 'object' ? ci.join('|') : ci;\n if (!this.chunks[ckey]) return undefined;\n return this.chunks[ckey].voxels[vi];\n};\n \nChunkMatrix.prototype._update = function (ci) {\n var game = this.game;\n var T = game.THREE;\n var size = game.cubeSize;\n var csize = size * game.chunkSize;\n var scale = new T.Vector3(size, size, size);\n \n var ckey = typeof ci === 'object' ? ci.join('|') : ci;\n var chunk = this.chunks[ckey];\n if (!chunk) return;\n \n var mesh = voxelMesh(chunk, voxel.meshers.greedy, scale);\n \n if (this.meshes[ckey]) {\n var s = this.meshes[ckey].surfaceMesh || this.meshes[ckey].wireMesh;\n delete this.meshes[s.id];\n this.emit('remove', s);\n this.rotationObject.remove(s);\n }\n this.meshes[ckey] = mesh;\n \n if (game.meshType === 'wireMesh') {\n mesh.createWireMesh();\n }\n else {\n mesh.createSurfaceMesh(game.material);\n }\n \n var surface = mesh.surfaceMesh || mesh.wireMesh;\n surface.position.x = -size / 2;\n surface.position.z = -size / 2;\n \n var xyz = ckey.split('|');\n surface.position.x += xyz[0] * csize;\n surface.position.y += xyz[1] * csize;\n surface.position.z += xyz[2] * csize;\n \n this.rotationObject.add(surface);\n \n game.applyTextures(mesh.geometry);\n \n this.emit('add', surface, this);\n this.emit('update', chunk, ckey);\n};\n\n//@ sourceURL=/node_modules/voxel-chunks/lib/chunk_matrix.js")),n.define("/node_modules/voxel-chunks/node_modules/inherits/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"./inherits.js"}\n//@ sourceURL=/node_modules/voxel-chunks/node_modules/inherits/package.json')),n.define("/node_modules/voxel-chunks/node_modules/inherits/inherits.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = inherits\n\nfunction inherits (c, p, proto) {\n proto = proto || {}\n var e = {}\n ;[c.prototype, proto].forEach(function (s) {\n Object.getOwnPropertyNames(s).forEach(function (k) {\n e[k] = Object.getOwnPropertyDescriptor(s, k)\n })\n })\n c.prototype = Object.create(p.prototype, e)\n c.super = p\n}\n\n//function Child () {\n// Child.super.call(this)\n// console.error([this\n// ,this.constructor\n// ,this.constructor === Child\n// ,this.constructor.super === Parent\n// ,Object.getPrototypeOf(this) === Child.prototype\n// ,Object.getPrototypeOf(Object.getPrototypeOf(this))\n// === Parent.prototype\n// ,this instanceof Child\n// ,this instanceof Parent])\n//}\n//function Parent () {}\n//inherits(Child, Parent)\n//new Child\n\n//@ sourceURL=/node_modules/voxel-chunks/node_modules/inherits/inherits.js")),n.define("/node_modules/voxel-chunks/lib/indexer.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = Indexer;\n\nfunction Indexer (opts) {\n if (!(this instanceof Indexer)) return new Indexer(opts);\n this.chunkSize = opts.chunkSize;\n this.cubeSize = opts.cubeSize;\n}\n\nIndexer.prototype.chunk = function (pos) {\n var chunkSize = this.chunkSize;\n var cubeSize = this.cubeSize;\n var cx = pos.x / cubeSize / chunkSize;\n var cy = pos.y / cubeSize / chunkSize;\n var cz = pos.z / cubeSize / chunkSize;\n var ckey = [ Math.floor(cx), Math.floor(cy), Math.floor(cz) ];\n return ckey.join('|');\n};\n\nIndexer.prototype.voxel = function (pos) {\n var size = this.chunkSize;\n var cubeSize = this.cubeSize;\n var vx = (size + Math.floor(pos.x / cubeSize) % size) % size;\n var vy = (size + Math.floor(pos.y / cubeSize) % size) % size;\n var vz = (size + Math.floor(pos.z / cubeSize) % size) % size;\n var x = Math.abs(vx);\n var y = Math.abs(vy);\n var z = Math.abs(vz);\n return x + y*size + z*size*size;\n};\n\n//@ sourceURL=/node_modules/voxel-chunks/lib/indexer.js")),n.define("/node_modules/voxel-engine/lib/stats.js",Function(["require","module","exports","__dirname","__filename","process","global"],"/**\n * @author mrdoob / http://mrdoob.com/\n */\n\nvar Stats = function () {\n\n var startTime = Date.now(), prevTime = startTime;\n var ms = 0, msMin = Infinity, msMax = 0;\n var fps = 0, fpsMin = Infinity, fpsMax = 0;\n var frames = 0, mode = 0;\n\n var container = document.createElement( 'div' );\n container.id = 'stats';\n container.addEventListener( 'mousedown', function ( event ) { event.preventDefault(); setMode( ++ mode % 2 ) }, false );\n container.style.cssText = 'width:80px;opacity:0.9;cursor:pointer';\n\n var fpsDiv = document.createElement( 'div' );\n fpsDiv.id = 'fps';\n fpsDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#002';\n container.appendChild( fpsDiv );\n\n var fpsText = document.createElement( 'div' );\n fpsText.id = 'fpsText';\n fpsText.style.cssText = 'color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px';\n fpsText.innerHTML = 'FPS';\n fpsDiv.appendChild( fpsText );\n\n var fpsGraph = document.createElement( 'div' );\n fpsGraph.id = 'fpsGraph';\n fpsGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0ff';\n fpsDiv.appendChild( fpsGraph );\n\n while ( fpsGraph.children.length < 74 ) {\n\n var bar = document.createElement( 'span' );\n bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#113';\n fpsGraph.appendChild( bar );\n\n }\n\n var msDiv = document.createElement( 'div' );\n msDiv.id = 'ms';\n msDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#020;display:none';\n container.appendChild( msDiv );\n\n var msText = document.createElement( 'div' );\n msText.id = 'msText';\n msText.style.cssText = 'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px';\n msText.innerHTML = 'MS';\n msDiv.appendChild( msText );\n\n var msGraph = document.createElement( 'div' );\n msGraph.id = 'msGraph';\n msGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0f0';\n msDiv.appendChild( msGraph );\n\n while ( msGraph.children.length < 74 ) {\n\n var bar = document.createElement( 'span' );\n bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#131';\n msGraph.appendChild( bar );\n\n }\n\n var setMode = function ( value ) {\n\n mode = value;\n\n switch ( mode ) {\n\n case 0:\n fpsDiv.style.display = 'block';\n msDiv.style.display = 'none';\n break;\n case 1:\n fpsDiv.style.display = 'none';\n msDiv.style.display = 'block';\n break;\n }\n\n }\n\n var updateGraph = function ( dom, value ) {\n\n var child = dom.appendChild( dom.firstChild );\n child.style.height = value + 'px';\n\n }\n\n return {\n\n REVISION: 11,\n\n domElement: container,\n\n setMode: setMode,\n\n begin: function () {\n\n startTime = Date.now();\n\n },\n\n end: function () {\n\n var time = Date.now();\n\n ms = time - startTime;\n msMin = Math.min( msMin, ms );\n msMax = Math.max( msMax, ms );\n\n msText.textContent = ms + ' MS (' + msMin + '-' + msMax + ')';\n updateGraph( msGraph, Math.min( 30, 30 - ( ms / 200 ) * 30 ) );\n\n frames ++;\n\n if ( time > prevTime + 1000 ) {\n\n fps = Math.round( ( frames * 1000 ) / ( time - prevTime ) );\n fpsMin = Math.min( fpsMin, fps );\n fpsMax = Math.max( fpsMax, fps );\n\n fpsText.textContent = fps + ' FPS (' + fpsMin + '-' + fpsMax + ')';\n updateGraph( fpsGraph, Math.min( 30, 30 - ( fps / 100 ) * 30 ) );\n\n prevTime = time;\n frames = 0;\n\n }\n\n return time;\n\n },\n\n update: function () {\n\n startTime = this.end();\n\n }\n\n }\n\n};\n\nmodule.exports = Stats\n//@ sourceURL=/node_modules/voxel-engine/lib/stats.js")),n.define("/node_modules/voxel-engine/lib/detector.js",Function(["require","module","exports","__dirname","__filename","process","global"],"/**\n * @author alteredq / http://alteredqualia.com/\n * @author mr.doob / http://mrdoob.com/\n */\n\nmodule.exports = function() {\n return {\n canvas : !! window.CanvasRenderingContext2D,\n webgl : ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(),\n workers : !! window.Worker,\n fileapi : window.File && window.FileReader && window.FileList && window.Blob,\n\n getWebGLErrorMessage : function () {\n\n var domElement = document.createElement( 'div' );\n\n domElement.style.fontFamily = 'monospace';\n domElement.style.fontSize = '13px';\n domElement.style.textAlign = 'center';\n domElement.style.background = '#eee';\n domElement.style.color = '#000';\n domElement.style.padding = '1em';\n domElement.style.width = '475px';\n domElement.style.margin = '5em auto 0';\n\n if ( ! this.webgl ) {\n\n domElement.innerHTML = window.WebGLRenderingContext ? [\n 'Your graphics card does not seem to support <a href=\"http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation\">WebGL</a>.<br />',\n 'Find out how to get it <a href=\"http://get.webgl.org/\">here</a>.'\n ].join( '\\n' ) : [\n 'Your browser does not seem to support <a href=\"http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation\">WebGL</a>.<br/>',\n 'Find out how to get it <a href=\"http://get.webgl.org/\">here</a>.'\n ].join( '\\n' );\n\n }\n\n return domElement;\n\n },\n\n addGetWebGLMessage : function ( parameters ) {\n\n var parent, id, domElement;\n\n parameters = parameters || {};\n\n parent = parameters.parent !== undefined ? parameters.parent : document.body;\n id = parameters.id !== undefined ? parameters.id : 'oldie';\n\n domElement = Detector.getWebGLErrorMessage();\n domElement.id = id;\n\n parent.appendChild( domElement );\n\n }\n\n };\n}\n\n//@ sourceURL=/node_modules/voxel-engine/lib/detector.js")),n.define("/node_modules/voxel-engine/node_modules/inherits/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"./inherits.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/inherits/package.json')),n.define("/node_modules/voxel-engine/node_modules/inherits/inherits.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = inherits\n\nfunction inherits (c, p, proto) {\n proto = proto || {}\n var e = {}\n ;[c.prototype, proto].forEach(function (s) {\n Object.getOwnPropertyNames(s).forEach(function (k) {\n e[k] = Object.getOwnPropertyDescriptor(s, k)\n })\n })\n c.prototype = Object.create(p.prototype, e)\n c.super = p\n}\n\n//function Child () {\n// Child.super.call(this)\n// console.error([this\n// ,this.constructor\n// ,this.constructor === Child\n// ,this.constructor.super === Parent\n// ,Object.getPrototypeOf(this) === Child.prototype\n// ,Object.getPrototypeOf(Object.getPrototypeOf(this))\n// === Parent.prototype\n// ,this instanceof Child\n// ,this instanceof Parent])\n//}\n//function Parent () {}\n//inherits(Child, Parent)\n//new Child\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/inherits/inherits.js")),n.define("/node_modules/voxel-engine/node_modules/interact/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/package.json')),n.define("/node_modules/voxel-engine/node_modules/interact/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var lock = require('pointer-lock')\n , drag = require('drag-stream')\n , full = require('fullscreen')\n\nvar EE = require('events').EventEmitter\n , Stream = require('stream').Stream\n\nmodule.exports = interact\n\nfunction interact(el, skiplock) {\n var ee = new EE\n , internal\n\n if(!lock.available() || skiplock) {\n internal = usedrag(el)\n } else {\n internal = uselock(el, politelydeclined)\n }\n\n ee.release = function() { internal.release && internal.release() }\n ee.request = function() { internal.request && internal.request() }\n ee.destroy = function() { internal.destroy && internal.destroy() }\n ee.pointerAvailable = function() { return lock.available() }\n ee.fullscreenAvailable = function() { return full.available() }\n\n forward()\n\n return ee\n\n function politelydeclined() {\n ee.emit('opt-out')\n internal.destroy()\n internal = usedrag(el)\n forward()\n }\n\n function forward() {\n internal.on('attain', function(stream) {\n ee.emit('attain', stream)\n })\n\n internal.on('release', function() {\n ee.emit('release')\n })\n }\n}\n\nfunction uselock(el, declined) {\n var pointer = lock(el)\n , fs = full(el)\n\n pointer.on('needs-fullscreen', function() {\n fs.once('attain', function() {\n pointer.request()\n })\n fs.request()\n })\n\n pointer.on('error', declined)\n\n return pointer\n}\n\nfunction usedrag(el) {\n var ee = new EE\n , d = drag(el)\n , stream\n\n d.paused = true\n\n d.on('resume', function() {\n stream = new Stream\n stream.readable = true\n stream.initial = null\n })\n\n d.on('data', function(datum) {\n if(!stream) {\n stream = new Stream\n stream.readable = true\n stream.initial = null\n }\n\n if(!stream.initial) {\n stream.initial = {\n x: datum.dx\n , y: datum.dy\n , t: datum.dt\n }\n return ee.emit('attain', stream)\n }\n\n if(stream.paused) {\n ee.emit('release')\n stream.emit('end')\n stream.readable = false\n stream.emit('close')\n stream = null\n }\n\n stream.emit('data', datum)\n })\n\n return ee\n}\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/index.js")),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/pointer-lock/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/pointer-lock/package.json')),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/pointer-lock/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = pointer\n\npointer.available = available\n\nvar EE = require('events').EventEmitter\n , Stream = require('stream').Stream\n\nfunction available() {\n return !!shim(document.body)\n}\n\nfunction pointer(el) {\n var ael = el.addEventListener || el.attachEvent\n , rel = el.removeEventListener || el.detachEvent\n , doc = el.ownerDocument\n , body = doc.body\n , rpl = shim(el) \n , out = {dx: 0, dy: 0, dt: 0}\n , ee = new EE\n , stream = null\n , lastPageX, lastPageY\n , needsFullscreen = false\n , mouseDownMS\n\n ael.call(el, 'mousedown', onmousedown, false)\n ael.call(el, 'mouseup', onmouseup, false)\n ael.call(body, 'mousemove', onmove, false)\n\n var vendors = ['', 'webkit', 'moz', 'ms', 'o']\n\n for(var i = 0, len = vendors.length; i < len; ++i) {\n ael.call(doc, vendors[i]+'pointerlockchange', onpointerlockchange)\n ael.call(doc, vendors[i]+'pointerlockerror', onpointerlockerror)\n }\n\n ee.release = release\n ee.target = pointerlockelement\n ee.request = onmousedown\n ee.destroy = function() {\n rel.call(el, 'mouseup', onmouseup, false)\n rel.call(el, 'mousedown', onmousedown, false)\n rel.call(el, 'mousemove', onmove, false)\n }\n\n if(!shim) {\n setTimeout(function() {\n ee.emit('error', new Error('pointer lock is not supported'))\n }, 0)\n }\n return ee\n\n function onmousedown(ev) {\n if(pointerlockelement()) {\n return\n }\n mouseDownMS = +new Date\n rpl.call(el)\n }\n\n function onmouseup(ev) {\n if(!needsFullscreen) {\n return\n }\n\n ee.emit('needs-fullscreen')\n needsFullscreen = false\n }\n\n function onpointerlockchange(ev) {\n if(!pointerlockelement()) {\n if(stream) release()\n return\n }\n\n stream = new Stream\n stream.readable = true\n stream.initial = {x: lastPageX, y: lastPageY, t: Date.now()}\n\n ee.emit('attain', stream)\n }\n\n function onpointerlockerror(ev) {\n var dt = +(new Date) - mouseDownMS\n if(dt < 100) {\n // we errored immediately, we need to do fullscreen first.\n needsFullscreen = true\n return\n }\n\n if(stream) {\n stream.emit('error', ev)\n stream = null\n }\n }\n\n function release() {\n ee.emit('release')\n\n if(stream) {\n stream.emit('end')\n stream.readable = false\n stream.emit('close')\n stream = null\n }\n\n var pel = pointerlockelement()\n if(!pel) {\n return\n }\n\n (doc.exitPointerLock ||\n doc.mozExitPointerLock ||\n doc.webkitExitPointerLock ||\n doc.msExitPointerLock ||\n doc.oExitPointerLock).call(doc)\n }\n\n function onmove(ev) {\n lastPageX = ev.pageX\n lastPageY = ev.pageY\n\n if(!stream) return\n\n // we're reusing a single object\n // because I'd like to avoid piling up\n // a ton of objects for the garbage\n // collector.\n out.dx =\n ev.movementX || ev.webkitMovementX ||\n ev.mozMovementX || ev.msMovementX ||\n ev.oMovementX || 0\n\n out.dy = \n ev.movementY || ev.webkitMovementY ||\n ev.mozMovementY || ev.msMovementY ||\n ev.oMovementY || 0\n\n out.dt = Date.now() - stream.initial.t\n\n ee.emit('data', out)\n stream.emit('data', out)\n }\n\n function pointerlockelement() {\n return 0 ||\n doc.pointerLockElement ||\n doc.mozPointerLockElement ||\n doc.webkitPointerLockElement ||\n doc.msPointerLockElement ||\n doc.oPointerLockElement ||\n null\n }\n}\n\nfunction shim(el) {\n return el.requestPointerLock ||\n el.webkitRequestPointerLock ||\n el.mozRequestPointerLock ||\n el.msRequestPointerLock ||\n el.oRequestPointerLock ||\n null\n}\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/pointer-lock/index.js")),n.define("stream",Function(["require","module","exports","__dirname","__filename","process","global"],"var events = require('events');\nvar util = require('util');\n\nfunction Stream() {\n events.EventEmitter.call(this);\n}\nutil.inherits(Stream, events.EventEmitter);\nmodule.exports = Stream;\n// Backwards-compat with node 0.4.x\nStream.Stream = Stream;\n\nStream.prototype.pipe = function(dest, options) {\n var source = this;\n\n function ondata(chunk) {\n if (dest.writable) {\n if (false === dest.write(chunk) && source.pause) {\n source.pause();\n }\n }\n }\n\n source.on('data', ondata);\n\n function ondrain() {\n if (source.readable && source.resume) {\n source.resume();\n }\n }\n\n dest.on('drain', ondrain);\n\n // If the 'end' option is not supplied, dest.end() will be called when\n // source gets the 'end' or 'close' events. Only dest.end() once, and\n // only when all sources have ended.\n if (!dest._isStdio && (!options || options.end !== false)) {\n dest._pipeCount = dest._pipeCount || 0;\n dest._pipeCount++;\n\n source.on('end', onend);\n source.on('close', onclose);\n }\n\n var didOnEnd = false;\n function onend() {\n if (didOnEnd) return;\n didOnEnd = true;\n\n dest._pipeCount--;\n\n // remove the listeners\n cleanup();\n\n if (dest._pipeCount > 0) {\n // waiting for other incoming streams to end.\n return;\n }\n\n dest.end();\n }\n\n\n function onclose() {\n if (didOnEnd) return;\n didOnEnd = true;\n\n dest._pipeCount--;\n\n // remove the listeners\n cleanup();\n\n if (dest._pipeCount > 0) {\n // waiting for other incoming streams to end.\n return;\n }\n\n dest.destroy();\n }\n\n // don't leave dangling pipes when there are errors.\n function onerror(er) {\n cleanup();\n if (this.listeners('error').length === 0) {\n throw er; // Unhandled stream error in pipe.\n }\n }\n\n source.on('error', onerror);\n dest.on('error', onerror);\n\n // remove all the event listeners that were added.\n function cleanup() {\n source.removeListener('data', ondata);\n dest.removeListener('drain', ondrain);\n\n source.removeListener('end', onend);\n source.removeListener('close', onclose);\n\n source.removeListener('error', onerror);\n dest.removeListener('error', onerror);\n\n source.removeListener('end', cleanup);\n source.removeListener('close', cleanup);\n\n dest.removeListener('end', cleanup);\n dest.removeListener('close', cleanup);\n }\n\n source.on('end', cleanup);\n source.on('close', cleanup);\n\n dest.on('end', cleanup);\n dest.on('close', cleanup);\n\n dest.emit('pipe', source);\n\n // Allow for unix-like usage: A.pipe(B).pipe(C)\n return dest;\n};\n\n//@ sourceURL=stream")),n.define("util",Function(["require","module","exports","__dirname","__filename","process","global"],"var events = require('events');\n\nexports.isArray = isArray;\nexports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'};\nexports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'};\n\n\nexports.print = function () {};\nexports.puts = function () {};\nexports.debug = function() {};\n\nexports.inspect = function(obj, showHidden, depth, colors) {\n var seen = [];\n\n var stylize = function(str, styleType) {\n // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics\n var styles =\n { 'bold' : [1, 22],\n 'italic' : [3, 23],\n 'underline' : [4, 24],\n 'inverse' : [7, 27],\n 'white' : [37, 39],\n 'grey' : [90, 39],\n 'black' : [30, 39],\n 'blue' : [34, 39],\n 'cyan' : [36, 39],\n 'green' : [32, 39],\n 'magenta' : [35, 39],\n 'red' : [31, 39],\n 'yellow' : [33, 39] };\n\n var style =\n { 'special': 'cyan',\n 'number': 'blue',\n 'boolean': 'yellow',\n 'undefined': 'grey',\n 'null': 'bold',\n 'string': 'green',\n 'date': 'magenta',\n // \"name\": intentionally not styling\n 'regexp': 'red' }[styleType];\n\n if (style) {\n return '\\033[' + styles[style][0] + 'm' + str +\n '\\033[' + styles[style][1] + 'm';\n } else {\n return str;\n }\n };\n if (! colors) {\n stylize = function(str, styleType) { return str; };\n }\n\n function format(value, recurseTimes) {\n // Provide a hook for user-specified inspect functions.\n // Check that value is an object with an inspect function on it\n if (value && typeof value.inspect === 'function' &&\n // Filter out the util module, it's inspect function is special\n value !== exports &&\n // Also filter out any prototype objects using the circular check.\n !(value.constructor && value.constructor.prototype === value)) {\n return value.inspect(recurseTimes);\n }\n\n // Primitive types cannot have properties\n switch (typeof value) {\n case 'undefined':\n return stylize('undefined', 'undefined');\n\n case 'string':\n var simple = '\\'' + JSON.stringify(value).replace(/^\"|\"$/g, '')\n .replace(/'/g, \"\\\\'\")\n .replace(/\\\\\"/g, '\"') + '\\'';\n return stylize(simple, 'string');\n\n case 'number':\n return stylize('' + value, 'number');\n\n case 'boolean':\n return stylize('' + value, 'boolean');\n }\n // For some reason typeof null is \"object\", so special case here.\n if (value === null) {\n return stylize('null', 'null');\n }\n\n // Look up the keys of the object.\n var visible_keys = Object_keys(value);\n var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys;\n\n // Functions without properties can be shortcutted.\n if (typeof value === 'function' && keys.length === 0) {\n if (isRegExp(value)) {\n return stylize('' + value, 'regexp');\n } else {\n var name = value.name ? ': ' + value.name : '';\n return stylize('[Function' + name + ']', 'special');\n }\n }\n\n // Dates without properties can be shortcutted\n if (isDate(value) && keys.length === 0) {\n return stylize(value.toUTCString(), 'date');\n }\n\n var base, type, braces;\n // Determine the object type\n if (isArray(value)) {\n type = 'Array';\n braces = ['[', ']'];\n } else {\n type = 'Object';\n braces = ['{', '}'];\n }\n\n // Make functions say that they are functions\n if (typeof value === 'function') {\n var n = value.name ? ': ' + value.name : '';\n base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']';\n } else {\n base = '';\n }\n\n // Make dates with properties first say the date\n if (isDate(value)) {\n base = ' ' + value.toUTCString();\n }\n\n if (keys.length === 0) {\n return braces[0] + base + braces[1];\n }\n\n if (recurseTimes < 0) {\n if (isRegExp(value)) {\n return stylize('' + value, 'regexp');\n } else {\n return stylize('[Object]', 'special');\n }\n }\n\n seen.push(value);\n\n var output = keys.map(function(key) {\n var name, str;\n if (value.__lookupGetter__) {\n if (value.__lookupGetter__(key)) {\n if (value.__lookupSetter__(key)) {\n str = stylize('[Getter/Setter]', 'special');\n } else {\n str = stylize('[Getter]', 'special');\n }\n } else {\n if (value.__lookupSetter__(key)) {\n str = stylize('[Setter]', 'special');\n }\n }\n }\n if (visible_keys.indexOf(key) < 0) {\n name = '[' + key + ']';\n }\n if (!str) {\n if (seen.indexOf(value[key]) < 0) {\n if (recurseTimes === null) {\n str = format(value[key]);\n } else {\n str = format(value[key], recurseTimes - 1);\n }\n if (str.indexOf('\\n') > -1) {\n if (isArray(value)) {\n str = str.split('\\n').map(function(line) {\n return ' ' + line;\n }).join('\\n').substr(2);\n } else {\n str = '\\n' + str.split('\\n').map(function(line) {\n return ' ' + line;\n }).join('\\n');\n }\n }\n } else {\n str = stylize('[Circular]', 'special');\n }\n }\n if (typeof name === 'undefined') {\n if (type === 'Array' && key.match(/^\\d+$/)) {\n return str;\n }\n name = JSON.stringify('' + key);\n if (name.match(/^\"([a-zA-Z_][a-zA-Z_0-9]*)\"$/)) {\n name = name.substr(1, name.length - 2);\n name = stylize(name, 'name');\n } else {\n name = name.replace(/'/g, \"\\\\'\")\n .replace(/\\\\\"/g, '\"')\n .replace(/(^\"|\"$)/g, \"'\");\n name = stylize(name, 'string');\n }\n }\n\n return name + ': ' + str;\n });\n\n seen.pop();\n\n var numLinesEst = 0;\n var length = output.reduce(function(prev, cur) {\n numLinesEst++;\n if (cur.indexOf('\\n') >= 0) numLinesEst++;\n return prev + cur.length + 1;\n }, 0);\n\n if (length > 50) {\n output = braces[0] +\n (base === '' ? '' : base + '\\n ') +\n ' ' +\n output.join(',\\n ') +\n ' ' +\n braces[1];\n\n } else {\n output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];\n }\n\n return output;\n }\n return format(obj, (typeof depth === 'undefined' ? 2 : depth));\n};\n\n\nfunction isArray(ar) {\n return ar instanceof Array ||\n Array.isArray(ar) ||\n (ar && ar !== Object.prototype && isArray(ar.__proto__));\n}\n\n\nfunction isRegExp(re) {\n return re instanceof RegExp ||\n (typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]');\n}\n\n\nfunction isDate(d) {\n if (d instanceof Date) return true;\n if (typeof d !== 'object') return false;\n var properties = Date.prototype && Object_getOwnPropertyNames(Date.prototype);\n var proto = d.__proto__ && Object_getOwnPropertyNames(d.__proto__);\n return JSON.stringify(proto) === JSON.stringify(properties);\n}\n\nfunction pad(n) {\n return n < 10 ? '0' + n.toString(10) : n.toString(10);\n}\n\nvar months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',\n 'Oct', 'Nov', 'Dec'];\n\n// 26 Feb 16:19:34\nfunction timestamp() {\n var d = new Date();\n var time = [pad(d.getHours()),\n pad(d.getMinutes()),\n pad(d.getSeconds())].join(':');\n return [d.getDate(), months[d.getMonth()], time].join(' ');\n}\n\nexports.log = function (msg) {};\n\nexports.pump = null;\n\nvar Object_keys = Object.keys || function (obj) {\n var res = [];\n for (var key in obj) res.push(key);\n return res;\n};\n\nvar Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) {\n var res = [];\n for (var key in obj) {\n if (Object.hasOwnProperty.call(obj, key)) res.push(key);\n }\n return res;\n};\n\nvar Object_create = Object.create || function (prototype, properties) {\n // from es5-shim\n var object;\n if (prototype === null) {\n object = { '__proto__' : null };\n }\n else {\n if (typeof prototype !== 'object') {\n throw new TypeError(\n 'typeof prototype[' + (typeof prototype) + '] != \\'object\\''\n );\n }\n var Type = function () {};\n Type.prototype = prototype;\n object = new Type();\n object.__proto__ = prototype;\n }\n if (typeof properties !== 'undefined' && Object.defineProperties) {\n Object.defineProperties(object, properties);\n }\n return object;\n};\n\nexports.inherits = function(ctor, superCtor) {\n ctor.super_ = superCtor;\n ctor.prototype = Object_create(superCtor.prototype, {\n constructor: {\n value: ctor,\n enumerable: false,\n writable: true,\n configurable: true\n }\n });\n};\n\nvar formatRegExp = /%[sdj%]/g;\nexports.format = function(f) {\n if (typeof f !== 'string') {\n var objects = [];\n for (var i = 0; i < arguments.length; i++) {\n objects.push(exports.inspect(arguments[i]));\n }\n return objects.join(' ');\n }\n\n var i = 1;\n var args = arguments;\n var len = args.length;\n var str = String(f).replace(formatRegExp, function(x) {\n if (x === '%%') return '%';\n if (i >= len) return x;\n switch (x) {\n case '%s': return String(args[i++]);\n case '%d': return Number(args[i++]);\n case '%j': return JSON.stringify(args[i++]);\n default:\n return x;\n }\n });\n for(var x = args[i]; i < len; x = args[++i]){\n if (x === null || typeof x !== 'object') {\n str += ' ' + x;\n } else {\n str += ' ' + exports.inspect(x);\n }\n }\n return str;\n};\n\n//@ sourceURL=util")),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/package.json')),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = dragstream\n\nvar Stream = require('stream')\n , read = require('domnode-dom').createReadStream\n , through = require('through')\n\nfunction dragstream(el) {\n var body = el.ownerDocument.body\n , down = read(el, 'mousedown')\n , up = read(body, 'mouseup', false)\n , move = read(body, 'mousemove', false)\n , anchor = {x: 0, y: 0, t: 0}\n , drag = through(on_move)\n\n // default to \"paused\"\n drag.pause()\n\n down.on('data', on_down)\n up.on('data', on_up)\n\n return move.pipe(drag)\n\n // listeners:\n\n function on_move(ev) {\n if(drag.paused) return\n\n drag.emit('data', datum(\n ev.screenX - anchor.x\n , ev.screenY - anchor.y\n , +new Date\n ))\n\n anchor.x = ev.screenX\n anchor.y = ev.screenY\n }\n\n function on_down(ev) {\n anchor.x = ev.screenX\n anchor.y = ev.screenY\n anchor.t = +new Date\n drag.resume()\n drag.emit('data', datum(\n anchor.x\n , anchor.y\n , anchor.t\n ))\n }\n\n function on_up(ev) {\n drag.pause()\n drag.emit('data', datum(\n ev.screenX - anchor.x\n , ev.screenY - anchor.y\n , +new Date\n ))\n }\n\n function datum(dx, dy, when) {\n return {\n dx: dx\n , dy: dy\n , dt: when - anchor.t\n }\n }\n}\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/index.js")),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/domnode-dom/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/domnode-dom/package.json')),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/domnode-dom/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = require('./lib/index')\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/domnode-dom/index.js")),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/domnode-dom/lib/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var WriteStream = require('./writable')\n , ReadStream = require('./readable')\n , DOMStream = {}\n\nDOMStream.WriteStream = WriteStream\nDOMStream.ReadStream = ReadStream\n\nDOMStream.createAppendStream = function(el, mimetype) {\n return new DOMStream.WriteStream(\n el\n , DOMStream.WriteStream.APPEND\n , mimetype\n )\n}\n\nDOMStream.createWriteStream = function(el, mimetype) {\n return new DOMStream.WriteStream(\n el\n , DOMStream.WriteStream.WRITE\n , mimetype\n )\n}\n\nDOMStream.createReadStream =\nDOMStream.createEventStream = function(el, type, preventDefault) {\n preventDefault = preventDefault === undefined ? true : preventDefault\n\n return new DOMStream.ReadStream(\n el\n , type\n , preventDefault\n )\n}\n\nmodule.exports = DOMStream\n\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/domnode-dom/lib/index.js")),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/domnode-dom/lib/writable.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = DOMStream\n\nvar Stream = require('stream').Stream\n\nfunction DOMStream(el, mode, mimetype) {\n this.el = el\n this.mode = mode\n this.mimetype = mimetype || 'text/html'\n\n Stream.call(this)\n}\n\nvar cons = DOMStream\n , proto = cons.prototype = new Stream\n\nproto.constructor = cons\n\ncons.APPEND = 0\ncons.WRITE = 1\n\nproto.writable = true\n\nproto.setMimetype = function(mime) {\n this.mimetype = mime\n}\n\nproto.write = function(data) {\n var result = (this.mode === cons.APPEND) ? this.append(data) : this.insert(data)\n this.emit('data', this.el.childNodes)\n return result\n}\n\nproto.insert = function(data) {\n this.el.innerHTML = ''\n return this.append(data)\n}\n\nproto.append = function(data) {\n var result = this[this.resolveMimetypeHandler()](data)\n\n for(var i = 0, len = result.length; i < len; ++i) {\n this.el.appendChild(result[i])\n }\n\n return true\n}\n\nproto.resolveMimetypeHandler = function() {\n var type = this.mimetype.replace(/(\\/\\w)/, function(x) {\n return x.slice(1).toUpperCase()\n })\n type = type.charAt(0).toUpperCase() + type.slice(1)\n\n return 'construct'+type\n}\n\nproto.constructTextHtml = function(data) {\n var isTableFragment = /(tr|td|th)/.test(data) && !/table/.test(data)\n , div\n\n if(isTableFragment) {\n // wuh-oh.\n div = document.createElement('table')\n }\n\n div = div || document.createElement('div')\n div.innerHTML = data \n\n return [].slice.call(div.childNodes)\n}\n\nproto.constructTextPlain = function(data) {\n var textNode = document.createTextNode(data)\n\n return [textNode]\n}\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/domnode-dom/lib/writable.js")),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/domnode-dom/lib/readable.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = DOMStream\n\nvar Stream = require('stream').Stream\n\nvar listener = function(el, type, onmsg) {\n return el.addEventListener(type, onmsg, false)\n}\n\nif(typeof $ !== 'undefined')\n listener = function(el, type, onmsg) {\n return el = $(el)[type](onmsg)\n }\n\nif(typeof document !== 'undefined' && !document.createElement('div').addEventListener)\n listener = function(el, type, onmsg) {\n return el.attachEvent('on'+type, onmsg)\n }\n\nfunction DOMStream(el, eventType, shouldPreventDefault) {\n this.el = el\n this.eventType = eventType\n this.shouldPreventDefault = shouldPreventDefault\n\n var self = this\n\n if(el && this.eventType)\n listener(\n this.el\n , this.eventType\n , function() { return self.listen.apply(self, arguments) }\n )\n\n Stream.call(this)\n}\n\nvar cons = DOMStream\n , proto = cons.prototype = new Stream\n\nproto.constructor = cons\n\nproto.listen = function(ev) { \n if(this.shouldPreventDefault)\n ev.preventDefault ? ev.preventDefault() : (ev.returnValue = false)\n\n var collectData = \n this.eventType === 'submit' ||\n this.eventType === 'change' ||\n this.eventType === 'keydown' ||\n this.eventType === 'keyup' ||\n this.eventType === 'input'\n\n if(collectData) {\n if(this.el.tagName.toUpperCase() === 'FORM')\n return this.handleFormSubmit(ev)\n\n return this.emit('data', valueFromElement(this.el))\n }\n\n this.emit('data', ev) \n}\n\nproto.handleFormSubmit = function(ev) {\n var elements = []\n\n if(this.el.querySelectorAll) {\n elements = this.el.querySelectorAll('input,textarea,select')\n } else {\n var inputs = {'INPUT':true, 'TEXTAREA':true, 'SELECT':true}\n\n var recurse = function(el) {\n for(var i = 0, len = el.childNodes.length; i < len; ++i) {\n if(el.childNodes[i].tagName) {\n if(inputs[el.childNodes[i].tagName.toUpperCase()]) {\n elements.push(el)\n } else {\n recurse(el.childNodes[i])\n }\n }\n }\n }\n\n recurse(this.el)\n }\n\n var output = {}\n , attr\n , val\n\n for(var i = 0, len = elements.length; i < len; ++i) {\n attr = elements[i].getAttribute('name')\n val = valueFromElement(elements[i])\n\n output[attr] = val\n }\n\n return this.emit('data', output)\n}\n\nfunction valueFromElement(el) {\n switch(el.getAttribute('type')) {\n case 'radio':\n return el.checked ? el.value : null\n case 'checkbox':\n return 'data', el.checked\n }\n return el.value\n}\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/domnode-dom/lib/readable.js")),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/through/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/through/package.json')),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/through/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var Stream = require('stream')\n\n// through\n//\n// a stream that does nothing but re-emit the input.\n// useful for aggregating a series of changing but not ending streams into one stream)\n\n\n\nexports = module.exports = through\nthrough.through = through\n\n//create a readable writable stream.\n\nfunction through (write, end) {\n write = write || function (data) { this.emit('data', data) }\n end = end || function () { this.emit('end') }\n\n var ended = false, destroyed = false\n var stream = new Stream(), buffer = []\n stream.buffer = buffer\n stream.readable = stream.writable = true\n stream.paused = false\n stream.write = function (data) {\n write.call(this, data)\n return !stream.paused\n }\n\n function drain() {\n while(buffer.length && !stream.paused) {\n var data = buffer.shift()\n if(null === data)\n return stream.emit('end')\n else\n stream.emit('data', data)\n }\n }\n\n stream.queue = function (data) {\n buffer.push(data)\n drain()\n }\n\n //this will be registered as the first 'end' listener\n //must call destroy next tick, to make sure we're after any\n //stream piped from here.\n //this is only a problem if end is not emitted synchronously.\n //a nicer way to do this is to make sure this is the last listener for 'end'\n\n stream.on('end', function () {\n stream.readable = false\n if(!stream.writable)\n process.nextTick(function () {\n stream.destroy()\n })\n })\n\n function _end () {\n stream.writable = false\n end.call(stream)\n if(!stream.readable)\n stream.destroy()\n }\n\n stream.end = function (data) {\n if(ended) return\n ended = true\n if(arguments.length) stream.write(data)\n _end() // will emit or queue\n }\n\n stream.destroy = function () {\n if(destroyed) return\n destroyed = true\n ended = true\n buffer.length = 0\n stream.writable = stream.readable = false\n stream.emit('close')\n }\n\n stream.pause = function () {\n if(stream.paused) return\n stream.paused = true\n stream.emit('pause')\n }\n stream.resume = function () {\n if(stream.paused) {\n stream.paused = false\n }\n drain()\n //may have become paused again,\n //as drain emits 'data'.\n if(!stream.paused)\n stream.emit('drain')\n }\n return stream\n}\n\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/drag-stream/node_modules/through/index.js")),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/fullscreen/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/fullscreen/package.json')),n.define("/node_modules/voxel-engine/node_modules/interact/node_modules/fullscreen/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = fullscreen\nfullscreen.available = available\n\nvar EE = require('events').EventEmitter\n\nfunction available() {\n return !!shim(document.body)\n}\n\nfunction fullscreen(el) {\n var ael = el.addEventListener || el.attachEvent\n , doc = el.ownerDocument\n , body = doc.body\n , rfs = shim(el)\n , ee = new EE\n\n var vendors = ['', 'webkit', 'moz', 'ms', 'o']\n\n for(var i = 0, len = vendors.length; i < len; ++i) {\n ael.call(doc, vendors[i]+'fullscreenchange', onfullscreenchange)\n ael.call(doc, vendors[i]+'fullscreenerror', onfullscreenerror)\n }\n\n ee.release = release\n ee.request = request\n ee.target = fullscreenelement\n\n if(!shim) {\n setTimeout(function() {\n ee.emit('error', new Error('fullscreen is not supported'))\n }, 0)\n }\n return ee\n\n function onfullscreenchange() {\n if(!fullscreenelement()) {\n return ee.emit('release')\n }\n ee.emit('attain')\n }\n\n function onfullscreenerror() {\n ee.emit('error')\n }\n\n function request() {\n return rfs.call(el)\n }\n\n function release() {\n (el.exitFullscreen ||\n el.exitFullscreen ||\n el.webkitExitFullScreen ||\n el.webkitExitFullscreen ||\n el.mozExitFullScreen ||\n el.mozExitFullscreen ||\n el.msExitFullScreen ||\n el.msExitFullscreen ||\n el.oExitFullScreen ||\n el.oExitFullscreen).call(el)\n } \n\n function fullscreenelement() {\n return 0 ||\n doc.fullScreenElement ||\n doc.fullscreenElement ||\n doc.webkitFullScreenElement ||\n doc.webkitFullscreenElement ||\n doc.mozFullScreenElement ||\n doc.mozFullscreenElement ||\n doc.msFullScreenElement ||\n doc.msFullscreenElement ||\n doc.oFullScreenElement ||\n doc.oFullscreenElement ||\n null\n }\n}\n\nfunction shim(el) {\n return (el.requestFullscreen ||\n el.webkitRequestFullscreen ||\n el.webkitRequestFullScreen ||\n el.mozRequestFullscreen ||\n el.mozRequestFullScreen ||\n el.msRequestFullscreen ||\n el.msRequestFullScreen ||\n el.oRequestFullscreen ||\n el.oRequestFullScreen)\n}\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/interact/node_modules/fullscreen/index.js")),n.define("/node_modules/voxel-engine/node_modules/player-physics/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = {}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/player-physics/package.json")),n.define("/node_modules/voxel-engine/node_modules/player-physics/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var THREE = require('three')\nvar inherits = require('inherits')\nvar stream = require('stream')\n\nvar PI_2 = Math.PI / 2\n\n/**\n * based on PointerLockControls by mrdoob / http://mrdoob.com/\n * converted to a module + stream by @maxogden and @substack\n */\n\nmodule.exports = function(camera, opts) {\n return new PlayerPhysics(camera, opts)\n}\n\nmodule.exports.PlayerPhysics = PlayerPhysics\n\nfunction PlayerPhysics(camera, opts) {\n if (!(this instanceof PlayerPhysics)) return new PlayerPhysics(camera, opts)\n var self = this\n if (!opts) opts = {}\n \n \n this.readable = true\n this.writable = true\n this.enabled = false\n \n this.speed = {\n jump: ( opts.jump === undefined ? 3.25 : opts.jump ),\n move: ( opts.move === undefined ? 0.2 : opts.move ),\n fall: ( opts.fall === undefined ? 0.3 : opts.fall ),\n }\n \n this.jumpTime = 250\n this.jumpRemaining = 0\n\n this.pitchObject = opts.pitchObject || new THREE.Object3D()\n if (camera) this.pitchObject.add( camera )\n\n this.yawObject = opts.yawObject || new THREE.Object3D()\n this.yawObject.position.y = 10\n this.yawObject.add( this.pitchObject )\n\n this.moveForward = false\n this.moveBackward = false\n this.moveLeft = false\n this.moveRight = false\n\n this.freedom = {\n 'x+': true,\n 'x-': true,\n 'y+': true,\n 'y-': true,\n 'z+': true,\n 'z-': true\n }\n \n this.wantsJump = false\n this.gravityEnabled = opts.gravityEnabled === undefined ? true : !!opts.gravityEnabled\n \n this.velocity = opts.velocityObject || new THREE.Vector3()\n\n this.on('command', function(command, setting) {\n self[command] = setting\n }) \n}\n\ninherits(PlayerPhysics, stream.Stream)\n\nPlayerPhysics.prototype.playerIsMoving = function() { \n var v = this.velocity\n if (Math.abs(v.x) > 0.1 || Math.abs(v.y) > 0.1 || Math.abs(v.z) > 0.1) return true\n return false\n}\n\nPlayerPhysics.prototype.write = function(data) {\n if (this.enabled === false) return\n this.applyRotationDeltas(data)\n}\n\nPlayerPhysics.prototype.end = function() {\n this.emit('end')\n}\n\nPlayerPhysics.prototype.applyRotationDeltas = function(deltas) {\n this.yawObject.rotation.y -= deltas.dx * 0.002\n this.pitchObject.rotation.x -= deltas.dy * 0.002\n this.pitchObject.rotation.x = Math.max(-PI_2, Math.min(PI_2, this.pitchObject.rotation.x))\n}\n\nPlayerPhysics.prototype.tick = function (delta, cb) {\n if (this.enabled === false) return\n\n delta *= 0.1\n\n this.velocity.x += (-this.velocity.x) * 0.08 * delta\n this.velocity.z += (-this.velocity.z) * 0.08 * delta\n\n if (this.freedom['y-']) this.wantsJump = false\n if (this.wantsJump && this.jumpRemaining <= 0) this.jumpRemaining = this.jumpTime\n if (this.jumpRemaining > 0) this.jumpRemaining -= delta * 100\n if (this.jumpRemaining > 0) {\n if(this.gravityEnabled) this.velocity.y += this.speed.jump * delta\n } else {\n this.jumpRemaining = 0\n if (this.gravityEnabled) this.velocity.y -= this.speed.fall * delta\n }\n\n if (this.moveForward) this.velocity.z -= this.speed.move * delta\n if (this.moveBackward) this.velocity.z += this.speed.move * delta\n\n if (this.moveLeft) this.velocity.x -= this.speed.move * delta\n if (this.moveRight) this.velocity.x += this.speed.move * delta\n \n if (!this.freedom['x-']) this.velocity.x = Math.max(0, this.velocity.x)\n if (!this.freedom['x+']) this.velocity.x = Math.min(0, this.velocity.x)\n if (!this.freedom['y-']) this.velocity.y = Math.max(-0.0001, this.velocity.y)\n if (!this.freedom['y+']) this.velocity.y = Math.min(0, this.velocity.y)\n if (!this.freedom['z-']) this.velocity.z = Math.max(0, this.velocity.z)\n if (!this.freedom['z+']) this.velocity.z = Math.min(0, this.velocity.z)\n \n if (cb) cb(this)\n}\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/player-physics/index.js")),n.define("/node_modules/voxel-engine/node_modules/raf/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/raf/package.json')),n.define("/node_modules/voxel-engine/node_modules/raf/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = raf\n\nvar EE = require('events').EventEmitter\n , global = typeof window === 'undefined' ? this : window\n\nvar _raf =\n global.requestAnimationFrame ||\n global.webkitRequestAnimationFrame ||\n global.mozRequestAnimationFrame ||\n global.msRequestAnimationFrame ||\n global.oRequestAnimationFrame ||\n (global.setImmediate ? function(fn, el) {\n setImmediate(fn)\n } :\n function(fn, el) {\n setTimeout(fn, 0)\n })\n\nfunction raf(el) {\n var now = raf.now()\n , ee = new EE\n\n ee.pause = function() { ee.paused = true }\n ee.resume = function() { ee.paused = false }\n\n _raf(iter, el)\n\n return ee\n\n function iter(timestamp) {\n var _now = raf.now()\n , dt = _now - now\n \n now = _now\n\n ee.emit('data', dt)\n\n if(!ee.paused) {\n _raf(iter, el)\n }\n }\n}\n\nraf.polyfill = _raf\nraf.now = function() { return Date.now() }\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/raf/index.js")),n.define("/node_modules/voxel-engine/node_modules/collide-3d-tilemap/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/collide-3d-tilemap/package.json')),n.define("/node_modules/voxel-engine/node_modules/collide-3d-tilemap/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = function(field, tilesize, dimensions, offset) {\n dimensions = dimensions || [ \n Math.sqrt(field.length) >> 0\n , Math.sqrt(field.length) >> 0\n , Math.sqrt(field.length) >> 0\n ] \n\n offset = offset || [\n 0\n , 0\n , 0\n ]\n\n field = typeof field === 'function' ? field : function(x, y, z) {\n return this[x + y * dimensions[1] + (z * dimensions[1] * dimensions[2])]\n }.bind(field) \n\n var coords\n\n coords = [0, 0, 0]\n\n return collide\n\n function collide(box, vec, oncollision) {\n if(vec[0] === 0 && vec[1] === 0 && vec[2] === 0) return\n\n // collide x, then y\n collideaxis(0)\n collideaxis(1)\n collideaxis(2)\n\n function collideaxis(i_axis) {\n var j_axis = (i_axis + 1) % 3\n , k_axis = (i_axis + 2) % 3 \n , posi = vec[i_axis] > 0\n , leading = box[posi ? 'max' : 'base'][i_axis] \n , dir = posi ? 1 : -1\n , i_start = Math.floor(leading / tilesize)\n , i_end = (Math.floor((leading + vec[i_axis]) / tilesize)) + dir\n , j_start = Math.floor(box.base[j_axis] / tilesize)\n , j_end = Math.ceil(box.max[j_axis] / tilesize)\n , k_start = Math.floor(box.base[k_axis] / tilesize) \n , k_end = Math.ceil(box.max[k_axis] / tilesize)\n , done = false\n , edge_vector\n , edge\n , tile\n\n // loop from the current tile coord to the dest tile coord\n // -> loop on the opposite axis to get the other candidates\n // -> if `oncollision` return `true` we've hit something and\n // should break out of the loops entirely.\n // NB: `oncollision` is where the client gets the chance\n // to modify the `vec` in-flight.\n // once we're done translate the box to the vec results\n\n var step = 0\n for(var i = i_start; !done && i !== i_end; ++step, i += dir) {\n if(i < offset[i_axis] || i >= dimensions[i_axis]) continue\n for(var j = j_start; !done && j !== j_end; ++j) {\n if(j < offset[j_axis] || j >= dimensions[j_axis]) continue\n for(var k = k_start; k !== k_end; ++k) {\n if(k < offset[k_axis] || k >= dimensions[k_axis]) continue\n coords[i_axis] = i\n coords[j_axis] = j\n coords[k_axis] = k\n tile = field.apply(field, coords)\n\n if(tile === undefined) continue\n\n edge = dir > 0 ? i * tilesize : (i + 1) * tilesize\n edge_vector = edge - leading\n\n if(oncollision(i_axis, tile, coords, dir, edge_vector)) {\n done = true\n break\n }\n } \n }\n }\n\n coords[0] = coords[1] = coords[2] = 0\n coords[i_axis] = vec[i_axis]\n box.translate(coords)\n }\n } \n}\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/collide-3d-tilemap/index.js")),n.define("/node_modules/voxel-engine/node_modules/aabb-3d/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/aabb-3d/package.json')),n.define("/node_modules/voxel-engine/node_modules/aabb-3d/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = AABB\n\nvar vec3 = require('gl-matrix').vec3\n\nfunction AABB(pos, vec) {\n if(!(this instanceof AABB)) {\n return new AABB(pos, vec)\n }\n\n this.base = pos\n this.vec = vec\n\n this.mag = vec3.length(this.vec)\n\n this.max = vec3.create()\n vec3.add(this.max, this.base, this.vec)\n}\n\nvar cons = AABB\n , proto = cons.prototype\n\nproto.width = function() {\n return this.vec[0]\n}\n\nproto.height = function() {\n return this.vec[1]\n}\n\nproto.depth = function() {\n return this.vec[2]\n}\n\nproto.x0 = function() {\n return this.base[0]\n}\n\nproto.y0 = function() {\n return this.base[1]\n}\n\nproto.z0 = function() {\n return this.base[2]\n}\n\nproto.x1 = function() {\n return this.max[0]\n}\n\nproto.y1 = function() {\n return this.max[1]\n}\n\nproto.z1 = function() {\n return this.max[2]\n}\n\nproto.translate = function(by) {\n vec3.add(this.max, this.max, by)\n vec3.add(this.base, this.base, by)\n return this\n}\n\nproto.expand = function(aabb) {\n var max = vec3.create()\n , min = vec3.create()\n\n vec3.max(max, aabb.max, this.max)\n vec3.min(min, aabb.base, this.base)\n vec3.sub(max, max, min)\n\n return new AABB(min, max)\n}\n\nproto.intersects = function(aabb) {\n if(aabb.base[0] > this.max[0]) return false\n if(aabb.base[1] > this.max[1]) return false\n if(aabb.base[2] > this.max[2]) return false\n if(aabb.max[0] < this.base[0]) return false\n if(aabb.max[1] < this.base[1]) return false\n if(aabb.max[2] < this.base[2]) return false\n\n return true\n}\n\nproto.union = function(aabb) {\n if(!this.intersects(aabb)) return null\n\n var base_x = Math.max(aabb.base[0], this.base[0])\n , base_y = Math.max(aabb.base[1], this.base[1])\n , base_z = Math.max(aabb.base[2], this.base[2])\n , max_x = Math.min(aabb.max[0], this.max[0])\n , max_y = Math.min(aabb.max[1], this.max[1])\n , max_z = Math.min(aabb.max[2], this.max[2])\n\n return new AABB([base_x, base_y, base_z], [max_x - base_x, max_y - base_y, max_z - base_z])\n}\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/aabb-3d/index.js")),n.define("/node_modules/voxel-engine/node_modules/aabb-3d/node_modules/gl-matrix/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"dist/gl-matrix.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/aabb-3d/node_modules/gl-matrix/package.json')),n.define("/node_modules/voxel-engine/node_modules/aabb-3d/node_modules/gl-matrix/dist/gl-matrix.js",Function(["require","module","exports","__dirname","__filename","process","global"],"/**\n * @fileoverview gl-matrix - High performance matrix and vector operations\n * @author Brandon Jones\n * @author Colin MacKenzie IV\n * @version 2.0.0\n */\n\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n\n(function() {\n \"use strict\";\n\n var shim = {};\n if (typeof(exports) === 'undefined') {\n if(typeof define == 'function' && typeof define.amd == 'object' && define.amd) {\n shim.exports = {};\n define(function() {\n return shim.exports;\n });\n } else {\n // gl-matrix lives in a browser, define its namespaces in global\n shim.exports = window;\n } \n }\n else {\n // gl-matrix lives in commonjs, define its namespaces in exports\n shim.exports = exports;\n }\n\n (function(exports) {\n /* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 2 Dimensional Vector\n * @name vec2\n */\n\nvar vec2 = {};\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n \n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\nvec2.create = function() {\n return new Float32Array(2);\n};\n\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {vec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\nvec2.clone = function(a) {\n var out = new Float32Array(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n};\n\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\nvec2.fromValues = function(x, y) {\n var out = new Float32Array(2);\n out[0] = x;\n out[1] = y;\n return out;\n};\n\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the source vector\n * @returns {vec2} out\n */\nvec2.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n};\n\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\nvec2.set = function(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n};\n\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n};\n\n/**\n * Subtracts two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.sub = vec2.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n};\n\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.mul = vec2.multiply = function(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n};\n\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.div = vec2.divide = function(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n};\n\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.min = function(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n};\n\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.max = function(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n};\n\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the vector to scale\n * @param {vec2} b amount to scale the vector by\n * @returns {vec2} out\n */\nvec2.scale = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n};\n\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {Number} distance between a and b\n */\nvec2.dist = vec2.distance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.sqrt(x*x + y*y);\n};\n\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\nvec2.sqrDist = vec2.squaredDistance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x*x + y*y;\n};\n\n/**\n * Caclulates the length of a vec2\n *\n * @param {vec2} a vector to calculate length of\n * @returns {Number} length of a\n */\nvec2.len = vec2.length = function (a) {\n var x = a[0],\n y = a[1];\n return Math.sqrt(x*x + y*y);\n};\n\n/**\n * Caclulates the squared length of a vec2\n *\n * @param {vec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nvec2.sqrLen = vec2.squaredLength = function (a) {\n var x = a[0],\n y = a[1];\n return x*x + y*y;\n};\n\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a vector to negate\n * @returns {vec2} out\n */\nvec2.negate = function(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n};\n\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a vector to normalize\n * @returns {vec2} out\n */\nvec2.normalize = function(out, a) {\n var x = a[0],\n y = a[1];\n var len = x*x + y*y;\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n }\n return out;\n};\n\n/**\n * Caclulates the dot product of two vec2's\n *\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {Number} dot product of a and b\n */\nvec2.dot = function (a, b) {\n return a[0] * b[0] + a[1] * b[1];\n};\n\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec3} out\n */\nvec2.cross = function(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n};\n\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec3} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec2} out\n */\nvec2.lerp = function (out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n};\n\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the vector to transform\n * @param {mat2} m matrix to transform with\n * @returns {vec2} out\n */\nvec2.transformMat2 = function(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = x * m[0] + y * m[1];\n out[1] = x * m[2] + y * m[3];\n return out;\n};\n\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n */\nvec2.forEach = (function() {\n var vec = new Float32Array(2);\n\n return function(a, stride, offset, count, fn, arg) {\n var i, l;\n if(!stride) {\n stride = 2;\n }\n\n if(!offset) {\n offset = 0;\n }\n \n if(count) {\n l = Math.min((count * stride) + offset, a.length);\n } else {\n l = a.length;\n }\n\n for(i = offset; i < l; i += stride) {\n vec[0] = a[i]; vec[1] = a[i+1];\n fn(vec, vec, arg);\n a[i] = vec[0]; a[i+1] = vec[1];\n }\n \n return a;\n };\n})();\n\n/**\n * Returns a string representation of a vector\n *\n * @param {vec2} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nvec2.str = function (a) {\n return 'vec2(' + a[0] + ', ' + a[1] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.vec2 = vec2;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 3 Dimensional Vector\n * @name vec3\n */\n\nvar vec3 = {};\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n \n/**\n * Creates a new, empty vec3\n *\n * @returns {vec3} a new 3D vector\n */\nvec3.create = function() {\n return new Float32Array(3);\n};\n\n/**\n * Creates a new vec3 initialized with values from an existing vector\n *\n * @param {vec3} a vector to clone\n * @returns {vec3} a new 3D vector\n */\nvec3.clone = function(a) {\n var out = new Float32Array(3);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n return out;\n};\n\n/**\n * Creates a new vec3 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @returns {vec3} a new 3D vector\n */\nvec3.fromValues = function(x, y, z) {\n var out = new Float32Array(3);\n out[0] = x;\n out[1] = y;\n out[2] = z;\n return out;\n};\n\n/**\n * Copy the values from one vec3 to another\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the source vector\n * @returns {vec3} out\n */\nvec3.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n return out;\n};\n\n/**\n * Set the components of a vec3 to the given values\n *\n * @param {vec3} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @returns {vec3} out\n */\nvec3.set = function(out, x, y, z) {\n out[0] = x;\n out[1] = y;\n out[2] = z;\n return out;\n};\n\n/**\n * Adds two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n return out;\n};\n\n/**\n * Subtracts two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.sub = vec3.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n return out;\n};\n\n/**\n * Multiplies two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.mul = vec3.multiply = function(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n out[2] = a[2] * b[2];\n return out;\n};\n\n/**\n * Divides two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.div = vec3.divide = function(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n out[2] = a[2] / b[2];\n return out;\n};\n\n/**\n * Returns the minimum of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.min = function(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n out[2] = Math.min(a[2], b[2]);\n return out;\n};\n\n/**\n * Returns the maximum of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.max = function(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n out[2] = Math.max(a[2], b[2]);\n return out;\n};\n\n/**\n * Scales a vec3 by a scalar number\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to scale\n * @param {vec3} b amount to scale the vector by\n * @returns {vec3} out\n */\nvec3.scale = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n return out;\n};\n\n/**\n * Calculates the euclidian distance between two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} distance between a and b\n */\nvec3.dist = vec3.distance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2];\n return Math.sqrt(x*x + y*y + z*z);\n};\n\n/**\n * Calculates the squared euclidian distance between two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} squared distance between a and b\n */\nvec3.sqrDist = vec3.squaredDistance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2];\n return x*x + y*y + z*z;\n};\n\n/**\n * Caclulates the length of a vec3\n *\n * @param {vec3} a vector to calculate length of\n * @returns {Number} length of a\n */\nvec3.len = vec3.length = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2];\n return Math.sqrt(x*x + y*y + z*z);\n};\n\n/**\n * Caclulates the squared length of a vec3\n *\n * @param {vec3} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nvec3.sqrLen = vec3.squaredLength = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2];\n return x*x + y*y + z*z;\n};\n\n/**\n * Negates the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to negate\n * @returns {vec3} out\n */\nvec3.negate = function(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n return out;\n};\n\n/**\n * Normalize a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to normalize\n * @returns {vec3} out\n */\nvec3.normalize = function(out, a) {\n var x = a[0],\n y = a[1],\n z = a[2];\n var len = x*x + y*y + z*z;\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n out[2] = a[2] * len;\n }\n return out;\n};\n\n/**\n * Caclulates the dot product of two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} dot product of a and b\n */\nvec3.dot = function (a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n};\n\n/**\n * Computes the cross product of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.cross = function(out, a, b) {\n var ax = a[0], ay = a[1], az = a[2],\n bx = b[0], by = b[1], bz = b[2];\n\n out[0] = ay * bz - az * by;\n out[1] = az * bx - ax * bz;\n out[2] = ax * by - ay * bx;\n return out;\n};\n\n/**\n * Performs a linear interpolation between two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec3} out\n */\nvec3.lerp = function (out, a, b, t) {\n var ax = a[0],\n ay = a[1],\n az = a[2];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n out[2] = az + t * (b[2] - az);\n return out;\n};\n\n/**\n * Transforms the vec3 with a mat4.\n * 4th vector component is implicitly '1'\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to transform\n * @param {mat4} m matrix to transform with\n * @returns {vec3} out\n */\nvec3.transformMat4 = function(out, a, m) {\n var x = a[0], y = a[1], z = a[2];\n out[0] = m[0] * x + m[4] * y + m[8] * z + m[12];\n out[1] = m[1] * x + m[5] * y + m[9] * z + m[13];\n out[2] = m[2] * x + m[6] * y + m[10] * z + m[14];\n return out;\n};\n\n/**\n * Transforms the vec3 with a quat\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to transform\n * @param {quat} q quaternion to transform with\n * @returns {vec3} out\n */\nvec3.transformQuat = function(out, a, q) {\n var x = a[0], y = a[1], z = a[2],\n qx = q[0], qy = q[1], qz = q[2], qw = q[3],\n\n // calculate quat * vec\n ix = qw * x + qy * z - qz * y,\n iy = qw * y + qz * x - qx * z,\n iz = qw * z + qx * y - qy * x,\n iw = -qx * x - qy * y - qz * z;\n\n // calculate result * inverse quat\n out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;\n out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;\n out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;\n return out;\n};\n\n/**\n * Perform some operation over an array of vec3s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n */\nvec3.forEach = (function() {\n var vec = new Float32Array(3);\n\n return function(a, stride, offset, count, fn, arg) {\n var i, l;\n if(!stride) {\n stride = 3;\n }\n\n if(!offset) {\n offset = 0;\n }\n \n if(count) {\n l = Math.min((count * stride) + offset, a.length);\n } else {\n l = a.length;\n }\n\n for(i = offset; i < l; i += stride) {\n vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2];\n fn(vec, vec, arg);\n a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2];\n }\n \n return a;\n };\n})();\n\n/**\n * Returns a string representation of a vector\n *\n * @param {vec3} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nvec3.str = function (a) {\n return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.vec3 = vec3;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 4 Dimensional Vector\n * @name vec4\n */\n\nvar vec4 = {};\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n\n/**\n * Creates a new, empty vec4\n *\n * @returns {vec4} a new 4D vector\n */\nvec4.create = function() {\n return new Float32Array(4);\n};\n\n/**\n * Creates a new vec4 initialized with values from an existing vector\n *\n * @param {vec4} a vector to clone\n * @returns {vec4} a new 4D vector\n */\nvec4.clone = function(a) {\n var out = new Float32Array(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Creates a new vec4 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {vec4} a new 4D vector\n */\nvec4.fromValues = function(x, y, z, w) {\n var out = new Float32Array(4);\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = w;\n return out;\n};\n\n/**\n * Copy the values from one vec4 to another\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the source vector\n * @returns {vec4} out\n */\nvec4.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Set the components of a vec4 to the given values\n *\n * @param {vec4} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {vec4} out\n */\nvec4.set = function(out, x, y, z, w) {\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = w;\n return out;\n};\n\n/**\n * Adds two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n};\n\n/**\n * Subtracts two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.sub = vec4.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n};\n\n/**\n * Multiplies two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.mul = vec4.multiply = function(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n out[2] = a[2] * b[2];\n out[3] = a[3] * b[3];\n return out;\n};\n\n/**\n * Divides two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.div = vec4.divide = function(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n out[2] = a[2] / b[2];\n out[3] = a[3] / b[3];\n return out;\n};\n\n/**\n * Returns the minimum of two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.min = function(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n out[2] = Math.min(a[2], b[2]);\n out[3] = Math.min(a[3], b[3]);\n return out;\n};\n\n/**\n * Returns the maximum of two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.max = function(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n out[2] = Math.max(a[2], b[2]);\n out[3] = Math.max(a[3], b[3]);\n return out;\n};\n\n/**\n * Scales a vec4 by a scalar number\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to scale\n * @param {vec4} b amount to scale the vector by\n * @returns {vec4} out\n */\nvec4.scale = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n};\n\n/**\n * Calculates the euclidian distance between two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} distance between a and b\n */\nvec4.dist = vec4.distance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2],\n w = b[3] - a[3];\n return Math.sqrt(x*x + y*y + z*z + w*w);\n};\n\n/**\n * Calculates the squared euclidian distance between two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} squared distance between a and b\n */\nvec4.sqrDist = vec4.squaredDistance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2],\n w = b[3] - a[3];\n return x*x + y*y + z*z + w*w;\n};\n\n/**\n * Caclulates the length of a vec4\n *\n * @param {vec4} a vector to calculate length of\n * @returns {Number} length of a\n */\nvec4.len = vec4.length = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2],\n w = a[3];\n return Math.sqrt(x*x + y*y + z*z + w*w);\n};\n\n/**\n * Caclulates the squared length of a vec4\n *\n * @param {vec4} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nvec4.sqrLen = vec4.squaredLength = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2],\n w = a[3];\n return x*x + y*y + z*z + w*w;\n};\n\n/**\n * Negates the components of a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to negate\n * @returns {vec4} out\n */\nvec4.negate = function(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = -a[3];\n return out;\n};\n\n/**\n * Normalize a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to normalize\n * @returns {vec4} out\n */\nvec4.normalize = function(out, a) {\n var x = a[0],\n y = a[1],\n z = a[2],\n w = a[3];\n var len = x*x + y*y + z*z + w*w;\n if (len > 0) {\n len = 1 / Math.sqrt(len);\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n out[2] = a[2] * len;\n out[3] = a[3] * len;\n }\n return out;\n};\n\n/**\n * Caclulates the dot product of two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} dot product of a and b\n */\nvec4.dot = function (a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];\n};\n\n/**\n * Performs a linear interpolation between two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec4} out\n */\nvec4.lerp = function (out, a, b, t) {\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n out[2] = az + t * (b[2] - az);\n out[3] = aw + t * (b[3] - aw);\n return out;\n};\n\n/**\n * Transforms the vec4 with a mat4.\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to transform\n * @param {mat4} m matrix to transform with\n * @returns {vec4} out\n */\nvec4.transformMat4 = function(out, a, m) {\n var x = a[0], y = a[1], z = a[2], w = a[3];\n out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;\n out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;\n out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;\n out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;\n return out;\n};\n\n/**\n * Transforms the vec4 with a quat\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to transform\n * @param {quat} q quaternion to transform with\n * @returns {vec4} out\n */\nvec4.transformQuat = function(out, a, q) {\n var x = a[0], y = a[1], z = a[2],\n qx = q[0], qy = q[1], qz = q[2], qw = q[3],\n\n // calculate quat * vec\n ix = qw * x + qy * z - qz * y,\n iy = qw * y + qz * x - qx * z,\n iz = qw * z + qx * y - qy * x,\n iw = -qx * x - qy * y - qz * z;\n\n // calculate result * inverse quat\n out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;\n out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;\n out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;\n return out;\n};\n\n/**\n * Perform some operation over an array of vec4s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n */\nvec4.forEach = (function() {\n var vec = new Float32Array(4);\n\n return function(a, stride, offset, count, fn, arg) {\n var i, l;\n if(!stride) {\n stride = 4;\n }\n\n if(!offset) {\n offset = 0;\n }\n \n if(count) {\n l = Math.min((count * stride) + offset, a.length);\n } else {\n l = a.length;\n }\n\n for(i = offset; i < l; i += stride) {\n vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3];\n fn(vec, vec, arg);\n a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3];\n }\n \n return a;\n };\n})();\n\n/**\n * Returns a string representation of a vector\n *\n * @param {vec4} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nvec4.str = function (a) {\n return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.vec4 = vec4;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 2x2 Matrix\n * @name mat2\n */\n\nvar mat2 = {};\n\nvar mat2Identity = new Float32Array([\n 1, 0,\n 0, 1\n]);\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\nmat2.create = function() {\n return new Float32Array(mat2Identity);\n};\n\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {mat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\nmat2.clone = function(a) {\n var out = new Float32Array(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\nmat2.identity = function(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n};\n\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.transpose = function(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n \n return out;\n};\n\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.invert = function(out, a) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n\n // Calculate the determinant\n det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n det = 1.0 / det;\n \n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n\n return out;\n};\n\n/**\n * Caclulates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.adjoint = function(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n\n return out;\n};\n\n/**\n * Calculates the determinant of a mat2\n *\n * @param {mat2} a the source matrix\n * @returns {Number} determinant of a\n */\nmat2.determinant = function (a) {\n return a[0] * a[3] - a[2] * a[1];\n};\n\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the first operand\n * @param {mat2} b the second operand\n * @returns {mat2} out\n */\nmat2.mul = mat2.multiply = function (out, a, b) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];\n var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];\n out[0] = a0 * b0 + a1 * b2;\n out[1] = a0 * b1 + a1 * b3;\n out[2] = a2 * b0 + a3 * b2;\n out[3] = a2 * b1 + a3 * b3;\n return out;\n};\n\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the matrix to rotate\n * @param {mat2} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\nmat2.rotate = function (out, a, rad) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = a0 * c + a1 * s;\n out[1] = a0 * -s + a1 * c;\n out[2] = a2 * c + a3 * s;\n out[3] = a2 * -s + a3 * c;\n return out;\n};\n\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the matrix to rotate\n * @param {mat2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\nmat2.scale = function(out, a, v) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n v0 = v[0], v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v1;\n out[2] = a2 * v0;\n out[3] = a3 * v1;\n return out;\n};\n\n/**\n * Returns a string representation of a mat2\n *\n * @param {mat2} mat matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\nmat2.str = function (a) {\n return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.mat2 = mat2;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 3x3 Matrix\n * @name mat3\n */\n\nvar mat3 = {};\n\nvar mat3Identity = new Float32Array([\n 1, 0, 0,\n 0, 1, 0,\n 0, 0, 1\n]);\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n\n/**\n * Creates a new identity mat3\n *\n * @returns {mat3} a new 3x3 matrix\n */\nmat3.create = function() {\n return new Float32Array(mat3Identity);\n};\n\n/**\n * Creates a new mat3 initialized with values from an existing matrix\n *\n * @param {mat3} a matrix to clone\n * @returns {mat3} a new 3x3 matrix\n */\nmat3.clone = function(a) {\n var out = new Float32Array(9);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n};\n\n/**\n * Copy the values from one mat3 to another\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n};\n\n/**\n * Set a mat3 to the identity matrix\n *\n * @param {mat3} out the receiving matrix\n * @returns {mat3} out\n */\nmat3.identity = function(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 1;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n};\n\n/**\n * Transpose the values of a mat3\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.transpose = function(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a01 = a[1], a02 = a[2], a12 = a[5];\n out[1] = a[3];\n out[2] = a[6];\n out[3] = a01;\n out[5] = a[7];\n out[6] = a02;\n out[7] = a12;\n } else {\n out[0] = a[0];\n out[1] = a[3];\n out[2] = a[6];\n out[3] = a[1];\n out[4] = a[4];\n out[5] = a[7];\n out[6] = a[2];\n out[7] = a[5];\n out[8] = a[8];\n }\n \n return out;\n};\n\n/**\n * Inverts a mat3\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.invert = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8],\n\n b01 = a22 * a11 - a12 * a21,\n b11 = -a22 * a10 + a12 * a20,\n b21 = a21 * a10 - a11 * a20,\n\n // Calculate the determinant\n det = a00 * b01 + a01 * b11 + a02 * b21;\n\n if (!det) { \n return null; \n }\n det = 1.0 / det;\n\n out[0] = b01 * det;\n out[1] = (-a22 * a01 + a02 * a21) * det;\n out[2] = (a12 * a01 - a02 * a11) * det;\n out[3] = b11 * det;\n out[4] = (a22 * a00 - a02 * a20) * det;\n out[5] = (-a12 * a00 + a02 * a10) * det;\n out[6] = b21 * det;\n out[7] = (-a21 * a00 + a01 * a20) * det;\n out[8] = (a11 * a00 - a01 * a10) * det;\n return out;\n};\n\n/**\n * Caclulates the adjugate of a mat3\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.adjoint = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8];\n\n out[0] = (a11 * a22 - a12 * a21);\n out[1] = (a02 * a21 - a01 * a22);\n out[2] = (a01 * a12 - a02 * a11);\n out[3] = (a12 * a20 - a10 * a22);\n out[4] = (a00 * a22 - a02 * a20);\n out[5] = (a02 * a10 - a00 * a12);\n out[6] = (a10 * a21 - a11 * a20);\n out[7] = (a01 * a20 - a00 * a21);\n out[8] = (a00 * a11 - a01 * a10);\n return out;\n};\n\n/**\n * Calculates the determinant of a mat3\n *\n * @param {mat3} a the source matrix\n * @returns {Number} determinant of a\n */\nmat3.determinant = function (a) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8];\n\n return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);\n};\n\n/**\n * Multiplies two mat3's\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the first operand\n * @param {mat3} b the second operand\n * @returns {mat3} out\n */\nmat3.mul = mat3.multiply = function (out, a, b) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8],\n\n b00 = b[0], b01 = b[1], b02 = b[2],\n b10 = b[3], b11 = b[4], b12 = b[5],\n b20 = b[6], b21 = b[7], b22 = b[8];\n\n out[0] = b00 * a00 + b01 * a10 + b02 * a20;\n out[1] = b00 * a01 + b01 * a11 + b02 * a21;\n out[2] = b00 * a02 + b01 * a12 + b02 * a22;\n\n out[3] = b10 * a00 + b11 * a10 + b12 * a20;\n out[4] = b10 * a01 + b11 * a11 + b12 * a21;\n out[5] = b10 * a02 + b11 * a12 + b12 * a22;\n\n out[6] = b20 * a00 + b21 * a10 + b22 * a20;\n out[7] = b20 * a01 + b21 * a11 + b22 * a21;\n out[8] = b20 * a02 + b21 * a12 + b22 * a22;\n return out;\n};\n\n/**\n * Returns a string representation of a mat3\n *\n * @param {mat3} mat matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\nmat3.str = function (a) {\n return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + \n a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + \n a[6] + ', ' + a[7] + ', ' + a[8] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.mat3 = mat3;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 4x4 Matrix\n * @name mat4\n */\n\nvar mat4 = {};\n\nvar mat4Identity = new Float32Array([\n 1, 0, 0, 0,\n 0, 1, 0, 0,\n 0, 0, 1, 0,\n 0, 0, 0, 1\n]);\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n\n/**\n * Creates a new identity mat4\n *\n * @returns {mat4} a new 4x4 matrix\n */\nmat4.create = function() {\n return new Float32Array(mat4Identity);\n};\n\n/**\n * Creates a new mat4 initialized with values from an existing matrix\n *\n * @param {mat4} a matrix to clone\n * @returns {mat4} a new 4x4 matrix\n */\nmat4.clone = function(a) {\n var out = new Float32Array(16);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n};\n\n/**\n * Copy the values from one mat4 to another\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n};\n\n/**\n * Set a mat4 to the identity matrix\n *\n * @param {mat4} out the receiving matrix\n * @returns {mat4} out\n */\nmat4.identity = function(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n};\n\n/**\n * Transpose the values of a mat4\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.transpose = function(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a01 = a[1], a02 = a[2], a03 = a[3],\n a12 = a[6], a13 = a[7],\n a23 = a[11];\n\n out[1] = a[4];\n out[2] = a[8];\n out[3] = a[12];\n out[4] = a01;\n out[6] = a[9];\n out[7] = a[13];\n out[8] = a02;\n out[9] = a12;\n out[11] = a[14];\n out[12] = a03;\n out[13] = a13;\n out[14] = a23;\n } else {\n out[0] = a[0];\n out[1] = a[4];\n out[2] = a[8];\n out[3] = a[12];\n out[4] = a[1];\n out[5] = a[5];\n out[6] = a[9];\n out[7] = a[13];\n out[8] = a[2];\n out[9] = a[6];\n out[10] = a[10];\n out[11] = a[14];\n out[12] = a[3];\n out[13] = a[7];\n out[14] = a[11];\n out[15] = a[15];\n }\n \n return out;\n};\n\n/**\n * Inverts a mat4\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.invert = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],\n\n b00 = a00 * a11 - a01 * a10,\n b01 = a00 * a12 - a02 * a10,\n b02 = a00 * a13 - a03 * a10,\n b03 = a01 * a12 - a02 * a11,\n b04 = a01 * a13 - a03 * a11,\n b05 = a02 * a13 - a03 * a12,\n b06 = a20 * a31 - a21 * a30,\n b07 = a20 * a32 - a22 * a30,\n b08 = a20 * a33 - a23 * a30,\n b09 = a21 * a32 - a22 * a31,\n b10 = a21 * a33 - a23 * a31,\n b11 = a22 * a33 - a23 * a32,\n\n // Calculate the determinant\n det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n\n if (!det) { \n return null; \n }\n det = 1.0 / det;\n\n out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;\n out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;\n out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;\n out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;\n out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;\n out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;\n out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;\n out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;\n out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;\n out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;\n out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;\n out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;\n out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;\n out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;\n out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;\n out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;\n\n return out;\n};\n\n/**\n * Caclulates the adjugate of a mat4\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.adjoint = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];\n\n out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22));\n out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));\n out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12));\n out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));\n out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));\n out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22));\n out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));\n out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12));\n out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21));\n out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));\n out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11));\n out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));\n out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));\n out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21));\n out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));\n out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11));\n return out;\n};\n\n/**\n * Calculates the determinant of a mat4\n *\n * @param {mat4} a the source matrix\n * @returns {Number} determinant of a\n */\nmat4.determinant = function (a) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],\n\n b00 = a00 * a11 - a01 * a10,\n b01 = a00 * a12 - a02 * a10,\n b02 = a00 * a13 - a03 * a10,\n b03 = a01 * a12 - a02 * a11,\n b04 = a01 * a13 - a03 * a11,\n b05 = a02 * a13 - a03 * a12,\n b06 = a20 * a31 - a21 * a30,\n b07 = a20 * a32 - a22 * a30,\n b08 = a20 * a33 - a23 * a30,\n b09 = a21 * a32 - a22 * a31,\n b10 = a21 * a33 - a23 * a31,\n b11 = a22 * a33 - a23 * a32;\n\n // Calculate the determinant\n return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n};\n\n/**\n * Multiplies two mat4's\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the first operand\n * @param {mat4} b the second operand\n * @returns {mat4} out\n */\nmat4.mul = mat4.multiply = function (out, a, b) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];\n\n // Cache only the current line of the second matrix\n var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; \n out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];\n out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];\n out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];\n out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n return out;\n};\n\n/**\n * Translate a mat4 by the given vector\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to translate\n * @param {vec3} v vector to translate by\n * @returns {mat4} out\n */\nmat4.translate = function (out, a, v) {\n var x = v[0], y = v[1], z = v[2],\n a00, a01, a02, a03,\n a10, a11, a12, a13,\n a20, a21, a22, a23;\n\n if (a === out) {\n out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];\n out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];\n out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];\n out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];\n } else {\n a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];\n a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];\n a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];\n\n out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03;\n out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13;\n out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23;\n\n out[12] = a00 * x + a10 * y + a20 * z + a[12];\n out[13] = a01 * x + a11 * y + a21 * z + a[13];\n out[14] = a02 * x + a12 * y + a22 * z + a[14];\n out[15] = a03 * x + a13 * y + a23 * z + a[15];\n }\n\n return out;\n};\n\n/**\n * Scales the mat4 by the dimensions in the given vec3\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to scale\n * @param {vec3} v the vec3 to scale the matrix by\n * @returns {mat4} out\n **/\nmat4.scale = function(out, a, v) {\n var x = v[0], y = v[1], z = v[2];\n\n out[0] = a[0] * x;\n out[1] = a[1] * x;\n out[2] = a[2] * x;\n out[3] = a[3] * x;\n out[4] = a[4] * y;\n out[5] = a[5] * y;\n out[6] = a[6] * y;\n out[7] = a[7] * y;\n out[8] = a[8] * z;\n out[9] = a[9] * z;\n out[10] = a[10] * z;\n out[11] = a[11] * z;\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n};\n\n/**\n * Rotates a mat4 by the given angle\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @param {vec3} axis the axis to rotate around\n * @returns {mat4} out\n */\nmat4.rotate = function (out, a, rad, axis) {\n var x = axis[0], y = axis[1], z = axis[2],\n len = Math.sqrt(x * x + y * y + z * z),\n s, c, t,\n a00, a01, a02, a03,\n a10, a11, a12, a13,\n a20, a21, a22, a23,\n b00, b01, b02,\n b10, b11, b12,\n b20, b21, b22;\n\n if (Math.abs(len) < GLMAT_EPSILON) { return null; }\n \n len = 1 / len;\n x *= len;\n y *= len;\n z *= len;\n\n s = Math.sin(rad);\n c = Math.cos(rad);\n t = 1 - c;\n\n a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];\n a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];\n a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];\n\n // Construct the elements of the rotation matrix\n b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s;\n b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s;\n b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c;\n\n // Perform rotation-specific matrix multiplication\n out[0] = a00 * b00 + a10 * b01 + a20 * b02;\n out[1] = a01 * b00 + a11 * b01 + a21 * b02;\n out[2] = a02 * b00 + a12 * b01 + a22 * b02;\n out[3] = a03 * b00 + a13 * b01 + a23 * b02;\n out[4] = a00 * b10 + a10 * b11 + a20 * b12;\n out[5] = a01 * b10 + a11 * b11 + a21 * b12;\n out[6] = a02 * b10 + a12 * b11 + a22 * b12;\n out[7] = a03 * b10 + a13 * b11 + a23 * b12;\n out[8] = a00 * b20 + a10 * b21 + a20 * b22;\n out[9] = a01 * b20 + a11 * b21 + a21 * b22;\n out[10] = a02 * b20 + a12 * b21 + a22 * b22;\n out[11] = a03 * b20 + a13 * b21 + a23 * b22;\n\n if (a !== out) { // If the source and destination differ, copy the unchanged last row\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the X axis\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.rotateX = function (out, a, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad),\n a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7],\n a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n\n if (a !== out) { // If the source and destination differ, copy the unchanged rows\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n out[4] = a10 * c + a20 * s;\n out[5] = a11 * c + a21 * s;\n out[6] = a12 * c + a22 * s;\n out[7] = a13 * c + a23 * s;\n out[8] = a20 * c - a10 * s;\n out[9] = a21 * c - a11 * s;\n out[10] = a22 * c - a12 * s;\n out[11] = a23 * c - a13 * s;\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the Y axis\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.rotateY = function (out, a, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad),\n a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3],\n a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n\n if (a !== out) { // If the source and destination differ, copy the unchanged rows\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n out[0] = a00 * c - a20 * s;\n out[1] = a01 * c - a21 * s;\n out[2] = a02 * c - a22 * s;\n out[3] = a03 * c - a23 * s;\n out[8] = a00 * s + a20 * c;\n out[9] = a01 * s + a21 * c;\n out[10] = a02 * s + a22 * c;\n out[11] = a03 * s + a23 * c;\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the Z axis\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.rotateZ = function (out, a, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad),\n a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3],\n a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n\n if (a !== out) { // If the source and destination differ, copy the unchanged last row\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n out[0] = a00 * c + a10 * s;\n out[1] = a01 * c + a11 * s;\n out[2] = a02 * c + a12 * s;\n out[3] = a03 * c + a13 * s;\n out[4] = a10 * c - a00 * s;\n out[5] = a11 * c - a01 * s;\n out[6] = a12 * c - a02 * s;\n out[7] = a13 * c - a03 * s;\n return out;\n};\n\n/**\n * Creates a matrix from a quaternion rotation and vector translation\n * This is equivalent to (but much faster than):\n *\n * mat4.identity(dest);\n * mat4.translate(dest, vec);\n * var quatMat = mat4.create();\n * quat4.toMat4(quat, quatMat);\n * mat4.multiply(dest, quatMat);\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {quat4} q Rotation quaternion\n * @param {vec3} v Translation vector\n * @returns {mat4} out\n */\nmat4.fromRotationTranslation = function (out, q, v) {\n // Quaternion math\n var x = q[0], y = q[1], z = q[2], w = q[3],\n x2 = x + x,\n y2 = y + y,\n z2 = z + z,\n\n xx = x * x2,\n xy = x * y2,\n xz = x * z2,\n yy = y * y2,\n yz = y * z2,\n zz = z * z2,\n wx = w * x2,\n wy = w * y2,\n wz = w * z2;\n\n out[0] = 1 - (yy + zz);\n out[1] = xy + wz;\n out[2] = xz - wy;\n out[3] = 0;\n out[4] = xy - wz;\n out[5] = 1 - (xx + zz);\n out[6] = yz + wx;\n out[7] = 0;\n out[8] = xz + wy;\n out[9] = yz - wx;\n out[10] = 1 - (xx + yy);\n out[11] = 0;\n out[12] = v[0];\n out[13] = v[1];\n out[14] = v[2];\n out[15] = 1;\n \n return out;\n};\n\n/**\n * Generates a frustum matrix with the given bounds\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {Number} left Left bound of the frustum\n * @param {Number} right Right bound of the frustum\n * @param {Number} bottom Bottom bound of the frustum\n * @param {Number} top Top bound of the frustum\n * @param {Number} near Near bound of the frustum\n * @param {Number} far Far bound of the frustum\n * @returns {mat4} out\n */\nmat4.frustum = function (out, left, right, bottom, top, near, far) {\n var rl = 1 / (right - left),\n tb = 1 / (top - bottom),\n nf = 1 / (near - far);\n out[0] = (near * 2) * rl;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = (near * 2) * tb;\n out[6] = 0;\n out[7] = 0;\n out[8] = (right + left) * rl;\n out[9] = (top + bottom) * tb;\n out[10] = (far + near) * nf;\n out[11] = -1;\n out[12] = 0;\n out[13] = 0;\n out[14] = (far * near * 2) * nf;\n out[15] = 0;\n return out;\n};\n\n/**\n * Generates a perspective projection matrix with the given bounds\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {number} fovy Vertical field of view in radians\n * @param {number} aspect Aspect ratio. typically viewport width/height\n * @param {number} near Near bound of the frustum\n * @param {number} far Far bound of the frustum\n * @returns {mat4} out\n */\nmat4.perspective = function (out, fovy, aspect, near, far) {\n var f = 1.0 / Math.tan(fovy / 2),\n nf = 1 / (near - far);\n out[0] = f / aspect;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = f;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = (far + near) * nf;\n out[11] = -1;\n out[12] = 0;\n out[13] = 0;\n out[14] = (2 * far * near) * nf;\n out[15] = 0;\n return out;\n};\n\n/**\n * Generates a orthogonal projection matrix with the given bounds\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {number} left Left bound of the frustum\n * @param {number} right Right bound of the frustum\n * @param {number} bottom Bottom bound of the frustum\n * @param {number} top Top bound of the frustum\n * @param {number} near Near bound of the frustum\n * @param {number} far Far bound of the frustum\n * @returns {mat4} out\n */\nmat4.ortho = function (out, left, right, bottom, top, near, far) {\n var lr = 1 / (left - right),\n bt = 1 / (bottom - top),\n nf = 1 / (near - far);\n out[0] = -2 * lr;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = -2 * bt;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 2 * nf;\n out[11] = 0;\n out[12] = (left + right) * lr;\n out[13] = (top + bottom) * bt;\n out[14] = (far + near) * nf;\n out[15] = 1;\n return out;\n};\n\n/**\n * Generates a look-at matrix with the given eye position, focal point, and up axis\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {vec3} eye Position of the viewer\n * @param {vec3} center Point the viewer is looking at\n * @param {vec3} up vec3 pointing up\n * @returns {mat4} out\n */\nmat4.lookAt = function (out, eye, center, up) {\n var x0, x1, x2, y0, y1, y2, z0, z1, z2, len,\n eyex = eye[0],\n eyey = eye[1],\n eyez = eye[2],\n upx = up[0],\n upy = up[1],\n upz = up[2],\n centerx = center[0],\n centery = center[1],\n centerz = center[2];\n\n if (Math.abs(eyex - centerx) < GLMAT_EPSILON &&\n Math.abs(eyey - centery) < GLMAT_EPSILON &&\n Math.abs(eyez - centerz) < GLMAT_EPSILON) {\n return mat4.identity(out);\n }\n\n z0 = eyex - centerx;\n z1 = eyey - centery;\n z2 = eyez - centerz;\n\n len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);\n z0 *= len;\n z1 *= len;\n z2 *= len;\n\n x0 = upy * z2 - upz * z1;\n x1 = upz * z0 - upx * z2;\n x2 = upx * z1 - upy * z0;\n len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);\n if (!len) {\n x0 = 0;\n x1 = 0;\n x2 = 0;\n } else {\n len = 1 / len;\n x0 *= len;\n x1 *= len;\n x2 *= len;\n }\n\n y0 = z1 * x2 - z2 * x1;\n y1 = z2 * x0 - z0 * x2;\n y2 = z0 * x1 - z1 * x0;\n\n len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);\n if (!len) {\n y0 = 0;\n y1 = 0;\n y2 = 0;\n } else {\n len = 1 / len;\n y0 *= len;\n y1 *= len;\n y2 *= len;\n }\n\n out[0] = x0;\n out[1] = y0;\n out[2] = z0;\n out[3] = 0;\n out[4] = x1;\n out[5] = y1;\n out[6] = z1;\n out[7] = 0;\n out[8] = x2;\n out[9] = y2;\n out[10] = z2;\n out[11] = 0;\n out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);\n out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);\n out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);\n out[15] = 1;\n\n return out;\n};\n\n/**\n * Returns a string representation of a mat4\n *\n * @param {mat4} mat matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\nmat4.str = function (a) {\n return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' +\n a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' +\n a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' + \n a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.mat4 = mat4;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class Quaternion\n * @name quat\n */\n\nvar quat = {};\n\nvar quatIdentity = new Float32Array([0, 0, 0, 1]);\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n\n/**\n * Creates a new identity quat\n *\n * @returns {quat} a new quaternion\n */\nquat.create = function() {\n return new Float32Array(quatIdentity);\n};\n\n/**\n * Creates a new quat initialized with values from an existing quaternion\n *\n * @param {quat} a quaternion to clone\n * @returns {quat} a new quaternion\n */\nquat.clone = vec4.clone;\n\n/**\n * Creates a new quat initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {quat} a new quaternion\n */\nquat.fromValues = vec4.fromValues;\n\n/**\n * Copy the values from one quat to another\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the source quaternion\n * @returns {quat} out\n */\nquat.copy = vec4.copy;\n\n/**\n * Set the components of a quat to the given values\n *\n * @param {quat} out the receiving quaternion\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {quat} out\n */\nquat.set = vec4.set;\n\n/**\n * Set a quat to the identity quaternion\n *\n * @param {quat} out the receiving quaternion\n * @returns {quat} out\n */\nquat.identity = function(out) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n};\n\n/**\n * Sets a quat from the given angle and rotation axis,\n * then returns it.\n *\n * @param {quat} out the receiving quaternion\n * @param {vec3} axis the axis around which to rotate\n * @param {Number} rad the angle in radians\n * @returns {quat} out\n **/\nquat.setAxisAngle = function(out, axis, rad) {\n rad = rad * 0.5;\n var s = Math.sin(rad);\n out[0] = s * axis[0];\n out[1] = s * axis[1];\n out[2] = s * axis[2];\n out[3] = Math.cos(rad);\n return out;\n};\n\n/**\n * Adds two quat's\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @returns {quat} out\n */\nquat.add = vec4.add;\n\n/**\n * Multiplies two quat's\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @returns {quat} out\n */\nquat.mul = quat.multiply = function(out, a, b) {\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bx = b[0], by = b[1], bz = b[2], bw = b[3];\n\n out[0] = ax * bw + aw * bx + ay * bz - az * by;\n out[1] = ay * bw + aw * by + az * bx - ax * bz;\n out[2] = az * bw + aw * bz + ax * by - ay * bx;\n out[3] = aw * bw - ax * bx - ay * by - az * bz;\n return out;\n};\n\n/**\n * Scales a quat by a scalar number\n *\n * @param {quat} out the receiving vector\n * @param {quat} a the vector to scale\n * @param {quat} b amount to scale the vector by\n * @returns {quat} out\n */\nquat.scale = vec4.scale;\n\n/**\n * Rotates a quaternion by the given angle around the X axis\n *\n * @param {quat} out quat receiving operation result\n * @param {quat} a quat to rotate\n * @param {number} rad angle (in radians) to rotate\n * @returns {quat} out\n */\nquat.rotateX = function (out, a, rad) {\n rad *= 0.5; \n\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bx = Math.sin(rad), bw = Math.cos(rad);\n\n out[0] = ax * bw + aw * bx;\n out[1] = ay * bw + az * bx;\n out[2] = az * bw - ay * bx;\n out[3] = aw * bw - ax * bx;\n return out;\n};\n\n/**\n * Rotates a quaternion by the given angle around the X axis\n *\n * @param {quat} out quat receiving operation result\n * @param {quat} a quat to rotate\n * @param {number} rad angle (in radians) to rotate\n * @returns {quat} out\n */\nquat.rotateY = function (out, a, rad) {\n rad *= 0.5; \n\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n by = Math.sin(rad), bw = Math.cos(rad);\n\n out[0] = ax * bw - az * by;\n out[1] = ay * bw + aw * by;\n out[2] = az * bw + ax * by;\n out[3] = aw * bw - ay * by;\n return out;\n};\n\n/**\n * Rotates a quaternion by the given angle around the X axis\n *\n * @param {quat} out quat receiving operation result\n * @param {quat} a quat to rotate\n * @param {number} rad angle (in radians) to rotate\n * @returns {quat} out\n */\nquat.rotateZ = function (out, a, rad) {\n rad *= 0.5; \n\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bz = Math.sin(rad), bw = Math.cos(rad);\n\n out[0] = ax * bw + ay * bz;\n out[1] = ay * bw - ax * bz;\n out[2] = az * bw + aw * bz;\n out[3] = aw * bw - az * bz;\n return out;\n};\n\n/**\n * Calculates the W component of a quat from the X, Y, and Z components.\n * Assumes that quaternion is 1 unit in length.\n * Any existing W component will be ignored.\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quat to calculate W component of\n * @returns {quat} out\n */\nquat.calculateW = function (out, a) {\n var x = a[0], y = a[1], z = a[2];\n\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = -Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));\n return out;\n};\n\n/**\n * Caclulates the dot product of two quat's\n *\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @returns {Number} dot product of a and b\n */\nquat.dot = vec4.dot;\n\n/**\n * Performs a linear interpolation between two quat's\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {quat} out\n */\nquat.lerp = vec4.lerp;\n\n/**\n * Performs a spherical linear interpolation between two quat\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {quat} out\n */\nquat.slerp = function (out, a, b, t) {\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bx = b[0], by = b[1], bz = b[2], bw = a[3];\n\n var cosHalfTheta = ax * bx + ay * by + az * bz + aw * bw,\n halfTheta,\n sinHalfTheta,\n ratioA,\n ratioB;\n\n if (Math.abs(cosHalfTheta) >= 1.0) {\n if (out !== a) {\n out[0] = ax;\n out[1] = ay;\n out[2] = az;\n out[3] = aw;\n }\n return out;\n }\n\n halfTheta = Math.acos(cosHalfTheta);\n sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta);\n\n if (Math.abs(sinHalfTheta) < 0.001) {\n out[0] = (ax * 0.5 + bx * 0.5);\n out[1] = (ay * 0.5 + by * 0.5);\n out[2] = (az * 0.5 + bz * 0.5);\n out[3] = (aw * 0.5 + bw * 0.5);\n return out;\n }\n\n ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta;\n ratioB = Math.sin(t * halfTheta) / sinHalfTheta;\n\n out[0] = (ax * ratioA + bx * ratioB);\n out[1] = (ay * ratioA + by * ratioB);\n out[2] = (az * ratioA + bz * ratioB);\n out[3] = (aw * ratioA + bw * ratioB);\n\n return out;\n};\n\n/**\n * Calculates the inverse of a quat\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quat to calculate inverse of\n * @returns {quat} out\n */\nquat.invert = function(out, a) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n dot = a0*a0 + a1*a1 + a2*a2 + a3*a3,\n invDot = dot ? 1.0/dot : 0;\n \n // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0\n\n out[0] = -a0*invDot;\n out[1] = -a1*invDot;\n out[2] = -a2*invDot;\n out[3] = a3*invDot;\n return out;\n};\n\n/**\n * Calculates the conjugate of a quat\n * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quat to calculate conjugate of\n * @returns {quat} out\n */\nquat.conjugate = function (out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Caclulates the length of a quat\n *\n * @param {quat} a vector to calculate length of\n * @returns {Number} length of a\n */\nquat.len = quat.length = vec4.length;\n\n/**\n * Caclulates the squared length of a quat\n *\n * @param {quat} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nquat.sqrLen = quat.squaredLength = vec4.squaredLength;\n\n/**\n * Normalize a quat\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quaternion to normalize\n * @returns {quat} out\n */\nquat.normalize = vec4.normalize;\n\n/**\n * Returns a string representation of a quatenion\n *\n * @param {quat} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nquat.str = function (a) {\n return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.quat = quat;\n}\n;\n\n\n\n\n\n\n\n\n\n\n })(shim.exports);\n})();\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/aabb-3d/node_modules/gl-matrix/dist/gl-matrix.js")),n.define("/node_modules/voxel-engine/node_modules/spatial-events/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/spatial-events/package.json')),n.define("/node_modules/voxel-engine/node_modules/spatial-events/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = SpatialEventEmitter\n\nvar slice = [].slice\n , Tree = require('./tree')\n , aabb = require('aabb-3d')\n\nfunction SpatialEventEmitter() {\n this.root = null\n this.infinites = {}\n}\n\nvar cons = SpatialEventEmitter\n , proto = cons.prototype\n\nproto.size = 16\n\nproto.addListener = \nproto.addEventListener = \nproto.on = function(event, bbox, listener) {\n if(!finite(bbox)) {\n (this.infinites[event] = this.infinites[event] || []).push({\n bbox: bbox\n , func: listener\n })\n return this\n }\n\n (this.root = this.root || this.create_root(bbox))\n .add(event, bbox, listener)\n\n return this\n}\n\nproto.once = function(event, bbox, listener) {\n var self = this\n\n self.on(event, bbox, function once() {\n listener.apply(null, arguments)\n self.remove(event, once)\n })\n\n return self\n}\n\nproto.removeListener =\nproto.removeEventListener =\nproto.remove = function(event, listener) {\n if(this.root) {\n this.root.remove(event, listener)\n }\n\n if(!this.infinites[event]) {\n return this\n }\n\n for(var i = 0, len = this.infinites[event].length; i < len; ++i) {\n if(this.infinites[event][i].func === listener) {\n break\n }\n }\n\n if(i !== len) {\n this.infinites[event].splice(i, 1)\n }\n\n return this\n}\n\nproto.emit = function(event, bbox/*, ...args */) {\n var args = slice.call(arguments, 2)\n\n // support point emitting\n if('0' in bbox) {\n bbox = aabb(bbox, [0, 0, 0]) \n }\n\n if(this.root) {\n this.root.send(event, bbox, args)\n }\n\n if(!this.infinites[event]) {\n return this\n }\n\n var list = this.infinites[event].slice()\n for(var i = 0, len = list.length; i < len; ++i) {\n if(list[i].bbox.intersects(bbox)) {\n list[i].func.apply(null, args) \n }\n }\n\n return this\n}\n\nproto.rootSize = function(size) {\n proto.size = size\n}\n\nproto.create_root = function(bbox) {\n var self = this\n , size = self.size\n , base = [\n Math.floor(bbox.x0() / size) * size\n , Math.floor(bbox.y0() / size) * size\n , Math.floor(bbox.z0() / size) * size\n ]\n , tree_bbox = new bbox.constructor(base, [size, size, size])\n\n function OurTree(size, bbox) {\n Tree.call(this, size, bbox, null)\n }\n\n OurTree.prototype = Object.create(Tree.prototype)\n OurTree.prototype.constructor = OurTree\n OurTree.prototype.grow = function(new_root) {\n self.root = new_root\n }\n OurTree.prototype.min_size = size\n\n return new OurTree(size, tree_bbox) \n}\n\nfunction finite(bbox) {\n return isFinite(bbox.x0()) &&\n isFinite(bbox.x1()) &&\n isFinite(bbox.y0()) &&\n isFinite(bbox.y1()) &&\n isFinite(bbox.z0()) &&\n isFinite(bbox.z1())\n}\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/spatial-events/index.js")),n.define("/node_modules/voxel-engine/node_modules/spatial-events/tree.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = Tree\n\nvar aabb = require('aabb-3d')\n\nfunction Tree(size, bbox, parent) {\n this.listeners = {}\n this.size = size\n this.bbox = bbox\n this.parent = parent\n this.children = []\n}\n\nvar cons = Tree\n , proto = cons.prototype\n\nproto.add = function(event, bbox, listener) {\n if(!this.parent && !this.contains(bbox)) {\n return this.expand(bbox).add(event, bbox, listener)\n }\n\n for(var i = 0, len = this.children.length; i < len; ++i) {\n if(this.children[i].contains(bbox)) {\n return this.children[i].add(event, bbox, listener)\n }\n }\n\n var size = this.size / 2\n\n if(size > this.min_size && bbox.vec[0] < size && bbox.vec[1] < size && bbox.vec[2] < size) {\n // if it fits into a child node, make that childnode\n if(Math.floor(bbox.x0() / size) === Math.floor(bbox.x1() / size) &&\n Math.floor(bbox.y0() / size) === Math.floor(bbox.y1() / size) &&\n Math.floor(bbox.z0() / size) === Math.floor(bbox.z1() / size)) {\n var inst = new this.constructor(\n size\n , aabb([\n Math.floor(bbox.x0() / size) * size\n , Math.floor(bbox.y0() / size) * size\n , Math.floor(bbox.z0() / size) * size\n ]\n , [size, size, size]\n )\n , this\n )\n this.children.push(inst)\n return inst.add(event, bbox, listener)\n }\n }\n\n (this.listeners[event] = this.listeners[event] || [])\n .push({bbox: bbox, func: listener})\n}\n\nproto.contains = function(bbox) {\n return bbox.x0() >= this.bbox.x0() &&\n bbox.y0() >= this.bbox.y0() &&\n bbox.z0() >= this.bbox.z0() &&\n bbox.x1() <= this.bbox.x1() &&\n bbox.y1() <= this.bbox.y1() &&\n bbox.z1() <= this.bbox.z1()\n}\n\nproto.expand = function(bbox) {\n var size = this.size\n , new_size = size * 2\n , expanded = this.bbox.expand(bbox)\n , new_i = Math.floor(bbox.x0() / size)\n , new_j = Math.floor(bbox.y0() / size)\n , new_k = Math.floor(bbox.z0() / size)\n , cur_i = Math.floor(this.bbox.x0() / size)\n , cur_j = Math.floor(this.bbox.y0() / size)\n , cur_k = Math.floor(this.bbox.z0() / size)\n , new_base = [\n new_i - cur_i >= 0 ? cur_i : cur_i - 1\n , new_j - cur_j >= 0 ? cur_j : cur_j - 1\n , new_k - cur_k >= 0 ? cur_k : cur_k - 1\n ].map(function(ii) { return ii * size })\n , new_bbox = aabb(new_base, [new_size, new_size, new_size])\n , new_root = new this.constructor(new_size, new_bbox)\n , self = this\n\n this.parent = new_root\n this.grow(this.parent)\n\n new_root.children.push(self)\n\n return new_root\n}\n\nproto.remove = function(event, listener) {\n var list = this.listeners[event]\n if(list) {\n for(var i = 0, len = list.length; i < len; ++i) {\n if(list[i].func === listener)\n break\n }\n\n if(i !== len) {\n list.splice(i, 1)\n }\n }\n for(var i = 0, len = this.children.length; i < len; ++i) {\n this.children[i].remove(event, listener)\n }\n}\n\nproto.send = function(event, bbox, args) {\n for(var i = 0, len = this.children.length; i < len; ++i) {\n if(bbox.intersects(this.children[i].bbox)) {\n this.children[i].send(event, bbox, args)\n }\n }\n\n var list = this.listeners[event]\n if(!list) {\n return\n }\n\n for(var i = 0, len = list.length; i < len; ++i) {\n if(list[i].bbox.intersects(bbox)) {\n list[i].func.apply(null, args)\n }\n }\n}\n\n//@ sourceURL=/node_modules/voxel-engine/node_modules/spatial-events/tree.js")),n.define("/node_modules/voxel-region-change/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = {}\n//@ sourceURL=/node_modules/voxel-region-change/package.json")),n.define("/node_modules/voxel-region-change/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = coordinates\n \nvar aabb = require('aabb-3d')\nvar events = require('events')\n \nfunction coordinates(spatial, box, regionWidth) {\n var emitter = new events.EventEmitter()\n var lastRegion = [NaN, NaN, NaN]\n var thisRegion\n\n if (arguments.length === 2) {\n regionWidth = box\n box = aabb([-Infinity, -Infinity, -Infinity], [Infinity, Infinity, Infinity])\n }\n\n spatial.on('position', box, updateRegion)\n \n function updateRegion(pos) {\n thisRegion = [Math.floor(pos.x / regionWidth), Math.floor(pos.y / regionWidth), Math.floor(pos.z / regionWidth)]\n if (thisRegion[0] !== lastRegion[0] || thisRegion[1] !== lastRegion[1] || thisRegion[2] !== lastRegion[2]) {\n emitter.emit('change', thisRegion)\n }\n lastRegion = thisRegion\n }\n \n return emitter\n}\n//@ sourceURL=/node_modules/voxel-region-change/index.js")),n.define("/node_modules/voxel-region-change/node_modules/aabb-3d/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-region-change/node_modules/aabb-3d/package.json')),n.define("/node_modules/voxel-region-change/node_modules/aabb-3d/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = AABB\n\nvar vec3 = require('gl-matrix').vec3\n\nfunction AABB(pos, vec) {\n if(!(this instanceof AABB)) {\n return new AABB(pos, vec)\n }\n\n this.base = pos\n this.vec = vec\n\n this.mag = vec3.length(this.vec)\n\n this.max = vec3.create()\n vec3.add(this.max, this.base, this.vec)\n}\n\nvar cons = AABB\n , proto = cons.prototype\n\nproto.width = function() {\n return this.vec[0]\n}\n\nproto.height = function() {\n return this.vec[1]\n}\n\nproto.depth = function() {\n return this.vec[2]\n}\n\nproto.x0 = function() {\n return this.base[0]\n}\n\nproto.y0 = function() {\n return this.base[1]\n}\n\nproto.z0 = function() {\n return this.base[2]\n}\n\nproto.x1 = function() {\n return this.max[0]\n}\n\nproto.y1 = function() {\n return this.max[1]\n}\n\nproto.z1 = function() {\n return this.max[2]\n}\n\nproto.translate = function(by) {\n vec3.add(this.max, this.max, by)\n vec3.add(this.base, this.base, by)\n return this\n}\n\nproto.expand = function(aabb) {\n var max = vec3.create()\n , min = vec3.create()\n\n vec3.max(max, aabb.max, this.max)\n vec3.min(min, aabb.base, this.base)\n vec3.sub(max, max, min)\n\n return new AABB(min, max)\n}\n\nproto.intersects = function(aabb) {\n if(aabb.base[0] > this.max[0]) return false\n if(aabb.base[1] > this.max[1]) return false\n if(aabb.base[2] > this.max[2]) return false\n if(aabb.max[0] < this.base[0]) return false\n if(aabb.max[1] < this.base[1]) return false\n if(aabb.max[2] < this.base[2]) return false\n\n return true\n}\n\nproto.union = function(aabb) {\n if(!this.intersects(aabb)) return null\n\n var base_x = Math.max(aabb.base[0], this.base[0])\n , base_y = Math.max(aabb.base[1], this.base[1])\n , base_z = Math.max(aabb.base[2], this.base[2])\n , max_x = Math.min(aabb.max[0], this.max[0])\n , max_y = Math.min(aabb.max[1], this.max[1])\n , max_z = Math.min(aabb.max[2], this.max[2])\n\n return new AABB([base_x, base_y, base_z], [max_x - base_x, max_y - base_y, max_z - base_z])\n}\n\n//@ sourceURL=/node_modules/voxel-region-change/node_modules/aabb-3d/index.js")),n.define("/node_modules/voxel-region-change/node_modules/aabb-3d/node_modules/gl-matrix/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"dist/gl-matrix.js"}\n//@ sourceURL=/node_modules/voxel-region-change/node_modules/aabb-3d/node_modules/gl-matrix/package.json')),n.define("/node_modules/voxel-region-change/node_modules/aabb-3d/node_modules/gl-matrix/dist/gl-matrix.js",Function(["require","module","exports","__dirname","__filename","process","global"],"/**\n * @fileoverview gl-matrix - High performance matrix and vector operations\n * @author Brandon Jones\n * @author Colin MacKenzie IV\n * @version 2.0.0\n */\n\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n\n(function() {\n \"use strict\";\n\n var shim = {};\n if (typeof(exports) === 'undefined') {\n if(typeof define == 'function' && typeof define.amd == 'object' && define.amd) {\n shim.exports = {};\n define(function() {\n return shim.exports;\n });\n } else {\n // gl-matrix lives in a browser, define its namespaces in global\n shim.exports = window;\n } \n }\n else {\n // gl-matrix lives in commonjs, define its namespaces in exports\n shim.exports = exports;\n }\n\n (function(exports) {\n /* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 2 Dimensional Vector\n * @name vec2\n */\n\nvar vec2 = {};\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n \n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\nvec2.create = function() {\n return new Float32Array(2);\n};\n\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {vec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\nvec2.clone = function(a) {\n var out = new Float32Array(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n};\n\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\nvec2.fromValues = function(x, y) {\n var out = new Float32Array(2);\n out[0] = x;\n out[1] = y;\n return out;\n};\n\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the source vector\n * @returns {vec2} out\n */\nvec2.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n};\n\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\nvec2.set = function(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n};\n\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n};\n\n/**\n * Subtracts two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.sub = vec2.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n};\n\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.mul = vec2.multiply = function(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n};\n\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.div = vec2.divide = function(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n};\n\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.min = function(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n};\n\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.max = function(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n};\n\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the vector to scale\n * @param {vec2} b amount to scale the vector by\n * @returns {vec2} out\n */\nvec2.scale = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n};\n\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {Number} distance between a and b\n */\nvec2.dist = vec2.distance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.sqrt(x*x + y*y);\n};\n\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\nvec2.sqrDist = vec2.squaredDistance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x*x + y*y;\n};\n\n/**\n * Caclulates the length of a vec2\n *\n * @param {vec2} a vector to calculate length of\n * @returns {Number} length of a\n */\nvec2.len = vec2.length = function (a) {\n var x = a[0],\n y = a[1];\n return Math.sqrt(x*x + y*y);\n};\n\n/**\n * Caclulates the squared length of a vec2\n *\n * @param {vec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nvec2.sqrLen = vec2.squaredLength = function (a) {\n var x = a[0],\n y = a[1];\n return x*x + y*y;\n};\n\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a vector to negate\n * @returns {vec2} out\n */\nvec2.negate = function(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n};\n\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a vector to normalize\n * @returns {vec2} out\n */\nvec2.normalize = function(out, a) {\n var x = a[0],\n y = a[1];\n var len = x*x + y*y;\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n }\n return out;\n};\n\n/**\n * Caclulates the dot product of two vec2's\n *\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {Number} dot product of a and b\n */\nvec2.dot = function (a, b) {\n return a[0] * b[0] + a[1] * b[1];\n};\n\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec3} out\n */\nvec2.cross = function(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n};\n\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec3} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec2} out\n */\nvec2.lerp = function (out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n};\n\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the vector to transform\n * @param {mat2} m matrix to transform with\n * @returns {vec2} out\n */\nvec2.transformMat2 = function(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = x * m[0] + y * m[1];\n out[1] = x * m[2] + y * m[3];\n return out;\n};\n\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n */\nvec2.forEach = (function() {\n var vec = new Float32Array(2);\n\n return function(a, stride, offset, count, fn, arg) {\n var i, l;\n if(!stride) {\n stride = 2;\n }\n\n if(!offset) {\n offset = 0;\n }\n \n if(count) {\n l = Math.min((count * stride) + offset, a.length);\n } else {\n l = a.length;\n }\n\n for(i = offset; i < l; i += stride) {\n vec[0] = a[i]; vec[1] = a[i+1];\n fn(vec, vec, arg);\n a[i] = vec[0]; a[i+1] = vec[1];\n }\n \n return a;\n };\n})();\n\n/**\n * Returns a string representation of a vector\n *\n * @param {vec2} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nvec2.str = function (a) {\n return 'vec2(' + a[0] + ', ' + a[1] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.vec2 = vec2;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 3 Dimensional Vector\n * @name vec3\n */\n\nvar vec3 = {};\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n \n/**\n * Creates a new, empty vec3\n *\n * @returns {vec3} a new 3D vector\n */\nvec3.create = function() {\n return new Float32Array(3);\n};\n\n/**\n * Creates a new vec3 initialized with values from an existing vector\n *\n * @param {vec3} a vector to clone\n * @returns {vec3} a new 3D vector\n */\nvec3.clone = function(a) {\n var out = new Float32Array(3);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n return out;\n};\n\n/**\n * Creates a new vec3 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @returns {vec3} a new 3D vector\n */\nvec3.fromValues = function(x, y, z) {\n var out = new Float32Array(3);\n out[0] = x;\n out[1] = y;\n out[2] = z;\n return out;\n};\n\n/**\n * Copy the values from one vec3 to another\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the source vector\n * @returns {vec3} out\n */\nvec3.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n return out;\n};\n\n/**\n * Set the components of a vec3 to the given values\n *\n * @param {vec3} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @returns {vec3} out\n */\nvec3.set = function(out, x, y, z) {\n out[0] = x;\n out[1] = y;\n out[2] = z;\n return out;\n};\n\n/**\n * Adds two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n return out;\n};\n\n/**\n * Subtracts two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.sub = vec3.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n return out;\n};\n\n/**\n * Multiplies two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.mul = vec3.multiply = function(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n out[2] = a[2] * b[2];\n return out;\n};\n\n/**\n * Divides two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.div = vec3.divide = function(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n out[2] = a[2] / b[2];\n return out;\n};\n\n/**\n * Returns the minimum of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.min = function(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n out[2] = Math.min(a[2], b[2]);\n return out;\n};\n\n/**\n * Returns the maximum of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.max = function(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n out[2] = Math.max(a[2], b[2]);\n return out;\n};\n\n/**\n * Scales a vec3 by a scalar number\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to scale\n * @param {vec3} b amount to scale the vector by\n * @returns {vec3} out\n */\nvec3.scale = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n return out;\n};\n\n/**\n * Calculates the euclidian distance between two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} distance between a and b\n */\nvec3.dist = vec3.distance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2];\n return Math.sqrt(x*x + y*y + z*z);\n};\n\n/**\n * Calculates the squared euclidian distance between two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} squared distance between a and b\n */\nvec3.sqrDist = vec3.squaredDistance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2];\n return x*x + y*y + z*z;\n};\n\n/**\n * Caclulates the length of a vec3\n *\n * @param {vec3} a vector to calculate length of\n * @returns {Number} length of a\n */\nvec3.len = vec3.length = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2];\n return Math.sqrt(x*x + y*y + z*z);\n};\n\n/**\n * Caclulates the squared length of a vec3\n *\n * @param {vec3} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nvec3.sqrLen = vec3.squaredLength = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2];\n return x*x + y*y + z*z;\n};\n\n/**\n * Negates the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to negate\n * @returns {vec3} out\n */\nvec3.negate = function(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n return out;\n};\n\n/**\n * Normalize a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to normalize\n * @returns {vec3} out\n */\nvec3.normalize = function(out, a) {\n var x = a[0],\n y = a[1],\n z = a[2];\n var len = x*x + y*y + z*z;\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n out[2] = a[2] * len;\n }\n return out;\n};\n\n/**\n * Caclulates the dot product of two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} dot product of a and b\n */\nvec3.dot = function (a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n};\n\n/**\n * Computes the cross product of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.cross = function(out, a, b) {\n var ax = a[0], ay = a[1], az = a[2],\n bx = b[0], by = b[1], bz = b[2];\n\n out[0] = ay * bz - az * by;\n out[1] = az * bx - ax * bz;\n out[2] = ax * by - ay * bx;\n return out;\n};\n\n/**\n * Performs a linear interpolation between two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec3} out\n */\nvec3.lerp = function (out, a, b, t) {\n var ax = a[0],\n ay = a[1],\n az = a[2];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n out[2] = az + t * (b[2] - az);\n return out;\n};\n\n/**\n * Transforms the vec3 with a mat4.\n * 4th vector component is implicitly '1'\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to transform\n * @param {mat4} m matrix to transform with\n * @returns {vec3} out\n */\nvec3.transformMat4 = function(out, a, m) {\n var x = a[0], y = a[1], z = a[2];\n out[0] = m[0] * x + m[4] * y + m[8] * z + m[12];\n out[1] = m[1] * x + m[5] * y + m[9] * z + m[13];\n out[2] = m[2] * x + m[6] * y + m[10] * z + m[14];\n return out;\n};\n\n/**\n * Transforms the vec3 with a quat\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to transform\n * @param {quat} q quaternion to transform with\n * @returns {vec3} out\n */\nvec3.transformQuat = function(out, a, q) {\n var x = a[0], y = a[1], z = a[2],\n qx = q[0], qy = q[1], qz = q[2], qw = q[3],\n\n // calculate quat * vec\n ix = qw * x + qy * z - qz * y,\n iy = qw * y + qz * x - qx * z,\n iz = qw * z + qx * y - qy * x,\n iw = -qx * x - qy * y - qz * z;\n\n // calculate result * inverse quat\n out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;\n out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;\n out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;\n return out;\n};\n\n/**\n * Perform some operation over an array of vec3s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n */\nvec3.forEach = (function() {\n var vec = new Float32Array(3);\n\n return function(a, stride, offset, count, fn, arg) {\n var i, l;\n if(!stride) {\n stride = 3;\n }\n\n if(!offset) {\n offset = 0;\n }\n \n if(count) {\n l = Math.min((count * stride) + offset, a.length);\n } else {\n l = a.length;\n }\n\n for(i = offset; i < l; i += stride) {\n vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2];\n fn(vec, vec, arg);\n a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2];\n }\n \n return a;\n };\n})();\n\n/**\n * Returns a string representation of a vector\n *\n * @param {vec3} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nvec3.str = function (a) {\n return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.vec3 = vec3;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 4 Dimensional Vector\n * @name vec4\n */\n\nvar vec4 = {};\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n\n/**\n * Creates a new, empty vec4\n *\n * @returns {vec4} a new 4D vector\n */\nvec4.create = function() {\n return new Float32Array(4);\n};\n\n/**\n * Creates a new vec4 initialized with values from an existing vector\n *\n * @param {vec4} a vector to clone\n * @returns {vec4} a new 4D vector\n */\nvec4.clone = function(a) {\n var out = new Float32Array(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Creates a new vec4 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {vec4} a new 4D vector\n */\nvec4.fromValues = function(x, y, z, w) {\n var out = new Float32Array(4);\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = w;\n return out;\n};\n\n/**\n * Copy the values from one vec4 to another\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the source vector\n * @returns {vec4} out\n */\nvec4.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Set the components of a vec4 to the given values\n *\n * @param {vec4} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {vec4} out\n */\nvec4.set = function(out, x, y, z, w) {\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = w;\n return out;\n};\n\n/**\n * Adds two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n};\n\n/**\n * Subtracts two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.sub = vec4.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n};\n\n/**\n * Multiplies two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.mul = vec4.multiply = function(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n out[2] = a[2] * b[2];\n out[3] = a[3] * b[3];\n return out;\n};\n\n/**\n * Divides two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.div = vec4.divide = function(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n out[2] = a[2] / b[2];\n out[3] = a[3] / b[3];\n return out;\n};\n\n/**\n * Returns the minimum of two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.min = function(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n out[2] = Math.min(a[2], b[2]);\n out[3] = Math.min(a[3], b[3]);\n return out;\n};\n\n/**\n * Returns the maximum of two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.max = function(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n out[2] = Math.max(a[2], b[2]);\n out[3] = Math.max(a[3], b[3]);\n return out;\n};\n\n/**\n * Scales a vec4 by a scalar number\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to scale\n * @param {vec4} b amount to scale the vector by\n * @returns {vec4} out\n */\nvec4.scale = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n};\n\n/**\n * Calculates the euclidian distance between two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} distance between a and b\n */\nvec4.dist = vec4.distance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2],\n w = b[3] - a[3];\n return Math.sqrt(x*x + y*y + z*z + w*w);\n};\n\n/**\n * Calculates the squared euclidian distance between two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} squared distance between a and b\n */\nvec4.sqrDist = vec4.squaredDistance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2],\n w = b[3] - a[3];\n return x*x + y*y + z*z + w*w;\n};\n\n/**\n * Caclulates the length of a vec4\n *\n * @param {vec4} a vector to calculate length of\n * @returns {Number} length of a\n */\nvec4.len = vec4.length = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2],\n w = a[3];\n return Math.sqrt(x*x + y*y + z*z + w*w);\n};\n\n/**\n * Caclulates the squared length of a vec4\n *\n * @param {vec4} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nvec4.sqrLen = vec4.squaredLength = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2],\n w = a[3];\n return x*x + y*y + z*z + w*w;\n};\n\n/**\n * Negates the components of a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to negate\n * @returns {vec4} out\n */\nvec4.negate = function(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = -a[3];\n return out;\n};\n\n/**\n * Normalize a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to normalize\n * @returns {vec4} out\n */\nvec4.normalize = function(out, a) {\n var x = a[0],\n y = a[1],\n z = a[2],\n w = a[3];\n var len = x*x + y*y + z*z + w*w;\n if (len > 0) {\n len = 1 / Math.sqrt(len);\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n out[2] = a[2] * len;\n out[3] = a[3] * len;\n }\n return out;\n};\n\n/**\n * Caclulates the dot product of two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} dot product of a and b\n */\nvec4.dot = function (a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];\n};\n\n/**\n * Performs a linear interpolation between two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec4} out\n */\nvec4.lerp = function (out, a, b, t) {\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n out[2] = az + t * (b[2] - az);\n out[3] = aw + t * (b[3] - aw);\n return out;\n};\n\n/**\n * Transforms the vec4 with a mat4.\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to transform\n * @param {mat4} m matrix to transform with\n * @returns {vec4} out\n */\nvec4.transformMat4 = function(out, a, m) {\n var x = a[0], y = a[1], z = a[2], w = a[3];\n out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;\n out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;\n out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;\n out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;\n return out;\n};\n\n/**\n * Transforms the vec4 with a quat\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to transform\n * @param {quat} q quaternion to transform with\n * @returns {vec4} out\n */\nvec4.transformQuat = function(out, a, q) {\n var x = a[0], y = a[1], z = a[2],\n qx = q[0], qy = q[1], qz = q[2], qw = q[3],\n\n // calculate quat * vec\n ix = qw * x + qy * z - qz * y,\n iy = qw * y + qz * x - qx * z,\n iz = qw * z + qx * y - qy * x,\n iw = -qx * x - qy * y - qz * z;\n\n // calculate result * inverse quat\n out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;\n out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;\n out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;\n return out;\n};\n\n/**\n * Perform some operation over an array of vec4s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n */\nvec4.forEach = (function() {\n var vec = new Float32Array(4);\n\n return function(a, stride, offset, count, fn, arg) {\n var i, l;\n if(!stride) {\n stride = 4;\n }\n\n if(!offset) {\n offset = 0;\n }\n \n if(count) {\n l = Math.min((count * stride) + offset, a.length);\n } else {\n l = a.length;\n }\n\n for(i = offset; i < l; i += stride) {\n vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3];\n fn(vec, vec, arg);\n a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3];\n }\n \n return a;\n };\n})();\n\n/**\n * Returns a string representation of a vector\n *\n * @param {vec4} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nvec4.str = function (a) {\n return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.vec4 = vec4;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 2x2 Matrix\n * @name mat2\n */\n\nvar mat2 = {};\n\nvar mat2Identity = new Float32Array([\n 1, 0,\n 0, 1\n]);\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\nmat2.create = function() {\n return new Float32Array(mat2Identity);\n};\n\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {mat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\nmat2.clone = function(a) {\n var out = new Float32Array(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\nmat2.identity = function(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n};\n\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.transpose = function(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n \n return out;\n};\n\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.invert = function(out, a) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n\n // Calculate the determinant\n det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n det = 1.0 / det;\n \n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n\n return out;\n};\n\n/**\n * Caclulates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.adjoint = function(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n\n return out;\n};\n\n/**\n * Calculates the determinant of a mat2\n *\n * @param {mat2} a the source matrix\n * @returns {Number} determinant of a\n */\nmat2.determinant = function (a) {\n return a[0] * a[3] - a[2] * a[1];\n};\n\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the first operand\n * @param {mat2} b the second operand\n * @returns {mat2} out\n */\nmat2.mul = mat2.multiply = function (out, a, b) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];\n var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];\n out[0] = a0 * b0 + a1 * b2;\n out[1] = a0 * b1 + a1 * b3;\n out[2] = a2 * b0 + a3 * b2;\n out[3] = a2 * b1 + a3 * b3;\n return out;\n};\n\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the matrix to rotate\n * @param {mat2} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\nmat2.rotate = function (out, a, rad) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = a0 * c + a1 * s;\n out[1] = a0 * -s + a1 * c;\n out[2] = a2 * c + a3 * s;\n out[3] = a2 * -s + a3 * c;\n return out;\n};\n\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the matrix to rotate\n * @param {mat2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\nmat2.scale = function(out, a, v) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n v0 = v[0], v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v1;\n out[2] = a2 * v0;\n out[3] = a3 * v1;\n return out;\n};\n\n/**\n * Returns a string representation of a mat2\n *\n * @param {mat2} mat matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\nmat2.str = function (a) {\n return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.mat2 = mat2;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 3x3 Matrix\n * @name mat3\n */\n\nvar mat3 = {};\n\nvar mat3Identity = new Float32Array([\n 1, 0, 0,\n 0, 1, 0,\n 0, 0, 1\n]);\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n\n/**\n * Creates a new identity mat3\n *\n * @returns {mat3} a new 3x3 matrix\n */\nmat3.create = function() {\n return new Float32Array(mat3Identity);\n};\n\n/**\n * Creates a new mat3 initialized with values from an existing matrix\n *\n * @param {mat3} a matrix to clone\n * @returns {mat3} a new 3x3 matrix\n */\nmat3.clone = function(a) {\n var out = new Float32Array(9);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n};\n\n/**\n * Copy the values from one mat3 to another\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n};\n\n/**\n * Set a mat3 to the identity matrix\n *\n * @param {mat3} out the receiving matrix\n * @returns {mat3} out\n */\nmat3.identity = function(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 1;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n};\n\n/**\n * Transpose the values of a mat3\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.transpose = function(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a01 = a[1], a02 = a[2], a12 = a[5];\n out[1] = a[3];\n out[2] = a[6];\n out[3] = a01;\n out[5] = a[7];\n out[6] = a02;\n out[7] = a12;\n } else {\n out[0] = a[0];\n out[1] = a[3];\n out[2] = a[6];\n out[3] = a[1];\n out[4] = a[4];\n out[5] = a[7];\n out[6] = a[2];\n out[7] = a[5];\n out[8] = a[8];\n }\n \n return out;\n};\n\n/**\n * Inverts a mat3\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.invert = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8],\n\n b01 = a22 * a11 - a12 * a21,\n b11 = -a22 * a10 + a12 * a20,\n b21 = a21 * a10 - a11 * a20,\n\n // Calculate the determinant\n det = a00 * b01 + a01 * b11 + a02 * b21;\n\n if (!det) { \n return null; \n }\n det = 1.0 / det;\n\n out[0] = b01 * det;\n out[1] = (-a22 * a01 + a02 * a21) * det;\n out[2] = (a12 * a01 - a02 * a11) * det;\n out[3] = b11 * det;\n out[4] = (a22 * a00 - a02 * a20) * det;\n out[5] = (-a12 * a00 + a02 * a10) * det;\n out[6] = b21 * det;\n out[7] = (-a21 * a00 + a01 * a20) * det;\n out[8] = (a11 * a00 - a01 * a10) * det;\n return out;\n};\n\n/**\n * Caclulates the adjugate of a mat3\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.adjoint = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8];\n\n out[0] = (a11 * a22 - a12 * a21);\n out[1] = (a02 * a21 - a01 * a22);\n out[2] = (a01 * a12 - a02 * a11);\n out[3] = (a12 * a20 - a10 * a22);\n out[4] = (a00 * a22 - a02 * a20);\n out[5] = (a02 * a10 - a00 * a12);\n out[6] = (a10 * a21 - a11 * a20);\n out[7] = (a01 * a20 - a00 * a21);\n out[8] = (a00 * a11 - a01 * a10);\n return out;\n};\n\n/**\n * Calculates the determinant of a mat3\n *\n * @param {mat3} a the source matrix\n * @returns {Number} determinant of a\n */\nmat3.determinant = function (a) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8];\n\n return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);\n};\n\n/**\n * Multiplies two mat3's\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the first operand\n * @param {mat3} b the second operand\n * @returns {mat3} out\n */\nmat3.mul = mat3.multiply = function (out, a, b) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8],\n\n b00 = b[0], b01 = b[1], b02 = b[2],\n b10 = b[3], b11 = b[4], b12 = b[5],\n b20 = b[6], b21 = b[7], b22 = b[8];\n\n out[0] = b00 * a00 + b01 * a10 + b02 * a20;\n out[1] = b00 * a01 + b01 * a11 + b02 * a21;\n out[2] = b00 * a02 + b01 * a12 + b02 * a22;\n\n out[3] = b10 * a00 + b11 * a10 + b12 * a20;\n out[4] = b10 * a01 + b11 * a11 + b12 * a21;\n out[5] = b10 * a02 + b11 * a12 + b12 * a22;\n\n out[6] = b20 * a00 + b21 * a10 + b22 * a20;\n out[7] = b20 * a01 + b21 * a11 + b22 * a21;\n out[8] = b20 * a02 + b21 * a12 + b22 * a22;\n return out;\n};\n\n/**\n * Returns a string representation of a mat3\n *\n * @param {mat3} mat matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\nmat3.str = function (a) {\n return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + \n a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + \n a[6] + ', ' + a[7] + ', ' + a[8] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.mat3 = mat3;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class 4x4 Matrix\n * @name mat4\n */\n\nvar mat4 = {};\n\nvar mat4Identity = new Float32Array([\n 1, 0, 0, 0,\n 0, 1, 0, 0,\n 0, 0, 1, 0,\n 0, 0, 0, 1\n]);\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n\n/**\n * Creates a new identity mat4\n *\n * @returns {mat4} a new 4x4 matrix\n */\nmat4.create = function() {\n return new Float32Array(mat4Identity);\n};\n\n/**\n * Creates a new mat4 initialized with values from an existing matrix\n *\n * @param {mat4} a matrix to clone\n * @returns {mat4} a new 4x4 matrix\n */\nmat4.clone = function(a) {\n var out = new Float32Array(16);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n};\n\n/**\n * Copy the values from one mat4 to another\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n};\n\n/**\n * Set a mat4 to the identity matrix\n *\n * @param {mat4} out the receiving matrix\n * @returns {mat4} out\n */\nmat4.identity = function(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n};\n\n/**\n * Transpose the values of a mat4\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.transpose = function(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a01 = a[1], a02 = a[2], a03 = a[3],\n a12 = a[6], a13 = a[7],\n a23 = a[11];\n\n out[1] = a[4];\n out[2] = a[8];\n out[3] = a[12];\n out[4] = a01;\n out[6] = a[9];\n out[7] = a[13];\n out[8] = a02;\n out[9] = a12;\n out[11] = a[14];\n out[12] = a03;\n out[13] = a13;\n out[14] = a23;\n } else {\n out[0] = a[0];\n out[1] = a[4];\n out[2] = a[8];\n out[3] = a[12];\n out[4] = a[1];\n out[5] = a[5];\n out[6] = a[9];\n out[7] = a[13];\n out[8] = a[2];\n out[9] = a[6];\n out[10] = a[10];\n out[11] = a[14];\n out[12] = a[3];\n out[13] = a[7];\n out[14] = a[11];\n out[15] = a[15];\n }\n \n return out;\n};\n\n/**\n * Inverts a mat4\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.invert = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],\n\n b00 = a00 * a11 - a01 * a10,\n b01 = a00 * a12 - a02 * a10,\n b02 = a00 * a13 - a03 * a10,\n b03 = a01 * a12 - a02 * a11,\n b04 = a01 * a13 - a03 * a11,\n b05 = a02 * a13 - a03 * a12,\n b06 = a20 * a31 - a21 * a30,\n b07 = a20 * a32 - a22 * a30,\n b08 = a20 * a33 - a23 * a30,\n b09 = a21 * a32 - a22 * a31,\n b10 = a21 * a33 - a23 * a31,\n b11 = a22 * a33 - a23 * a32,\n\n // Calculate the determinant\n det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n\n if (!det) { \n return null; \n }\n det = 1.0 / det;\n\n out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;\n out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;\n out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;\n out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;\n out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;\n out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;\n out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;\n out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;\n out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;\n out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;\n out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;\n out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;\n out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;\n out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;\n out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;\n out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;\n\n return out;\n};\n\n/**\n * Caclulates the adjugate of a mat4\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.adjoint = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];\n\n out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22));\n out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));\n out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12));\n out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));\n out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));\n out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22));\n out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));\n out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12));\n out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21));\n out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));\n out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11));\n out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));\n out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));\n out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21));\n out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));\n out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11));\n return out;\n};\n\n/**\n * Calculates the determinant of a mat4\n *\n * @param {mat4} a the source matrix\n * @returns {Number} determinant of a\n */\nmat4.determinant = function (a) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],\n\n b00 = a00 * a11 - a01 * a10,\n b01 = a00 * a12 - a02 * a10,\n b02 = a00 * a13 - a03 * a10,\n b03 = a01 * a12 - a02 * a11,\n b04 = a01 * a13 - a03 * a11,\n b05 = a02 * a13 - a03 * a12,\n b06 = a20 * a31 - a21 * a30,\n b07 = a20 * a32 - a22 * a30,\n b08 = a20 * a33 - a23 * a30,\n b09 = a21 * a32 - a22 * a31,\n b10 = a21 * a33 - a23 * a31,\n b11 = a22 * a33 - a23 * a32;\n\n // Calculate the determinant\n return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n};\n\n/**\n * Multiplies two mat4's\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the first operand\n * @param {mat4} b the second operand\n * @returns {mat4} out\n */\nmat4.mul = mat4.multiply = function (out, a, b) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];\n\n // Cache only the current line of the second matrix\n var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; \n out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];\n out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];\n out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];\n out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n return out;\n};\n\n/**\n * Translate a mat4 by the given vector\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to translate\n * @param {vec3} v vector to translate by\n * @returns {mat4} out\n */\nmat4.translate = function (out, a, v) {\n var x = v[0], y = v[1], z = v[2],\n a00, a01, a02, a03,\n a10, a11, a12, a13,\n a20, a21, a22, a23;\n\n if (a === out) {\n out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];\n out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];\n out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];\n out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];\n } else {\n a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];\n a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];\n a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];\n\n out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03;\n out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13;\n out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23;\n\n out[12] = a00 * x + a10 * y + a20 * z + a[12];\n out[13] = a01 * x + a11 * y + a21 * z + a[13];\n out[14] = a02 * x + a12 * y + a22 * z + a[14];\n out[15] = a03 * x + a13 * y + a23 * z + a[15];\n }\n\n return out;\n};\n\n/**\n * Scales the mat4 by the dimensions in the given vec3\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to scale\n * @param {vec3} v the vec3 to scale the matrix by\n * @returns {mat4} out\n **/\nmat4.scale = function(out, a, v) {\n var x = v[0], y = v[1], z = v[2];\n\n out[0] = a[0] * x;\n out[1] = a[1] * x;\n out[2] = a[2] * x;\n out[3] = a[3] * x;\n out[4] = a[4] * y;\n out[5] = a[5] * y;\n out[6] = a[6] * y;\n out[7] = a[7] * y;\n out[8] = a[8] * z;\n out[9] = a[9] * z;\n out[10] = a[10] * z;\n out[11] = a[11] * z;\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n};\n\n/**\n * Rotates a mat4 by the given angle\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @param {vec3} axis the axis to rotate around\n * @returns {mat4} out\n */\nmat4.rotate = function (out, a, rad, axis) {\n var x = axis[0], y = axis[1], z = axis[2],\n len = Math.sqrt(x * x + y * y + z * z),\n s, c, t,\n a00, a01, a02, a03,\n a10, a11, a12, a13,\n a20, a21, a22, a23,\n b00, b01, b02,\n b10, b11, b12,\n b20, b21, b22;\n\n if (Math.abs(len) < GLMAT_EPSILON) { return null; }\n \n len = 1 / len;\n x *= len;\n y *= len;\n z *= len;\n\n s = Math.sin(rad);\n c = Math.cos(rad);\n t = 1 - c;\n\n a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];\n a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];\n a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];\n\n // Construct the elements of the rotation matrix\n b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s;\n b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s;\n b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c;\n\n // Perform rotation-specific matrix multiplication\n out[0] = a00 * b00 + a10 * b01 + a20 * b02;\n out[1] = a01 * b00 + a11 * b01 + a21 * b02;\n out[2] = a02 * b00 + a12 * b01 + a22 * b02;\n out[3] = a03 * b00 + a13 * b01 + a23 * b02;\n out[4] = a00 * b10 + a10 * b11 + a20 * b12;\n out[5] = a01 * b10 + a11 * b11 + a21 * b12;\n out[6] = a02 * b10 + a12 * b11 + a22 * b12;\n out[7] = a03 * b10 + a13 * b11 + a23 * b12;\n out[8] = a00 * b20 + a10 * b21 + a20 * b22;\n out[9] = a01 * b20 + a11 * b21 + a21 * b22;\n out[10] = a02 * b20 + a12 * b21 + a22 * b22;\n out[11] = a03 * b20 + a13 * b21 + a23 * b22;\n\n if (a !== out) { // If the source and destination differ, copy the unchanged last row\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the X axis\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.rotateX = function (out, a, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad),\n a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7],\n a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n\n if (a !== out) { // If the source and destination differ, copy the unchanged rows\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n out[4] = a10 * c + a20 * s;\n out[5] = a11 * c + a21 * s;\n out[6] = a12 * c + a22 * s;\n out[7] = a13 * c + a23 * s;\n out[8] = a20 * c - a10 * s;\n out[9] = a21 * c - a11 * s;\n out[10] = a22 * c - a12 * s;\n out[11] = a23 * c - a13 * s;\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the Y axis\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.rotateY = function (out, a, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad),\n a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3],\n a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n\n if (a !== out) { // If the source and destination differ, copy the unchanged rows\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n out[0] = a00 * c - a20 * s;\n out[1] = a01 * c - a21 * s;\n out[2] = a02 * c - a22 * s;\n out[3] = a03 * c - a23 * s;\n out[8] = a00 * s + a20 * c;\n out[9] = a01 * s + a21 * c;\n out[10] = a02 * s + a22 * c;\n out[11] = a03 * s + a23 * c;\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the Z axis\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.rotateZ = function (out, a, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad),\n a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3],\n a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n\n if (a !== out) { // If the source and destination differ, copy the unchanged last row\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n out[0] = a00 * c + a10 * s;\n out[1] = a01 * c + a11 * s;\n out[2] = a02 * c + a12 * s;\n out[3] = a03 * c + a13 * s;\n out[4] = a10 * c - a00 * s;\n out[5] = a11 * c - a01 * s;\n out[6] = a12 * c - a02 * s;\n out[7] = a13 * c - a03 * s;\n return out;\n};\n\n/**\n * Creates a matrix from a quaternion rotation and vector translation\n * This is equivalent to (but much faster than):\n *\n * mat4.identity(dest);\n * mat4.translate(dest, vec);\n * var quatMat = mat4.create();\n * quat4.toMat4(quat, quatMat);\n * mat4.multiply(dest, quatMat);\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {quat4} q Rotation quaternion\n * @param {vec3} v Translation vector\n * @returns {mat4} out\n */\nmat4.fromRotationTranslation = function (out, q, v) {\n // Quaternion math\n var x = q[0], y = q[1], z = q[2], w = q[3],\n x2 = x + x,\n y2 = y + y,\n z2 = z + z,\n\n xx = x * x2,\n xy = x * y2,\n xz = x * z2,\n yy = y * y2,\n yz = y * z2,\n zz = z * z2,\n wx = w * x2,\n wy = w * y2,\n wz = w * z2;\n\n out[0] = 1 - (yy + zz);\n out[1] = xy + wz;\n out[2] = xz - wy;\n out[3] = 0;\n out[4] = xy - wz;\n out[5] = 1 - (xx + zz);\n out[6] = yz + wx;\n out[7] = 0;\n out[8] = xz + wy;\n out[9] = yz - wx;\n out[10] = 1 - (xx + yy);\n out[11] = 0;\n out[12] = v[0];\n out[13] = v[1];\n out[14] = v[2];\n out[15] = 1;\n \n return out;\n};\n\n/**\n * Generates a frustum matrix with the given bounds\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {Number} left Left bound of the frustum\n * @param {Number} right Right bound of the frustum\n * @param {Number} bottom Bottom bound of the frustum\n * @param {Number} top Top bound of the frustum\n * @param {Number} near Near bound of the frustum\n * @param {Number} far Far bound of the frustum\n * @returns {mat4} out\n */\nmat4.frustum = function (out, left, right, bottom, top, near, far) {\n var rl = 1 / (right - left),\n tb = 1 / (top - bottom),\n nf = 1 / (near - far);\n out[0] = (near * 2) * rl;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = (near * 2) * tb;\n out[6] = 0;\n out[7] = 0;\n out[8] = (right + left) * rl;\n out[9] = (top + bottom) * tb;\n out[10] = (far + near) * nf;\n out[11] = -1;\n out[12] = 0;\n out[13] = 0;\n out[14] = (far * near * 2) * nf;\n out[15] = 0;\n return out;\n};\n\n/**\n * Generates a perspective projection matrix with the given bounds\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {number} fovy Vertical field of view in radians\n * @param {number} aspect Aspect ratio. typically viewport width/height\n * @param {number} near Near bound of the frustum\n * @param {number} far Far bound of the frustum\n * @returns {mat4} out\n */\nmat4.perspective = function (out, fovy, aspect, near, far) {\n var f = 1.0 / Math.tan(fovy / 2),\n nf = 1 / (near - far);\n out[0] = f / aspect;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = f;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = (far + near) * nf;\n out[11] = -1;\n out[12] = 0;\n out[13] = 0;\n out[14] = (2 * far * near) * nf;\n out[15] = 0;\n return out;\n};\n\n/**\n * Generates a orthogonal projection matrix with the given bounds\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {number} left Left bound of the frustum\n * @param {number} right Right bound of the frustum\n * @param {number} bottom Bottom bound of the frustum\n * @param {number} top Top bound of the frustum\n * @param {number} near Near bound of the frustum\n * @param {number} far Far bound of the frustum\n * @returns {mat4} out\n */\nmat4.ortho = function (out, left, right, bottom, top, near, far) {\n var lr = 1 / (left - right),\n bt = 1 / (bottom - top),\n nf = 1 / (near - far);\n out[0] = -2 * lr;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = -2 * bt;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 2 * nf;\n out[11] = 0;\n out[12] = (left + right) * lr;\n out[13] = (top + bottom) * bt;\n out[14] = (far + near) * nf;\n out[15] = 1;\n return out;\n};\n\n/**\n * Generates a look-at matrix with the given eye position, focal point, and up axis\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {vec3} eye Position of the viewer\n * @param {vec3} center Point the viewer is looking at\n * @param {vec3} up vec3 pointing up\n * @returns {mat4} out\n */\nmat4.lookAt = function (out, eye, center, up) {\n var x0, x1, x2, y0, y1, y2, z0, z1, z2, len,\n eyex = eye[0],\n eyey = eye[1],\n eyez = eye[2],\n upx = up[0],\n upy = up[1],\n upz = up[2],\n centerx = center[0],\n centery = center[1],\n centerz = center[2];\n\n if (Math.abs(eyex - centerx) < GLMAT_EPSILON &&\n Math.abs(eyey - centery) < GLMAT_EPSILON &&\n Math.abs(eyez - centerz) < GLMAT_EPSILON) {\n return mat4.identity(out);\n }\n\n z0 = eyex - centerx;\n z1 = eyey - centery;\n z2 = eyez - centerz;\n\n len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);\n z0 *= len;\n z1 *= len;\n z2 *= len;\n\n x0 = upy * z2 - upz * z1;\n x1 = upz * z0 - upx * z2;\n x2 = upx * z1 - upy * z0;\n len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);\n if (!len) {\n x0 = 0;\n x1 = 0;\n x2 = 0;\n } else {\n len = 1 / len;\n x0 *= len;\n x1 *= len;\n x2 *= len;\n }\n\n y0 = z1 * x2 - z2 * x1;\n y1 = z2 * x0 - z0 * x2;\n y2 = z0 * x1 - z1 * x0;\n\n len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);\n if (!len) {\n y0 = 0;\n y1 = 0;\n y2 = 0;\n } else {\n len = 1 / len;\n y0 *= len;\n y1 *= len;\n y2 *= len;\n }\n\n out[0] = x0;\n out[1] = y0;\n out[2] = z0;\n out[3] = 0;\n out[4] = x1;\n out[5] = y1;\n out[6] = z1;\n out[7] = 0;\n out[8] = x2;\n out[9] = y2;\n out[10] = z2;\n out[11] = 0;\n out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);\n out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);\n out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);\n out[15] = 1;\n\n return out;\n};\n\n/**\n * Returns a string representation of a mat4\n *\n * @param {mat4} mat matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\nmat4.str = function (a) {\n return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' +\n a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' +\n a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' + \n a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.mat4 = mat4;\n}\n;\n/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation \n and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\n\n/**\n * @class Quaternion\n * @name quat\n */\n\nvar quat = {};\n\nvar quatIdentity = new Float32Array([0, 0, 0, 1]);\n\nif(!GLMAT_EPSILON) {\n var GLMAT_EPSILON = 0.000001;\n}\n\n/**\n * Creates a new identity quat\n *\n * @returns {quat} a new quaternion\n */\nquat.create = function() {\n return new Float32Array(quatIdentity);\n};\n\n/**\n * Creates a new quat initialized with values from an existing quaternion\n *\n * @param {quat} a quaternion to clone\n * @returns {quat} a new quaternion\n */\nquat.clone = vec4.clone;\n\n/**\n * Creates a new quat initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {quat} a new quaternion\n */\nquat.fromValues = vec4.fromValues;\n\n/**\n * Copy the values from one quat to another\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the source quaternion\n * @returns {quat} out\n */\nquat.copy = vec4.copy;\n\n/**\n * Set the components of a quat to the given values\n *\n * @param {quat} out the receiving quaternion\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {quat} out\n */\nquat.set = vec4.set;\n\n/**\n * Set a quat to the identity quaternion\n *\n * @param {quat} out the receiving quaternion\n * @returns {quat} out\n */\nquat.identity = function(out) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n};\n\n/**\n * Sets a quat from the given angle and rotation axis,\n * then returns it.\n *\n * @param {quat} out the receiving quaternion\n * @param {vec3} axis the axis around which to rotate\n * @param {Number} rad the angle in radians\n * @returns {quat} out\n **/\nquat.setAxisAngle = function(out, axis, rad) {\n rad = rad * 0.5;\n var s = Math.sin(rad);\n out[0] = s * axis[0];\n out[1] = s * axis[1];\n out[2] = s * axis[2];\n out[3] = Math.cos(rad);\n return out;\n};\n\n/**\n * Adds two quat's\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @returns {quat} out\n */\nquat.add = vec4.add;\n\n/**\n * Multiplies two quat's\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @returns {quat} out\n */\nquat.mul = quat.multiply = function(out, a, b) {\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bx = b[0], by = b[1], bz = b[2], bw = b[3];\n\n out[0] = ax * bw + aw * bx + ay * bz - az * by;\n out[1] = ay * bw + aw * by + az * bx - ax * bz;\n out[2] = az * bw + aw * bz + ax * by - ay * bx;\n out[3] = aw * bw - ax * bx - ay * by - az * bz;\n return out;\n};\n\n/**\n * Scales a quat by a scalar number\n *\n * @param {quat} out the receiving vector\n * @param {quat} a the vector to scale\n * @param {quat} b amount to scale the vector by\n * @returns {quat} out\n */\nquat.scale = vec4.scale;\n\n/**\n * Rotates a quaternion by the given angle around the X axis\n *\n * @param {quat} out quat receiving operation result\n * @param {quat} a quat to rotate\n * @param {number} rad angle (in radians) to rotate\n * @returns {quat} out\n */\nquat.rotateX = function (out, a, rad) {\n rad *= 0.5; \n\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bx = Math.sin(rad), bw = Math.cos(rad);\n\n out[0] = ax * bw + aw * bx;\n out[1] = ay * bw + az * bx;\n out[2] = az * bw - ay * bx;\n out[3] = aw * bw - ax * bx;\n return out;\n};\n\n/**\n * Rotates a quaternion by the given angle around the X axis\n *\n * @param {quat} out quat receiving operation result\n * @param {quat} a quat to rotate\n * @param {number} rad angle (in radians) to rotate\n * @returns {quat} out\n */\nquat.rotateY = function (out, a, rad) {\n rad *= 0.5; \n\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n by = Math.sin(rad), bw = Math.cos(rad);\n\n out[0] = ax * bw - az * by;\n out[1] = ay * bw + aw * by;\n out[2] = az * bw + ax * by;\n out[3] = aw * bw - ay * by;\n return out;\n};\n\n/**\n * Rotates a quaternion by the given angle around the X axis\n *\n * @param {quat} out quat receiving operation result\n * @param {quat} a quat to rotate\n * @param {number} rad angle (in radians) to rotate\n * @returns {quat} out\n */\nquat.rotateZ = function (out, a, rad) {\n rad *= 0.5; \n\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bz = Math.sin(rad), bw = Math.cos(rad);\n\n out[0] = ax * bw + ay * bz;\n out[1] = ay * bw - ax * bz;\n out[2] = az * bw + aw * bz;\n out[3] = aw * bw - az * bz;\n return out;\n};\n\n/**\n * Calculates the W component of a quat from the X, Y, and Z components.\n * Assumes that quaternion is 1 unit in length.\n * Any existing W component will be ignored.\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quat to calculate W component of\n * @returns {quat} out\n */\nquat.calculateW = function (out, a) {\n var x = a[0], y = a[1], z = a[2];\n\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = -Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));\n return out;\n};\n\n/**\n * Caclulates the dot product of two quat's\n *\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @returns {Number} dot product of a and b\n */\nquat.dot = vec4.dot;\n\n/**\n * Performs a linear interpolation between two quat's\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {quat} out\n */\nquat.lerp = vec4.lerp;\n\n/**\n * Performs a spherical linear interpolation between two quat\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {quat} out\n */\nquat.slerp = function (out, a, b, t) {\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bx = b[0], by = b[1], bz = b[2], bw = a[3];\n\n var cosHalfTheta = ax * bx + ay * by + az * bz + aw * bw,\n halfTheta,\n sinHalfTheta,\n ratioA,\n ratioB;\n\n if (Math.abs(cosHalfTheta) >= 1.0) {\n if (out !== a) {\n out[0] = ax;\n out[1] = ay;\n out[2] = az;\n out[3] = aw;\n }\n return out;\n }\n\n halfTheta = Math.acos(cosHalfTheta);\n sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta);\n\n if (Math.abs(sinHalfTheta) < 0.001) {\n out[0] = (ax * 0.5 + bx * 0.5);\n out[1] = (ay * 0.5 + by * 0.5);\n out[2] = (az * 0.5 + bz * 0.5);\n out[3] = (aw * 0.5 + bw * 0.5);\n return out;\n }\n\n ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta;\n ratioB = Math.sin(t * halfTheta) / sinHalfTheta;\n\n out[0] = (ax * ratioA + bx * ratioB);\n out[1] = (ay * ratioA + by * ratioB);\n out[2] = (az * ratioA + bz * ratioB);\n out[3] = (aw * ratioA + bw * ratioB);\n\n return out;\n};\n\n/**\n * Calculates the inverse of a quat\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quat to calculate inverse of\n * @returns {quat} out\n */\nquat.invert = function(out, a) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n dot = a0*a0 + a1*a1 + a2*a2 + a3*a3,\n invDot = dot ? 1.0/dot : 0;\n \n // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0\n\n out[0] = -a0*invDot;\n out[1] = -a1*invDot;\n out[2] = -a2*invDot;\n out[3] = a3*invDot;\n return out;\n};\n\n/**\n * Calculates the conjugate of a quat\n * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quat to calculate conjugate of\n * @returns {quat} out\n */\nquat.conjugate = function (out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Caclulates the length of a quat\n *\n * @param {quat} a vector to calculate length of\n * @returns {Number} length of a\n */\nquat.len = quat.length = vec4.length;\n\n/**\n * Caclulates the squared length of a quat\n *\n * @param {quat} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nquat.sqrLen = quat.squaredLength = vec4.squaredLength;\n\n/**\n * Normalize a quat\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quaternion to normalize\n * @returns {quat} out\n */\nquat.normalize = vec4.normalize;\n\n/**\n * Returns a string representation of a quatenion\n *\n * @param {quat} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nquat.str = function (a) {\n return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n};\n\nif(typeof(exports) !== 'undefined') {\n exports.quat = quat;\n}\n;\n\n\n\n\n\n\n\n\n\n\n })(shim.exports);\n})();\n\n//@ sourceURL=/node_modules/voxel-region-change/node_modules/aabb-3d/node_modules/gl-matrix/dist/gl-matrix.js")),n.define("/node_modules/voxel-texture/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = {}\n//@ sourceURL=/node_modules/voxel-texture/package.json")),n.define("/node_modules/voxel-texture/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var transparent = require('opaque').transparent;\n\nfunction Texture(opts) {\n var self = this;\n if (!(this instanceof Texture)) return new Texture(opts || {});\n this.THREE = opts.THREE || require('three');\n this.materials = [];\n this.texturePath = opts.texturePath || '/textures/';\n this.materialParams = opts.materialParams || {};\n this.materialType = opts.materialType || this.THREE.MeshLambertMaterial;\n this.materialIndex = [];\n this._animations = [];\n this._materialDefaults = { ambient: 0xbbbbbb };\n this.applyTextureParams = opts.applyTextureParams || function(map) {\n map.magFilter = self.THREE.NearestFilter;\n map.minFilter = self.THREE.LinearMipMapLinearFilter;\n map.wrapT = self.THREE.RepeatWrapping;\n map.wrapS = self.THREE.RepeatWrapping;\n }\n}\nmodule.exports = Texture;\n\nTexture.prototype.load = function(names, opts) {\n var self = this;\n opts = self._options(opts);\n if (!isArray(names)) names = [names];\n if (!hasSubArray(names)) names = [names];\n return [].concat.apply([], names.map(function(name) {\n name = self._expandName(name);\n self.materialIndex.push([self.materials.length, self.materials.length + name.length]);\n return name.map(function(n) {\n if (n instanceof self.THREE.Texture) {\n var map = n;\n n = n.name;\n } else if (typeof n === 'string') {\n var map = self.THREE.ImageUtils.loadTexture(self.texturePath + ext(n));\n } else {\n var map = new self.THREE.Texture(n);\n n = map.name;\n }\n self.applyTextureParams.call(self, map);\n var mat = new opts.materialType(opts.materialParams);\n mat.map = map;\n mat.name = n;\n if (opts.transparent == null) self._isTransparent(mat);\n self.materials.push(mat);\n return mat;\n });\n }));\n};\n\nTexture.prototype.get = function(index) {\n if (index == null) return this.materials;\n if (typeof index === 'number') {\n index = this.materialIndex[index];\n } else {\n var i = this.find(index);\n if (i !== -1) index = i;\n for (var i = 0; i < this.materialIndex.length; i++) {\n var idx = this.materialIndex[i];\n if (index >= idx[0] && index < idx[1]) {\n index = idx;\n break;\n }\n }\n }\n return this.materials.slice(index[0], index[1]);\n};\n\nTexture.prototype.find = function(name) {\n for (var i = 0; i < this.materials.length; i++) {\n if (name === this.materials[i].name) return i;\n }\n return -1;\n};\n\nTexture.prototype._expandName = function(name) {\n if (name.top) return [name.back, name.front, name.top, name.bottom, name.left, name.right];\n if (!isArray(name)) name = [name];\n // load the 0 texture to all\n if (name.length === 1) name = [name[0],name[0],name[0],name[0],name[0],name[0]];\n // 0 is top/bottom, 1 is sides\n if (name.length === 2) name = [name[1],name[1],name[0],name[0],name[1],name[1]];\n // 0 is top, 1 is bottom, 2 is sides\n if (name.length === 3) name = [name[2],name[2],name[0],name[1],name[2],name[2]];\n // 0 is top, 1 is bottom, 2 is front/back, 3 is left/right\n if (name.length === 4) name = [name[2],name[2],name[0],name[1],name[3],name[3]];\n return name;\n};\n\nTexture.prototype._options = function(opts) {\n opts = opts || {};\n opts.materialType = opts.materialType || this.materialType;\n opts.materialParams = defaults(opts.materialParams || {}, this._materialDefaults, this.materialParams);\n opts.applyTextureParams = opts.applyTextureParams || this.applyTextureParams;\n return opts;\n};\n\nTexture.prototype.paint = function(geom) {\n var self = this;\n geom.faces.forEach(function(face, i) {\n var c = face.vertexColors[0];\n var index = Math.floor(c.b*255 + c.g*255*255 + c.r*255*255*255);\n index = self.materialIndex[Math.floor(Math.max(0, index - 1) % self.materialIndex.length)][0];\n\n // BACK, FRONT, TOP, BOTTOM, LEFT, RIGHT\n if (face.normal.z === 1) index += 1;\n else if (face.normal.y === 1) index += 2;\n else if (face.normal.y === -1) index += 3;\n else if (face.normal.x === -1) index += 4;\n else if (face.normal.x === 1) index += 5;\n\n face.materialIndex = index;\n });\n};\n\nTexture.prototype.sprite = function(name, w, h, cb) {\n var self = this;\n if (typeof w === 'function') { cb = w; w = null; }\n if (typeof h === 'function') { cb = h; h = null; }\n w = w || 16; h = h || w;\n var img = new Image();\n img.src = self.texturePath + ext(name);\n img.onerror = cb;\n img.onload = function() {\n var textures = [];\n for (var x = 0; x < img.width; x += w) {\n for (var y = 0; y < img.height; y += h) {\n var canvas = document.createElement('canvas');\n canvas.width = w; canvas.height = h;\n var ctx = canvas.getContext('2d');\n ctx.drawImage(img, x, y, w, h, 0, 0, w, h);\n var tex = new self.THREE.Texture(canvas);\n tex.name = name + '_' + x + '_' + y;\n tex.needsUpdate = true;\n textures.push(tex);\n }\n }\n cb(null, textures);\n };\n return self;\n};\n\nTexture.prototype.animate = function(names, delay) {\n var self = this;\n delay = delay || 1000;\n names = names.map(function(name) {\n return (typeof name === 'string') ? self.find(name) : name;\n }).filter(function(name) {\n return (name !== -1);\n });\n if (names.length < 2) return false;\n if (self._clock == null) self._clock = new self.THREE.Clock();\n var mat = self.materials[names[0]].clone();\n self.materials.push(mat);\n names = [self.materials.length - 1, delay, 0].concat(names);\n self._animations.push(names);\n return mat;\n};\n\nTexture.prototype.tick = function() {\n var self = this;\n if (self._animations.length < 1 || self._clock == null) return false;\n var t = self._clock.getElapsedTime();\n self._animations.forEach(function(anim) {\n var mats = anim.slice(3);\n var i = Math.round(t / (anim[1] / 1000)) % (mats.length);\n if (anim[2] !== i) {\n self.materials[anim[0]].map = self.materials[mats[i]].map;\n self.materials[anim[0]].needsUpdate = true;\n anim[2] = i;\n }\n });\n};\n\nTexture.prototype._isTransparent = function(material) {\n if (!material.map) return;\n if (!material.map.image) return;\n if (material.map.image.nodeName.toLowerCase() === 'img') {\n material.map.image.onload = function() {\n if (transparent(this)) {\n material.transparent = true;\n material.needsUpdate = true;\n }\n };\n } else {\n if (transparent(material.map.image)) {\n material.transparent = true;\n material.needsUpdate = true;\n }\n }\n};\n\nfunction ext(name) {\n return (String(name).indexOf('.') !== -1) ? name : name + '.png';\n}\n\n// copied from https://github.com/joyent/node/blob/master/lib/util.js#L433\nfunction isArray(ar) {\n return Array.isArray(ar) || (typeof ar === 'object' && Object.prototype.toString.call(ar) === '[object Array]');\n}\n\nfunction hasSubArray(ar) {\n var has = false;\n ar.forEach(function(a) { if (isArray(a)) { has = true; return false; } });\n return has;\n}\n\nfunction defaults(obj) {\n [].slice.call(arguments, 1).forEach(function(from) {\n if (from) for (var k in from) if (obj[k] == null) obj[k] = from[k];\n });\n return obj;\n}\n\n//@ sourceURL=/node_modules/voxel-texture/index.js")),n.define("/node_modules/voxel-texture/node_modules/opaque/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-texture/node_modules/opaque/package.json')),n.define("/node_modules/voxel-texture/node_modules/opaque/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"function opaque(image) {\n var canvas, ctx\n\n if (image.nodeName.toLowerCase() === 'img') {\n canvas = document.createElement('canvas')\n canvas.width = image.width\n canvas.height = image.height\n ctx = canvas.getContext('2d')\n ctx.drawImage(image, 0, 0)\n } else {\n canvas = image\n ctx = canvas.getContext('2d')\n }\n\n var imageData = ctx.getImageData(0, 0, canvas.height, canvas.width)\n , data = imageData.data\n\n for (var i = 3, l = data.length; i < l; i += 4)\n if (data[i] !== 255)\n return false\n\n return true\n};\n\nmodule.exports = opaque\nmodule.exports.opaque = opaque\nmodule.exports.transparent = function(image) {\n return !opaque(image)\n};\n//@ sourceURL=/node_modules/voxel-texture/node_modules/opaque/index.js")),n.define("/node_modules/voxel-tetris/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-tetris/package.json')),n.define("/node_modules/voxel-tetris/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"\r\nmodule.exports = function(game,opts) {\r\n var updated = {};\r\n if (!opts) opts = {};\r\n if (!opts.pos) opts.pos = {\r\n x:0,\r\n y:0,\r\n z:0\r\n };\r\n if (!opts.width) opts.width = 10;\r\n if (!opts.height) opts.height = 20;\r\n if (!opts.material) opts.material = 1;\r\n if (!opts.droprate) opts.droprate = 25;\r\n if (!opts.levels) opts.levels = [1,5,10,25,50,100,200,500,1000,50000];\r\n if (!opts.speedincrease) opts.speedincrease = 0.20;\r\n \r\n var voxels = game.voxels;\r\n var size = voxels.cubeSize;\r\n \r\n var pieces = [];\r\n var droplocation;\r\n var droprate = opts.droprate;\r\n var time = 0;\r\n var rowsremoved = 0;\r\n \r\n this.command = function(c,pindex) {\r\n if (!pindex) pindex = 0;\r\n switch(c){\r\n case 0:\r\n spin(pindex,1);\r\n break;\r\n case 1:\r\n spin(pindex,-1);\r\n break;\r\n case 2:\r\n move(pindex,1,0,0);\r\n break;\r\n case 3:\r\n move(pindex,-1,0,0);\r\n break;\r\n case 4:\r\n moveDown(pindex);\r\n break;\r\n case 5:\r\n slam(pindex);\r\n break;\r\n }\r\n }\r\n this.slam = function(pindex) {\r\n if (!pindex) pindex = 0;\r\n var piece = pieces[pindex];\r\n unshow(piece);\r\n do {\r\n piece.dy -= 1; \r\n reposition(piece);\r\n } while (isValid(piece));\r\n piece.dy += 1;\r\n reposition(piece);\r\n show(piece);\r\n flush();\r\n checkRows();\r\n pieces.pop();\r\n }\r\n this.moveDown = function(pindex) {\r\n if (!pindex) pindex = 0;\r\n move(pindex,0,-1,0,function() {\r\n checkRows();\r\n pieces.pop();\r\n });\r\n }\r\n \r\n this.touch = function(pos) {\r\n if (pos.y < (opts.pos.y - size)) {\r\n command(5);\r\n return;\r\n }\r\n if (pos.y < opts.pos.y) {\r\n command(4);\r\n return;\r\n }\r\n if (pos.x > (opts.pos.x + (opts.width*size))) {\r\n command(2);\r\n return;\r\n }\r\n if (pos.x < (opts.pos.x)) {\r\n command(3);\r\n return;\r\n }\r\n command(0); //no longer turn the other direction.\r\n }\r\n \r\n this.spin = function(pindex, cw, failop) {\r\n var piece = pieces[pindex];\r\n unshow(piece);\r\n piece.spin += cw;\r\n reposition(piece);\r\n if (!isValid(piece)) {\r\n piece.spin -= cw;\r\n reposition(piece);\r\n show(piece);\r\n if (failop) failop();\r\n return false;\r\n }\r\n else {\r\n show(piece);\r\n }\r\n flush();\r\n return true;\r\n }\r\n \r\n this.move = function (pindex, mx, my, mz, failop) {\r\n var piece = pieces[pindex];\r\n unshow(piece);\r\n piece.dx += mx;\r\n piece.dy += my;\r\n piece.dz += mz;\r\n reposition(piece);\r\n if (!isValid(piece)) {\r\n piece.dx -= mx;\r\n piece.dy -= my;\r\n piece.dz -= mz; \r\n reposition(piece);\r\n show(piece);\r\n if (failop) failop();\r\n return false;\r\n }\r\n else {\r\n show(piece);\r\n }\r\n flush();\r\n return true;\r\n }\r\n \r\n this.removeRow = function(m) {\r\n for (var r = 0; r < opts.width; r++) {\r\n set({\r\n x: opts.pos.x + (r * size), \r\n y: opts.pos.y + (m * size), \r\n z: opts.pos.z\r\n },0);\r\n }\r\n for (var k = m; k < opts.height; k++) {\r\n for (var j = 0; j < opts.width; j++) {\r\n set({\r\n x: opts.pos.x + (j * size), \r\n y: opts.pos.y + (k * size), \r\n z: opts.pos.z\r\n },voxels.voxelAtPosition({\r\n x: opts.pos.x + (j * size), \r\n y: opts.pos.y + ((k+1) * size),\r\n z: opts.pos.z\r\n }));\r\n }\r\n }\r\n rowsremoved++;\r\n checkLevel();\r\n flush();\r\n }\r\n this.checkLevel = function() {\r\n for (var i = 0; i < opts.levels.length; i++) {\r\n if (rowsremoved == opts.levels[i]) {\r\n setBoard(i);\r\n faster();\r\n return;\r\n }\r\n if (rowsremoved < opts.levels[i]) {\r\n return;\r\n }\r\n }\r\n }\r\n this.gameOver = function() {\r\n clearBoard();\r\n resetSpeed();\r\n setBoard(opts.material);\r\n rowsremoved = 0;\r\n }\r\n \r\n this.checkRows = function() {\r\n var row;\r\n for (var m = 0; m < opts.height; m++) {\r\n row = true;\r\n for (var n = 0; n < opts.width; n++) {\r\n if (!voxels.voxelAtPosition({\r\n x: opts.pos.x + (n * size), \r\n y: opts.pos.y + (m * size), \r\n z: opts.pos.z\r\n })) {\r\n row = false;\r\n break;\r\n }\r\n }\r\n if (row) {\r\n removeRow(m);\r\n m--;\r\n }\r\n }\r\n }\r\n \r\n this.doTick = function() {\r\n if ((!pieces) || pieces.length == 0) {\r\n makePiece();\r\n }\r\n\r\n if (!pieces) return;\r\n for (var i = 0; i < pieces.length; i++) {\r\n moveDown(i);\r\n }\r\n }\r\n this.tick = function () {\r\n time++;\r\n if (time % droprate == 0) {\r\n doTick();\r\n }\r\n }\r\n this.faster = function() {\r\n droprate = Math.ceil(droprate * (1-opts.speedincrease));\r\n }\r\n this.slower = function() {\r\n droprate = Math.ceil(droprate * (1-opts.speedincrease));\r\n }\r\n this.resetSpeed = function() {\r\n droprate = opts.droprate;\r\n }\r\n this.clearBoard = function() {\r\n var x = opts.pos.x, y = opts.pos.y, z = opts.pos.z;\r\n for (var m = 0; m < opts.height+5; m++) {\r\n for (var n = 0; n < opts.width; n++) {\r\n set({\r\n x: x + size*n , \r\n y: y+size*m, \r\n z: z\r\n },0);\r\n }\r\n }\r\n }\r\n this.setBoard = function(material) {\r\n var x = opts.pos.x, y = opts.pos.y, z = opts.pos.z;\r\n if (!material) material = opts.material;\r\n \r\n for (var m = -1; m <= opts.height; m++) {\r\n set({\r\n x: x -1, \r\n y: y+size*m, \r\n z: z\r\n }, material);\r\n set({\r\n x: x + size*opts.width, \r\n y: y+size*m, \r\n z: z\r\n }, material);\r\n }\r\n for (var q = -1; q <= opts.width; q++) {\r\n set({\r\n x: x + size * q , \r\n y: y - 1*size, \r\n z: z\r\n }, material);\r\n }\r\n }\r\n \r\n this.setDroplocation = function(x,y,z) {\r\n droplocation = {\r\n x: x, \r\n y: y, \r\n z: z\r\n };\r\n }\r\n this.makeBoard = function() {\r\n var x = opts.pos.x, y = opts.pos.y, z = opts.pos.z;\r\n clearBoard();\r\n setBoard(opts.material);\r\n setDroplocation(x + (opts.width * size)/2,y + (opts.height * size),z);\r\n flush();\r\n }\r\n\r\n this.makePiece = function(pos, type) {\r\n if (!pos) pos = droplocation;\r\n if (!type) type = Math.floor((Math.random() * 7));\r\n var piece = [];\r\n switch (type) {\r\n case 0: //block\r\n piece = [{corex: 0, corey: 0, corez: 0}, {corex: 0, corey: 1, corez: 0},{corex: 1, corey: 0, corez: 0},{corex: 1, corey: 1, corez: 0}]\r\n break;\r\n\r\n case 1: //long\r\n piece = [{corex: -1, corey: 0, corez: 0}, {corex: 0, corey: 0, corez: 0},{corex: 1, corey: 0, corez: 0},{corex: 2, corey: 0, corez: 0}]\r\n break;\r\n\r\n case 2: //L\r\n piece = [{corex: 0, corey: -2, corez: 0}, {corex: 0, corey: -1, corez: 0},{corex: 0, corey: 0, corez: 0},{corex: 1, corey: 0, corez: 0}]\r\n break;\r\n\r\n case 3: //Inverted L\r\n piece = [{corex: 0, corey: -2, corez: 0}, {corex: 0, corey: -1, corez: 0},{corex: 0, corey: 0, corez: 0},{corex: -1, corey: 0, corez: 0}]\r\n break;\r\n\r\n case 4: //T\r\n piece = [{corex: -1, corey: 0, corez: 0}, {corex: 0, corey: 0, corez: 0},{corex: 1, corey: 0, corez: 0},{corex: 0, corey: 1, corez: 0}]\r\n break;\r\n\r\n case 5://S\r\n piece = [{corex: 0, corey: 1, corez: 0}, {corex: 0, corey: 0, corez: 0},{corex: -1, corey: 0, corez: 0},{corex: -1, corey: -1, corez: 0}]\r\n break;\r\n\r\n case 6://Inverted S\r\n piece = [{corex: 0, corey: 1, corez: 0}, {corex: 0, corey: 0, corez: 0},{corex: 1, corey: 0, corez: 0},{corex: 1, corey: -1, corez: 0}]\r\n break;\r\n }\r\n piece.material = type+1;\r\n piece.initx = pos.x;\r\n piece.inity = pos.y;\r\n piece.initz = pos.z;\r\n piece.dx = 0;\r\n piece.dy = 0;\r\n piece.dz = 0;\r\n piece.spin = 0;\r\n reposition(piece);\r\n if (!isValid(piece)) {\r\n gameOver();\r\n }\r\n show(piece);\r\n if (!pieces) pieces = [];\r\n pieces.push(piece);\r\n flush();\r\n }\r\n \r\n this.reposition = function(piece) {\r\n for (var i = 0; i < piece.length; i++) {\r\n var block = piece[i];\r\n var nx;\r\n var ny;\r\n var nz = block.corez;\r\n var spin = piece.spin;\r\n while (spin < 0) spin+=4;\r\n spin %= 4;\r\n switch (spin) {\r\n case 0:\r\n nx = block.corex;\r\n ny = block.corey;\r\n break; \r\n case 1:\r\n nx = block.corey;\r\n ny = -block.corex;\r\n break;\r\n case 2:\r\n nx = -block.corex;\r\n ny = -block.corey;\r\n break;\r\n case 3:\r\n nx = -block.corey;\r\n ny = block.corex;\r\n }\r\n block.x = ((nx + piece.dx) * size) + piece.initx;\r\n block.y = ((ny + piece.dy) * size) + piece.inity;\r\n block.z = ((nz + piece.dz) * size) + piece.initz;\r\n }\r\n }\r\n \r\n var show = function(piece) {\r\n for (var i = 0; i < piece.length; i++) {\r\n set(piece[i],piece.material);\r\n }\r\n }\r\n \r\n var unshow = function(piece) {\r\n for (var i = 0; i < piece.length; i++) {\r\n set(piece[i],0);\r\n }\r\n }\r\n\r\n \r\n function isValid(piece) {\r\n for (var i = 0; i < piece.length; i++) {\r\n if (voxels.voxelAtPosition(piece[i])) return false;\r\n }\r\n return true;\r\n }\r\n \r\n function set (posxyz, value) {\r\n voxels.voxelAtPosition(posxyz, value);\r\n var c = voxels.chunkAtPosition(posxyz);\r\n var key = c.join('|');\r\n if (!updated[key] && voxels.chunks[key]) {\r\n updated[key] = voxels.chunks[key];\r\n }\r\n }\r\n \r\n function flush() {\r\n Object.keys(updated).forEach(function (key) {\r\n game.showChunk(updated[key]);\r\n });\r\n }\r\n \r\n \r\n \r\n makeBoard();\r\n return this;\r\n};\r\n\n//@ sourceURL=/node_modules/voxel-tetris/index.js")),n.define("/node_modules/voxel-audio/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = {}\n//@ sourceURL=/node_modules/voxel-audio/package.json")),n.define("/node_modules/voxel-audio/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"/*\n * Thanks to the following sources of info\n * http://www.html5rocks.com/en/tutorials/webaudio/games/\n * https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#PannerNode\n*/\n\nvar bresenham3d = require('bresenham3d'),\n init = false,\n calculateAbsorption = false,\n audioInstances = [],\n defaultDensity = 1,\n densityMapping = [],\n densityGainMin = 0.005,\n tickCount = 0,\n calculateAbsorptionOnTick = 15,\n audioContext,\n game,\n audioDestination;\n\n\nexports.initGameAudio = function(game_, settings) {\n audioContext = new webkitAudioContext();\n audioDestination = audioContext.destination;\n game = game_;\n\n if (!settings) settings = {};\n if (settings.calculateAbsorption) calculateAbsorption = true;\n if (settings.defaultDensity) defaultDensity = settings.defaultDensity;\n if (settings.densityMapping) densityMapping = settings.densityMapping;\n if (settings.densityGainMin) densityGainMin = settings.densityGainMin;\n if (settings.calculateAbsorptionOnTick) calculateAbsorptionOnTick = settings.calculateAbsorptionOnTick;\n\n game.on('tick', tick);\n init = true;\n};\n\n\nexports.getAudioContext = function() {\n return audioContext;\n};\n\nexports.PositionAudio = function(options) {\n var self = this;\n\n if (!init) throw new Error('initGameAudio must be called first.');\n\n self.options = options;\n self.createPanner();\n // need one of source, buffer, or url\n if (options.url) self.initURL();\n if (options.buffer) self.initBuffer();\n if (options.source) self.initSource();\n if (options.name) self.name = options.name;\n\n // should add a distroy so not to leave things around....\n audioInstances.push(self);\n};\n\nexports.PositionAudio.prototype.createPanner = function() {\n var self = this;\n self.panner = audioContext.createPanner();\n self.gainNode = audioContext.createGainNode();\n\n var startingPosition = self.options.startingPosition;\n if (!startingPosition || startingPosition.length !== 3) throw new Error('startingPosition required option. format: [x,y,z]');\n\n self.panner.setPosition(startingPosition[0], startingPosition[1], startingPosition[2]);\n self.position = {\n x: startingPosition[0],\n y: startingPosition[1],\n z: startingPosition[2]\n };\n self.panner.coneOuterGain = self.options.coneOuterGain || Number(0);\n self.panner.coneOuterAngle = self.options.coneOuterAngle || 360;\n self.panner.coneInnerAngle = self.options.coneInnerAngle || 350;\n self.panner.refDistance = self.options.refDistance || 0.8;\n self.panner.maxDistance = self.options.maxDistance || 200000;\n // use the built in settings, for the following\n if (self.options.distanceModel) self.panner.distanceModel = self.options.distanceModel;\n if (self.options.rolloffFactor) self.panner.rolloffFactor = self.options.rolloffFactor;\n if (self.options.panningModel) self.panner.panningModel = self.options.panningModel;\n};\n\nexports.PositionAudio.prototype.initURL = function() {\n var self = this;\n self.url = self.options.url;\n self.ready = false;\n};\n\nexports.PositionAudio.prototype.initBuffer = function() {\n var self = this;\n self.options.source = audioContext.createBufferSource();\n self.options.source.buffer = self.options.buffer;\n self.initSource();\n};\n\nexports.PositionAudio.prototype.initSource = function() {\n var self = this;\n self.source = self.options.source;\n self.source.loop = self.options.loop || false;\n self.ready = true;\n};\n\n\nexports.PositionAudio.prototype.play = function() {\n var self = this;\n if (!self.ready) throw new Error('Audio not ready. Did you call load?');\n\n self.gainNode.connect(audioDestination);\n self.panner.connect(self.gainNode);\n self.source.connect(self.panner);\n if (self.source.noteOn) self.source.noteOn(0);\n self.isPlaying = true;\n};\n\n\nexports.PositionAudio.prototype.load = function(callback) {\n var self = this;\n var request = new XMLHttpRequest();\n request.open('GET', this.url, true);\n request.responseType = 'arraybuffer';\n\n // Decode asynchronously\n request.onload = function() {\n audioContext.decodeAudioData( request.response, function(buffer) {\n self.options.buffer = buffer;\n self.initBuffer();\n callback(null);\n }, function(err){callback(err);});\n };\n request.send();\n};\n\n\n\nfunction tick() {\n tickCount++;\n game.camera.updateMatrixWorld();\n var position = game.camera.matrixWorld.getPosition();\n var velocity = game.controls.velocity.clone();\n\n audioContext.listener.setPosition(position.x, position.y, position.z);\n audioContext.listener.setVelocity(velocity.x, velocity.y, velocity.z);\n\n\n var m = game.camera.matrixWorld;\n // Multiply the orientation vector by the world matrix of the camera.\n var vec = m.multiplyVector3(new game.THREE.Vector3(0,0,1));\n var direction = vec.subSelf(position).normalize();\n var vec2 = m.multiplyVector3(new game.THREE.Vector3(0,-1,0));\n var up_direction = vec2.subSelf(position).normalize();\n\n\n // Set the orientation and the up-vector for the listener.\n audioContext.listener.setOrientation(direction.x, direction.y, direction.z, up_direction.x, up_direction.y, up_direction.z);\n\n\n if (!calculateAbsorption || (tickCount < calculateAbsorptionOnTick )) return;\n audioInstances.forEach(function(audio){\n adjustDensityGain(audio, position);\n });\n}\n\n// calculate absorption of things in the way. this is using the Beer-Lambert Law\n// see https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law\nfunction adjustDensityGain(audio, position) {\n var totalDistance = Math.sqrt( (Math.abs(audio.position.x - position.x))^2 + (Math.abs(audio.position.y - position.y))^2 + (Math.abs(audio.position.z - position.z))^2 );\n var memo = {\n audio: audio,\n position: position,\n totalDistance: totalDistance,\n count: 0,\n densitySum: 0,\n totalCount: 0\n };\n bresenham3d(audio.position, position, memo, calculatePointDensity, setDensityGain);\n\n}\n\nfunction calculatePointDensity(pos, memo) {\n memo.totalCount++;\n var block = game.getBlock(pos);\n if (block) {\n memo.count++;\n var density = densityMapping[block] || defaultDensity;\n var block_distance_from_listener = Math.sqrt( (Math.abs(pos.x - memo.position.x))^2 + (Math.abs(pos.y - memo.position.y))^2 + (Math.abs(pos.z - memo.position.z))^2 );\n var percent = block_distance_from_listener/memo.totalDistance;\n memo.densitySum+= (((1.4*percent)-0.5)^2 + 0.5); // a u shape\n }\n}\n\nfunction setDensityGain(memo) {\n var gain = 1;\n if (memo.count > 0) {\n var exp = -1 * (memo.densitySum/120);\n gain = Math.pow(10, exp);\n if (gain < densityGainMin) gain = 0;\n if (gain > 1) gain = 1;\n }\n memo.audio.gainNode.gain.value = gain;\n tickCount = 0;\n}\n\n\n\n//@ sourceURL=/node_modules/voxel-audio/index.js")),n.define("/node_modules/voxel-audio/node_modules/bresenham3d/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],"module.exports = {}\n//@ sourceURL=/node_modules/voxel-audio/node_modules/bresenham3d/package.json")),n.define("/node_modules/voxel-audio/node_modules/bresenham3d/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"/*\n arguments\n ---------\n \n - `from_position` - an object with x,y,z properties, eg {x: 23, y: -21, z: 49}\n - `to_position` - an object with x,y,z properties, eg {x: -32, y: 40, z: 49}\n - 'memo' - an object used to store values (see onPoint below). eg {count: 0}\n - `onPoint` - a function that is called for each integer point found on the path. function(pos, memo) {}\n - 'onComplete' - [optional] a function that is called when complete. function(memo) {}\n\n*/\nmodule.exports = function(from_position, to_position, memo, onPoint, onComplete) {\n var temp;\n\n // safty first kids\n var x0 = Math.floor(from_position.x);\n var y0 = Math.floor(from_position.y);\n var z0 = Math.floor(from_position.z);\n var x1 = Math.floor(to_position.x);\n var y1 = Math.floor(to_position.y);\n var z1 = Math.floor(to_position.z);\n\n //'steep' xy Line, make longest delta x plane\n var swap_xy = Math.abs(y1 - y0) > Math.abs(x1 - x0);\n if (swap_xy) {\n temp = x0; x0 = y0; y0 = temp; //swap(x0, y0);\n temp = x1; x1 = y1; y1 = temp; //swap(x1, y1);\n }\n //do same for xz\n var swap_xz = Math.abs(z1 - z0) > Math.abs(x1 - x0);\n if (swap_xz) {\n temp = x0; x0 = z0; z0 = temp; //swap(x0, z0);\n temp = x1; x1 = z1; z1 = temp; //swap(x1, z1);\n }\n\n //delta is Length in each plane\n var delta_x = Math.abs(x1 - x0);\n var delta_y = Math.abs(y1 - y0);\n var delta_z = Math.abs(z1 - z0);\n \n //drift controls when to step in 'shallow' planes\n //starting value keeps Line centred\n var drift_xy = (delta_x / 2);\n var drift_xz = (delta_x / 2);\n\n //direction of line\n var step_x = 1;\n if (x0 > x1) step_x = -1;\n var step_y = 1;\n if (y0 > y1) step_y = -1;\n var step_z = 1;\n if (z0 > z1) step_z = -1;\n\n\n //starting point\n var y = y0;\n var z = z0;\n\n var cx, cy, cz;\n\n //step through longest delta (which we have swapped to x)\n for (var x = x0; x !== x1; x += step_x) {\n \n //copy position\n cx = x; cy = y; cz = z;\n\n //unswap (in reverse)\n if (swap_xz) {\n temp = cx; cx = cz; cz = temp; //swap(cx, cz);\n }\n if (swap_xy) {\n temp = cx; cx = cy; cy = temp; //swap(cx, cy);\n }\n //passes through this point\n if (onPoint) onPoint({x: cx, y: cy, z: cz}, memo);\n \n \n //update progress in other planes\n drift_xy = drift_xy - delta_y;\n drift_xz = drift_xz - delta_z;\n\n //step in y plane\n if (drift_xy < 0) {\n y = y + step_y;\n drift_xy = drift_xy + delta_x;\n }\n \n //same in z\n if (drift_xz < 0) {\n z = z + step_z;\n drift_xz = drift_xz + delta_x;\n }\n }\n if (onComplete) onComplete(memo);\n\n\n};\n\n\n//@ sourceURL=/node_modules/voxel-audio/node_modules/bresenham3d/index.js")),n.define("/app.js",Function(["require","module","exports","__dirname","__filename","process","global"],"// Voxel Tetris by @tatarize\n// Click the board side to make the piece go that way.\n// Click something on the board (eg, the falling piece) to make it turn.\n// Turns are currently logged counter clockwise/counter-clockwise depending on the height you clicked at.\n\nvar createGame = require('voxel-engine')\nvar chunkSize = 32\nvar chunkDistance = 3\n\nvar game = createGame({\n texturePath: '/textures/',\nmaterials: [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt', 'obsidian', 'whitewool', 'cobblestone'],\n generate: function(x,y,z) {\n return (y < -2 && Math.abs(x) < 100 && Math.abs(z) < 100) ? 1 : 0\n },\n controlOptions: {\n jump: 0,\n move: 0,\n fall: 0\n },\n startingPosition:[161,322,500]\n})\n\nvar container = document.body\ngame.appendTo(container)\nwindow.game = game\n\nvar tetris = require('voxel-tetris')(game)\n\ngame.on('mousedown', function (pos) {\n tetris.touch(pos)\n})\n\ngame.on('tick', function() {\n tetris.tick()\n})\n\ngame.controls.on('command', function(cmd,up) {\nif (!up) return;\n switch(cmd) {\n case 'moveForward':\n tetris.command(0);\n break;\n case 'moveLeft':\n tetris.command(3);\n break;\n case 'moveRight':\n tetris.command(2);\n break;\n case 'moveBackward':\n tetris.command(4);\n break;\n case 'wantsJump':\n tetris.command(5);\n break;\n }\n});\nvar audio = require('voxel-audio')\naudio.initGameAudio(game)\n\nvar tetrisTheme = new audio.PositionAudio({\n url : 'http://commondatastorage.googleapis.com/maxomusic/tetris-gameboy-02.mp3',\n startingPosition:[161,322,500],\n coneOuterAngle : 360,\n coneInnerAngle : 360,\n refDistance : 2.0,\n loop: true \n});\n\ntetrisTheme.load(function(err){\n console.log('playing')\n tetrisTheme.play()\n})\n\n// obtain pointer lock\ngame.setupPointerLock(container)\n\n//@ sourceURL=/app.js")),n("/app.js")
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment