Skip to content

Instantly share code, notes, and snippets.

@techwraith
Created February 17, 2013 03:09
Show Gist options
  • Save techwraith/4969905 to your computer and use it in GitHub Desktop.
Save techwraith/4969905 to your computer and use it in GitHub Desktop.
voxel.js game
var createGame = require('voxel-engine')
var simplex = require('voxel-simplex-terrain')
var url = require('url')
var chunkSize = 32
var chunkDistance = 3
var seed
var parsedURL = url.parse(window.location.href, true)
if (parsedURL.query) seed = parsedURL.query.seed
window.generator = simplex({seed: seed, scaleFactor: 10, chunkDistance: chunkDistance})
window.game = createGame({
generateVoxelChunk: generator,
materials: ['grass', 'obsidian', 'dirt', 'whitewool', 'crate', 'brick'],
cubeSize: 25,
chunkSize: chunkSize,
chunkDistance: chunkDistance,
startingPosition: [0, 3000, 1000],
worldOrigin: [0,0,0],
controlOptions: {jump: 6}
})
// point camera down initially
game.controls.pitchObject.rotation.x = -1.5
game.on('collision', function (item) {
game.removeItem(item)
})
var currentMaterial = 1
function createDebris (pos, value) {
var mesh = new game.THREE.Mesh(
new game.THREE.CubeGeometry(4, 4, 4),
game.material
)
mesh.geometry.faces.forEach(function (face) {
face.materialIndex = value - 1
})
mesh.translateX(pos.x)
mesh.translateY(pos.y)
mesh.translateZ(pos.z)
return {
mesh: mesh,
size: 4,
collisionRadius: 22,
value: value
}
}
function explode (pos, value) {
if (!value) return
var item = createDebris(pos, value)
item.velocity = {
x: (Math.random() * 2 - 1) * 0.05,
y: (Math.random() * 2 - 1) * 0.05,
z: (Math.random() * 2 - 1) * 0.05,
}
game.addItem(item)
setTimeout(function (item) {
game.removeItem(item)
}, 15 * 1000 + Math.random() * 15 * 1000, item)
}
game.appendTo('body')
game.on('mousedown', function (pos) {
var cid = game.voxels.chunkAtPosition(pos)
var vid = game.voxels.voxelAtPosition(pos)
if (erase) {
explode(pos, game.getBlock(pos))
game.setBlock(pos, 0)
} else {
game.createBlock(pos, currentMaterial)
}
})
var erase = true
window.addEventListener('keydown', function (ev) {
if (ev.keyCode === 'X'.charCodeAt(0)) {
erase = !erase
}
ctrlDown = ev.ctrlKey
})
function ctrlToggle (ev) { erase = !ev.ctrlKey }
window.addEventListener('keyup', ctrlToggle)
window.addEventListener('keydown', ctrlToggle)
game.requestPointerLock('canvas')
(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-simplex-terrain/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-simplex-terrain/package.json')),n.define("/node_modules/voxel-simplex-terrain/index.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var SimplexNoise = require('simplex-noise')\nvar Alea = require('alea')\nvar voxel = require('voxel')\n\nmodule.exports = function generate(opts) {\n if (!opts) opts = {}\n if (typeof opts === 'string') opts = {seed: opts}\n var seed = opts.seed || ~~(Math.random()*10000000)\n var alea = new Alea(seed)\n function seedFunc() { return alea() }\n var simplex = new SimplexNoise(seedFunc)\n var chunkDistance = opts.chunkDistance || 2\n var chunkSize = opts.chunkSize || 32\n var scaleFactor = opts.scaleFactor || chunkDistance * chunkSize\n\n var width = chunkDistance * 2 * chunkSize\n var lowerLeft = [0, 0]\n var upperRight = [width, width]\n \n getMaterialIndex = opts.getMaterialIndex || getMaterialIndex\n \n return function getChunk(l, h) {\n var fromLow = chunkSize * -chunkDistance\n var fromHigh = chunkSize * chunkDistance\n var toLow = lowerLeft[0]\n var toHigh = upperRight[0]\n return voxel.generate(l, h, function(x, y, z, n) {\n return getMaterialIndex(seed, simplex, width, x, y, z)\n })\n }\n}\n\nfunction getMaterialIndex(seed, simplex, width, x, y, z) {\n // the contents of this function come from \n // https://github.com/jwagner/voxelworlds/\n var intensity = 16\n var xd = x-width*0.25,\n yd = y-width*0.20,\n zd = z-width*0.25;\n if(yd > 0) yd *= yd*0.05;\n var xz = simplex.noise2D(x, z);\n var distance = (xd*xd+yd*yd*intensity+zd*zd)*0.0004,\n density = simplex.noise3D(x/intensity, y/intensity, z/intensity)-distance;\n if(density > -0.75){\n return 3;\n }\n if(density > -0.85){\n return 2;\n }\n if(density > -1.0){\n return y > intensity+xz*4 ? 1 : 2;\n }\n \n // makes spikey things\n if(seed[0] === \"6\"){\n var density0 = simplex.noise3D(x/intensity, intensity, z/intensity);\n if(density0-xd*xd*0.002-zd*zd*0.002 > -1.0 && y > intensity && y*0.01 < simplex.noise2D(x/4, z/4)*simplex.noise2D(x/intensity, z/intensity)){\n return y > (intensity * 1.5)+xz*(intensity/2) ? 5 : 4;\n }\n }\n\n // makes rocky outcroppings\n if(seed[0] != '0'){\n if(density > -0.50-y*0.01+simplex.noise2D(x/4, z/4)*simplex.noise2D(x/intensity+5, z/intensity+5)){\n return 3;\n }\n }\n\n return 0.0;\n}\n\nfunction scale( x, fromLow, fromHigh, toLow, toHigh ) {\n return ( x - fromLow ) * ( toHigh - toLow ) / ( fromHigh - fromLow ) + toLow\n}\n;\n//@ sourceURL=/node_modules/voxel-simplex-terrain/index.js")),n.define("/node_modules/simplex-noise/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"./simplex-noise"}\n//@ sourceURL=/node_modules/simplex-noise/package.json')),n.define("/node_modules/simplex-noise/simplex-noise.js",Function(["require","module","exports","__dirname","__filename","process","global"],"/*\n * A fast javascript implementation of simplex noise by Jonas Wagner\n *\n * Based on a speed-improved simplex noise algorithm for 2D, 3D and 4D in Java.\n * Which is based on example code by Stefan Gustavson ([email protected]).\n * With Optimisations by Peter Eastman ([email protected]).\n * Better rank ordering method by Stefan Gustavson in 2012.\n *\n *\n * Copyright (C) 2012 Jonas Wagner\n *\n * Permission is hereby granted, free of charge, to any person obtaining\n * a copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n */\n(function () {\n\nvar F2 = 0.5 * (Math.sqrt(3.0) - 1.0),\n G2 = (3.0 - Math.sqrt(3.0)) / 6.0,\n F3 = 1.0 / 3.0,\n G3 = 1.0 / 6.0,\n F4 = (Math.sqrt(5.0) - 1.0) / 4.0,\n G4 = (5.0 - Math.sqrt(5.0)) / 20.0;\n\n\nfunction SimplexNoise(random) {\n if (!random) random = Math.random;\n this.p = new Uint8Array(256);\n this.perm = new Uint8Array(512);\n this.permMod12 = new Uint8Array(512);\n for (var i = 0; i < 256; i++) {\n this.p[i] = random() * 256;\n }\n for (i = 0; i < 512; i++) {\n this.perm[i] = this.p[i & 255];\n this.permMod12[i] = this.perm[i] % 12;\n }\n\n}\nSimplexNoise.prototype = {\n grad3: new Float32Array([1, 1, 0,\n - 1, 1, 0,\n 1, - 1, 0,\n\n - 1, - 1, 0,\n 1, 0, 1,\n - 1, 0, 1,\n\n 1, 0, - 1,\n - 1, 0, - 1,\n 0, 1, 1,\n\n 0, - 1, 1,\n 0, 1, - 1,\n 0, - 1, - 1]),\n grad4: new Float32Array([0, 1, 1, 1, 0, 1, 1, - 1, 0, 1, - 1, 1, 0, 1, - 1, - 1,\n 0, - 1, 1, 1, 0, - 1, 1, - 1, 0, - 1, - 1, 1, 0, - 1, - 1, - 1,\n 1, 0, 1, 1, 1, 0, 1, - 1, 1, 0, - 1, 1, 1, 0, - 1, - 1,\n - 1, 0, 1, 1, - 1, 0, 1, - 1, - 1, 0, - 1, 1, - 1, 0, - 1, - 1,\n 1, 1, 0, 1, 1, 1, 0, - 1, 1, - 1, 0, 1, 1, - 1, 0, - 1,\n - 1, 1, 0, 1, - 1, 1, 0, - 1, - 1, - 1, 0, 1, - 1, - 1, 0, - 1,\n 1, 1, 1, 0, 1, 1, - 1, 0, 1, - 1, 1, 0, 1, - 1, - 1, 0,\n - 1, 1, 1, 0, - 1, 1, - 1, 0, - 1, - 1, 1, 0, - 1, - 1, - 1, 0]),\n noise2D: function (xin, yin) {\n var permMod12 = this.permMod12,\n perm = this.perm,\n grad3 = this.grad3;\n var n0, n1, n2; // Noise contributions from the three corners\n // Skew the input space to determine which simplex cell we're in\n var s = (xin + yin) * F2; // Hairy factor for 2D\n var i = Math.floor(xin + s);\n var j = Math.floor(yin + s);\n var t = (i + j) * G2;\n var X0 = i - t; // Unskew the cell origin back to (x,y) space\n var Y0 = j - t;\n var x0 = xin - X0; // The x,y distances from the cell origin\n var y0 = yin - Y0;\n // For the 2D case, the simplex shape is an equilateral triangle.\n // Determine which simplex we are in.\n var i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords\n if (x0 > y0) {\n i1 = 1;\n j1 = 0;\n } // lower triangle, XY order: (0,0)->(1,0)->(1,1)\n else {\n i1 = 0;\n j1 = 1;\n } // upper triangle, YX order: (0,0)->(0,1)->(1,1)\n // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and\n // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where\n // c = (3-sqrt(3))/6\n var x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords\n var y1 = y0 - j1 + G2;\n var x2 = x0 - 1.0 + 2.0 * G2; // Offsets for last corner in (x,y) unskewed coords\n var y2 = y0 - 1.0 + 2.0 * G2;\n // Work out the hashed gradient indices of the three simplex corners\n var ii = i & 255;\n var jj = j & 255;\n // Calculate the contribution from the three corners\n var t0 = 0.5 - x0 * x0 - y0 * y0;\n if (t0 < 0) n0 = 0.0;\n else {\n var gi0 = permMod12[ii + perm[jj]] * 3;\n t0 *= t0;\n n0 = t0 * t0 * (grad3[gi0] * x0 + grad3[gi0 + 1] * y0); // (x,y) of grad3 used for 2D gradient\n }\n var t1 = 0.5 - x1 * x1 - y1 * y1;\n if (t1 < 0) n1 = 0.0;\n else {\n var gi1 = permMod12[ii + i1 + perm[jj + j1]] * 3;\n t1 *= t1;\n n1 = t1 * t1 * (grad3[gi1] * x1 + grad3[gi1 + 1] * y1);\n }\n var t2 = 0.5 - x2 * x2 - y2 * y2;\n if (t2 < 0) n2 = 0.0;\n else {\n var gi2 = permMod12[ii + 1 + perm[jj + 1]] * 3;\n t2 *= t2;\n n2 = t2 * t2 * (grad3[gi2] * x2 + grad3[gi2 + 1] * y2);\n }\n // Add contributions from each corner to get the final noise value.\n // The result is scaled to return values in the interval [-1,1].\n return 70.0 * (n0 + n1 + n2);\n },\n // 3D simplex noise\n noise3D: function (xin, yin, zin) {\n var permMod12 = this.permMod12,\n perm = this.perm,\n grad3 = this.grad3;\n var n0, n1, n2, n3; // Noise contributions from the four corners\n // Skew the input space to determine which simplex cell we're in\n var s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D\n var i = Math.floor(xin + s);\n var j = Math.floor(yin + s);\n var k = Math.floor(zin + s);\n var t = (i + j + k) * G3;\n var X0 = i - t; // Unskew the cell origin back to (x,y,z) space\n var Y0 = j - t;\n var Z0 = k - t;\n var x0 = xin - X0; // The x,y,z distances from the cell origin\n var y0 = yin - Y0;\n var z0 = zin - Z0;\n // For the 3D case, the simplex shape is a slightly irregular tetrahedron.\n // Determine which simplex we are in.\n var i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords\n var i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords\n if (x0 >= y0) {\n if (y0 >= z0) {\n i1 = 1;\n j1 = 0;\n k1 = 0;\n i2 = 1;\n j2 = 1;\n k2 = 0;\n } // X Y Z order\n else if (x0 >= z0) {\n i1 = 1;\n j1 = 0;\n k1 = 0;\n i2 = 1;\n j2 = 0;\n k2 = 1;\n } // X Z Y order\n else {\n i1 = 0;\n j1 = 0;\n k1 = 1;\n i2 = 1;\n j2 = 0;\n k2 = 1;\n } // Z X Y order\n }\n else { // x0<y0\n if (y0 < z0) {\n i1 = 0;\n j1 = 0;\n k1 = 1;\n i2 = 0;\n j2 = 1;\n k2 = 1;\n } // Z Y X order\n else if (x0 < z0) {\n i1 = 0;\n j1 = 1;\n k1 = 0;\n i2 = 0;\n j2 = 1;\n k2 = 1;\n } // Y Z X order\n else {\n i1 = 0;\n j1 = 1;\n k1 = 0;\n i2 = 1;\n j2 = 1;\n k2 = 0;\n } // Y X Z order\n }\n // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),\n // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and\n // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where\n // c = 1/6.\n var x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords\n var y1 = y0 - j1 + G3;\n var z1 = z0 - k1 + G3;\n var x2 = x0 - i2 + 2.0 * G3; // Offsets for third corner in (x,y,z) coords\n var y2 = y0 - j2 + 2.0 * G3;\n var z2 = z0 - k2 + 2.0 * G3;\n var x3 = x0 - 1.0 + 3.0 * G3; // Offsets for last corner in (x,y,z) coords\n var y3 = y0 - 1.0 + 3.0 * G3;\n var z3 = z0 - 1.0 + 3.0 * G3;\n // Work out the hashed gradient indices of the four simplex corners\n var ii = i & 255;\n var jj = j & 255;\n var kk = k & 255;\n // Calculate the contribution from the four corners\n var t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;\n if (t0 < 0) n0 = 0.0;\n else {\n var gi0 = permMod12[ii + perm[jj + perm[kk]]] * 3;\n t0 *= t0;\n n0 = t0 * t0 * (grad3[gi0] * x0 + grad3[gi0 + 1] * y0 + grad3[gi0 + 2] * z0);\n }\n var t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;\n if (t1 < 0) n1 = 0.0;\n else {\n var gi1 = permMod12[ii + i1 + perm[jj + j1 + perm[kk + k1]]] * 3;\n t1 *= t1;\n n1 = t1 * t1 * (grad3[gi1] * x1 + grad3[gi1 + 1] * y1 + grad3[gi1 + 2] * z1);\n }\n var t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;\n if (t2 < 0) n2 = 0.0;\n else {\n var gi2 = permMod12[ii + i2 + perm[jj + j2 + perm[kk + k2]]] * 3;\n t2 *= t2;\n n2 = t2 * t2 * (grad3[gi2] * x2 + grad3[gi2 + 1] * y2 + grad3[gi2 + 2] * z2);\n }\n var t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;\n if (t3 < 0) n3 = 0.0;\n else {\n var gi3 = permMod12[ii + 1 + perm[jj + 1 + perm[kk + 1]]] * 3;\n t3 *= t3;\n n3 = t3 * t3 * (grad3[gi3] * x3 + grad3[gi3 + 1] * y3 + grad3[gi3 + 2] * z3);\n }\n // Add contributions from each corner to get the final noise value.\n // The result is scaled to stay just inside [-1,1]\n return 32.0 * (n0 + n1 + n2 + n3);\n },\n // 4D simplex noise, better simplex rank ordering method 2012-03-09\n noise4D: function (x, y, z, w) {\n var permMod12 = this.permMod12,\n perm = this.perm,\n grad4 = this.grad4;\n\n var n0, n1, n2, n3, n4; // Noise contributions from the five corners\n // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in\n var s = (x + y + z + w) * F4; // Factor for 4D skewing\n var i = Math.floor(x + s);\n var j = Math.floor(y + s);\n var k = Math.floor(z + s);\n var l = Math.floor(w + s);\n var t = (i + j + k + l) * G4; // Factor for 4D unskewing\n var X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space\n var Y0 = j - t;\n var Z0 = k - t;\n var W0 = l - t;\n var x0 = x - X0; // The x,y,z,w distances from the cell origin\n var y0 = y - Y0;\n var z0 = z - Z0;\n var w0 = w - W0;\n // For the 4D case, the simplex is a 4D shape I won't even try to describe.\n // To find out which of the 24 possible simplices we're in, we need to\n // determine the magnitude ordering of x0, y0, z0 and w0.\n // Six pair-wise comparisons are performed between each possible pair\n // of the four coordinates, and the results are used to rank the numbers.\n var rankx = 0;\n var ranky = 0;\n var rankz = 0;\n var rankw = 0;\n if (x0 > y0) rankx++;\n else ranky++;\n if (x0 > z0) rankx++;\n else rankz++;\n if (x0 > w0) rankx++;\n else rankw++;\n if (y0 > z0) ranky++;\n else rankz++;\n if (y0 > w0) ranky++;\n else rankw++;\n if (z0 > w0) rankz++;\n else rankw++;\n var i1, j1, k1, l1; // The integer offsets for the second simplex corner\n var i2, j2, k2, l2; // The integer offsets for the third simplex corner\n var i3, j3, k3, l3; // The integer offsets for the fourth simplex corner\n // simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order.\n // Many values of c will never occur, since e.g. x>y>z>w makes x<z, y<w and x<w\n // impossible. Only the 24 indices which have non-zero entries make any sense.\n // We use a thresholding to set the coordinates in turn from the largest magnitude.\n // Rank 3 denotes the largest coordinate.\n i1 = rankx >= 3 ? 1 : 0;\n j1 = ranky >= 3 ? 1 : 0;\n k1 = rankz >= 3 ? 1 : 0;\n l1 = rankw >= 3 ? 1 : 0;\n // Rank 2 denotes the second largest coordinate.\n i2 = rankx >= 2 ? 1 : 0;\n j2 = ranky >= 2 ? 1 : 0;\n k2 = rankz >= 2 ? 1 : 0;\n l2 = rankw >= 2 ? 1 : 0;\n // Rank 1 denotes the second smallest coordinate.\n i3 = rankx >= 1 ? 1 : 0;\n j3 = ranky >= 1 ? 1 : 0;\n k3 = rankz >= 1 ? 1 : 0;\n l3 = rankw >= 1 ? 1 : 0;\n // The fifth corner has all coordinate offsets = 1, so no need to compute that.\n var x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords\n var y1 = y0 - j1 + G4;\n var z1 = z0 - k1 + G4;\n var w1 = w0 - l1 + G4;\n var x2 = x0 - i2 + 2.0 * G4; // Offsets for third corner in (x,y,z,w) coords\n var y2 = y0 - j2 + 2.0 * G4;\n var z2 = z0 - k2 + 2.0 * G4;\n var w2 = w0 - l2 + 2.0 * G4;\n var x3 = x0 - i3 + 3.0 * G4; // Offsets for fourth corner in (x,y,z,w) coords\n var y3 = y0 - j3 + 3.0 * G4;\n var z3 = z0 - k3 + 3.0 * G4;\n var w3 = w0 - l3 + 3.0 * G4;\n var x4 = x0 - 1.0 + 4.0 * G4; // Offsets for last corner in (x,y,z,w) coords\n var y4 = y0 - 1.0 + 4.0 * G4;\n var z4 = z0 - 1.0 + 4.0 * G4;\n var w4 = w0 - 1.0 + 4.0 * G4;\n // Work out the hashed gradient indices of the five simplex corners\n var ii = i & 255;\n var jj = j & 255;\n var kk = k & 255;\n var ll = l & 255;\n // Calculate the contribution from the five corners\n var t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;\n if (t0 < 0) n0 = 0.0;\n else {\n var gi0 = (perm[ii + perm[jj + perm[kk + perm[ll]]]] % 32) * 4;\n t0 *= t0;\n n0 = t0 * t0 * (grad4[gi0] * x0 + grad4[gi0 + 1] * y0 + grad4[gi0 + 2] * z0 + grad4[gi0 + 3] * w0);\n }\n var t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;\n if (t1 < 0) n1 = 0.0;\n else {\n var gi1 = (perm[ii + i1 + perm[jj + j1 + perm[kk + k1 + perm[ll + l1]]]] % 32) * 4;\n t1 *= t1;\n n1 = t1 * t1 * (grad4[gi1] * x1 + grad4[gi1 + 1] * y1 + grad4[gi1 + 2] * z1 + grad4[gi1 + 3] * w1);\n }\n var t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;\n if (t2 < 0) n2 = 0.0;\n else {\n var gi2 = (perm[ii + i2 + perm[jj + j2 + perm[kk + k2 + perm[ll + l2]]]] % 32) * 4;\n t2 *= t2;\n n2 = t2 * t2 * (grad4[gi2] * x2 + grad4[gi2 + 1] * y2 + grad4[gi2 + 2] * z2 + grad4[gi2 + 3] * w2);\n }\n var t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;\n if (t3 < 0) n3 = 0.0;\n else {\n var gi3 = (perm[ii + i3 + perm[jj + j3 + perm[kk + k3 + perm[ll + l3]]]] % 32) * 4;\n t3 *= t3;\n n3 = t3 * t3 * (grad4[gi3] * x3 + grad4[gi3 + 1] * y3 + grad4[gi3 + 2] * z3 + grad4[gi3 + 3] * w3);\n }\n var t4 = 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;\n if (t4 < 0) n4 = 0.0;\n else {\n var gi4 = (perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32) * 4;\n t4 *= t4;\n n4 = t4 * t4 * (grad4[gi4] * x4 + grad4[gi4 + 1] * y4 + grad4[gi4 + 2] * z4 + grad4[gi4 + 3] * w4);\n }\n // Sum up and scale the result to cover the range [-1,1]\n return 27.0 * (n0 + n1 + n2 + n3 + n4);\n }\n\n\n};\n\n// amd\nif (typeof define !== 'undefined' && define.amd) define(function(){return SimplexNoise;});\n// browser\nelse if (typeof window !== 'undefined') window.SimplexNoise = SimplexNoise;\n//common js\nif (typeof exports !== 'undefined') exports.SimplexNoise = SimplexNoise;\n// nodejs\nif (typeof module !== 'undefined') {\n module.exports = SimplexNoise;\n}\n\n})();\n\n//@ sourceURL=/node_modules/simplex-noise/simplex-noise.js")),n.define("/node_modules/voxel-simplex-terrain/node_modules/alea/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"alea.js"}\n//@ sourceURL=/node_modules/voxel-simplex-terrain/node_modules/alea/package.json')),n.define("/node_modules/voxel-simplex-terrain/node_modules/alea/alea.js",Function(["require","module","exports","__dirname","__filename","process","global"],"(function (root, factory) {\n if (typeof exports === 'object') {\n module.exports = factory();\n } else if (typeof define === 'function' && define.amd) {\n define(factory);\n } else {\n root.returnExports = factory();\n }\n}(this, function () {\n\n 'use strict';\n\n // From http://baagoe.com/en/RandomMusings/javascript/\n\n // importState to sync generator states\n Alea.importState = function(i){\n var random = new Alea();\n random.importState(i);\n return random;\n };\n\n return Alea;\n\n function Alea() {\n return (function(args) {\n // Johannes Baagøe <[email protected]>, 2010\n var s0 = 0;\n var s1 = 0;\n var s2 = 0;\n var c = 1;\n\n if (args.length == 0) {\n args = [+new Date];\n }\n var mash = Mash();\n s0 = mash(' ');\n s1 = mash(' ');\n s2 = mash(' ');\n\n for (var i = 0; i < args.length; i++) {\n s0 -= mash(args[i]);\n if (s0 < 0) {\n s0 += 1;\n }\n s1 -= mash(args[i]);\n if (s1 < 0) {\n s1 += 1;\n }\n s2 -= mash(args[i]);\n if (s2 < 0) {\n s2 += 1;\n }\n }\n mash = null;\n\n var random = function() {\n var t = 2091639 * s0 + c * 2.3283064365386963e-10; // 2^-32\n s0 = s1;\n s1 = s2;\n return s2 = t - (c = t | 0);\n };\n random.uint32 = function() {\n return random() * 0x100000000; // 2^32\n };\n random.fract53 = function() {\n return random() + \n (random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53\n };\n random.version = 'Alea 0.9';\n random.args = args;\n\n // my own additions to sync state between two generators\n random.exportState = function(){\n return [s0, s1, s2, c];\n };\n random.importState = function(i){\n s0 = +i[0] || 0;\n s1 = +i[1] || 0;\n s2 = +i[2] || 0;\n c = +i[3] || 0;\n };\n \n return random;\n\n } (Array.prototype.slice.call(arguments)));\n }\n\n function Mash() {\n var n = 0xefc8249d;\n\n var mash = function(data) {\n data = data.toString();\n for (var i = 0; i < data.length; i++) {\n n += data.charCodeAt(i);\n var h = 0.02519603282416938 * n;\n n = h >>> 0;\n h -= n;\n h *= n;\n n = h >>> 0;\n h -= n;\n n += h * 0x100000000; // 2^32\n }\n return (n >>> 0) * 2.3283064365386963e-10; // 2^-32\n };\n\n mash.version = 'Mash 0.9';\n return mash;\n }\n}));\n\n//@ sourceURL=/node_modules/voxel-simplex-terrain/node_modules/alea/alea.js")),n.define("/node_modules/voxel-simplex-terrain/node_modules/voxel/package.json",Function(["require","module","exports","__dirname","__filename","process","global"],'module.exports = {"main":"index.js"}\n//@ sourceURL=/node_modules/voxel-simplex-terrain/node_modules/voxel/package.json')),n.define("/node_modules/voxel-simplex-terrain/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\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-simplex-terrain/node_modules/voxel/index.js")),n.define("/node_modules/voxel-simplex-terrain/node_modules/voxel/chunker.js",Function(["require","module","exports","__dirname","__filename","process","global"],"module.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\nChunker.prototype.generateMissingChunks = function(position) {\n var current = this.chunkAtPosition(position)\n var x = current[0]\n var y = current[1]\n var z = current[2]\n var dist = this.distance\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 if (!this.chunks[[cx, cy, cz].join('|')]) {\n this.generateChunk(cx, cy, cz)\n }\n }\n }\n }\n return this.chunks\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(pos) {\n var size = this.chunkSize\n var v = this.voxelVector(pos)\n var vidx = v.x + v.y*size + v.z*size*size\n return vidx\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 vidx = this.voxelIndex(pos)\n if (!vidx) 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-simplex-terrain/node_modules/voxel/chunker.js")),n.define("/node_modules/voxel-simplex-terrain/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-simplex-terrain/node_modules/voxel/meshers/culled.js")),n.define("/node_modules/voxel-simplex-terrain/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 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, l, w, h\n , u = (d+1)%3\n , v = (d+2)%3\n , x = [0,0,0]\n , q = [0,0,0];\n if(mask.length < dims[u] * dims[v]) {\n mask = new Int32Array(dims[u] * dims[v]);\n }\n q[d] = 1;\n for(x[d]=-1; x[d]<dims[d]; ) {\n //Compute mask\n var n = 0;\n for(x[v]=0; x[v]<dims[v]; ++x[v])\n for(x[u]=0; x[u]<dims[u]; ++x[u], ++n) {\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 if((!!a) === (!!b) ) {\n mask[n] = 0;\n } else if(!!a) {\n mask[n] = a;\n } else {\n mask[n] = -b;\n }\n }\n //Increment x[d]\n ++x[d];\n //Generate mesh for mask using lexicographic ordering\n n = 0;\n for(j=0; j<dims[v]; ++j)\n for(i=0; i<dims[u]; ) {\n var c = mask[n];\n if(!!c) {\n //Compute width\n for(w=1; c === mask[n+w] && i+w<dims[u]; ++w) {\n }\n //Compute height (this is slightly awkward\n var done = false;\n for(h=1; j+h<dims[v]; ++h) {\n for(k=0; k<w; ++k) {\n if(c !== mask[n+k+h*dims[u]]) {\n done = true;\n break;\n }\n }\n if(done) {\n break;\n }\n }\n //Add quad\n x[u] = i; x[v] = j;\n var du = [0,0,0]\n , dv = [0,0,0]; \n if(c > 0) {\n dv[v] = h;\n du[u] = w;\n } else {\n c = -c;\n du[v] = h;\n dv[u] = w;\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 for(l=0; l<h; ++l)\n for(k=0; k<w; ++k) {\n mask[n+k+l*dims[u]] = 0;\n }\n //Increment counters and continue\n i += w; n += w;\n } else {\n ++i; ++n;\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-simplex-terrain/node_modules/voxel/meshers/greedy.js")),n.define("/node_modules/voxel-simplex-terrain/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-simplex-terrain/node_modules/voxel/meshers/monotone.js')),n.define("/node_modules/voxel-simplex-terrain/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-simplex-terrain/node_modules/voxel/meshers/stupid.js")),n.define("url",Function(["require","module","exports","__dirname","__filename","process","global"],"var punycode = { encode : function (s) { return s } };\n\nexports.parse = urlParse;\nexports.resolve = urlResolve;\nexports.resolveObject = urlResolveObject;\nexports.format = urlFormat;\n\nfunction arrayIndexOf(array, subject) {\n for (var i = 0, j = array.length; i < j; i++) {\n if(array[i] == subject) return i;\n }\n return -1;\n}\n\nvar objectKeys = Object.keys || function objectKeys(object) {\n if (object !== Object(object)) throw new TypeError('Invalid object');\n var keys = [];\n for (var key in object) if (object.hasOwnProperty(key)) keys[keys.length] = key;\n return keys;\n}\n\n// Reference: RFC 3986, RFC 1808, RFC 2396\n\n// define these here so at least they only have to be\n// compiled once on the first module load.\nvar protocolPattern = /^([a-z0-9.+-]+:)/i,\n portPattern = /:[0-9]+$/,\n // RFC 2396: characters reserved for delimiting URLs.\n delims = ['<', '>', '\"', '`', ' ', '\\r', '\\n', '\\t'],\n // RFC 2396: characters not allowed for various reasons.\n unwise = ['{', '}', '|', '\\\\', '^', '~', '[', ']', '`'].concat(delims),\n // Allowed by RFCs, but cause of XSS attacks. Always escape these.\n autoEscape = ['\\''],\n // Characters that are never ever allowed in a hostname.\n // Note that any invalid chars are also handled, but these\n // are the ones that are *expected* to be seen, so we fast-path\n // them.\n nonHostChars = ['%', '/', '?', ';', '#']\n .concat(unwise).concat(autoEscape),\n nonAuthChars = ['/', '@', '?', '#'].concat(delims),\n hostnameMaxLen = 255,\n hostnamePartPattern = /^[a-zA-Z0-9][a-z0-9A-Z_-]{0,62}$/,\n hostnamePartStart = /^([a-zA-Z0-9][a-z0-9A-Z_-]{0,62})(.*)$/,\n // protocols that can allow \"unsafe\" and \"unwise\" chars.\n unsafeProtocol = {\n 'javascript': true,\n 'javascript:': true\n },\n // protocols that never have a hostname.\n hostlessProtocol = {\n 'javascript': true,\n 'javascript:': true\n },\n // protocols that always have a path component.\n pathedProtocol = {\n 'http': true,\n 'https': true,\n 'ftp': true,\n 'gopher': true,\n 'file': true,\n 'http:': true,\n 'ftp:': true,\n 'gopher:': true,\n 'file:': true\n },\n // protocols that always contain a // bit.\n slashedProtocol = {\n 'http': true,\n 'https': true,\n 'ftp': true,\n 'gopher': true,\n 'file': true,\n 'http:': true,\n 'https:': true,\n 'ftp:': true,\n 'gopher:': true,\n 'file:': true\n },\n querystring = require('querystring');\n\nfunction urlParse(url, parseQueryString, slashesDenoteHost) {\n if (url && typeof(url) === 'object' && url.href) return url;\n\n if (typeof url !== 'string') {\n throw new TypeError(\"Parameter 'url' must be a string, not \" + typeof url);\n }\n\n var out = {},\n rest = url;\n\n // cut off any delimiters.\n // This is to support parse stuff like \"<http://foo.com>\"\n for (var i = 0, l = rest.length; i < l; i++) {\n if (arrayIndexOf(delims, rest.charAt(i)) === -1) break;\n }\n if (i !== 0) rest = rest.substr(i);\n\n\n var proto = protocolPattern.exec(rest);\n if (proto) {\n proto = proto[0];\n var lowerProto = proto.toLowerCase();\n out.protocol = lowerProto;\n rest = rest.substr(proto.length);\n }\n\n // figure out if it's got a host\n // user@server is *always* interpreted as a hostname, and url\n // resolution will treat //foo/bar as host=foo,path=bar because that's\n // how the browser resolves relative URLs.\n if (slashesDenoteHost || proto || rest.match(/^\\/\\/[^@\\/]+@[^@\\/]+/)) {\n var slashes = rest.substr(0, 2) === '//';\n if (slashes && !(proto && hostlessProtocol[proto])) {\n rest = rest.substr(2);\n out.slashes = true;\n }\n }\n\n if (!hostlessProtocol[proto] &&\n (slashes || (proto && !slashedProtocol[proto]))) {\n // there's a hostname.\n // the first instance of /, ?, ;, or # ends the host.\n // don't enforce full RFC correctness, just be unstupid about it.\n\n // If there is an @ in the hostname, then non-host chars *are* allowed\n // to the left of the first @ sign, unless some non-auth character\n // comes *before* the @-sign.\n // URLs are obnoxious.\n var atSign = arrayIndexOf(rest, '@');\n if (atSign !== -1) {\n // there *may be* an auth\n var hasAuth = true;\n for (var i = 0, l = nonAuthChars.length; i < l; i++) {\n var index = arrayIndexOf(rest, nonAuthChars[i]);\n if (index !== -1 && index < atSign) {\n // not a valid auth. Something like http://foo.com/bar@baz/\n hasAuth = false;\n break;\n }\n }\n if (hasAuth) {\n // pluck off the auth portion.\n out.auth = rest.substr(0, atSign);\n rest = rest.substr(atSign + 1);\n }\n }\n\n var firstNonHost = -1;\n for (var i = 0, l = nonHostChars.length; i < l; i++) {\n var index = arrayIndexOf(rest, nonHostChars[i]);\n if (index !== -1 &&\n (firstNonHost < 0 || index < firstNonHost)) firstNonHost = index;\n }\n\n if (firstNonHost !== -1) {\n out.host = rest.substr(0, firstNonHost);\n rest = rest.substr(firstNonHost);\n } else {\n out.host = rest;\n rest = '';\n }\n\n // pull out port.\n var p = parseHost(out.host);\n var keys = objectKeys(p);\n for (var i = 0, l = keys.length; i < l; i++) {\n var key = keys[i];\n out[key] = p[key];\n }\n\n // we've indicated that there is a hostname,\n // so even if it's empty, it has to be present.\n out.hostname = out.hostname || '';\n\n // validate a little.\n if (out.hostname.length > hostnameMaxLen) {\n out.hostname = '';\n } else {\n var hostparts = out.hostname.split(/\\./);\n for (var i = 0, l = hostparts.length; i < l; i++) {\n var part = hostparts[i];\n if (!part) continue;\n if (!part.match(hostnamePartPattern)) {\n var newpart = '';\n for (var j = 0, k = part.length; j < k; j++) {\n if (part.charCodeAt(j) > 127) {\n // we replace non-ASCII char with a temporary placeholder\n // we need this to make sure size of hostname is not\n // broken by replacing non-ASCII by nothing\n newpart += 'x';\n } else {\n newpart += part[j];\n }\n }\n // we test again with ASCII char only\n if (!newpart.match(hostnamePartPattern)) {\n var validParts = hostparts.slice(0, i);\n var notHost = hostparts.slice(i + 1);\n var bit = part.match(hostnamePartStart);\n if (bit) {\n validParts.push(bit[1]);\n notHost.unshift(bit[2]);\n }\n if (notHost.length) {\n rest = '/' + notHost.join('.') + rest;\n }\n out.hostname = validParts.join('.');\n break;\n }\n }\n }\n }\n\n // hostnames are always lower case.\n out.hostname = out.hostname.toLowerCase();\n\n // IDNA Support: Returns a puny coded representation of \"domain\".\n // It only converts the part of the domain name that\n // has non ASCII characters. I.e. it dosent matter if\n // you call it with a domain that already is in ASCII.\n var domainArray = out.hostname.split('.');\n var newOut = [];\n for (var i = 0; i < domainArray.length; ++i) {\n var s = domainArray[i];\n newOut.push(s.match(/[^A-Za-z0-9_-]/) ?\n 'xn--' + punycode.encode(s) : s);\n }\n out.hostname = newOut.join('.');\n\n out.host = (out.hostname || '') +\n ((out.port) ? ':' + out.port : '');\n out.href += out.host;\n }\n\n // now rest is set to the post-host stuff.\n // chop off any delim chars.\n if (!unsafeProtocol[lowerProto]) {\n\n // First, make 100% sure that any \"autoEscape\" chars get\n // escaped, even if encodeURIComponent doesn't think they\n // need to be.\n for (var i = 0, l = autoEscape.length; i < l; i++) {\n var ae = autoEscape[i];\n var esc = encodeURIComponent(ae);\n if (esc === ae) {\n esc = escape(ae);\n }\n rest = rest.split(ae).join(esc);\n }\n\n // Now make sure that delims never appear in a url.\n var chop = rest.length;\n for (var i = 0, l = delims.length; i < l; i++) {\n var c = arrayIndexOf(rest, delims[i]);\n if (c !== -1) {\n chop = Math.min(c, chop);\n }\n }\n rest = rest.substr(0, chop);\n }\n\n\n // chop off from the tail first.\n var hash = arrayIndexOf(rest, '#');\n if (hash !== -1) {\n // got a fragment string.\n out.hash = rest.substr(hash);\n rest = rest.slice(0, hash);\n }\n var qm = arrayIndexOf(rest, '?');\n if (qm !== -1) {\n out.search = rest.substr(qm);\n out.query = rest.substr(qm + 1);\n if (parseQueryString) {\n out.query = querystring.parse(out.query);\n }\n rest = rest.slice(0, qm);\n } else if (parseQueryString) {\n // no query string, but parseQueryString still requested\n out.search = '';\n out.query = {};\n }\n if (rest) out.pathname = rest;\n if (slashedProtocol[proto] &&\n out.hostname && !out.pathname) {\n out.pathname = '/';\n }\n\n //to support http.request\n if (out.pathname || out.search) {\n out.path = (out.pathname ? out.pathname : '') +\n (out.search ? out.search : '');\n }\n\n // finally, reconstruct the href based on what has been validated.\n out.href = urlFormat(out);\n return out;\n}\n\n// format a parsed object into a url string\nfunction urlFormat(obj) {\n // ensure it's an object, and not a string url.\n // If it's an obj, this is a no-op.\n // this way, you can call url_format() on strings\n // to clean up potentially wonky urls.\n if (typeof(obj) === 'string') obj = urlParse(obj);\n\n var auth = obj.auth || '';\n if (auth) {\n auth = auth.split('@').join('%40');\n for (var i = 0, l = nonAuthChars.length; i < l; i++) {\n var nAC = nonAuthChars[i];\n auth = auth.split(nAC).join(encodeURIComponent(nAC));\n }\n auth += '@';\n }\n\n var protocol = obj.protocol || '',\n host = (obj.host !== undefined) ? auth + obj.host :\n obj.hostname !== undefined ? (\n auth + obj.hostname +\n (obj.port ? ':' + obj.port : '')\n ) :\n false,\n pathname = obj.pathname || '',\n query = obj.query &&\n ((typeof obj.query === 'object' &&\n objectKeys(obj.query).length) ?\n querystring.stringify(obj.query) :\n '') || '',\n search = obj.search || (query && ('?' + query)) || '',\n hash = obj.hash || '';\n\n if (protocol && protocol.substr(-1) !== ':') protocol += ':';\n\n // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.\n // unless they had them to begin with.\n if (obj.slashes ||\n (!protocol || slashedProtocol[protocol]) && host !== false) {\n host = '//' + (host || '');\n if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;\n } else if (!host) {\n host = '';\n }\n\n if (hash && hash.charAt(0) !== '#') hash = '#' + hash;\n if (search && search.charAt(0) !== '?') search = '?' + search;\n\n return protocol + host + pathname + search + hash;\n}\n\nfunction urlResolve(source, relative) {\n return urlFormat(urlResolveObject(source, relative));\n}\n\nfunction urlResolveObject(source, relative) {\n if (!source) return relative;\n\n source = urlParse(urlFormat(source), false, true);\n relative = urlParse(urlFormat(relative), false, true);\n\n // hash is always overridden, no matter what.\n source.hash = relative.hash;\n\n if (relative.href === '') {\n source.href = urlFormat(source);\n return source;\n }\n\n // hrefs like //foo/bar always cut to the protocol.\n if (relative.slashes && !relative.protocol) {\n relative.protocol = source.protocol;\n //urlParse appends trailing / to urls like http://www.example.com\n if (slashedProtocol[relative.protocol] &&\n relative.hostname && !relative.pathname) {\n relative.path = relative.pathname = '/';\n }\n relative.href = urlFormat(relative);\n return relative;\n }\n\n if (relative.protocol && relative.protocol !== source.protocol) {\n // if it's a known url protocol, then changing\n // the protocol does weird things\n // first, if it's not file:, then we MUST have a host,\n // and if there was a path\n // to begin with, then we MUST have a path.\n // if it is file:, then the host is dropped,\n // because that's known to be hostless.\n // anything else is assumed to be absolute.\n if (!slashedProtocol[relative.protocol]) {\n relative.href = urlFormat(relative);\n return relative;\n }\n source.protocol = relative.protocol;\n if (!relative.host && !hostlessProtocol[relative.protocol]) {\n var relPath = (relative.pathname || '').split('/');\n while (relPath.length && !(relative.host = relPath.shift()));\n if (!relative.host) relative.host = '';\n if (!relative.hostname) relative.hostname = '';\n if (relPath[0] !== '') relPath.unshift('');\n if (relPath.length < 2) relPath.unshift('');\n relative.pathname = relPath.join('/');\n }\n source.pathname = relative.pathname;\n source.search = relative.search;\n source.query = relative.query;\n source.host = relative.host || '';\n source.auth = relative.auth;\n source.hostname = relative.hostname || relative.host;\n source.port = relative.port;\n //to support http.request\n if (source.pathname !== undefined || source.search !== undefined) {\n source.path = (source.pathname ? source.pathname : '') +\n (source.search ? source.search : '');\n }\n source.slashes = source.slashes || relative.slashes;\n source.href = urlFormat(source);\n return source;\n }\n\n var isSourceAbs = (source.pathname && source.pathname.charAt(0) === '/'),\n isRelAbs = (\n relative.host !== undefined ||\n relative.pathname && relative.pathname.charAt(0) === '/'\n ),\n mustEndAbs = (isRelAbs || isSourceAbs ||\n (source.host && relative.pathname)),\n removeAllDots = mustEndAbs,\n srcPath = source.pathname && source.pathname.split('/') || [],\n relPath = relative.pathname && relative.pathname.split('/') || [],\n psychotic = source.protocol &&\n !slashedProtocol[source.protocol];\n\n // if the url is a non-slashed url, then relative\n // links like ../.. should be able\n // to crawl up to the hostname, as well. This is strange.\n // source.protocol has already been set by now.\n // Later on, put the first path part into the host field.\n if (psychotic) {\n\n delete source.hostname;\n delete source.port;\n if (source.host) {\n if (srcPath[0] === '') srcPath[0] = source.host;\n else srcPath.unshift(source.host);\n }\n delete source.host;\n if (relative.protocol) {\n delete relative.hostname;\n delete relative.port;\n if (relative.host) {\n if (relPath[0] === '') relPath[0] = relative.host;\n else relPath.unshift(relative.host);\n }\n delete relative.host;\n }\n mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');\n }\n\n if (isRelAbs) {\n // it's absolute.\n source.host = (relative.host || relative.host === '') ?\n relative.host : source.host;\n source.hostname = (relative.hostname || relative.hostname === '') ?\n relative.hostname : source.hostname;\n source.search = relative.search;\n source.query = relative.query;\n srcPath = relPath;\n // fall through to the dot-handling below.\n } else if (relPath.length) {\n // it's relative\n // throw away the existing file, and take the new path instead.\n if (!srcPath) srcPath = [];\n srcPath.pop();\n srcPath = srcPath.concat(relPath);\n source.search = relative.search;\n source.query = relative.query;\n } else if ('search' in relative) {\n // just pull out the search.\n // like href='?foo'.\n // Put this after the other two cases because it simplifies the booleans\n if (psychotic) {\n source.hostname = source.host = srcPath.shift();\n //occationaly the auth can get stuck only in host\n //this especialy happens in cases like\n //url.resolveObject('mailto:local1@domain1', 'local2@domain2')\n var authInHost = source.host && arrayIndexOf(source.host, '@') > 0 ?\n source.host.split('@') : false;\n if (authInHost) {\n source.auth = authInHost.shift();\n source.host = source.hostname = authInHost.shift();\n }\n }\n source.search = relative.search;\n source.query = relative.query;\n //to support http.request\n if (source.pathname !== undefined || source.search !== undefined) {\n source.path = (source.pathname ? source.pathname : '') +\n (source.search ? source.search : '');\n }\n source.href = urlFormat(source);\n return source;\n }\n if (!srcPath.length) {\n // no path at all. easy.\n // we've already handled the other stuff above.\n delete source.pathname;\n //to support http.request\n if (!source.search) {\n source.path = '/' + source.search;\n } else {\n delete source.path;\n }\n source.href = urlFormat(source);\n return source;\n }\n // if a url ENDs in . or .., then it must get a trailing slash.\n // however, if it ends in anything else non-slashy,\n // then it must NOT get a trailing slash.\n var last = srcPath.slice(-1)[0];\n var hasTrailingSlash = (\n (source.host || relative.host) && (last === '.' || last === '..') ||\n last === '');\n\n // strip single dots, resolve double dots to parent dir\n // if the path tries to go above the root, `up` ends up > 0\n var up = 0;\n for (var i = srcPath.length; i >= 0; i--) {\n last = srcPath[i];\n if (last == '.') {\n srcPath.splice(i, 1);\n } else if (last === '..') {\n srcPath.splice(i, 1);\n up++;\n } else if (up) {\n srcPath.splice(i, 1);\n up--;\n }\n }\n\n // if the path is allowed to go above the root, restore leading ..s\n if (!mustEndAbs && !removeAllDots) {\n for (; up--; up) {\n srcPath.unshift('..');\n }\n }\n\n if (mustEndAbs && srcPath[0] !== '' &&\n (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {\n srcPath.unshift('');\n }\n\n if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {\n srcPath.push('');\n }\n\n var isAbsolute = srcPath[0] === '' ||\n (srcPath[0] && srcPath[0].charAt(0) === '/');\n\n // put the host back\n if (psychotic) {\n source.hostname = source.host = isAbsolute ? '' :\n srcPath.length ? srcPath.shift() : '';\n //occationaly the auth can get stuck only in host\n //this especialy happens in cases like\n //url.resolveObject('mailto:local1@domain1', 'local2@domain2')\n var authInHost = source.host && arrayIndexOf(source.host, '@') > 0 ?\n source.host.split('@') : false;\n if (authInHost) {\n source.auth = authInHost.shift();\n source.host = source.hostname = authInHost.shift();\n }\n }\n\n mustEndAbs = mustEndAbs || (source.host && srcPath.length);\n\n if (mustEndAbs && !isAbsolute) {\n srcPath.unshift('');\n }\n\n source.pathname = srcPath.join('/');\n //to support request.http\n if (source.pathname !== undefined || source.search !== undefined) {\n source.path = (source.pathname ? source.pathname : '') +\n (source.search ? source.search : '');\n }\n source.auth = relative.auth || source.auth;\n source.slashes = source.slashes || relative.slashes;\n source.href = urlFormat(source);\n return source;\n}\n\nfunction parseHost(host) {\n var out = {};\n var port = portPattern.exec(host);\n if (port) {\n port = port[0];\n out.port = port.substr(1);\n host = host.substr(0, host.length - port.length);\n }\n if (host) out.hostname = host;\n return out;\n}\n\n//@ sourceURL=url")),n.define("querystring",Function(["require","module","exports","__dirname","__filename","process","global"],"var isArray = typeof Array.isArray === 'function'\n ? Array.isArray\n : function (xs) {\n return Object.prototype.toString.call(xs) === '[object Array]'\n };\n\nvar objectKeys = Object.keys || function objectKeys(object) {\n if (object !== Object(object)) throw new TypeError('Invalid object');\n var keys = [];\n for (var key in object) if (object.hasOwnProperty(key)) keys[keys.length] = key;\n return keys;\n}\n\n\n/*!\n * querystring\n * Copyright(c) 2010 TJ Holowaychuk <[email protected]>\n * MIT Licensed\n */\n\n/**\n * Library version.\n */\n\nexports.version = '0.3.1';\n\n/**\n * Object#toString() ref for stringify().\n */\n\nvar toString = Object.prototype.toString;\n\n/**\n * Cache non-integer test regexp.\n */\n\nvar notint = /[^0-9]/;\n\n/**\n * Parse the given query `str`, returning an object.\n *\n * @param {String} str\n * @return {Object}\n * @api public\n */\n\nexports.parse = function(str){\n if (null == str || '' == str) return {};\n\n function promote(parent, key) {\n if (parent[key].length == 0) return parent[key] = {};\n var t = {};\n for (var i in parent[key]) t[i] = parent[key][i];\n parent[key] = t;\n return t;\n }\n\n return String(str)\n .split('&')\n .reduce(function(ret, pair){\n try{ \n pair = decodeURIComponent(pair.replace(/\\+/g, ' '));\n } catch(e) {\n // ignore\n }\n\n var eql = pair.indexOf('=')\n , brace = lastBraceInKey(pair)\n , key = pair.substr(0, brace || eql)\n , val = pair.substr(brace || eql, pair.length)\n , val = val.substr(val.indexOf('=') + 1, val.length)\n , parent = ret;\n\n // ?foo\n if ('' == key) key = pair, val = '';\n\n // nested\n if (~key.indexOf(']')) {\n var parts = key.split('[')\n , len = parts.length\n , last = len - 1;\n\n function parse(parts, parent, key) {\n var part = parts.shift();\n\n // end\n if (!part) {\n if (isArray(parent[key])) {\n parent[key].push(val);\n } else if ('object' == typeof parent[key]) {\n parent[key] = val;\n } else if ('undefined' == typeof parent[key]) {\n parent[key] = val;\n } else {\n parent[key] = [parent[key], val];\n }\n // array\n } else {\n obj = parent[key] = parent[key] || [];\n if (']' == part) {\n if (isArray(obj)) {\n if ('' != val) obj.push(val);\n } else if ('object' == typeof obj) {\n obj[objectKeys(obj).length] = val;\n } else {\n obj = parent[key] = [parent[key], val];\n }\n // prop\n } else if (~part.indexOf(']')) {\n part = part.substr(0, part.length - 1);\n if(notint.test(part) && isArray(obj)) obj = promote(parent, key);\n parse(parts, obj, part);\n // key\n } else {\n if(notint.test(part) && isArray(obj)) obj = promote(parent, key);\n parse(parts, obj, part);\n }\n }\n }\n\n parse(parts, parent, 'base');\n // optimize\n } else {\n if (notint.test(key) && isArray(parent.base)) {\n var t = {};\n for(var k in parent.base) t[k] = parent.base[k];\n parent.base = t;\n }\n set(parent.base, key, val);\n }\n\n return ret;\n }, {base: {}}).base;\n};\n\n/**\n * Turn the given `obj` into a query string\n *\n * @param {Object} obj\n * @return {String}\n * @api public\n */\n\nvar stringify = exports.stringify = function(obj, prefix) {\n if (isArray(obj)) {\n return stringifyArray(obj, prefix);\n } else if ('[object Object]' == toString.call(obj)) {\n return stringifyObject(obj, prefix);\n } else if ('string' == typeof obj) {\n return stringifyString(obj, prefix);\n } else {\n return prefix;\n }\n};\n\n/**\n * Stringify the given `str`.\n *\n * @param {String} str\n * @param {String} prefix\n * @return {String}\n * @api private\n */\n\nfunction stringifyString(str, prefix) {\n if (!prefix) throw new TypeError('stringify expects an object');\n return prefix + '=' + encodeURIComponent(str);\n}\n\n/**\n * Stringify the given `arr`.\n *\n * @param {Array} arr\n * @param {String} prefix\n * @return {String}\n * @api private\n */\n\nfunction stringifyArray(arr, prefix) {\n var ret = [];\n if (!prefix) throw new TypeError('stringify expects an object');\n for (var i = 0; i < arr.length; i++) {\n ret.push(stringify(arr[i], prefix + '[]'));\n }\n return ret.join('&');\n}\n\n/**\n * Stringify the given `obj`.\n *\n * @param {Object} obj\n * @param {String} prefix\n * @return {String}\n * @api private\n */\n\nfunction stringifyObject(obj, prefix) {\n var ret = []\n , keys = objectKeys(obj)\n , key;\n for (var i = 0, len = keys.length; i < len; ++i) {\n key = keys[i];\n ret.push(stringify(obj[key], prefix\n ? prefix + '[' + encodeURIComponent(key) + ']'\n : encodeURIComponent(key)));\n }\n return ret.join('&');\n}\n\n/**\n * Set `obj`'s `key` to `val` respecting\n * the weird and wonderful syntax of a qs,\n * where \"foo=bar&foo=baz\" becomes an array.\n *\n * @param {Object} obj\n * @param {String} key\n * @param {String} val\n * @api private\n */\n\nfunction set(obj, key, val) {\n var v = obj[key];\n if (undefined === v) {\n obj[key] = val;\n } else if (isArray(v)) {\n v.push(val);\n } else {\n obj[key] = [v, val];\n }\n}\n\n/**\n * Locate last brace in `str` within the key.\n *\n * @param {String} str\n * @return {Number}\n * @api private\n */\n\nfunction lastBraceInKey(str) {\n var len = str.length\n , brace\n , c;\n for (var i = 0; i < len; ++i) {\n c = str[i];\n if (']' == c) brace = false;\n if ('[' == c) brace = true;\n if ('=' == c && !brace) return i;\n }\n}\n\n//@ sourceURL=querystring")),n.define("/app.js",Function(["require","module","exports","__dirname","__filename","process","global"],"var createGame = require('voxel-engine')\nvar simplex = require('voxel-simplex-terrain')\nvar url = require('url')\nvar chunkSize = 32\nvar chunkDistance = 3\n\nvar seed\nvar parsedURL = url.parse(window.location.href, true)\nif (parsedURL.query) seed = parsedURL.query.seed\n\nwindow.generator = simplex({seed: seed, scaleFactor: 10, chunkDistance: chunkDistance})\nwindow.game = createGame({\n generateVoxelChunk: generator,\n materials: ['grass', 'obsidian', 'dirt', 'whitewool', 'crate', 'brick'],\n cubeSize: 25,\n chunkSize: chunkSize,\n chunkDistance: chunkDistance,\n startingPosition: [0, 3000, 1000],\n worldOrigin: [0,0,0],\n controlOptions: {jump: 6}\n})\n\n// point camera down initially\ngame.controls.pitchObject.rotation.x = -1.5\n\ngame.on('collision', function (item) {\n game.removeItem(item)\n})\n\nvar currentMaterial = 1\n\nfunction createDebris (pos, value) {\n var mesh = new game.THREE.Mesh(\n new game.THREE.CubeGeometry(4, 4, 4),\n game.material\n )\n mesh.geometry.faces.forEach(function (face) {\n face.materialIndex = value - 1\n })\n mesh.translateX(pos.x)\n mesh.translateY(pos.y)\n mesh.translateZ(pos.z)\n \n return {\n mesh: mesh,\n size: 4,\n collisionRadius: 22,\n value: value\n }\n}\n\nfunction explode (pos, value) {\n if (!value) return\n var item = createDebris(pos, value)\n item.velocity = {\n x: (Math.random() * 2 - 1) * 0.05,\n y: (Math.random() * 2 - 1) * 0.05,\n z: (Math.random() * 2 - 1) * 0.05,\n }\n game.addItem(item)\n setTimeout(function (item) {\n game.removeItem(item)\n }, 15 * 1000 + Math.random() * 15 * 1000, item)\n}\n\ngame.appendTo('body')\n\ngame.on('mousedown', function (pos) {\n var cid = game.voxels.chunkAtPosition(pos)\n var vid = game.voxels.voxelAtPosition(pos)\n if (erase) {\n explode(pos, game.getBlock(pos))\n game.setBlock(pos, 0)\n } else {\n game.createBlock(pos, currentMaterial)\n }\n})\n\nvar erase = true\nwindow.addEventListener('keydown', function (ev) {\n if (ev.keyCode === 'X'.charCodeAt(0)) {\n erase = !erase\n }\n ctrlDown = ev.ctrlKey\n})\n\nfunction ctrlToggle (ev) { erase = !ev.ctrlKey }\nwindow.addEventListener('keyup', ctrlToggle)\nwindow.addEventListener('keydown', ctrlToggle)\n\ngame.requestPointerLock('canvas')\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