UNPKG

voxel-spider

Version:

blocky spider creatures for your voxel.js game

232 lines (193 loc) 1.41 MB
(function(){var require = function (file, cwd) { var resolved = require.resolve(file, cwd || '/'); var mod = require.modules[resolved]; if (!mod) throw new Error( 'Failed to resolve module ' + file + ', tried ' + resolved ); var cached = require.cache[resolved]; var res = cached? cached.exports : mod(); return res; }; require.paths = []; require.modules = {}; require.cache = {}; require.extensions = [".js",".coffee",".json"]; require._core = { 'assert': true, 'events': true, 'fs': true, 'path': true, 'vm': true }; require.resolve = (function () { return function (x, cwd) { if (!cwd) cwd = '/'; if (require._core[x]) return x; var path = require.modules.path(); cwd = path.resolve('/', cwd); var y = cwd || '/'; if (x.match(/^(?:\.\.?\/|\/)/)) { var m = loadAsFileSync(path.resolve(y, x)) || loadAsDirectorySync(path.resolve(y, x)); if (m) return m; } var n = loadNodeModulesSync(x, y); if (n) return n; throw new Error("Cannot find module '" + x + "'"); function loadAsFileSync (x) { x = path.normalize(x); if (require.modules[x]) { return x; } for (var i = 0; i < require.extensions.length; i++) { var ext = require.extensions[i]; if (require.modules[x + ext]) return x + ext; } } function loadAsDirectorySync (x) { x = x.replace(/\/+$/, ''); var pkgfile = path.normalize(x + '/package.json'); if (require.modules[pkgfile]) { var pkg = require.modules[pkgfile](); var b = pkg.browserify; if (typeof b === 'object' && b.main) { var m = loadAsFileSync(path.resolve(x, b.main)); if (m) return m; } else if (typeof b === 'string') { var m = loadAsFileSync(path.resolve(x, b)); if (m) return m; } else if (pkg.main) { var m = loadAsFileSync(path.resolve(x, pkg.main)); if (m) return m; } } return loadAsFileSync(x + '/index'); } function loadNodeModulesSync (x, start) { var dirs = nodeModulesPathsSync(start); for (var i = 0; i < dirs.length; i++) { var dir = dirs[i]; var m = loadAsFileSync(dir + '/' + x); if (m) return m; var n = loadAsDirectorySync(dir + '/' + x); if (n) return n; } var m = loadAsFileSync(x); if (m) return m; } function nodeModulesPathsSync (start) { var parts; if (start === '/') parts = [ '' ]; else parts = path.normalize(start).split('/'); var dirs = []; for (var i = parts.length - 1; i >= 0; i--) { if (parts[i] === 'node_modules') continue; var dir = parts.slice(0, i + 1).join('/') + '/node_modules'; dirs.push(dir); } return dirs; } }; })(); require.alias = function (from, to) { var path = require.modules.path(); var res = null; try { res = require.resolve(from + '/package.json', '/'); } catch (err) { res = require.resolve(from, '/'); } var basedir = path.dirname(res); var keys = (Object.keys || function (obj) { var res = []; for (var key in obj) res.push(key); return res; })(require.modules); for (var i = 0; i < keys.length; i++) { var key = keys[i]; if (key.slice(0, basedir.length + 1) === basedir + '/') { var f = key.slice(basedir.length); require.modules[to + f] = require.modules[basedir + f]; } else if (key === basedir) { require.modules[to] = require.modules[basedir]; } } }; (function () { var process = {}; var global = typeof window !== 'undefined' ? window : {}; var definedProcess = false; require.define = function (filename, fn) { if (!definedProcess && require.modules.__browserify_process) { process = require.modules.__browserify_process(); definedProcess = true; } var dirname = require._core[filename] ? '' : require.modules.path().dirname(filename) ; var require_ = function (file) { var requiredModule = require(file, dirname); var cached = require.cache[require.resolve(file, dirname)]; if (cached && cached.parent === null) { cached.parent = module_; } return requiredModule; }; require_.resolve = function (name) { return require.resolve(name, dirname); }; require_.modules = require.modules; require_.define = require.define; require_.cache = require.cache; var module_ = { id : filename, filename: filename, exports : {}, loaded : false, parent: null }; require.modules[filename] = function () { require.cache[filename] = module_; fn.call( module_.exports, require_, module_, module_.exports, dirname, filename, process, global ); module_.loaded = true; return module_.exports; }; }; })(); require.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" )); require.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" )); require.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" )); require.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 control = require('voxel-control')\n\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 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 kb = require('kb-controls')\nvar AXES = ['x', 'y', 'z']\nvar physical = require('voxel-physical')\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.mesher = opts.mesher || voxel.meshers.greedy\n this.materialType = opts.materialType || THREE.MeshLambertMaterial\n this.materialParams = opts.materialParams || {}\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\n if (!opts.lightsDisabled) this.addLights(this.scene)\n this.skyColor = opts.skyColor || 0xBFD1E5\n this.fogScale = opts.fogScale || 1\n this.collideVoxels = collisions(\n this.getTileAtIJK.bind(this),\n this.cubeSize,\n [Infinity, Infinity, Infinity],\n [-Infinity, -Infinity, -Infinity]\n )\n\n this.spatial = new SpatialEventEmitter\n this.region = regionChange(this.spatial, aabb([0, 0, 0], [this.cubeSize, this.cubeSize, this.cubeSize]), this.chunkSize)\n this.voxelRegion = regionChange(this.spatial, this.cubeSize)\n this.chunkRegion = regionChange(this.spatial, this.cubeSize * this.chunkSize)\n // contains chunks that has had an update this tick. Will be generated right before redrawing the frame\n this.chunksNeedsUpdate = {}\n\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\n if (process.browser) {\n this.materials.load(opts.materials || [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'])\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 // client side only\n if (!process.browser) { return }\n \n this.initializeRendering()\n for(var chunkIndex in this.voxels.chunks) {\n this.showChunk(this.voxels.chunks[chunkIndex])\n }\n\n // player control\n this.buttons = kb(document.body, opts.keybindings || this.defaultButtons)\n this.buttons.disable()\n this.optout = false\n this.interact = interact(this.element)\n this.interact\n .on('attain', this.onControlChange.bind(this, true))\n .on('release', this.onControlChange.bind(this, false))\n .on('opt-out', this.onControlOptOut.bind(this))\n\n opts.controls = opts.controls || {}\n opts.controls.onfire = this.onFire.bind(this)\n this.controls = control(this.buttons, opts.controls)\n this.items.push(this.controls)\n this.controlling = null\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.defaultButtons = {\n 'W': 'forward'\n, 'A': 'left'\n, 'S': 'backward'\n, 'D': 'right'\n, '<mouse 1>': 'fire'\n, '<mouse 2>': 'firealt'\n, '<space>': 'jump'\n, '<control>': 'alt'\n}\n\nvar temporaryPosition = new THREE.Vector3\n , temporaryVector = new THREE.Vector3\n\nGame.prototype.cameraPosition = function() {\n temporaryPosition.multiplyScalar(0)\n this.camera.matrixWorld.multiplyVector3(temporaryPosition)\n return temporaryPosition \n}\n\nGame.prototype.cameraVector = function() {\n temporaryVector.multiplyScalar(0)\n temporaryVector.z = -1\n this.camera.matrixWorld.multiplyVector3(temporaryVector)\n temporaryVector.subSelf(this.cameraPosition()).normalize()\n return temporaryVector\n}\n\nGame.prototype.makePhysical = function(target, envelope, blocksCreation) {\n var obj = physical(target, this.potentialCollisionSet(), envelope || new THREE.Vector3(\n this.cubeSize / 2, this.cubeSize * 1.5, this.cubeSize / 2\n ))\n obj.blocksCreation = !!blocksCreation\n return obj\n}\n\nGame.prototype.control = function(target) {\n this.controlling = target\n return this.controls.target(target)\n}\n\nGame.prototype.potentialCollisionSet = function() {\n return [{ collide: this.collideTerrain.bind(this) }]\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.worldspaceToTilespace = function(pos) {\n return {\n i: Math.floor(pos.x / this.cubeSize),\n j: Math.floor(pos.y / this.cubeSize),\n k: Math.floor(pos.z / 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 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.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 return mesh\n}\n\nGame.prototype.addVoxelMarker = function(i, j, k, color) {\n var pos = this.tilespaceToWorldspace(i, j, k)\n , bbox = aabb([pos.x, pos.y, pos.z], [this.cubeSize, this.cubeSize, this.cubeSize])\n\n return this.addAABBMarker(bbox, color)\n}\n\nGame.prototype.addItem = function(item) {\n if(!item.tick) {\n var newItem = physical(\n item.mesh,\n this.potentialCollisionSet.bind(this),\n new THREE.Vector3(item.size, item.size, item.size)\n )\n\n if(item.velocity) {\n newItem.velocity.copy(item.velocity)\n newItem.subjectTo(new THREE.Vector3(0, -9.8/100000, 0))\n } \n\n newItem.repr = function() { return 'debris' }\n newItem.mesh = item.mesh\n\n item = newItem \n }\n\n this.items.push(item)\n if(item.mesh) {\n this.scene.add(item.mesh)\n }\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 if(item.mesh) {\n this.scene.remove(item.mesh)\n }\n}\n\nGame.prototype.onControlChange = function(gained, stream) {\n console.log('control '+(gained ? 'gained' : 'lost'))\n if(!gained && !this.optout) {\n this.buttons.disable()\n return\n }\n\n this.buttons.enable()\n stream.pipe(this.controls.createWriteRotationStream())\n}\n\nGame.prototype.onControlOptOut = function() {\n this.optout = true\n}\n\nGame.prototype.onFire = function(state) {\n this.emit('fire', this.controlling, state)\n}\n\nGame.prototype.raycast = \nGame.prototype.intersectAllMeshes = function(start, direction, maxDistance) {\n if(!start.clone) {\n return this.raycast(this.cameraPosition(), this.cameraVector(), 10000)\n }\n\n var ray = new THREE.Raycaster(start, direction, 0, maxDistance)\n , curMaxDist = Infinity\n , curMaxIDX = null\n , meshes = []\n , idx = 0\n , intersections\n , closest\n , point\n\n for(var key in this.voxels.meshes) {\n meshes[idx++] = this.voxels.meshes[key][this.meshType]\n }\n\n intersections = ray.intersectObjects(meshes)\n if(!intersections.length) {\n return false\n }\n \n for(var i = 0, len = intersections.length; i < len; ++i) {\n if(intersections[i].distance < curMaxDist) {\n curMaxDist = intersections[i].distance\n curMaxIDX = i\n }\n }\n\n closest = intersections[curMaxIDX]\n\n point = new THREE.Vector3\n\n point.copy(closest.point)\n point.intersect = closest\n point.direction = direction\n point.chunkMatrix = this.chunkGroups.chunkMatricies[closest.object.id] || null\n point.addSelf(direction)\n return point\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.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.addLights = function(scene) {\n var ambientLight, directionalLight\n ambientLight = new THREE.AmbientLight(0xcccccc)\n scene.add(ambientLight)\n var light\t= new THREE.DirectionalLight( 0xffffff , 1)\n light.position.set( 1, 1, 0.5 ).normalize()\n scene.add( light )\n};\n\nGame.prototype.checkBlock = function(pos) {\n var floored = pos.clone().multiplyScalar(1 / this.cubeSize)\n var bbox\n\n floored.x = Math.floor(floored.x)\n floored.y = Math.floor(floored.y)\n floored.z = Math.floor(floored.z)\n\n bbox = aabb([floored.x * this.cubeSize, floored.y * this.cubeSize, floored.z * this.cubeSize], [this.cubeSize, this.cubeSize, this.cubeSize])\n\n for (var i = 0, len = this.items.length; i < len; ++i) {\n if (this.items[i].blocksCreation && this.items[i].aabb && bbox.intersects(this.items[i].aabb())) {\n return\n }\n }\n\n var chunkKeyArr = this.voxels.chunkAtPosition(pos)\n var chunkKey = chunkKeyArr.join('|')\n var chunk = this.voxels.chunks[chunkKey]\n\n if(!chunk) {\n return\n }\n\n var chunkPosition = this.chunkspaceToTilespace(chunk.position)\n var voxelPosition = new THREE.Vector3(\n floored.x - chunkPosition.i,\n floored.y - chunkPosition.j,\n floored.z - chunkPosition.k \n )\n\n return {chunkIndex: chunkKey, voxelVector: voxelPosition}\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 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.collideTerrain = function(other, bbox, vec, resting) {\n var spatial = this.spatial\n , vec3 = [vec.x, vec.y, vec.z]\n\n i = 0\n var self = this\n\n this.collideVoxels(bbox, vec3, function hit(axis, tile, coords, dir, edge) {\n if(!tile) {\n return\n }\n\n if(Math.abs(vec3[axis]) < Math.abs(edge)) {\n return\n }\n\n vec3[axis] = vec[AXES[axis]] = edge\n other.acceleration[AXES[axis]] = 0\n\n resting[AXES[axis]] = dir \n\n other.friction[AXES[(axis + 1) % 3]] = \n other.friction[AXES[(axis + 2) % 3]] = axis === 1 ? 0.5 : 1.\n return true\n })\n}\n\nGame.prototype.tick = function(delta) {\n for(var i = 0, len = this.items.length; i < len; ++i) {\n this.items[i].tick(delta)\n }\n if (this.materials) {\n this.materials.tick()\n }\n if (Object.keys(this.chunksNeedsUpdate).length > 0) {\n this.updateDirtyChunks()\n }\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" )); require.define("/node_modules/voxel-engine/node_modules/voxel/package.json",Function(['require','module','exports','__dirname','__filename','process','global'],"module.exports = {\"main\":\"index.js\"}\n//@ sourceURL=/node_modules/voxel-engine/node_modules/voxel/package.json" )); require.define("/node_modules/voxel-engine/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-engine/node_modules/voxel/index.js" )); require.define("/node_modules/voxel-engine/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-engine/node_modules/voxel/chunker.js" )); require.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" )); require.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" )); require.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" )); require.define("/node_modules/voxel-engine/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-engine/node_modules/voxel/meshers/culled.js" )); require.define("/node_modules/voxel-engine/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 i