From 9625531bad2be64a123133bb566055f89ecaf4e4 Mon Sep 17 00:00:00 2001 From: Chris Kelley Date: Mon, 13 May 2013 15:46:46 +0200 Subject: [PATCH 001/256] bump 3.js to 0.58.9 and voxel-view to repository --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7473b3d..0ba2e77 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "dependencies": { "voxel": "0.3.1", "voxel-mesh": "0.2.1", - "voxel-view": "0.0.6", + "voxel-view": "git://github.com/snagy/voxel-view.git", "voxel-chunks": "0.0.2", "voxel-raycast": "0.2.1", "voxel-control": "0.0.7", @@ -17,7 +17,7 @@ "voxel-physical": "0.0.8", "voxel-region-change": "0.1.0", "raf": "0.0.1", - "three": "0.56.0", + "three": "0.58.9", "pin-it": "0.0.1", "aabb-3d": "0.0.0", "inherits": "1.0.0", From 3e7058da5eaf8c9db4d1e428b6fd6b4bd8dfd3cf Mon Sep 17 00:00:00 2001 From: Chris Kelley Date: Mon, 13 May 2013 16:27:13 +0200 Subject: [PATCH 002/256] Checking for browser when loading materials Blows up in server otherwise. --- index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 918756e..1437cc5 100644 --- a/index.js +++ b/index.js @@ -86,13 +86,15 @@ function Game(opts) { this.chunksNeedsUpdate = {} // contains new chunks yet to be generated. Handled by game.loadPendingChunks this.pendingChunks = [] - - this.materials = texture({ - game: this, - texturePath: opts.texturePath || './textures/', - materialType: opts.materialType || THREE.MeshLambertMaterial, - materialParams: opts.materialParams || {} - }) + + if (process.browser) { + this.materials = texture({ + game: this, + texturePath: opts.texturePath || './textures/', + materialType: opts.materialType || THREE.MeshLambertMaterial, + materialParams: opts.materialParams || {} + }) + } this.materialNames = opts.materials || [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'] From 0f57d9dfbe095ce86f182d2e70c2c0a1f7927ca9 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Mon, 8 Jul 2013 16:08:29 -0500 Subject: [PATCH 003/256] initial version --- .gitignore | 15 +++++++++ LICENSE | 22 +++++++++++++ index.js | 80 +++++++++++++++++++++++++++++++++++++++++++++++ lib/createMesh.js | 73 ++++++++++++++++++++++++++++++++++++++++++ lib/examples.js | 72 ++++++++++++++++++++++++++++++++++++++++++ lib/wireShader.js | 16 ++++++++++ 6 files changed, 278 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 index.js create mode 100644 lib/createMesh.js create mode 100644 lib/examples.js create mode 100644 lib/wireShader.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d1b0b0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz + +pids +logs +results + +npm-debug.log +node_modules/* \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8ce206a --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ + +The MIT License (MIT) + +Copyright (c) 2013 Mikola Lysenko + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/index.js b/index.js new file mode 100644 index 0000000..08dfcef --- /dev/null +++ b/index.js @@ -0,0 +1,80 @@ +"use strict" + +var shell = require("gl-now")() +var camera = require("game-shell-orbit-camera")(shell) +var createTileMap = require("gl-tile-map") +var ndarray = require("ndarray") +var terrain = require("isabella-texture-pack") +var createWireShader = require("./lib/wireShader.js") +var createAOShader = require("ao-shader") +var examples = require("./lib/examples.js") +var createVoxelMesh = require("./lib/createMesh.js") +var glm = require("gl-matrix") +var mat4 = glm.mat4 + +//Tile size parameters +var TILE_SIZE = Math.floor(terrain.shape[0] / 16)|0 + +//Config variables +var texture, shader, mesh, wireShader + +function selectMesh(name) { + mesh = createVoxelMesh(shell.gl, name, examples[name]) + var c = mesh.center + camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) +} + +shell.on("gl-init", function() { + var gl = shell.gl + + //Create shaders + shader = createAOShader(gl) + wireShader = createWireShader(gl) + + //Select bunny mesh + selectMesh("terrain") + + //Create texture atlas + var tiles = ndarray(terrain.data, + [16,16,terrain.shape[0]>>4,terrain.shape[1]>>4,4], + [terrain.stride[0]*16, terrain.stride[1]*16, terrain.stride[0], terrain.stride[1], terrain.stride[2]], 0) + texture = createTileMap(gl, tiles, 2) + texture.mipSamples = 4 +}) + +shell.on("gl-render", function(t) { + var gl = shell.gl + + //Calculation projection matrix + var projection = mat4.perspective(new Float32Array(16), Math.PI/4.0, shell.width/shell.height, 1.0, 1000.0) + var model = mat4.identity(new Float32Array(16)) + var view = camera.view() + + gl.enable(gl.CULL_FACE) + gl.enable(gl.DEPTH_TEST) + + //Bind the shader + shader.bind() + shader.attributes.attrib0.location = 0 + shader.attributes.attrib1.location = 1 + shader.uniforms.projection = projection + shader.uniforms.view = view + shader.uniforms.model = model + shader.uniforms.tileSize = TILE_SIZE + shader.uniforms.tileMap = texture.bind() + + mesh.triangleVAO.bind() + gl.drawArrays(gl.TRIANGLES, 0, mesh.triangleVertexCount) + mesh.triangleVAO.unbind() + + //Bind the wire shader + wireShader.bind() + wireShader.attributes.position.location = 0 + wireShader.uniforms.projection = projection + wireShader.uniforms.model = model + wireShader.uniforms.view = view + + mesh.wireVAO.bind() + gl.drawArrays(gl.LINES, 0, mesh.wireVertexCount) + mesh.wireVAO.unbind() +}) diff --git a/lib/createMesh.js b/lib/createMesh.js new file mode 100644 index 0000000..10f0d15 --- /dev/null +++ b/lib/createMesh.js @@ -0,0 +1,73 @@ +"use strict" + +var ndarray = require("ndarray") +var createBuffer = require("gl-buffer") +var createVAO = require("gl-vao") +var createAOMesh = require("ao-mesher") +var ops = require("ndarray-ops") + +var cached = {} + +//Creates a mesh from a set of voxels +function createVoxelMesh(gl, name, voxels) { + if(name in cached) { + return cached[name] + } + + //Create mesh + var vert_data = createAOMesh(voxels) + + //Upload triangle mesh to WebGL + var triangleVertexCount = Math.floor(vert_data.length/8) + var vert_buf = createBuffer(gl, vert_data) + var triangleVAO = createVAO(gl, undefined, [ + { "buffer": vert_buf, + "type": gl.UNSIGNED_BYTE, + "size": 4, + "offset": 0, + "stride": 8, + "normalized": false + }, + { "buffer": vert_buf, + "type": gl.UNSIGNED_BYTE, + "size": 4, + "offset": 4, + "stride": 8, + "normalized": false + } + ]) + + //Create wire mesh + var wireVertexCount = 2 * triangleVertexCount + var wireVertexArray = ndarray(new Uint8Array(wireVertexCount * 3), [triangleVertexCount, 2, 3]) + var trianglePositions = ndarray(vert_data, [triangleVertexCount, 3], [8, 1], 0) + ops.assign(wireVertexArray.pick(undefined, 0, undefined), trianglePositions) + var wires = wireVertexArray.pick(undefined, 1, undefined) + for(var i=0; i<3; ++i) { + ops.assign(wires.lo(i).step(3), trianglePositions.lo((i+1)%3).step(3)) + } + var wireBuf = createBuffer(gl, wireVertexArray.data) + var wireVAO = createVAO(gl, undefined, [ + { "buffer": wireBuf, + "type": gl.UNSIGNED_BYTE, + "size": 3, + "offset": 0, + "stride": 3, + "normalized": false + } + ]) + + //Bundle result and return + var result = { + triangleVertexCount: triangleVertexCount, + triangleVAO: triangleVAO, + wireVertexCount: wireVertexCount, + wireVAO: wireVAO, + center: [voxels.shape[0]>>1, voxels.shape[1]>>1, voxels.shape[2]>>1], + radius: voxels.shape[2] + } + cached[name] = result + return result +} + +module.exports = createVoxelMesh \ No newline at end of file diff --git a/lib/examples.js b/lib/examples.js new file mode 100644 index 0000000..8a35864 --- /dev/null +++ b/lib/examples.js @@ -0,0 +1,72 @@ +"use strict" + +var ndarray = require("ndarray") +var fill = require("ndarray-fill") +var ops = require("ndarray-ops") +var lazyProperty = require("lazy-property") + +//Fill ndarray +function makeFill(name, size, func) { + lazyProperty(exports, name, function() { + var result = ndarray(new Int32Array(size[0]*size[1]*size[2]), size) + fill(result, func) + return result + }, true) +} + +//Sphere +makeFill("sphere", [32,32,32], function(i,j,k) { + var x = i - 16 + var y = j - 16 + var z = k - 16 + return (x*x + y*y + z*z) < 30 ? (1<<15) + 0x81 : 0 +}) + +//Cuboid +makeFill("box", [32,32,32], function(i,j,k) { + var x = Math.abs(i - 16) + var y = Math.abs(j - 16) + var z = Math.abs(k - 16) + return (x*x + y*y + z*z) < 12 ? (1<<15) + 0x19 : 0 +}) + +//Terrain +makeFill("terrain", [33,33,33], function(i,j,k) { + if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { + return 0 + } + var h0 = 3.0 * Math.sin(Math.PI * i / 12.0 - Math.PI * k * 0.1) + 27 + if(j > h0+1) { + return 0 + } + if(h0 <= j) { + return (1<<15)+0x19 + } + var h1 = 2.0 * Math.sin(Math.PI * i * 0.25 - Math.PI * k * 0.3) + 20 + if(h1 <= j) { + return (1<<15)+0x20 + } + if(4 < j) { + return Math.random() < 0.1 ? (1<<15)+0x23 : (1<<15)+0x10 + } + return (1<<15)+0xff +}) + +//Random +makeFill("random", [16,16,16], function(i,j,k) { + if(Math.random() < 0.6) { + return 0 + } + return ((Math.random()*255)|0) + (1<<15) +}) + +/* +//Create a bunny +var bunny = require("bunny") +var voxelize = require("voxelize") +lazyProperty(exports, "bunny", function() { + var result = voxelize(bunny.cells, bunny.positions, 0.1) + ops.mulseq(result.voxels, (1<<15)+0x10) + return result.voxels +}, true) +*/ \ No newline at end of file diff --git a/lib/wireShader.js b/lib/wireShader.js new file mode 100644 index 0000000..fbef92a --- /dev/null +++ b/lib/wireShader.js @@ -0,0 +1,16 @@ +"use strict" +var createShader = require("gl-shader") + +module.exports = function(gl) { + return createShader(gl, +"attribute vec3 position;\ +uniform mat4 projection;\ +uniform mat4 view;\ +uniform mat4 model;\ +void main() {\ + gl_Position=projection * view * model * vec4(position, 1.0);\ +}", +"void main() {\ + gl_FragColor = vec4(0, 1, 0, 1);\ +}") +} \ No newline at end of file From d6060b00c74720daf4f94c2e65746c329be3491d Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Mon, 8 Jul 2013 21:26:08 -0500 Subject: [PATCH 004/256] added github ribbon --- index.html | 31 +++++++++++++++++++ lib/examples.js | 50 ++++++++++++++++++++----------- main.css | 12 ++++++++ index.js => main.js | 73 +++++++++++++++++++++++++++++++++++---------- package.json | 47 +++++++++++++++++++++++++++++ 5 files changed, 181 insertions(+), 32 deletions(-) create mode 100644 index.html create mode 100644 main.css rename index.js => main.js (56%) create mode 100644 package.json diff --git a/index.html b/index.html new file mode 100644 index 0000000..b7d18a1 --- /dev/null +++ b/index.html @@ -0,0 +1,31 @@ + + + + + Voxel Mipmap Demo + + + + Fork me on GitHub +
+

+ + +

+

+ + +

+

+ + +

+
+ + + \ No newline at end of file diff --git a/lib/examples.js b/lib/examples.js index 8a35864..4d44456 100644 --- a/lib/examples.js +++ b/lib/examples.js @@ -3,9 +3,13 @@ var ndarray = require("ndarray") var fill = require("ndarray-fill") var ops = require("ndarray-ops") +var voxelize = require("voxelize") var lazyProperty = require("lazy-property") -//Fill ndarray +var bunny = require("bunny") +var teapot = require("teapot") + +//Fill ndarray with function function makeFill(name, size, func) { lazyProperty(exports, name, function() { var result = ndarray(new Int32Array(size[0]*size[1]*size[2]), size) @@ -14,24 +18,39 @@ function makeFill(name, size, func) { }, true) } +//Fill ndarray with voxelized mesh +function makeMesh(name, mesh, tolerance, fill) { + lazyProperty(exports, name, function() { + var result = voxelize(mesh.cells, mesh.positions, tolerance) + var voxels = result.voxels + var nshape = result.voxels.shape.slice(0) + for(var i=0; i<3; ++i) { + nshape[i] += 2 + } + var padded = ndarray(new Int32Array(nshape[0]*nshape[1]*nshape[2]), nshape) + ops.muls(padded, result.voxels, fill) + return padded + }, true) +} + //Sphere -makeFill("sphere", [32,32,32], function(i,j,k) { +makeFill("Sphere", [32,32,32], function(i,j,k) { var x = i - 16 var y = j - 16 var z = k - 16 - return (x*x + y*y + z*z) < 30 ? (1<<15) + 0x81 : 0 + return (x*x + y*y + z*z) < 30 ? (1<<15) + 0x18 : 0 }) //Cuboid -makeFill("box", [32,32,32], function(i,j,k) { +makeFill("Box", [32,32,32], function(i,j,k) { var x = Math.abs(i - 16) var y = Math.abs(j - 16) var z = Math.abs(k - 16) - return (x*x + y*y + z*z) < 12 ? (1<<15) + 0x19 : 0 + return Math.max(x,y,z) < 13 ? (1<<15) + 0x91 : 0 }) //Terrain -makeFill("terrain", [33,33,33], function(i,j,k) { +makeFill("Terrain", [33,33,33], function(i,j,k) { if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { return 0 } @@ -53,20 +72,17 @@ makeFill("terrain", [33,33,33], function(i,j,k) { }) //Random -makeFill("random", [16,16,16], function(i,j,k) { +makeFill("Random", [16,16,16], function(i,j,k) { + if(i <=1 || i>=14 || j <= 1 || j >= 14 || k <= 1 || k >= 14) { + return 0 + } if(Math.random() < 0.6) { return 0 } return ((Math.random()*255)|0) + (1<<15) }) -/* -//Create a bunny -var bunny = require("bunny") -var voxelize = require("voxelize") -lazyProperty(exports, "bunny", function() { - var result = voxelize(bunny.cells, bunny.positions, 0.1) - ops.mulseq(result.voxels, (1<<15)+0x10) - return result.voxels -}, true) -*/ \ No newline at end of file +//Create meshes +makeMesh("Teapot", teapot, 1.0, (1<<15)+0x81) +makeMesh("Bunny", bunny, 0.1, (1<<15)+0x01) + diff --git a/main.css b/main.css new file mode 100644 index 0000000..464bbfb --- /dev/null +++ b/main.css @@ -0,0 +1,12 @@ +.controlPanel { + position: absolute; + top: 0; + left: 0; + z-index: 10; + background-color: rgba(129, 129, 129, 0.5); + padding-top: 10px; + padding-left: 10px; + padding-right: 10px; + padding-bottom: 10px; + border-radius: 10px; +} diff --git a/index.js b/main.js similarity index 56% rename from index.js rename to main.js index 08dfcef..9a24dc3 100644 --- a/index.js +++ b/main.js @@ -12,18 +12,56 @@ var createVoxelMesh = require("./lib/createMesh.js") var glm = require("gl-matrix") var mat4 = glm.mat4 +//Load selectors +var selectModel = document.querySelector("#selectModel") +var showWire = document.querySelector("#showWire") +var selectMip = document.querySelector("#selectMip") + +//Add options to model select +;(function() { + for(var id in examples) { + var option = document.createElement("option") + option.value = id + option.innerHTML = id + selectModel.add(option) + } +})() + //Tile size parameters var TILE_SIZE = Math.floor(terrain.shape[0] / 16)|0 //Config variables var texture, shader, mesh, wireShader -function selectMesh(name) { +function meshChange() { + var name = selectModel.value mesh = createVoxelMesh(shell.gl, name, examples[name]) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) } +function mipChange() { + var gl = shell.gl + switch(selectMip.value) { + case "none": + texture.magFilter = gl.NEAREST + texture.minFilter = gl.NEAREST + texture.mipSamples = 1 + break + case "linear": + texture.magFilter = gl.LINEAR + texture.minFilter = gl.LINEAR_MIPMAP_LINEAR + texture.mipSamples = 1 + break + case "aniso": + texture.magFilter = gl.LINEAR + texture.minFilter = gl.LINEAR_MIPMAP_LINEAR + texture.mipSamples = 4 + break + } +} + + shell.on("gl-init", function() { var gl = shell.gl @@ -31,15 +69,18 @@ shell.on("gl-init", function() { shader = createAOShader(gl) wireShader = createWireShader(gl) - //Select bunny mesh - selectMesh("terrain") - //Create texture atlas var tiles = ndarray(terrain.data, [16,16,terrain.shape[0]>>4,terrain.shape[1]>>4,4], [terrain.stride[0]*16, terrain.stride[1]*16, terrain.stride[0], terrain.stride[1], terrain.stride[2]], 0) texture = createTileMap(gl, tiles, 2) - texture.mipSamples = 4 + + //Hook event listeners + selectMip.addEventListener("change", mipChange) + mipChange() + + selectModel.addEventListener("change", meshChange) + meshChange() }) shell.on("gl-render", function(t) { @@ -67,14 +108,16 @@ shell.on("gl-render", function(t) { gl.drawArrays(gl.TRIANGLES, 0, mesh.triangleVertexCount) mesh.triangleVAO.unbind() - //Bind the wire shader - wireShader.bind() - wireShader.attributes.position.location = 0 - wireShader.uniforms.projection = projection - wireShader.uniforms.model = model - wireShader.uniforms.view = view - - mesh.wireVAO.bind() - gl.drawArrays(gl.LINES, 0, mesh.wireVertexCount) - mesh.wireVAO.unbind() + if(showWire.checked) { + //Bind the wire shader + wireShader.bind() + wireShader.attributes.position.location = 0 + wireShader.uniforms.projection = projection + wireShader.uniforms.model = model + wireShader.uniforms.view = view + + mesh.wireVAO.bind() + gl.drawArrays(gl.LINES, 0, mesh.wireVertexCount) + mesh.wireVAO.unbind() + } }) diff --git a/package.json b/package.json new file mode 100644 index 0000000..0d4b75e --- /dev/null +++ b/package.json @@ -0,0 +1,47 @@ +{ + "name": "voxel-mipmap-demo", + "version": "0.0.0", + "description": "Demonstration of mipmapping for voxel terrain", + "main": "main.js", + "dependencies": { + "ao-mesher": "~0.2.3", + "game-shell-orbit-camera": "~0.0.0", + "ao-shader": "~0.2.2", + "gl-buffer": "~0.1.0", + "gl-matrix": "~2.0.0", + "gl-now": "~0.0.3", + "gl-shader": "~0.0.5", + "gl-vao": "~0.0.2", + "gl-tile-map": "~0.3.0", + "isabella-texture-pack": "~0.0.1", + "lazy-property": "~0.0.0", + "ndarray": "~1.0.3", + "ndarray-fill": "~0.1.0", + "ndarray-ops": "~1.1.0", + "bunny": "~1.0.0", + "voxelize": "~0.1.0", + "brfs": "0.0.6" + }, + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git://github.com/mikolalysenko/voxel-mipmap-demo.git" + }, + "keywords": [ + "mipmap", + "voxel", + "terrain" + ], + "author": "Mikola Lysenko", + "license": "MIT", + "gitHead": "0f57d9dfbe095ce86f182d2e70c2c0a1f7927ca9", + "bugs": { + "url": "https://github.com/mikolalysenko/voxel-mipmap-demo/issues" + }, + "browser": { + "transform": "brfs" + } +} From 98d58da355894b640be8cb284137b54a96843e4d Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Mon, 8 Jul 2013 21:32:53 -0500 Subject: [PATCH 005/256] added crazy css gradient background --- main.css | 13 +++++++++++++ main.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/main.css b/main.css index 464bbfb..4de62d1 100644 --- a/main.css +++ b/main.css @@ -10,3 +10,16 @@ padding-bottom: 10px; border-radius: 10px; } +html,body{ + font-family: sans-serif; +} +body{ +background: rgb(240,249,255); /* Old browsers */ +background: -moz-linear-gradient(-45deg, rgba(240,249,255,1) 0%, rgba(203,235,255,1) 53%, rgba(161,219,255,1) 100%); /* FF3.6+ */ +background: -webkit-gradient(linear, left top, right bottom, color-stop(0%,rgba(240,249,255,1)), color-stop(53%,rgba(203,235,255,1)), color-stop(100%,rgba(161,219,255,1))); /* Chrome,Safari4+ */ +background: -webkit-linear-gradient(-45deg, rgba(240,249,255,1) 0%,rgba(203,235,255,1) 53%,rgba(161,219,255,1) 100%); /* Chrome10+,Safari5.1+ */ +background: -o-linear-gradient(-45deg, rgba(240,249,255,1) 0%,rgba(203,235,255,1) 53%,rgba(161,219,255,1) 100%); /* Opera 11.10+ */ +background: -ms-linear-gradient(-45deg, rgba(240,249,255,1) 0%,rgba(203,235,255,1) 53%,rgba(161,219,255,1) 100%); /* IE10+ */ +background: linear-gradient(135deg, rgba(240,249,255,1) 0%,rgba(203,235,255,1) 53%,rgba(161,219,255,1) 100%); /* W3C */ +filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f0f9ff', endColorstr='#a1dbff',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */ +} \ No newline at end of file diff --git a/main.js b/main.js index 9a24dc3..9b2fb80 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,6 @@ "use strict" -var shell = require("gl-now")() +var shell = require("gl-now")({clearColor: [0,0,0,0]}) var camera = require("game-shell-orbit-camera")(shell) var createTileMap = require("gl-tile-map") var ndarray = require("ndarray") From d6e313284839113648e4d7ced588ab0b935f36b5 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Mon, 8 Jul 2013 22:03:19 -0500 Subject: [PATCH 006/256] adding css stuff, error page --- index.html | 1 + main.css | 15 +++++++++++++++ main.js | 6 +++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index b7d18a1..1d81a3b 100644 --- a/index.html +++ b/index.html @@ -26,6 +26,7 @@

+
Your browser can't handle WebGL!
\ No newline at end of file diff --git a/main.css b/main.css index 4de62d1..e891f12 100644 --- a/main.css +++ b/main.css @@ -10,6 +10,21 @@ padding-bottom: 10px; border-radius: 10px; } +.noWebGL { + background-color: red; + color: white; + transform:rotate(-37deg); + -ms-transform:rotate(-37deg); + -webkit-transform:rotate(-37deg); + position: absolute; + width: 100%; + font-size: 90; + top: 50%; + text-align: center; + z-index:30; + zoom: 4.0; -moz-transform: scale(4.0); + display: none; +} html,body{ font-family: sans-serif; } diff --git a/main.js b/main.js index 9b2fb80..25a2ebc 100644 --- a/main.js +++ b/main.js @@ -61,7 +61,6 @@ function mipChange() { } } - shell.on("gl-init", function() { var gl = shell.gl @@ -83,6 +82,11 @@ shell.on("gl-init", function() { meshChange() }) +shell.on("gl-error", function() { + document.querySelector(".selectModel").style.display = "none" + document.querySelector(".noWebGL").style.display = "none" +}) + shell.on("gl-render", function(t) { var gl = shell.gl From 771b75eb020d3ff5b6ed02a814c12bf2cc9db46e Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Mon, 8 Jul 2013 22:04:48 -0500 Subject: [PATCH 007/256] adding README --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..3426dbe --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +voxel-mipmap-demo +================= +Demonstration of texture mapping with greedy meshing. + +* Left click rotates +* Right click/shift pans +* Middle click/scroll/alt zooms + +## Credits +(c) 2013 Mikola Lysenko. MIT License From 28437a7b0fd33fd39482701fcb8861c261694baa Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Tue, 9 Jul 2013 00:31:02 -0500 Subject: [PATCH 008/256] upgraded all modules probably --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0d4b75e..c66457e 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "ndarray-ops": "~1.1.0", "bunny": "~1.0.0", "voxelize": "~0.1.0", - "brfs": "0.0.6" + "brfs": "0.0.6", + "teapot": "0.0.1" }, "devDependencies": {}, "scripts": { From 61e75347ba17f35d26828cf5e3e1a3eb7cc75139 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Tue, 9 Jul 2013 00:47:13 -0500 Subject: [PATCH 009/256] added link in readme --- README.md | 2 ++ lib/examples.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 3426dbe..99067ff 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,7 @@ Demonstration of texture mapping with greedy meshing. * Right click/shift pans * Middle click/scroll/alt zooms +[Check it out in your browser](http://mikolalysenko.github.io/voxel-mipmap-demo/) + ## Credits (c) 2013 Mikola Lysenko. MIT License diff --git a/lib/examples.js b/lib/examples.js index 4d44456..c135970 100644 --- a/lib/examples.js +++ b/lib/examples.js @@ -82,6 +82,8 @@ makeFill("Random", [16,16,16], function(i,j,k) { return ((Math.random()*255)|0) + (1<<15) }) +make + //Create meshes makeMesh("Teapot", teapot, 1.0, (1<<15)+0x81) makeMesh("Bunny", bunny, 0.1, (1<<15)+0x01) From 6762f2151c6195a9a9597186ea96d2dfca7a68b1 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Tue, 9 Jul 2013 08:33:58 -0500 Subject: [PATCH 010/256] added a tree --- lib/examples.js | 16 +++++++++++++++- main.css | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/examples.js b/lib/examples.js index c135970..ac9b707 100644 --- a/lib/examples.js +++ b/lib/examples.js @@ -82,7 +82,21 @@ makeFill("Random", [16,16,16], function(i,j,k) { return ((Math.random()*255)|0) + (1<<15) }) -make +makeFill("Tree", [16,16,16], function(i,j,k) { + if(i === 8 && k === 8 && 4 Date: Tue, 9 Jul 2013 10:00:04 -0500 Subject: [PATCH 011/256] adding changed game-shell version --- index.html | 2 +- main.css | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 1d81a3b..db30c97 100644 --- a/index.html +++ b/index.html @@ -26,7 +26,7 @@

-
Your browser can't handle WebGL!
+
Requires WebGL!
\ No newline at end of file diff --git a/main.css b/main.css index cde8b09..a089747 100644 --- a/main.css +++ b/main.css @@ -18,11 +18,10 @@ -webkit-transform:rotate(-37deg); position: absolute; width: 100%; - font-size: 90; + font-size: 90pt; top: 50%; text-align: center; z-index:30; - zoom: 4.0; -moz-transform: scale(4.0); display: none; } html,body{ From c56e3a7ce45226a60a4e5a47a31fcd585944ca13 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Tue, 9 Jul 2013 10:08:20 -0500 Subject: [PATCH 012/256] adding link to blog in README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 99067ff..04e8354 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,9 @@ Demonstration of texture mapping with greedy meshing. [Check it out in your browser](http://mikolalysenko.github.io/voxel-mipmap-demo/) +For more information see the following blog post: + +* [Texture atlases, wrapping and mip mapping](http://0fps.wordpress.com/2013/07/09/texture-atlases-wrapping-and-mip-mapping/) + ## Credits (c) 2013 Mikola Lysenko. MIT License From e2bd9d98d4b69e77874e156260f929543d8d2cc3 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Tue, 9 Jul 2013 12:44:24 -0500 Subject: [PATCH 013/256] used wrong version mesher in demo --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c66457e..a4ebd5a 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "ao-mesher": "~0.2.3", + "ao-mesher": "~0.2.5", "game-shell-orbit-camera": "~0.0.0", - "ao-shader": "~0.2.2", + "ao-shader": "~0.2.3", "gl-buffer": "~0.1.0", "gl-matrix": "~2.0.0", "gl-now": "~0.0.3", From 07634dcb4e5c223ccd2ac7d99c08f5ea0386dacc Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Thu, 11 Jul 2013 12:01:51 -0500 Subject: [PATCH 014/256] added npm start script --- package.json | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index a4ebd5a..90c4e96 100644 --- a/package.json +++ b/package.json @@ -20,12 +20,16 @@ "ndarray-ops": "~1.1.0", "bunny": "~1.0.0", "voxelize": "~0.1.0", - "brfs": "0.0.6", - "teapot": "0.0.1" + "brfs": "~0.0.6", + "teapot": "~0.0.1" + }, + "devDependencies": { + "beefy": "~0.4.0", + "browserify": "~2.25.0" }, - "devDependencies": {}, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "start": "beefy main.js" }, "repository": { "type": "git", From 8235f719beabc8ce9a06a1692a983db13954bc24 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Thu, 11 Jul 2013 12:09:14 -0500 Subject: [PATCH 015/256] added readme stuff --- README.md | 15 +++++++++++++++ package.json | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 04e8354..d5e4d6e 100644 --- a/README.md +++ b/README.md @@ -12,5 +12,20 @@ For more information see the following blog post: * [Texture atlases, wrapping and mip mapping](http://0fps.wordpress.com/2013/07/09/texture-atlases-wrapping-and-mip-mapping/) +## How to run locally +First you will need to install npm, which comes with node.js. You can get that by going to here: + + https://npmjs.org/ + +Then, go into the root directory of the project and type: + + npm install + +Once that is done, you can run the project in your browser by typing: + + npm start + +That will start a local server. To view the demo in your browser, connect to localhost on the port that shows up. For example, http://localhost:9966 + ## Credits (c) 2013 Mikola Lysenko. MIT License diff --git a/package.json b/package.json index 90c4e96..1a7c4b7 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "beefy main.js" + "start": "beefy main.js --open" }, "repository": { "type": "git", From f3a5abbf8a7a82d25ad6abb9bb667454d05f4a51 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Thu, 11 Jul 2013 12:12:57 -0500 Subject: [PATCH 016/256] fixed link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d5e4d6e..fbad754 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ For more information see the following blog post: ## How to run locally First you will need to install npm, which comes with node.js. You can get that by going to here: - https://npmjs.org/ +* [https://nodejs.org/](https://nodejs.org/) Then, go into the root directory of the project and type: From f16e0a73c49a701cf7d28112fe31d5e7d7b3d237 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Thu, 1 Aug 2013 08:50:38 -0700 Subject: [PATCH 017/256] Convert to ndarray --- index.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 44497f0..0d5cca4 100644 --- a/index.js +++ b/index.js @@ -51,8 +51,8 @@ function Game(opts) { this.playerHeight = opts.playerHeight || 1.62 this.meshType = opts.meshType || 'surfaceMesh' this.mesher = opts.mesher || voxel.meshers.culled - this.materialType = opts.materialType || THREE.MeshLambertMaterial - this.materialParams = opts.materialParams || {} + //this.materialType = opts.materialType || THREE.MeshLambertMaterial + //this.materialParams = opts.materialParams || {} this.items = [] this.voxels = voxel(this) this.scene = new THREE.Scene() @@ -86,21 +86,21 @@ function Game(opts) { // contains new chunks yet to be generated. Handled by game.loadPendingChunks this.pendingChunks = [] - this.materials = texture({ + /*this.materials = texture({ game: this, texturePath: opts.texturePath || './textures/', materialType: opts.materialType || THREE.MeshLambertMaterial, materialParams: opts.materialParams || {}, materialFlatColor: opts.materialFlatColor === true - }) - - this.materialNames = opts.materials || [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'] + })*/ + //this.materialNames = opts.materials || [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'] + this.materials = opts.materials self.chunkRegion.on('change', function(newChunk) { self.removeFarChunks() }) - if (process.browser) this.materials.load(this.materialNames) + //if (process.browser) this.materials.load(this.materialNames) if (this.generateChunks) this.handleChunkGeneration() @@ -431,7 +431,7 @@ Game.prototype.configureChunkLoading = function(opts) { if (!opts.generateChunks) return if (!opts.generate) { this.generate = function(x,y,z) { - return x*x+y*y+z*z <= 15*15 ? 1 : 0 // sphere world + return x*x+y*y+z*z <= 15*15 ? 1 + (1<<15) : 0 // sphere world } } else { this.generate = opts.generate @@ -473,7 +473,7 @@ Game.prototype.removeFarChunks = function(playerPosition) { var chunkPosition = chunk.position if (mesh) { self.scene.remove(mesh[self.meshType]) - mesh[self.meshType].geometry.dispose() + //mesh[self.meshType].geometry.dispose() delete mesh.data delete mesh.geometry delete mesh.meshed @@ -525,6 +525,7 @@ Game.prototype.getChunkAtPosition = function(pos) { return chunk } + Game.prototype.showChunk = function(chunk) { var chunkIndex = chunk.position.join('|') var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position) @@ -535,8 +536,7 @@ Game.prototype.showChunk = function(chunk) { this.voxels.meshes[chunkIndex] = mesh if (process.browser) { if (this.meshType === 'wireMesh') mesh.createWireMesh() - else mesh.createSurfaceMesh(this.materials.material) - this.materials.paint(mesh) + else mesh.createSurfaceMesh(this.materials) } mesh.setPosition(bounds[0][0], bounds[0][1], bounds[0][2]) mesh.addToScene(this.scene) @@ -600,7 +600,7 @@ Game.prototype.tick = function(delta) { this.items[i].tick(delta) } - if (this.materials) this.materials.tick(delta) + //if (this.materials) this.materials.tick(delta) if (this.pendingChunks.length) this.loadPendingChunks() if (Object.keys(this.chunksNeedsUpdate).length > 0) this.updateDirtyChunks() From 112acd1edacef4c1014dc60218d429acb38ea2d5 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Fri, 2 Aug 2013 21:48:58 -0700 Subject: [PATCH 018/256] Point deps to ndarray branches --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e558bb5..a2e4d71 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "url": "git@github.com:maxogden/voxel-engine.git" }, "dependencies": { - "voxel": "0.3.1", - "voxel-mesh": "0.2.1", + "voxel": "git://github.com/shama/voxel#ndarray", + "voxel-mesh": "git://github.com/shama/voxel-mesh#ndarray", "voxel-view": "0.0.6", "voxel-raycast": "0.2.1", "voxel-control": "0.0.7", From 52261679581b8e647b44fae4acda99c12957693f Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 16 Nov 2013 12:10:44 -0800 Subject: [PATCH 019/256] Update to voxel-control 0.0.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 07912b5..3ae0a49 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "voxel-mesh": "0.2.1", "voxel-view": "0.0.6", "voxel-raycast": "0.2.1", - "voxel-control": "0.0.7", + "voxel-control": "0.0.8", "voxel-texture": "0.5.6", "voxel-physical": "0.0.10", "voxel-region-change": "0.1.0", From 2b5a730224a4fb3bf3eb5bc967f8adc00ea04c0f Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 16 Nov 2013 15:23:28 -0800 Subject: [PATCH 020/256] Update voxel-control dependency to my branch --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 89459ec..4a08194 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "voxel-mesh": "0.2.1", "voxel-view": "git://github.com/snagy/voxel-view.git", "voxel-raycast": "0.2.1", - "voxel-control": "0.0.8", + "voxel-control": "git://github.com/deathcap/voxel-control.git", "voxel-texture": "0.5.6", "voxel-physical": "0.0.10", "voxel-region-change": "0.1.0", From 7d487acd1fa1efe929cce2d9f94b510f9b8937ea Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 30 Nov 2013 13:49:58 -0800 Subject: [PATCH 021/256] Add sprint keybinding (tab) For use with https://github.com/deathcap/voxel-control/commit/0b85f9085a1f834e5900ec2caf02a38a3499ee0a --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 55a46d6..11eab8d 100644 --- a/index.js +++ b/index.js @@ -297,6 +297,7 @@ Game.prototype.defaultButtons = { , '': 'jump' , '': 'crouch' , '': 'alt' +, '': 'sprint' } // used in methods that have identity function(pos) {} From 96647acb732da9c4dc70f5abc2bea274793d6163 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 30 Nov 2013 22:06:48 -0800 Subject: [PATCH 022/256] Update dependencies to use my branch of voxel-view --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4a08194..dac780b 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "dependencies": { "voxel": "0.3.1", "voxel-mesh": "0.2.1", - "voxel-view": "git://github.com/snagy/voxel-view.git", + "voxel-view": "git://github.com/deathcap/voxel-view.git", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git", "voxel-texture": "0.5.6", From 586908e381ea2e295e7646c05bb51bf071cb161d Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 1 Dec 2013 13:04:16 -0800 Subject: [PATCH 023/256] Update example defaults in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6989914..67c67c6 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Returns a new game instance. `options` defaults to: { texturePath: './textures/', generate: function(x,y,z) { - return x*x+y*y+z*z <= 20*20 ? 1 : 0 // sphere world + return x*x+y*y+z*z <= 15*15 ? 1 : 0 // sphere world }, materials: [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'], materialFlatColor: false, @@ -37,7 +37,7 @@ Returns a new game instance. `options` defaults to: lightsDisabled: false, fogDisabled: false, generateChunks: true, - mesher: voxel.meshers.greedy, + mesher: voxel.meshers.culled, playerHeight: 1.62 } ``` From 47a05ba8132263d9490e8b6f895f689befaf17fa Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 2 Dec 2013 19:01:30 -0800 Subject: [PATCH 024/256] Revert to pre-atlas voxel-texture. Fixes https://github.com/deathcap/voxpopuli/issues/14 voxel-texture 0.5.0 switched to use texture atlases, packing all the block textures into one graphic for efficiency purposes. However, this introduces two problems: - With the culled mesher (default as of voxel-engine 0.17+), I get serious lag spikes (30-60 ms frames, or unplayably higher) when placing/breaking blocks, and also slow page load as the meshes are built (see https://github.com/deathcap/voxpopuli/issues/10) - With the greedy mesher, performance is much better (fixes first issue) but textures are stretched across each of the greedily constructed meshes, instead of tiled across each block (see https://github.com/deathcap/voxpopuli/issues/14) Example: https://f.cloud.github.com/assets/5897956/1651233/1f478c9e-5aca-11e3-82cc-4028f1e1b1da.png There are techniques for texturing greedy meshes, detailed in this article: http://0fps.wordpress.com/2013/07/09/texture-atlases-wrapping-and-mip-mapping/ - Using array textures is ideal, but they won't be supported until WebGL 2.0 at earliest https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7 - Otherwise, they can be tiled manually, but this requires a few tricks, would certainly be worthwhile to implement, but is fairly complex. Maybe later, once I understand it better. So for now, (unfortunately) I've reverted back to voxel-texture without atlases. This keeps mesh recalculation fast (when breaking/placing blocks) and avoids stretched textures but may slow down complex scenes with many materials (see performance improvement @shama noted in https://github.com/maxogden/voxel-engine/pull/69). --- README.md | 12 +++++++++--- index.js | 13 ++++++++----- package.json | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 67c67c6..755810d 100644 --- a/README.md +++ b/README.md @@ -242,11 +242,17 @@ For example, here we have 4 faces colliding with the bottom of our object: ### Textures -Loading textures onto the texture atlas. +Loading textures creates multiple "materials". -```game.materials.load(['obsidian', 'dirt'], function(textures) { })``` +```var materials = game.materials.load(['obsidian', 'dirt'])``` -Both of these textures will be loaded into the texture atlas and expanded creating 2 voxel block types. +Both of these textures come with 6 materials, one for each side of a cube, giving a total of 12 materials. By default, faces 1 to 6 are assigned materials 1 to 6. You can assign materials to faces in however you want. For example, we could load materials 7 to 12 (e.g. the dirt materials) like so: + +```js +mesh.geometry.faces.forEach(function (face, index) { + face.materialIndex = index + 6 // obsidian texture indices 0 - 5, dirt 6 - 11 +}) +``` ### Texture-less worlds with flat colors diff --git a/index.js b/index.js index 8fb8710..e14f3ad 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ function Game(opts) { this.playerHeight = opts.playerHeight || 1.62 this.meshType = opts.meshType || 'surfaceMesh' - this.mesher = opts.mesher || voxel.meshers.culled + this.mesher = opts.mesher || voxel.meshers.greedy this.materialType = opts.materialType || THREE.MeshLambertMaterial this.materialParams = opts.materialParams || {} this.items = [] @@ -92,6 +92,7 @@ function Game(opts) { if (process.browser) { this.materials = texture({ game: this, + THREE: THREE, texturePath: opts.texturePath || './textures/', materialType: opts.materialType || THREE.MeshLambertMaterial, materialParams: opts.materialParams || {}, @@ -226,14 +227,16 @@ Game.prototype.canCreateBlock = function(pos) { } Game.prototype.createBlock = function(pos, val) { - if (typeof val === 'string') val = this.materials.find(val) + if (typeof val === 'string') val = this.materials.findIndex(val) + if (pos.chunkMatrix) return this.chunkGroups.createBlock(pos, val) if (!this.canCreateBlock(pos)) return false this.setBlock(pos, val) return true } Game.prototype.setBlock = function(pos, val) { - if (typeof val === 'string') val = this.materials.find(val) + if (typeof val === 'string') val = this.materials.findIndex(val) + if (pos.chunkMatrix) return this.chunkGroups.setBlock(pos, val) var old = this.voxels.voxelAtPosition(pos, val) var c = this.voxels.chunkAtPosition(pos) var chunk = this.voxels.chunks[c.join('|')] @@ -546,8 +549,8 @@ Game.prototype.showChunk = function(chunk) { this.voxels.meshes[chunkIndex] = mesh if (this.isClient) { if (this.meshType === 'wireMesh') mesh.createWireMesh() - else mesh.createSurfaceMesh(this.materials.material) - this.materials.paint(mesh) + else mesh.createSurfaceMesh(new THREE.MeshFaceMaterial(this.materials.get())) + this.materials.paint(mesh.geometry) } mesh.setPosition(bounds[0][0], bounds[0][1], bounds[0][2]) mesh.addToScene(this.scene) diff --git a/package.json b/package.json index 8da168c..028a51a 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "voxel-view": "git://github.com/deathcap/voxel-view.git", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git", - "voxel-texture": "0.5.6", + "voxel-texture": "0.4.0", "voxel-physical": "0.0.10", "voxel-region-change": "0.1.0", "raf": "0.0.1", From c845d3fd0ee5eead8060f0c2dec4643b53e3e68b Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 7 Dec 2013 19:34:37 -0800 Subject: [PATCH 025/256] Dispose of any mesh, instead of current mesh -- allows for dynamically switching mesh type With this change you can now change in-game (e.g. with voxel-debug): game.meshType = 'surfaceMesh' game.meshType = 'wireMesh' and explore new chunks, then the old meshes will be properly cleaned up (vs crashing). --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e14f3ad..f424157 100644 --- a/index.js +++ b/index.js @@ -486,8 +486,14 @@ Game.prototype.removeFarChunks = function(playerPosition) { if (!chunk) return var chunkPosition = chunk.position if (mesh) { - self.scene.remove(mesh[self.meshType]) - mesh[self.meshType].geometry.dispose() + if (mesh.surfaceMesh) { + self.scene.remove(mesh.surfaceMesh) + mesh.surfaceMesh.geometry.dispose() + } + if (mesh.wireMesh) { + mesh.wireMesh.geometry.dispose() + self.scene.remove(mesh.wireMesh) + } delete mesh.data delete mesh.geometry delete mesh.meshed From 22ecba90663c5a9c93d18a4f0e36c9d55bcb203b Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 7 Dec 2013 19:52:49 -0800 Subject: [PATCH 026/256] Add missing delete for wireMesh --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index f424157..f50407f 100644 --- a/index.js +++ b/index.js @@ -498,6 +498,7 @@ Game.prototype.removeFarChunks = function(playerPosition) { delete mesh.geometry delete mesh.meshed delete mesh.surfaceMesh + delete mesh.wireMesh } delete self.voxels.chunks[chunkIndex] self.emit('removeChunk', chunkPosition) From 4ef7f944822acc2ff038aaffadd1faa8229af01e Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 8 Dec 2013 09:40:52 -0800 Subject: [PATCH 027/256] Remove available mesh type from scene, instead of current mesh Allows you to dynamically change the mesh type at runtime: game.meshType = 'surfaceMesh' game.meshType = 'wireMesh' then explore new chunks, and revisit old (unloaded) chunks -- the new meshes will be displayed correctly, instead of overlapping the older mesh type. With this change and c845d3fd, meshType is now only used for determining the type when _creating_ new meshes. --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f50407f..3db2bee 100644 --- a/index.js +++ b/index.js @@ -552,7 +552,10 @@ Game.prototype.showChunk = function(chunk) { var scale = new THREE.Vector3(1, 1, 1) var mesh = voxelMesh(chunk, this.mesher, scale, this.THREE) this.voxels.chunks[chunkIndex] = chunk - if (this.voxels.meshes[chunkIndex]) this.scene.remove(this.voxels.meshes[chunkIndex][this.meshType]) + if (this.voxels.meshes[chunkIndex]) { + if (this.voxels.meshes[chunkIndex].surfaceMesh) this.scene.remove(this.voxels.meshes[chunkIndex].surfaceMesh) + if (this.voxels.meshes[chunkIndex].wireMesh) this.scene.remove(this.voxels.meshes[chunkIndex].wireMesh) + } this.voxels.meshes[chunkIndex] = mesh if (this.isClient) { if (this.meshType === 'wireMesh') mesh.createWireMesh() From b3206df42bcec6487d9deee36a80bac6396073a6 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 8 Dec 2013 09:50:29 -0800 Subject: [PATCH 028/256] Add showAllChunks() to re-render all chunks Useful for refreshing after changing rendering settings. --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3db2bee..24bda36 100644 --- a/index.js +++ b/index.js @@ -115,8 +115,8 @@ function Game(opts) { this.paused = true this.initializeRendering(opts) - - for (var chunkIndex in this.voxels.chunks) this.showChunk(this.voxels.chunks[chunkIndex]) + + this.showAllChunks() setTimeout(function() { self.asyncChunkGeneration = 'asyncChunkGeneration' in opts ? opts.asyncChunkGeneration : true @@ -546,6 +546,12 @@ Game.prototype.getChunkAtPosition = function(pos) { return chunk } +Game.prototype.showAllChunks = function() { + for (var chunkIndex in this.voxels.chunks) { + this.showChunk(this.voxels.chunks[chunkIndex]) + } +} + Game.prototype.showChunk = function(chunk) { var chunkIndex = chunk.position.join('|') var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position) From c674690599d24099dc85b7f8580430650b4a092a Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 10 Dec 2013 18:49:04 -0800 Subject: [PATCH 029/256] Don't load materials on initialization if none given. Allows for dynamic material loading. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 24bda36..43ec36a 100644 --- a/index.js +++ b/index.js @@ -106,7 +106,7 @@ function Game(opts) { self.removeFarChunks() }) - if (this.isClient) this.materials.load(this.materialNames) + if (this.isClient && this.materialNames.length) this.materials.load(this.materialNames) if (this.generateChunks) this.handleChunkGeneration() From 096617fd58027fc20db20eff5b183eb338599b5b Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 11 Dec 2013 18:58:56 -0800 Subject: [PATCH 030/256] Remove unnecessary changes added in texture atlas revert Unused, so removed -- was accidentally added in https://github.com/deathcap/voxel-engine/commit/47a05ba8132263d9490e8b6f895f689befaf17fa --- index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.js b/index.js index 43ec36a..9949a14 100644 --- a/index.js +++ b/index.js @@ -228,7 +228,6 @@ Game.prototype.canCreateBlock = function(pos) { Game.prototype.createBlock = function(pos, val) { if (typeof val === 'string') val = this.materials.findIndex(val) - if (pos.chunkMatrix) return this.chunkGroups.createBlock(pos, val) if (!this.canCreateBlock(pos)) return false this.setBlock(pos, val) return true @@ -236,7 +235,6 @@ Game.prototype.createBlock = function(pos, val) { Game.prototype.setBlock = function(pos, val) { if (typeof val === 'string') val = this.materials.findIndex(val) - if (pos.chunkMatrix) return this.chunkGroups.setBlock(pos, val) var old = this.voxels.voxelAtPosition(pos, val) var c = this.voxels.chunkAtPosition(pos) var chunk = this.voxels.chunks[c.join('|')] From 4d7ac544e4b2c3e5917164ad58aa2edb3568ab22 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 11 Dec 2013 19:22:18 -0800 Subject: [PATCH 031/256] Update to use my branch of voxel-texture --- index.js | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9949a14..969fc58 100644 --- a/index.js +++ b/index.js @@ -93,6 +93,7 @@ function Game(opts) { this.materials = texture({ game: this, THREE: THREE, + useAtlas: true, texturePath: opts.texturePath || './textures/', materialType: opts.materialType || THREE.MeshLambertMaterial, materialParams: opts.materialParams || {}, diff --git a/package.json b/package.json index 028a51a..2c22c7f 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "voxel-view": "git://github.com/deathcap/voxel-view.git", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git", - "voxel-texture": "0.4.0", + "voxel-texture": "git://github.com/deathcap/voxel-texture.git", "voxel-physical": "0.0.10", "voxel-region-change": "0.1.0", "raf": "0.0.1", From 58967dba81734134f1ad8d52b18d7203eafc27c3 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 11 Dec 2013 19:33:52 -0800 Subject: [PATCH 032/256] Use more compatible texture API Requires https://github.com/deathcap/voxel-texture/commit/42c6f3b10f669181b1b9f51de030af1d15e5a73d Ref https://github.com/deathcap/voxpopuli/issues/19 --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 969fc58..cb4c288 100644 --- a/index.js +++ b/index.js @@ -93,7 +93,7 @@ function Game(opts) { this.materials = texture({ game: this, THREE: THREE, - useAtlas: true, + useAtlas: false, texturePath: opts.texturePath || './textures/', materialType: opts.materialType || THREE.MeshLambertMaterial, materialParams: opts.materialParams || {}, @@ -564,8 +564,8 @@ Game.prototype.showChunk = function(chunk) { this.voxels.meshes[chunkIndex] = mesh if (this.isClient) { if (this.meshType === 'wireMesh') mesh.createWireMesh() - else mesh.createSurfaceMesh(new THREE.MeshFaceMaterial(this.materials.get())) - this.materials.paint(mesh.geometry) + else mesh.createSurfaceMesh(this.materials.getMesh()); + this.materials.paintMesh(mesh) } mesh.setPosition(bounds[0][0], bounds[0][1], bounds[0][2]) mesh.addToScene(this.scene) From 97b99064d917bf589a7b96fd09ff31281d6c0689 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 11 Dec 2013 20:15:19 -0800 Subject: [PATCH 033/256] Add option to enable or disable texture atlases --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index cb4c288..b60bce2 100644 --- a/index.js +++ b/index.js @@ -90,10 +90,8 @@ function Game(opts) { this.pendingChunks = [] if (process.browser) { - this.materials = texture({ - game: this, - THREE: THREE, - useAtlas: false, + this.materials = texture(this, { + useAtlas: (opts.useAtlas === undefined) ? false : opts.useAtlas, texturePath: opts.texturePath || './textures/', materialType: opts.materialType || THREE.MeshLambertMaterial, materialParams: opts.materialParams || {}, From d7da1f4bec62bc642f4e0f213b3f62eb693e220e Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 11 Dec 2013 20:20:43 -0800 Subject: [PATCH 034/256] Revert "Don't load materials on initialization if none given." Moved to voxel-texture https://github.com/deathcap/voxel-texture/commit/fd5b723179d6f78de038506923edcd77ff27c7ef This reverts commit c674690599d24099dc85b7f8580430650b4a092a. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b60bce2..975a916 100644 --- a/index.js +++ b/index.js @@ -105,7 +105,7 @@ function Game(opts) { self.removeFarChunks() }) - if (this.isClient && this.materialNames.length) this.materials.load(this.materialNames) + if (this.isClient) this.materials.load(this.materialNames) if (this.generateChunks) this.handleChunkGeneration() From 791c74ad818db9ed96475dd1e812debd709a8a1b Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 25 Dec 2013 19:44:52 -0800 Subject: [PATCH 035/256] Change to use kb-bindings instead of kb-controls See https://github.com/deathcap/kb-bindings --- index.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 975a916..0f561a8 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ var glMatrix = require('gl-matrix') var vector = glMatrix.vec3 var SpatialEventEmitter = require('spatial-events') var regionChange = require('voxel-region-change') -var kb = require('kb-controls') +var kb = require('kb-bindings') var physical = require('voxel-physical') var pin = require('pin-it') var tic = require('tic')() diff --git a/package.json b/package.json index 2c22c7f..8ce221c 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "inherits": "1.0.0", "interact": "0.0.2", "gl-matrix": "2.0.0", - "kb-controls": "0.0.2", + "kb-bindings": "0.0.3", "spatial-events": "0.0.1", "spatial-trigger": "0.0.0", "collide-3d-tilemap": "0.0.1", From a563fa389662cfcd39a246808d6506ba09a6ad5d Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 25 Dec 2013 21:32:05 -0800 Subject: [PATCH 036/256] Update to kb-bindings 0.0.5 (required for kb-bindings-ui) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ce221c..8c7cd85 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "inherits": "1.0.0", "interact": "0.0.2", "gl-matrix": "2.0.0", - "kb-bindings": "0.0.3", + "kb-bindings": "0.0.5", "spatial-events": "0.0.1", "spatial-trigger": "0.0.0", "collide-3d-tilemap": "0.0.1", From 19d99da776d853bcdc8f4f7aff576dee7d6afa73 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 29 Dec 2013 17:46:19 -0800 Subject: [PATCH 037/256] Add opts appendDocument and exposeGlobal for convenience --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 3d8a0de..b487255 100644 --- a/index.js +++ b/index.js @@ -97,6 +97,8 @@ function Game(opts) { materialParams: opts.materialParams || {}, materialFlatColor: opts.materialFlatColor === true }) + if (opts.appendDocument) this.appendTo(document.body) + if (opts.exposeGlobal) window.game = window.g = this } this.materialNames = opts.materials || [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'] From b20be5a05e38ec33c7272f71aa00df59fe60b564 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 3 Jan 2014 12:43:26 -0800 Subject: [PATCH 038/256] Update to use my branch of 'voxel' --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 611a256..0b4f26e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "url": "git@github.com:maxogden/voxel-engine.git" }, "dependencies": { - "voxel": "0.3.1", + "voxel": "git://github.com/deathcap/voxel.git#9fe75f0388b1a1d9499076c2e4e1536ebd7a46d1", "voxel-mesh": "0.2.1", "voxel-view": "git://github.com/deathcap/voxel-view.git", "voxel-raycast": "0.2.1", From 0d5a809494a9268f63a80dce30b9d45bcf18798c Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 3 Jan 2014 12:44:51 -0800 Subject: [PATCH 039/256] Add git commit revisions --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0b4f26e..8ca10c0 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,10 @@ "dependencies": { "voxel": "git://github.com/deathcap/voxel.git#9fe75f0388b1a1d9499076c2e4e1536ebd7a46d1", "voxel-mesh": "0.2.1", - "voxel-view": "git://github.com/deathcap/voxel-view.git", + "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", - "voxel-control": "git://github.com/deathcap/voxel-control.git", - "voxel-texture": "git://github.com/deathcap/voxel-texture.git", + "voxel-control": "git://github.com/deathcap/voxel-control.git#1de90a89347d9667ce4f9689a0a101b9d8704020", + "voxel-texture": "git://github.com/deathcap/voxel-texture.git#f3759178093652652a00856db334396119c7aa16", "voxel-physical": "0.0.10", "voxel-region-change": "0.1.0", "raf": "0.0.1", From 80e625fedc75191b2ed42a85f20e429ffde2b883 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 3 Jan 2014 12:59:32 -0800 Subject: [PATCH 040/256] Update voxel - add transgreedy mesher deathcap/voxel@b45d02db42395ac95120eb66073999b846814a77 Export the transgreedy mesher deathcap/voxel@3800e7ab6efcf1b4b393b391c9fe0963cf2e60cd Add transgreedy mesher by @vogonistic Commit message generated by https://github.com/deathcap/lmno-cl --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ca10c0..ddcf7e2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "url": "git@github.com:maxogden/voxel-engine.git" }, "dependencies": { - "voxel": "git://github.com/deathcap/voxel.git#9fe75f0388b1a1d9499076c2e4e1536ebd7a46d1", + "voxel": "git://github.com/deathcap/voxel.git#b45d02db42395ac95120eb66073999b846814a77", "voxel-mesh": "0.2.1", "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", From b6bff6d23ff358f826e60b34989f043d1dd29cb3 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 12 Jan 2014 05:45:02 -0800 Subject: [PATCH 041/256] Update voxel-texture - add greedy mesher + atlas texturing support deathcap/voxel-texture@a58b2878b23ad6d42d166cacb0f3a64f56bae073 Add custom ShaderMaterial supporting greedy meshing + atlas texturing deathcap/voxel-texture@dad8347d8ec0c214dbc5087cedddf64847861c9b Remove material option configurability Commit message generated by https://github.com/deathcap/lmno-cl --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ddcf7e2..1ff63c8 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#1de90a89347d9667ce4f9689a0a101b9d8704020", - "voxel-texture": "git://github.com/deathcap/voxel-texture.git#f3759178093652652a00856db334396119c7aa16", + "voxel-texture": "git://github.com/deathcap/voxel-texture.git#a58b2878b23ad6d42d166cacb0f3a64f56bae073", "voxel-physical": "0.0.10", "voxel-region-change": "0.1.0", "raf": "0.0.1", From 76123a25194a487857769069b4b3a29c7d16ef7b Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 12 Jan 2014 14:05:22 -0800 Subject: [PATCH 042/256] Update voxel-texture - adds 4-tap sampling deathcap/voxel-texture@094612492644750d7267619dbcf616f82439aa05 Add 4-tap sampling to fix artifacts near texture boundaries deathcap/voxel-texture@83bc8010722773880ed9b6fe0807eb4fe2c48607 Discard transparent pixels in fragment shader Commit message generated by https://github.com/deathcap/lmno-cl --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1ff63c8..ea539fd 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#1de90a89347d9667ce4f9689a0a101b9d8704020", - "voxel-texture": "git://github.com/deathcap/voxel-texture.git#a58b2878b23ad6d42d166cacb0f3a64f56bae073", + "voxel-texture": "git://github.com/deathcap/voxel-texture.git#094612492644750d7267619dbcf616f82439aa05", "voxel-physical": "0.0.10", "voxel-region-change": "0.1.0", "raf": "0.0.1", From 990e941f922e7f56feb348bdddf225a1c3d9686d Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 13 Jan 2014 21:38:58 -0800 Subject: [PATCH 043/256] Revert "Change to use kb-bindings instead of kb-controls" This reverts commit 791c74ad818db9ed96475dd1e812debd709a8a1b. Conflicts: package.json --- index.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b487255..c4f15e8 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ var glMatrix = require('gl-matrix') var vector = glMatrix.vec3 var SpatialEventEmitter = require('spatial-events') var regionChange = require('voxel-region-change') -var kb = require('kb-bindings') +var kb = require('kb-controls') var physical = require('voxel-physical') var pin = require('pin-it') var tic = require('tic')() diff --git a/package.json b/package.json index ea539fd..0bf56ef 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "inherits": "1.0.0", "interact": "0.0.2", "gl-matrix": "2.0.0", - "kb-bindings": "0.0.5", + "kb-controls": "0.0.2", "spatial-events": "0.0.1", "spatial-trigger": "0.0.0", "collide-3d-tilemap": "0.0.1", From 61177bd73ee38f13e925115768776d42f15476e3 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 13 Jan 2014 21:40:19 -0800 Subject: [PATCH 044/256] Add options to specify kb and texture modules to use --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c4f15e8..beaae9e 100644 --- a/index.js +++ b/index.js @@ -45,6 +45,8 @@ function Game(opts) { this.arrayType = opts.arrayType || Uint8Array this.cubeSize = 1 // backwards compat this.chunkSize = opts.chunkSize || 32 + this.kb_module = opts.kb_module || kb; + this.texture_module = opts.texture_module || texture; // chunkDistance and removeDistance should not be set to the same thing // as it causes lag when you go back and forth on a chunk boundary @@ -90,7 +92,7 @@ function Game(opts) { this.pendingChunks = [] if (process.browser) { - this.materials = texture(this, { + this.materials = this.texture_module(this, { useAtlas: (opts.useAtlas === undefined) ? false : opts.useAtlas, texturePath: opts.texturePath || './textures/', materialType: opts.materialType || THREE.MeshLambertMaterial, @@ -703,7 +705,7 @@ Game.prototype.initializeRendering = function(opts) { Game.prototype.initializeControls = function(opts) { // player control this.keybindings = opts.keybindings || this.defaultButtons - this.buttons = kb(document.body, this.keybindings) + this.buttons = this.kb_module(document.body, this.keybindings) this.buttons.disable() this.optout = false this.interact = interact(opts.interactElement || this.view.element, opts.interactMouseDrag) From 0c1a787cacf51f1227e2badc66b9580c3e3b91af Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 17 Jan 2014 22:20:43 -0800 Subject: [PATCH 045/256] Pass through artPacks option to texturer and Update voxel-texture deathcap/voxel-texture@32d3847a4ed6eafa4200778ff08aa23d053a2515 Change to load textures using 'artpacks' module deathcap/voxel-texture@57998e0723b63e87cd50c456dbb07716a50cf049 Remove optional require('three') deathcap/voxel-texture@6a90b85eb31b825b0c784e5e8d4944aa66705f6e Add three.js shader chunks, fixes missing lighting deathcap/voxel-texture@3f1b5d5dbdb16b1f2297659e2809fc9fabbc7c70 Cleanup tileSizeUV / tileSize unused code Commit message generated by https://github.com/deathcap/lmno-cl --- index.js | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index beaae9e..f3acddf 100644 --- a/index.js +++ b/index.js @@ -95,6 +95,7 @@ function Game(opts) { this.materials = this.texture_module(this, { useAtlas: (opts.useAtlas === undefined) ? false : opts.useAtlas, texturePath: opts.texturePath || './textures/', + artPacks: opts.artPacks, materialType: opts.materialType || THREE.MeshLambertMaterial, materialParams: opts.materialParams || {}, materialFlatColor: opts.materialFlatColor === true diff --git a/package.json b/package.json index 0bf56ef..0df4539 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#1de90a89347d9667ce4f9689a0a101b9d8704020", - "voxel-texture": "git://github.com/deathcap/voxel-texture.git#094612492644750d7267619dbcf616f82439aa05", + "voxel-texture": "git://github.com/deathcap/voxel-texture.git#32d3847a4ed6eafa4200778ff08aa23d053a2515", "voxel-physical": "0.0.10", "voxel-region-change": "0.1.0", "raf": "0.0.1", From a8ef28f7c2645dc106737bbae556e816d2409fbe Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 19 Jan 2014 10:41:29 -0800 Subject: [PATCH 046/256] Increase atlas size to 2048x2048 from 512x512 According to http://webglstats.com/#h_texsize, 100% of WebGL users in the wild support up to 2048x2048 textures. With 4x4 repeated/padded textures 16x16 each, this will support up to 1024 textures per atlas. --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index f3acddf..0dfa2f8 100644 --- a/index.js +++ b/index.js @@ -94,6 +94,8 @@ function Game(opts) { if (process.browser) { this.materials = this.texture_module(this, { useAtlas: (opts.useAtlas === undefined) ? false : opts.useAtlas, + atlasWidth: 2048, + atlasHeight: 2048, texturePath: opts.texturePath || './textures/', artPacks: opts.artPacks, materialType: opts.materialType || THREE.MeshLambertMaterial, From 37bacfb9e24094a2a30617aa21300176308ef800 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 19 Jan 2014 10:52:06 -0800 Subject: [PATCH 047/256] Restore support for voxel-texture 0.5.6 Revert "Use more compatible texture API" This reverts commit 58967dba81734134f1ad8d52b18d7203eafc27c3. Conflicts: index.js --- index.js | 7 ++++--- package.json | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0dfa2f8..71a31e3 100644 --- a/index.js +++ b/index.js @@ -92,7 +92,8 @@ function Game(opts) { this.pendingChunks = [] if (process.browser) { - this.materials = this.texture_module(this, { + this.materials = this.texture_module({ + game: this, useAtlas: (opts.useAtlas === undefined) ? false : opts.useAtlas, atlasWidth: 2048, atlasHeight: 2048, @@ -569,8 +570,8 @@ Game.prototype.showChunk = function(chunk) { this.voxels.meshes[chunkIndex] = mesh if (this.isClient) { if (this.meshType === 'wireMesh') mesh.createWireMesh() - else mesh.createSurfaceMesh(this.materials.getMesh()); - this.materials.paintMesh(mesh) + else mesh.createSurfaceMesh(this.materials.material) + this.materials.paint(mesh) } mesh.setPosition(bounds[0][0], bounds[0][1], bounds[0][2]) mesh.addToScene(this.scene) diff --git a/package.json b/package.json index 0df4539..1e3169d 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#1de90a89347d9667ce4f9689a0a101b9d8704020", - "voxel-texture": "git://github.com/deathcap/voxel-texture.git#32d3847a4ed6eafa4200778ff08aa23d053a2515", + "voxel-texture": "0.5.6", "voxel-physical": "0.0.10", "voxel-region-change": "0.1.0", "raf": "0.0.1", From 98e25e30fb018fcf5d70c550ca22e160a5bf1b47 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 19 Jan 2014 11:34:53 -0800 Subject: [PATCH 048/256] Add support for multiple texture modules --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 71a31e3..1b53856 100644 --- a/index.js +++ b/index.js @@ -46,7 +46,7 @@ function Game(opts) { this.cubeSize = 1 // backwards compat this.chunkSize = opts.chunkSize || 32 this.kb_module = opts.kb_module || kb; - this.texture_module = opts.texture_module || texture; + this.texture_modules = opts.texture_modules || [texture]; // chunkDistance and removeDistance should not be set to the same thing // as it causes lag when you go back and forth on a chunk boundary @@ -92,7 +92,7 @@ function Game(opts) { this.pendingChunks = [] if (process.browser) { - this.materials = this.texture_module({ + this.materials = this.texture_modules[0](this.texture_opts = { game: this, useAtlas: (opts.useAtlas === undefined) ? false : opts.useAtlas, atlasWidth: 2048, From 500427b089987c3844f7236983f47c1752198704 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 19 Jan 2014 20:46:40 -0800 Subject: [PATCH 049/256] Revert "Increase atlas size to 2048x2048 from 512x512" This reverts commit a8ef28f7c2645dc106737bbae556e816d2409fbe. Moved to deathcap/voxel-texture-shader@73806ef3eee719d7a27509a57d516899f7706dd4 --- index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.js b/index.js index 1b53856..bc9ae1d 100644 --- a/index.js +++ b/index.js @@ -95,8 +95,6 @@ function Game(opts) { this.materials = this.texture_modules[0](this.texture_opts = { game: this, useAtlas: (opts.useAtlas === undefined) ? false : opts.useAtlas, - atlasWidth: 2048, - atlasHeight: 2048, texturePath: opts.texturePath || './textures/', artPacks: opts.artPacks, materialType: opts.materialType || THREE.MeshLambertMaterial, From 56b99f9c1f08cb88e46c12a007a7f0f25c254edc Mon Sep 17 00:00:00 2001 From: Justin Swanhart Date: Fri, 24 Jan 2014 23:23:25 -0800 Subject: [PATCH 050/256] Texture engine was not being initialized properly. Texture() was reverted to no longer take (game,opt), it just takes (opt). This caused initialization failure in voxpopuli because voxel-texture tries to get game.THREE and game.ao, but there was no game member on the opts object (in fact, the opts object was game itself and so it was completely broken). --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f3acddf..069c5ca 100644 --- a/index.js +++ b/index.js @@ -92,13 +92,14 @@ function Game(opts) { this.pendingChunks = [] if (process.browser) { - this.materials = this.texture_module(this, { + this.materials = this.texture_module({ useAtlas: (opts.useAtlas === undefined) ? false : opts.useAtlas, texturePath: opts.texturePath || './textures/', artPacks: opts.artPacks, materialType: opts.materialType || THREE.MeshLambertMaterial, materialParams: opts.materialParams || {}, - materialFlatColor: opts.materialFlatColor === true + materialFlatColor: opts.materialFlatColor === true, + game: this }) if (opts.appendDocument) this.appendTo(document.body) if (opts.exposeGlobal) window.game = window.g = this From c82bdef6b23efdfd10483716ac92253612326bcf Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 28 Jan 2014 19:49:34 -0800 Subject: [PATCH 051/256] Update to voxel-texture 0.5.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1e3169d..f78b196 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#1de90a89347d9667ce4f9689a0a101b9d8704020", - "voxel-texture": "0.5.6", + "voxel-texture": "0.5.8", "voxel-physical": "0.0.10", "voxel-region-change": "0.1.0", "raf": "0.0.1", From 6643f87d2b0751fad267ae5e9d8b1751837f4976 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 29 Jan 2014 18:25:05 -0800 Subject: [PATCH 052/256] Fix process.browser -> this.isClient in material loading --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 3610868..7f5a31a 100644 --- a/index.js +++ b/index.js @@ -91,7 +91,7 @@ function Game(opts) { // contains new chunks yet to be generated. Handled by game.loadPendingChunks this.pendingChunks = [] - if (process.browser) { + if (this.isClient) { this.materials = this.texture_modules[0](this.texture_opts = { useAtlas: (opts.useAtlas === undefined) ? false : opts.useAtlas, texturePath: opts.texturePath || './textures/', From dca59e5acc80638b9c99a7b75e4cd1cb200f0f6a Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 12 Feb 2014 18:16:23 -0800 Subject: [PATCH 053/256] Revert remnants of reverted non-atlas texture changes, reduce upstream diff --- README.md | 12 +++--------- index.js | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 755810d..67c67c6 100644 --- a/README.md +++ b/README.md @@ -242,17 +242,11 @@ For example, here we have 4 faces colliding with the bottom of our object: ### Textures -Loading textures creates multiple "materials". +Loading textures onto the texture atlas. -```var materials = game.materials.load(['obsidian', 'dirt'])``` +```game.materials.load(['obsidian', 'dirt'], function(textures) { })``` -Both of these textures come with 6 materials, one for each side of a cube, giving a total of 12 materials. By default, faces 1 to 6 are assigned materials 1 to 6. You can assign materials to faces in however you want. For example, we could load materials 7 to 12 (e.g. the dirt materials) like so: - -```js -mesh.geometry.faces.forEach(function (face, index) { - face.materialIndex = index + 6 // obsidian texture indices 0 - 5, dirt 6 - 11 -}) -``` +Both of these textures will be loaded into the texture atlas and expanded creating 2 voxel block types. ### Texture-less worlds with flat colors diff --git a/index.js b/index.js index 7f5a31a..7ac4f69 100644 --- a/index.js +++ b/index.js @@ -232,14 +232,14 @@ Game.prototype.canCreateBlock = function(pos) { } Game.prototype.createBlock = function(pos, val) { - if (typeof val === 'string') val = this.materials.findIndex(val) + if (typeof val === 'string') val = this.materials.find(val) if (!this.canCreateBlock(pos)) return false this.setBlock(pos, val) return true } Game.prototype.setBlock = function(pos, val) { - if (typeof val === 'string') val = this.materials.findIndex(val) + if (typeof val === 'string') val = this.materials.find(val) var old = this.voxels.voxelAtPosition(pos, val) var c = this.voxels.chunkAtPosition(pos) var chunk = this.voxels.chunks[c.join('|')] From 548ca12ae491ffe8f216ad65cd43dc66120a2867 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 15 Feb 2014 11:08:55 -0800 Subject: [PATCH 054/256] Update voxel-physical to my fork, with fall distance calculation --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f78b196..8977f87 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#1de90a89347d9667ce4f9689a0a101b9d8704020", "voxel-texture": "0.5.8", - "voxel-physical": "0.0.10", + "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", "voxel-region-change": "0.1.0", "raf": "0.0.1", "three": "0.58.9", From bde4d9faba2c60c61fbc7d7b085f1b42b53ec1a3 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 15 Feb 2014 15:23:29 -0800 Subject: [PATCH 055/256] Add arrayTypeSize option, alternative to passing constructor in arrayType --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7ac4f69..1c1586e 100644 --- a/index.js +++ b/index.js @@ -42,7 +42,7 @@ function Game(opts) { this.THREE = THREE this.vector = vector this.glMatrix = glMatrix - this.arrayType = opts.arrayType || Uint8Array + this.arrayType = opts.arrayType || {1:Uint8Array, 2:Uint16Array, 4:Uint32Array}[opts.arrayTypeSize] || Uint8Array this.cubeSize = 1 // backwards compat this.chunkSize = opts.chunkSize || 32 this.kb_module = opts.kb_module || kb; From b77675d8471c5910f0c0a8fdbf0f433358d1bc1c Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 15 Feb 2014 16:13:15 -0800 Subject: [PATCH 056/256] Remove kb_module option, since it cannot be JSON-serialized --- index.js | 5 ++--- package.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 1c1586e..b34b90c 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ var glMatrix = require('gl-matrix') var vector = glMatrix.vec3 var SpatialEventEmitter = require('spatial-events') var regionChange = require('voxel-region-change') -var kb = require('kb-controls') +var kb = require('kb-bindings') var physical = require('voxel-physical') var pin = require('pin-it') var tic = require('tic')() @@ -45,7 +45,6 @@ function Game(opts) { this.arrayType = opts.arrayType || {1:Uint8Array, 2:Uint16Array, 4:Uint32Array}[opts.arrayTypeSize] || Uint8Array this.cubeSize = 1 // backwards compat this.chunkSize = opts.chunkSize || 32 - this.kb_module = opts.kb_module || kb; this.texture_modules = opts.texture_modules || [texture]; // chunkDistance and removeDistance should not be set to the same thing @@ -707,7 +706,7 @@ Game.prototype.initializeRendering = function(opts) { Game.prototype.initializeControls = function(opts) { // player control this.keybindings = opts.keybindings || this.defaultButtons - this.buttons = this.kb_module(document.body, this.keybindings) + this.buttons = kb(document.body, this.keybindings) this.buttons.disable() this.optout = false this.interact = interact(opts.interactElement || this.view.element, opts.interactMouseDrag) diff --git a/package.json b/package.json index 8977f87..4ac3ab4 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "inherits": "1.0.0", "interact": "0.0.2", "gl-matrix": "2.0.0", - "kb-controls": "0.0.2", + "kb-bindings": "0.2.0", "spatial-events": "0.0.1", "spatial-trigger": "0.0.0", "collide-3d-tilemap": "0.0.1", From 7d9d7ff0ec8b8f6b7f86bc85f5290ec32fa91875 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 23 Feb 2014 13:04:16 -0800 Subject: [PATCH 057/256] Use transgreedy mesher, fixes voxel transparency Ref https://github.com/maxogden/voxel/issues/16 --- index.js | 6 ++++-- package.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b34b90c..c665f2c 100644 --- a/index.js +++ b/index.js @@ -55,9 +55,10 @@ function Game(opts) { this.skyColor = opts.skyColor || 0xBFD1E5 this.playerHeight = opts.playerHeight || 1.62 this.meshType = opts.meshType || 'surfaceMesh' - this.mesher = opts.mesher || voxel.meshers.greedy + this.mesher = opts.mesher || voxel.meshers.transgreedy this.materialType = opts.materialType || THREE.MeshLambertMaterial this.materialParams = opts.materialParams || {} + this.materialTransparentTypes = opts.materialTransparentTypes || {} // TODO: automatically get from voxel-texture this.items = [] this.voxels = voxel(this) this.scene = new THREE.Scene() @@ -558,7 +559,8 @@ Game.prototype.showChunk = function(chunk) { var chunkIndex = chunk.position.join('|') var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position) var scale = new THREE.Vector3(1, 1, 1) - var mesh = voxelMesh(chunk, this.mesher, scale, this.THREE) + var transparentTypes = this.materials.getTransparentVoxelTypes ? this.materials.getTransparentVoxelTypes() : {}; + var mesh = voxelMesh(chunk, this.mesher, scale, this.THREE, {transparentTypes: transparentTypes}) this.voxels.chunks[chunkIndex] = chunk if (this.voxels.meshes[chunkIndex]) { if (this.voxels.meshes[chunkIndex].surfaceMesh) this.scene.remove(this.voxels.meshes[chunkIndex].surfaceMesh) diff --git a/package.json b/package.json index 4ac3ab4..a7d28e3 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "dependencies": { "voxel": "git://github.com/deathcap/voxel.git#b45d02db42395ac95120eb66073999b846814a77", - "voxel-mesh": "0.2.1", + "voxel-mesh": "git://github.com/deathcap/voxel-mesh.git#4bc4d2b2f3b5804367360ffd16d506349e1dab09", "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#1de90a89347d9667ce4f9689a0a101b9d8704020", From 2e35ba372cdc994f9f1c60a061fe6230766d5ae3 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 23 Feb 2014 13:14:28 -0800 Subject: [PATCH 058/256] Update voxel, voxel-control deathcap/voxel@2fe6ca876a34d9ec654f1ae572c99376256815df Accept transparent voxel list for transgreedy mesher in mesherExtraData deathcap/voxel@f184d7bc842bbfc1440284ab91ced2859f4c6725 Add missing removeFlags() in transgreedy, fixes incorrect voxel textures deathcap/voxel-control@d9ac73b0423ec0deb0ebcd54711bf7c656f9ddb6 Add sneaking - move very slowly when crouching Commit message generated by https://github.com/deathcap/lmno-cl --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a7d28e3..7a2c71d 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,11 @@ "url": "git@github.com:maxogden/voxel-engine.git" }, "dependencies": { - "voxel": "git://github.com/deathcap/voxel.git#b45d02db42395ac95120eb66073999b846814a77", + "voxel": "git://github.com/deathcap/voxel.git#2fe6ca876a34d9ec654f1ae572c99376256815df", "voxel-mesh": "git://github.com/deathcap/voxel-mesh.git#4bc4d2b2f3b5804367360ffd16d506349e1dab09", "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", - "voxel-control": "git://github.com/deathcap/voxel-control.git#1de90a89347d9667ce4f9689a0a101b9d8704020", + "voxel-control": "git://github.com/deathcap/voxel-control.git#d9ac73b0423ec0deb0ebcd54711bf7c656f9ddb6", "voxel-texture": "0.5.8", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", "voxel-region-change": "0.1.0", From fccb268d5d0d034f04f62e5eb784e5b911b96397 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 3 Mar 2014 19:26:46 -0800 Subject: [PATCH 059/256] Load textures through artpacks module --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c665f2c..85c67f9 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ var voxel = require('voxel') var voxelMesh = require('voxel-mesh') var ray = require('voxel-raycast') var texture = require('voxel-texture') +var artpacks = require('artpacks'); var control = require('voxel-control') var voxelView = require('voxel-view') var THREE = require('three') @@ -95,7 +96,7 @@ function Game(opts) { this.materials = this.texture_modules[0](this.texture_opts = { useAtlas: (opts.useAtlas === undefined) ? false : opts.useAtlas, texturePath: opts.texturePath || './textures/', - artPacks: opts.artPacks, + artPacks: artpacks(opts.artPacks), materialType: opts.materialType || THREE.MeshLambertMaterial, materialParams: opts.materialParams || {}, materialFlatColor: opts.materialFlatColor === true, From 31b97a35599e0d96212f436bb3ceacbc38fe0c4f Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 5 Mar 2014 20:49:30 -0800 Subject: [PATCH 060/256] Add missing artpacks dependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 7a2c71d..57b4a8e 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#d9ac73b0423ec0deb0ebcd54711bf7c656f9ddb6", "voxel-texture": "0.5.8", + "artpacks": "git://github.com/deathcap/artpacks.git#a78684d2d180f94638c43fec1e1d65f3ef9ce945", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", "voxel-region-change": "0.1.0", "raf": "0.0.1", From d59de8e901644fbbb5a4895fa0e9f78b5de03b60 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 10 Mar 2014 20:44:13 -0700 Subject: [PATCH 061/256] Update artpacks, voxel, voxel-mesh deathcap/artpacks@c0a5bfc27df93f7f96f9f87a707a4763e617ff01 Refresh (invalid blob URLs) after loading packs deathcap/artpacks@5375c65a952ed5fe960d010c54d68b06b2a2280d Reverse iteration order, so addPack effectively prepends (vs appends) deathcap/artpacks@da91048ecdb7930ff528f8d81d51774a59e41ae8 Change demo to add by default, replace if holding shift deathcap/artpacks@72dc2eb4139042a170274cc1a1caedf73a9a4f3e Return array from getTextureImage() for animations. Closes GH-7 deathcap/artpacks@eda9f03c6f65d77dd600009225df0e318dcc5118 Read .mcmeta files, pass to decoder. Ref GH-7 deathcap/artpacks@7e97debfaf79364af1ec9e8316503f21ecc1dce7 Update demo to use getTextureImage, async deathcap/artpacks@c974c6626c037b2e7cf1e81915ea6be053e75970 Use mcmeta module to split animation frames. Ref GH-7 deathcap/artpacks@98ccb240741131ea5a27da08dc4f8eade6b2bd25 Update to ProgrammerArt-2.2-dev-ResourcePack-20140308 deathcap/voxel@4ce16e8b8d10362a0114483c21cc66777f5702f2 Remove voxel-engine peer dependency (sorry) deathcap/voxel-mesh@6a881552c2281648a8ad8f50e6dd71ff610ef770 Remove three@* peer dependency, fixes npm ERR! missing: three@*, required by voxel-mesh@0.3.0 Commit message generated by https://github.com/deathcap/lmno-cl --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 57b4a8e..00b28f7 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,13 @@ "url": "git@github.com:maxogden/voxel-engine.git" }, "dependencies": { - "voxel": "git://github.com/deathcap/voxel.git#2fe6ca876a34d9ec654f1ae572c99376256815df", - "voxel-mesh": "git://github.com/deathcap/voxel-mesh.git#4bc4d2b2f3b5804367360ffd16d506349e1dab09", + "voxel": "git://github.com/deathcap/voxel.git#4ce16e8b8d10362a0114483c21cc66777f5702f2", + "voxel-mesh": "git://github.com/deathcap/voxel-mesh.git#6a881552c2281648a8ad8f50e6dd71ff610ef770", "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#d9ac73b0423ec0deb0ebcd54711bf7c656f9ddb6", "voxel-texture": "0.5.8", - "artpacks": "git://github.com/deathcap/artpacks.git#a78684d2d180f94638c43fec1e1d65f3ef9ce945", + "artpacks": "git://github.com/deathcap/artpacks.git#c0a5bfc27df93f7f96f9f87a707a4763e617ff01", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", "voxel-region-change": "0.1.0", "raf": "0.0.1", From 3a424083eff5b25255e283b4fb59c5b31ab24355 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 13 Mar 2014 19:49:25 -0700 Subject: [PATCH 062/256] Update artpacks - add static foliage colorization deathcap/artpacks@326defb7dbb867456bd918a33143d3729b7ab2f9 Add static foliage colorization. Closes GH-8 Commit message generated by https://github.com/deathcap/lmno-cl --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 00b28f7..fb01f4f 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#d9ac73b0423ec0deb0ebcd54711bf7c656f9ddb6", "voxel-texture": "0.5.8", - "artpacks": "git://github.com/deathcap/artpacks.git#c0a5bfc27df93f7f96f9f87a707a4763e617ff01", + "artpacks": "git://github.com/deathcap/artpacks.git#326defb7dbb867456bd918a33143d3729b7ab2f9", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", "voxel-region-change": "0.1.0", "raf": "0.0.1", From 86a775f6bf2a291052e2ac164a3094da185f1358 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 14 Mar 2014 21:39:38 -0700 Subject: [PATCH 063/256] Fix invalid JSON --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a12f85b..bca35f5 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "contributors": [ "Max Ogden (https://github.com/maxogden)", "Kumavis (https://github.com/kumavis)", - "Deathcap (https://github.com/deathcap)", + "Deathcap (https://github.com/deathcap)" ], "dependencies": { "voxel": "git://github.com/deathcap/voxel.git#4ce16e8b8d10362a0114483c21cc66777f5702f2", From 5bdbe09332b67aaad05c38a7625c8d6701f96c85 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 21 Mar 2014 18:35:56 -0700 Subject: [PATCH 064/256] Update dependencies to my ndarray branches --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 66d46f8..b3baaea 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "Deathcap (https://github.com/deathcap)" ], "dependencies": { - "voxel": "git://github.com/shama/voxel#ndarray", - "voxel-mesh": "git://github.com/shama/voxel-mesh#ndarray", + "voxel": "git://github.com/deathcap/voxel#ndarray", + "voxel-mesh": "git://github.com/deathcap/voxel-mesh#ndarray", "voxel-view": "0.0.6", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#d9ac73b0423ec0deb0ebcd54711bf7c656f9ddb6", From 487bd65cf53c54edb04f8bccdf8732021a88d4f1 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 29 Mar 2014 17:10:43 -0700 Subject: [PATCH 065/256] Replace game-shell-orbit-camera with game-shell-fps-camera --- main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 25a2ebc..c7f4d45 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,7 @@ "use strict" -var shell = require("gl-now")({clearColor: [0,0,0,0]}) -var camera = require("game-shell-orbit-camera")(shell) +var shell = require("gl-now")({clearColor: [0,0,0,0], pointerLock: true}) +var camera = require("game-shell-fps-camera")(shell) var createTileMap = require("gl-tile-map") var ndarray = require("ndarray") var terrain = require("isabella-texture-pack") diff --git a/package.json b/package.json index 1a7c4b7..7b893c4 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "main.js", "dependencies": { "ao-mesher": "~0.2.5", - "game-shell-orbit-camera": "~0.0.0", + "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git", "ao-shader": "~0.2.3", "gl-buffer": "~0.1.0", "gl-matrix": "~2.0.0", From aaba84d642aed5ced00245e069dfd22e6e1fbfa3 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 30 Mar 2014 21:31:54 -0700 Subject: [PATCH 066/256] Remove UI controls --- index.html | 23 +---------------- lib/examples.js | 19 --------------- main.css | 39 ----------------------------- main.js | 65 +++++++++---------------------------------------- 4 files changed, 13 insertions(+), 133 deletions(-) delete mode 100644 main.css diff --git a/index.html b/index.html index db30c97..bbfbde3 100644 --- a/index.html +++ b/index.html @@ -3,30 +3,9 @@ Voxel Mipmap Demo - Fork me on GitHub -
-

- - -

-

- - -

-

- - -

-
-
Requires WebGL!
- \ No newline at end of file + diff --git a/lib/examples.js b/lib/examples.js index ac9b707..c574505 100644 --- a/lib/examples.js +++ b/lib/examples.js @@ -33,22 +33,6 @@ function makeMesh(name, mesh, tolerance, fill) { }, true) } -//Sphere -makeFill("Sphere", [32,32,32], function(i,j,k) { - var x = i - 16 - var y = j - 16 - var z = k - 16 - return (x*x + y*y + z*z) < 30 ? (1<<15) + 0x18 : 0 -}) - -//Cuboid -makeFill("Box", [32,32,32], function(i,j,k) { - var x = Math.abs(i - 16) - var y = Math.abs(j - 16) - var z = Math.abs(k - 16) - return Math.max(x,y,z) < 13 ? (1<<15) + 0x91 : 0 -}) - //Terrain makeFill("Terrain", [33,33,33], function(i,j,k) { if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { @@ -98,7 +82,4 @@ makeFill("Tree", [16,16,16], function(i,j,k) { return 0 }) -//Create meshes -makeMesh("Teapot", teapot, 1.0, (1<<15)+0x81) -makeMesh("Bunny", bunny, 0.1, (1<<15)+0x01) diff --git a/main.css b/main.css deleted file mode 100644 index a089747..0000000 --- a/main.css +++ /dev/null @@ -1,39 +0,0 @@ -.controlPanel { - position: absolute; - top: 1%; - left: 1%; - z-index: 10; - background-color: rgba(129, 129, 129, 0.5); - padding-top: 10px; - padding-left: 10px; - padding-right: 10px; - padding-bottom: 10px; - border-radius: 10px; -} -.noWebGL { - background-color: red; - color: white; - transform:rotate(-37deg); - -ms-transform:rotate(-37deg); - -webkit-transform:rotate(-37deg); - position: absolute; - width: 100%; - font-size: 90pt; - top: 50%; - text-align: center; - z-index:30; - display: none; -} -html,body{ - font-family: sans-serif; -} -body{ -background: rgb(240,249,255); /* Old browsers */ -background: -moz-linear-gradient(-45deg, rgba(240,249,255,1) 0%, rgba(203,235,255,1) 53%, rgba(161,219,255,1) 100%); /* FF3.6+ */ -background: -webkit-gradient(linear, left top, right bottom, color-stop(0%,rgba(240,249,255,1)), color-stop(53%,rgba(203,235,255,1)), color-stop(100%,rgba(161,219,255,1))); /* Chrome,Safari4+ */ -background: -webkit-linear-gradient(-45deg, rgba(240,249,255,1) 0%,rgba(203,235,255,1) 53%,rgba(161,219,255,1) 100%); /* Chrome10+,Safari5.1+ */ -background: -o-linear-gradient(-45deg, rgba(240,249,255,1) 0%,rgba(203,235,255,1) 53%,rgba(161,219,255,1) 100%); /* Opera 11.10+ */ -background: -ms-linear-gradient(-45deg, rgba(240,249,255,1) 0%,rgba(203,235,255,1) 53%,rgba(161,219,255,1) 100%); /* IE10+ */ -background: linear-gradient(135deg, rgba(240,249,255,1) 0%,rgba(203,235,255,1) 53%,rgba(161,219,255,1) 100%); /* W3C */ -filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f0f9ff', endColorstr='#a1dbff',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */ -} \ No newline at end of file diff --git a/main.js b/main.js index c7f4d45..f7868c0 100644 --- a/main.js +++ b/main.js @@ -12,55 +12,12 @@ var createVoxelMesh = require("./lib/createMesh.js") var glm = require("gl-matrix") var mat4 = glm.mat4 -//Load selectors -var selectModel = document.querySelector("#selectModel") -var showWire = document.querySelector("#showWire") -var selectMip = document.querySelector("#selectMip") - -//Add options to model select -;(function() { - for(var id in examples) { - var option = document.createElement("option") - option.value = id - option.innerHTML = id - selectModel.add(option) - } -})() - //Tile size parameters var TILE_SIZE = Math.floor(terrain.shape[0] / 16)|0 //Config variables var texture, shader, mesh, wireShader -function meshChange() { - var name = selectModel.value - mesh = createVoxelMesh(shell.gl, name, examples[name]) - var c = mesh.center - camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) -} - -function mipChange() { - var gl = shell.gl - switch(selectMip.value) { - case "none": - texture.magFilter = gl.NEAREST - texture.minFilter = gl.NEAREST - texture.mipSamples = 1 - break - case "linear": - texture.magFilter = gl.LINEAR - texture.minFilter = gl.LINEAR_MIPMAP_LINEAR - texture.mipSamples = 1 - break - case "aniso": - texture.magFilter = gl.LINEAR - texture.minFilter = gl.LINEAR_MIPMAP_LINEAR - texture.mipSamples = 4 - break - } -} - shell.on("gl-init", function() { var gl = shell.gl @@ -73,20 +30,22 @@ shell.on("gl-init", function() { [16,16,terrain.shape[0]>>4,terrain.shape[1]>>4,4], [terrain.stride[0]*16, terrain.stride[1]*16, terrain.stride[0], terrain.stride[1], terrain.stride[2]], 0) texture = createTileMap(gl, tiles, 2) - - //Hook event listeners - selectMip.addEventListener("change", mipChange) - mipChange() - - selectModel.addEventListener("change", meshChange) - meshChange() + + texture.magFilter = gl.LINEAR + texture.minFilter = gl.LINEAR_MIPMAP_LINEAR + texture.mipSamples = 4 + + mesh = createVoxelMesh(shell.gl, 'Terrain', examples.Terrain) + var c = mesh.center + camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) }) shell.on("gl-error", function() { - document.querySelector(".selectModel").style.display = "none" - document.querySelector(".noWebGL").style.display = "none" + // TODO }) +var showWire = true; + shell.on("gl-render", function(t) { var gl = shell.gl @@ -112,7 +71,7 @@ shell.on("gl-render", function(t) { gl.drawArrays(gl.TRIANGLES, 0, mesh.triangleVertexCount) mesh.triangleVAO.unbind() - if(showWire.checked) { + if(showWire) { //Bind the wire shader wireShader.bind() wireShader.attributes.position.location = 0 From 531a7585e869f57ead891c094b05e62339b1c1c4 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 31 Mar 2014 19:38:04 -0700 Subject: [PATCH 067/256] Change magnification filter to NEAREST, fix fuzziness --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index f7868c0..efab1e6 100644 --- a/main.js +++ b/main.js @@ -31,7 +31,7 @@ shell.on("gl-init", function() { [terrain.stride[0]*16, terrain.stride[1]*16, terrain.stride[0], terrain.stride[1], terrain.stride[2]], 0) texture = createTileMap(gl, tiles, 2) - texture.magFilter = gl.LINEAR + texture.magFilter = gl.NEAREST texture.minFilter = gl.LINEAR_MIPMAP_LINEAR texture.mipSamples = 4 From 709bf38b4bac3a2c0aed1c498df960adcbbecfc2 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 31 Mar 2014 22:16:39 -0700 Subject: [PATCH 068/256] Update dependencies --- package.json | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 1a7c4b7..1d52350 100644 --- a/package.json +++ b/package.json @@ -4,28 +4,28 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "ao-mesher": "~0.2.5", - "game-shell-orbit-camera": "~0.0.0", - "ao-shader": "~0.2.3", - "gl-buffer": "~0.1.0", - "gl-matrix": "~2.0.0", - "gl-now": "~0.0.3", - "gl-shader": "~0.0.5", - "gl-vao": "~0.0.2", - "gl-tile-map": "~0.3.0", - "isabella-texture-pack": "~0.0.1", - "lazy-property": "~0.0.0", - "ndarray": "~1.0.3", - "ndarray-fill": "~0.1.0", - "ndarray-ops": "~1.1.0", - "bunny": "~1.0.0", - "voxelize": "~0.1.0", - "brfs": "~0.0.6", - "teapot": "~0.0.1" + "ao-mesher": "^0.2.9", + "game-shell-orbit-camera": "^0.0.0", + "ao-shader": "^0.2.3", + "gl-buffer": "^2.0.6", + "gl-matrix": "^2.2.1", + "gl-now": "^1.0.1", + "gl-shader": "^3.0.0", + "gl-vao": "^1.1.2", + "gl-tile-map": "^0.3.0", + "isabella-texture-pack": "^0.0.1", + "lazy-property": "^0.0.2", + "ndarray": "^1.0.10", + "ndarray-fill": "^0.1.0", + "ndarray-ops": "^1.2.1", + "bunny": "^1.0.1", + "voxelize": "^0.1.0", + "brfs": "^1.0.0", + "teapot": "^0.0.1" }, "devDependencies": { - "beefy": "~0.4.0", - "browserify": "~2.25.0" + "beefy": "^1.1.0", + "browserify": "^3.38.0" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", From 9450ad72d0486d9bc8e22e4bddc211ebdeffe654 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 31 Mar 2014 22:17:27 -0700 Subject: [PATCH 069/256] Update createVAO for gl-vao ~1, attributes now before elements --- lib/createMesh.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/createMesh.js b/lib/createMesh.js index 10f0d15..ad6b0f2 100644 --- a/lib/createMesh.js +++ b/lib/createMesh.js @@ -20,7 +20,7 @@ function createVoxelMesh(gl, name, voxels) { //Upload triangle mesh to WebGL var triangleVertexCount = Math.floor(vert_data.length/8) var vert_buf = createBuffer(gl, vert_data) - var triangleVAO = createVAO(gl, undefined, [ + var triangleVAO = createVAO(gl, [ { "buffer": vert_buf, "type": gl.UNSIGNED_BYTE, "size": 4, @@ -47,7 +47,7 @@ function createVoxelMesh(gl, name, voxels) { ops.assign(wires.lo(i).step(3), trianglePositions.lo((i+1)%3).step(3)) } var wireBuf = createBuffer(gl, wireVertexArray.data) - var wireVAO = createVAO(gl, undefined, [ + var wireVAO = createVAO(gl, [ { "buffer": wireBuf, "type": gl.UNSIGNED_BYTE, "size": 3, From 17221c7556d3e56056fd1543a98b184d4e855a37 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 2 Apr 2014 19:25:42 -0700 Subject: [PATCH 070/256] Remove --open from beefy --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 807672f..aced64d 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "beefy main.js --open" + "start": "beefy main.js" }, "repository": { "type": "git", From 9a2655d95c58456bad942b5419020a3939702810 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 2 Apr 2014 19:33:29 -0700 Subject: [PATCH 071/256] Rename to game-shell-voxel --- README.md | 15 +++++++++++++-- package.json | 6 +++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fbad754..1a29d1e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,16 @@ -voxel-mipmap-demo -================= +game-shell-voxel +================ + +Experiment with using [game-shell](https://github.com/mikolalysenko/game-shell), +[gl-now](https://github.com/gl-modules/gl-now), +[ndarray](https://github.com/mikolalysenko/ndarray), etc. for an interactive voxel world + +Based on @mikolalysenko's [voxel-mipmap-demo](https://github.com/mikolalysenko/voxel-mipmap-demo), +somewhat simplified. + +--- + +## voxel-mipmap-demo Demonstration of texture mapping with greedy meshing. * Left click rotates diff --git a/package.json b/package.json index aced64d..fcd9bfd 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "voxel-mipmap-demo", + "name": "game-shell-voxel", "version": "0.0.0", "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", @@ -33,7 +33,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/mikolalysenko/voxel-mipmap-demo.git" + "url": "git://github.com/deathcap/game-shell-voxel.git" }, "keywords": [ "mipmap", @@ -44,7 +44,7 @@ "license": "MIT", "gitHead": "0f57d9dfbe095ce86f182d2e70c2c0a1f7927ca9", "bugs": { - "url": "https://github.com/mikolalysenko/voxel-mipmap-demo/issues" + "url": "https://github.com/deathcap/game-shell-voxel/issues" }, "browser": { "transform": "brfs" From c47bb939e3c5a33034e5ec68dc2884365696e38b Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 2 Apr 2014 19:34:44 -0700 Subject: [PATCH 072/256] Remove html, use default from beefy --- index.html | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 index.html diff --git a/index.html b/index.html deleted file mode 100644 index bbfbde3..0000000 --- a/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - Voxel Mipmap Demo - - - Fork me on GitHub - - - From 4f2c0be9a99c9cc1e82fb711c99fbc8a5dea8e03 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 2 Apr 2014 19:36:52 -0700 Subject: [PATCH 073/256] Remove examples except for terrain --- lib/examples.js | 47 ----------------------------------------------- package.json | 5 +---- 2 files changed, 1 insertion(+), 51 deletions(-) diff --git a/lib/examples.js b/lib/examples.js index c574505..23c0270 100644 --- a/lib/examples.js +++ b/lib/examples.js @@ -2,13 +2,8 @@ var ndarray = require("ndarray") var fill = require("ndarray-fill") -var ops = require("ndarray-ops") -var voxelize = require("voxelize") var lazyProperty = require("lazy-property") -var bunny = require("bunny") -var teapot = require("teapot") - //Fill ndarray with function function makeFill(name, size, func) { lazyProperty(exports, name, function() { @@ -18,21 +13,6 @@ function makeFill(name, size, func) { }, true) } -//Fill ndarray with voxelized mesh -function makeMesh(name, mesh, tolerance, fill) { - lazyProperty(exports, name, function() { - var result = voxelize(mesh.cells, mesh.positions, tolerance) - var voxels = result.voxels - var nshape = result.voxels.shape.slice(0) - for(var i=0; i<3; ++i) { - nshape[i] += 2 - } - var padded = ndarray(new Int32Array(nshape[0]*nshape[1]*nshape[2]), nshape) - ops.muls(padded, result.voxels, fill) - return padded - }, true) -} - //Terrain makeFill("Terrain", [33,33,33], function(i,j,k) { if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { @@ -55,31 +35,4 @@ makeFill("Terrain", [33,33,33], function(i,j,k) { return (1<<15)+0xff }) -//Random -makeFill("Random", [16,16,16], function(i,j,k) { - if(i <=1 || i>=14 || j <= 1 || j >= 14 || k <= 1 || k >= 14) { - return 0 - } - if(Math.random() < 0.6) { - return 0 - } - return ((Math.random()*255)|0) + (1<<15) -}) - -makeFill("Tree", [16,16,16], function(i,j,k) { - if(i === 8 && k === 8 && 4 Date: Wed, 2 Apr 2014 19:44:42 -0700 Subject: [PATCH 074/256] Show an error message and link to get.webgl.org on gl-error --- main.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index efab1e6..6f77c46 100644 --- a/main.js +++ b/main.js @@ -40,8 +40,15 @@ shell.on("gl-init", function() { camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) }) -shell.on("gl-error", function() { - // TODO +shell.on("gl-error", function(err) { + var a = document.createElement('a') + a.textContent = 'You need a modern WebGL browser (Chrome/Firefox) to play this game. Click here for more information. (WebGL error: ' + err + ')' + a.style.webkitUserSelect = '' + a.href = 'http://get.webgl.org/'; + + while(document.body.firstChild) document.body.removeChild(document.body.firstChild) + + document.body.appendChild(a) }) var showWire = true; From 27afdcb938917538cdff8a777baacc7292dcda83 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 2 Apr 2014 19:46:58 -0700 Subject: [PATCH 075/256] Add demo.js, change main.js to export shell --- demo.js | 5 +++++ main.js | 3 +++ package.json | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 demo.js diff --git a/demo.js b/demo.js new file mode 100644 index 0000000..08b77f4 --- /dev/null +++ b/demo.js @@ -0,0 +1,5 @@ +'use strict'; + +var shell = require('./'); + + diff --git a/main.js b/main.js index 6f77c46..4068f6b 100644 --- a/main.js +++ b/main.js @@ -91,3 +91,6 @@ shell.on("gl-render", function(t) { mesh.wireVAO.unbind() } }) + +module.exports = shell + diff --git a/package.json b/package.json index 9acef87..94ec289 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "beefy main.js" + "start": "beefy demo.js" }, "repository": { "type": "git", From 91d0901164dd812ae4f8939d9f0b3fbb96b91fcd Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 2 Apr 2014 19:49:22 -0700 Subject: [PATCH 076/256] Show wireframe when F is held down --- main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 4068f6b..ebb3643 100644 --- a/main.js +++ b/main.js @@ -38,6 +38,8 @@ shell.on("gl-init", function() { mesh = createVoxelMesh(shell.gl, 'Terrain', examples.Terrain) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) + + shell.bind('wireframe', 'F') }) shell.on("gl-error", function(err) { @@ -51,8 +53,6 @@ shell.on("gl-error", function(err) { document.body.appendChild(a) }) -var showWire = true; - shell.on("gl-render", function(t) { var gl = shell.gl @@ -78,7 +78,7 @@ shell.on("gl-render", function(t) { gl.drawArrays(gl.TRIANGLES, 0, mesh.triangleVertexCount) mesh.triangleVAO.unbind() - if(showWire) { + if(shell.wasDown('wireframe')) { //Bind the wire shader wireShader.bind() wireShader.attributes.position.location = 0 From 1f0ade0577b4d510163c2b878fdda7eb3803e98b Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 2 Apr 2014 21:02:31 -0700 Subject: [PATCH 077/256] Load plugins --- demo.js | 3 ++- main.js | 26 +++++++++++++++++++++++--- package.json | 3 ++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/demo.js b/demo.js index 08b77f4..84b3ed9 100644 --- a/demo.js +++ b/demo.js @@ -1,5 +1,6 @@ 'use strict'; -var shell = require('./'); +var createShell = require('./'); +createShell(); diff --git a/main.js b/main.js index ebb3643..d50cab4 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,7 @@ "use strict" -var shell = require("gl-now")({clearColor: [0,0,0,0], pointerLock: true}) -var camera = require("game-shell-fps-camera")(shell) +var createShell = require("gl-now") +var createCamera = require("game-shell-fps-camera") var createTileMap = require("gl-tile-map") var ndarray = require("ndarray") var terrain = require("isabella-texture-pack") @@ -12,12 +12,31 @@ var createVoxelMesh = require("./lib/createMesh.js") var glm = require("gl-matrix") var mat4 = glm.mat4 +var createPlugins = require('voxel-plugins') + //Tile size parameters var TILE_SIZE = Math.floor(terrain.shape[0] / 16)|0 //Config variables var texture, shader, mesh, wireShader +var main = function(opts) { + opts = opts || {}; + opts.clearColor = [0,0,0,0]; + opts.pointerLock = true; + + var shell = createShell(opts); + var camera = require("game-shell-fps-camera")(shell) + + var plugins = createPlugins(shell, {require: shell.require || require}); + shell.plugins = plugins; + + for (var name in opts.pluginOpts) { + plugins.add(name, opts.pluginOpts[name]); + } + plugins.loadAll(); + + shell.on("gl-init", function() { var gl = shell.gl @@ -91,6 +110,7 @@ shell.on("gl-render", function(t) { mesh.wireVAO.unbind() } }) +} -module.exports = shell +module.exports = main diff --git a/package.json b/package.json index 94ec289..e7da564 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "ndarray-ops": "^1.2.1", - "brfs": "^1.0.0" + "brfs": "^1.0.0", + "voxel-plugins": "^0.3.0" }, "devDependencies": { "beefy": "^1.1.0", From f580511cc7a3db0f30c3ed533ffefc2e7b00cfd2 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 2 Apr 2014 21:04:04 -0700 Subject: [PATCH 078/256] Reduce globals --- main.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index d50cab4..6f12920 100644 --- a/main.js +++ b/main.js @@ -17,9 +17,6 @@ var createPlugins = require('voxel-plugins') //Tile size parameters var TILE_SIZE = Math.floor(terrain.shape[0] / 16)|0 -//Config variables -var texture, shader, mesh, wireShader - var main = function(opts) { opts = opts || {}; opts.clearColor = [0,0,0,0]; @@ -36,6 +33,8 @@ var main = function(opts) { } plugins.loadAll(); +//Config variables +var texture, shader, mesh, wireShader shell.on("gl-init", function() { var gl = shell.gl From b30ffe20b23f1a14e9b787bbb8c3fd50d222088c Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 2 Apr 2014 21:27:13 -0700 Subject: [PATCH 079/256] Add voxel-plugins-ui plugin --- demo.js | 12 +++++++++++- main.js | 7 ++++++- package.json | 6 +++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/demo.js b/demo.js index 84b3ed9..3e760e0 100644 --- a/demo.js +++ b/demo.js @@ -1,6 +1,16 @@ 'use strict'; var createShell = require('./'); +var createGUI = require('dat-gui'); -createShell(); +require('kb-bindings-ui'); +require('voxel-plugins-ui'); +createShell({require: require, pluginOpts: + { + 'voxel-plugins-ui': {gui: new createGUI.GUI()}, + //'kb-bindings-ui': {gui: new createGUI.GUI()}, // TODO: add compatibility, game-shell bindings object is different than kb-bindings + } +}); + +document.querySelector('.dg.ac').style.zIndex = 1; // fix datgui behind canvas diff --git a/main.js b/main.js index 6f12920..2622ba1 100644 --- a/main.js +++ b/main.js @@ -25,7 +25,12 @@ var main = function(opts) { var shell = createShell(opts); var camera = require("game-shell-fps-camera")(shell) - var plugins = createPlugins(shell, {require: shell.require || require}); + var game = {}; + game.isClient = true; + game.buttons = {}; + game.buttons.bindings = shell.bindings; + + var plugins = createPlugins(game, {require: opts.require || require}); shell.plugins = plugins; for (var name in opts.pluginOpts) { diff --git a/package.json b/package.json index e7da564..2877bea 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,11 @@ "ndarray-fill": "^0.1.0", "ndarray-ops": "^1.2.1", "brfs": "^1.0.0", - "voxel-plugins": "^0.3.0" + "voxel-plugins": "^0.3.0", + "kb-bindings": "^0.2.0", + "kb-bindings-ui": "^0.2.0", + "dat-gui": "^0.5.0", + "voxel-plugins-ui": "^0.2.0" }, "devDependencies": { "beefy": "^1.1.0", From 857e5dfd466faaf0e84e2ea3fb2f7cc1df3f3a38 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 2 Apr 2014 21:38:12 -0700 Subject: [PATCH 080/256] Specify a better default camera position --- main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 2622ba1..266805e 100644 --- a/main.js +++ b/main.js @@ -23,7 +23,11 @@ var main = function(opts) { opts.pointerLock = true; var shell = createShell(opts); - var camera = require("game-shell-fps-camera")(shell) + var camera = createCamera(shell); + + camera.position[0] = -20; + camera.position[1] = -33; + camera.position[2] = -40; var game = {}; game.isClient = true; From f9a5bcce6f3468e697fab11207a120604a1412a5 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 2 Apr 2014 21:44:49 -0700 Subject: [PATCH 081/256] Add some documentation --- README.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a29d1e..b8ab2e1 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,30 @@ Experiment with using [game-shell](https://github.com/mikolalysenko/game-shell), [gl-now](https://github.com/gl-modules/gl-now), [ndarray](https://github.com/mikolalysenko/ndarray), etc. for an interactive voxel world -Based on @mikolalysenko's [voxel-mipmap-demo](https://github.com/mikolalysenko/voxel-mipmap-demo), -somewhat simplified. +Based on @mikolalysenko's [voxel-mipmap-demo](https://github.com/mikolalysenko/voxel-mipmap-demo). + +Warning: this is only a test + +# Usage + + var createShell = require('game-shell-voxel'); + + createShell({require: require, pluginOpts: { + // list plugins and options here + }); + +For an example run `npm start` or check out the [live demo](http://deathcap.github.io/game-shell-voxel). + +Click the canvas to interact. Added features: + +* Mouse and key controls (WASD, space, shift) using [game-shell-fps-camera](https://github.com/deathcap/game-shell-fps-camera) +* Plugin support using [voxel-plugins](https://github.com/deathcap/voxel-plugins) +* ... --- +original voxel-mipmap-demo readme: + ## voxel-mipmap-demo Demonstration of texture mapping with greedy meshing. From 0cbd807927aeb72bc1bc56a08a10d43f577b5835 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 3 Apr 2014 12:36:40 -0700 Subject: [PATCH 082/256] Add voxel-registry --- demo.js | 2 ++ package.json | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/demo.js b/demo.js index 3e760e0..2dd8f49 100644 --- a/demo.js +++ b/demo.js @@ -5,9 +5,11 @@ var createGUI = require('dat-gui'); require('kb-bindings-ui'); require('voxel-plugins-ui'); +require('voxel-registry'); createShell({require: require, pluginOpts: { + 'voxel-registry': {}, 'voxel-plugins-ui': {gui: new createGUI.GUI()}, //'kb-bindings-ui': {gui: new createGUI.GUI()}, // TODO: add compatibility, game-shell bindings object is different than kb-bindings } diff --git a/package.json b/package.json index 2877bea..cbae378 100644 --- a/package.json +++ b/package.json @@ -20,12 +20,13 @@ "ndarray-ops": "^1.2.1", "brfs": "^1.0.0", "voxel-plugins": "^0.3.0", - "kb-bindings": "^0.2.0", - "kb-bindings-ui": "^0.2.0", - "dat-gui": "^0.5.0", - "voxel-plugins-ui": "^0.2.0" + "dat-gui": "^0.5.0" }, "devDependencies": { + "kb-bindings": "^0.2.0", + "kb-bindings-ui": "^0.2.0", + "voxel-plugins-ui": "^0.2.0", + "voxel-registry": "^0.3.0", "beefy": "^1.1.0", "browserify": "^3.38.0" }, From 589ee0075407b8d9490ad31cf971a11c71c42ca1 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 12:52:14 -0700 Subject: [PATCH 083/256] Load textures with dynamic atlas built from voxel-stitch. Closes GH-1 --- demo.js | 2 ++ lib/examples.js | 14 ++++++++------ main.js | 23 ++++++++++++++++++++++- package.json | 3 ++- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/demo.js b/demo.js index 2dd8f49..bdd9237 100644 --- a/demo.js +++ b/demo.js @@ -6,10 +6,12 @@ var createGUI = require('dat-gui'); require('kb-bindings-ui'); require('voxel-plugins-ui'); require('voxel-registry'); +require('voxel-stitch'); createShell({require: require, pluginOpts: { 'voxel-registry': {}, + 'voxel-stitch': {}, 'voxel-plugins-ui': {gui: new createGUI.GUI()}, //'kb-bindings-ui': {gui: new createGUI.GUI()}, // TODO: add compatibility, game-shell bindings object is different than kb-bindings } diff --git a/lib/examples.js b/lib/examples.js index 23c0270..e91f39d 100644 --- a/lib/examples.js +++ b/lib/examples.js @@ -16,23 +16,25 @@ function makeFill(name, size, func) { //Terrain makeFill("Terrain", [33,33,33], function(i,j,k) { if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { - return 0 + return 0 // air } var h0 = 3.0 * Math.sin(Math.PI * i / 12.0 - Math.PI * k * 0.1) + 27 if(j > h0+1) { - return 0 + return 0 // air } if(h0 <= j) { - return (1<<15)+0x19 + return (1<<15)+5//0x19 // grass } var h1 = 2.0 * Math.sin(Math.PI * i * 0.25 - Math.PI * k * 0.3) + 20 if(h1 <= j) { - return (1<<15)+0x20 + return (1<<15)+0//0x20 // dirt } if(4 < j) { - return Math.random() < 0.1 ? (1<<15)+0x23 : (1<<15)+0x10 + return Math.random() < 0.1 ? + (1<<15)+4 : //0x23 : // diamond + (1<<15)+2 //0x10 // stone } - return (1<<15)+0xff + return (1<<15)+3// lava }) diff --git a/main.js b/main.js index 266805e..bd635c4 100644 --- a/main.js +++ b/main.js @@ -56,11 +56,32 @@ shell.on("gl-init", function() { var tiles = ndarray(terrain.data, [16,16,terrain.shape[0]>>4,terrain.shape[1]>>4,4], [terrain.stride[0]*16, terrain.stride[1]*16, terrain.stride[0], terrain.stride[1], terrain.stride[2]], 0) + + var registry = shell.plugins.get('voxel-registry') // test blocks TODO: move + registry.registerBlock('dirt', {texture: 'dirt'}) + registry.registerBlock('stone', {texture: 'stone'}) + registry.registerBlock('grass', {texture: 'grass_top'}) // TODO: arrays + registry.registerBlock('cobblestone', {texture: 'cobblestone'}) + registry.registerBlock('lava', {texture: 'lava_still'}) + registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) + + var stitcher = shell.plugins.get('voxel-stitch') // TODO: load not as a plugin? + var updateTexture = function() { + texture = createTileMap(gl, stitcher.atlas, 2) + texture.magFilter = gl.NEAREST + texture.minFilter = gl.LINEAR_MIPMAP_LINEAR + texture.mipSamples = 4 + } + stitcher.on('added', updateTexture) + stitcher.stitch() + + /* texture = createTileMap(gl, tiles, 2) texture.magFilter = gl.NEAREST texture.minFilter = gl.LINEAR_MIPMAP_LINEAR texture.mipSamples = 4 + */ mesh = createVoxelMesh(shell.gl, 'Terrain', examples.Terrain) var c = mesh.center @@ -99,7 +120,7 @@ shell.on("gl-render", function(t) { shader.uniforms.view = view shader.uniforms.model = model shader.uniforms.tileSize = TILE_SIZE - shader.uniforms.tileMap = texture.bind() + if (texture) shader.uniforms.tileMap = texture.bind() // texture might not have loaded yet mesh.triangleVAO.bind() gl.drawArrays(gl.TRIANGLES, 0, mesh.triangleVertexCount) diff --git a/package.json b/package.json index cbae378..c7c72a1 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "main.js", "dependencies": { "ao-mesher": "^0.2.9", - "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git", + "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git#3d69d8d2cde740b69855d92a02a8f9e23666ea40", + "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#791e536482540190ba2bdae91624d01a75c1455c", "ao-shader": "^0.2.3", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", From a37235d1f66a443f411ed9abbc627d334579d5b6 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 18:15:52 -0700 Subject: [PATCH 084/256] Fix cobblestone -> stone The (1>>15)+x IDs are off by one (block ID x-1) --- lib/examples.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/examples.js b/lib/examples.js index e91f39d..eca893f 100644 --- a/lib/examples.js +++ b/lib/examples.js @@ -32,7 +32,7 @@ makeFill("Terrain", [33,33,33], function(i,j,k) { if(4 < j) { return Math.random() < 0.1 ? (1<<15)+4 : //0x23 : // diamond - (1<<15)+2 //0x10 // stone + (1<<15)+1 //0x10 // stone } return (1<<15)+3// lava }) From ba98d3b93522fff2aa01ec2b05134ace8924970f Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 18:44:29 -0700 Subject: [PATCH 085/256] Add multiple textures for grass block (but still only using top texture) Update voxel-stitch deathcap/voxel-stitch@8026d9e64fc0534a3eb3becf01e8363222af494d Fill tile slots deterministically, in order called deathcap/voxel-stitch@0fed713e179105c4067f7ff843691cad7c798872 Support multiple textures as arrays; refactor addTextureName/Pixels Commit message generated by https://github.com/deathcap/lmno-cl --- lib/examples.js | 6 +++--- main.js | 2 +- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/examples.js b/lib/examples.js index eca893f..ce5acbc 100644 --- a/lib/examples.js +++ b/lib/examples.js @@ -23,7 +23,7 @@ makeFill("Terrain", [33,33,33], function(i,j,k) { return 0 // air } if(h0 <= j) { - return (1<<15)+5//0x19 // grass + return (1<<15)+2//0x19 // grass } var h1 = 2.0 * Math.sin(Math.PI * i * 0.25 - Math.PI * k * 0.3) + 20 if(h1 <= j) { @@ -31,10 +31,10 @@ makeFill("Terrain", [33,33,33], function(i,j,k) { } if(4 < j) { return Math.random() < 0.1 ? - (1<<15)+4 : //0x23 : // diamond + (1<<15)+7 : //0x23 : // diamond (1<<15)+1 //0x10 // stone } - return (1<<15)+3// lava + return (1<<15)+6 // lava }) diff --git a/main.js b/main.js index bd635c4..4513b6f 100644 --- a/main.js +++ b/main.js @@ -60,7 +60,7 @@ shell.on("gl-init", function() { var registry = shell.plugins.get('voxel-registry') // test blocks TODO: move registry.registerBlock('dirt', {texture: 'dirt'}) registry.registerBlock('stone', {texture: 'stone'}) - registry.registerBlock('grass', {texture: 'grass_top'}) // TODO: arrays + registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) registry.registerBlock('cobblestone', {texture: 'cobblestone'}) registry.registerBlock('lava', {texture: 'lava_still'}) registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) diff --git a/package.json b/package.json index c7c72a1..8fea163 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "ao-mesher": "^0.2.9", "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git#3d69d8d2cde740b69855d92a02a8f9e23666ea40", - "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#791e536482540190ba2bdae91624d01a75c1455c", + "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#8026d9e64fc0534a3eb3becf01e8363222af494d", "ao-shader": "^0.2.3", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", From 25a00cb7e45a4fbda44c6bee1f8319152885f45f Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 18:47:26 -0700 Subject: [PATCH 086/256] Grass block last --- lib/examples.js | 6 +++--- main.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/examples.js b/lib/examples.js index ce5acbc..6fc821e 100644 --- a/lib/examples.js +++ b/lib/examples.js @@ -23,7 +23,7 @@ makeFill("Terrain", [33,33,33], function(i,j,k) { return 0 // air } if(h0 <= j) { - return (1<<15)+2//0x19 // grass + return (1<<15)+5//0x19 // grass } var h1 = 2.0 * Math.sin(Math.PI * i * 0.25 - Math.PI * k * 0.3) + 20 if(h1 <= j) { @@ -31,10 +31,10 @@ makeFill("Terrain", [33,33,33], function(i,j,k) { } if(4 < j) { return Math.random() < 0.1 ? - (1<<15)+7 : //0x23 : // diamond + (1<<15)+4 : //0x23 : // diamond (1<<15)+1 //0x10 // stone } - return (1<<15)+6 // lava + return (1<<15)+3 // lava }) diff --git a/main.js b/main.js index 4513b6f..0d0f192 100644 --- a/main.js +++ b/main.js @@ -60,10 +60,10 @@ shell.on("gl-init", function() { var registry = shell.plugins.get('voxel-registry') // test blocks TODO: move registry.registerBlock('dirt', {texture: 'dirt'}) registry.registerBlock('stone', {texture: 'stone'}) - registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) registry.registerBlock('cobblestone', {texture: 'cobblestone'}) registry.registerBlock('lava', {texture: 'lava_still'}) registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) + registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) var stitcher = shell.plugins.get('voxel-stitch') // TODO: load not as a plugin? var updateTexture = function() { From ec90df323fda9addf32f1f6613d517fea4149dd0 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 18:51:53 -0700 Subject: [PATCH 087/256] Move sample blocks to a plugin --- demo.js | 2 ++ main.js | 8 -------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/demo.js b/demo.js index bdd9237..fa1715f 100644 --- a/demo.js +++ b/demo.js @@ -7,6 +7,7 @@ require('kb-bindings-ui'); require('voxel-plugins-ui'); require('voxel-registry'); require('voxel-stitch'); +require('./lib/blocks.js'); createShell({require: require, pluginOpts: { @@ -14,6 +15,7 @@ createShell({require: require, pluginOpts: 'voxel-stitch': {}, 'voxel-plugins-ui': {gui: new createGUI.GUI()}, //'kb-bindings-ui': {gui: new createGUI.GUI()}, // TODO: add compatibility, game-shell bindings object is different than kb-bindings + './lib/blocks.js': {}, } }); diff --git a/main.js b/main.js index 0d0f192..9035a32 100644 --- a/main.js +++ b/main.js @@ -57,14 +57,6 @@ shell.on("gl-init", function() { [16,16,terrain.shape[0]>>4,terrain.shape[1]>>4,4], [terrain.stride[0]*16, terrain.stride[1]*16, terrain.stride[0], terrain.stride[1], terrain.stride[2]], 0) - var registry = shell.plugins.get('voxel-registry') // test blocks TODO: move - registry.registerBlock('dirt', {texture: 'dirt'}) - registry.registerBlock('stone', {texture: 'stone'}) - registry.registerBlock('cobblestone', {texture: 'cobblestone'}) - registry.registerBlock('lava', {texture: 'lava_still'}) - registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) - registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) - var stitcher = shell.plugins.get('voxel-stitch') // TODO: load not as a plugin? var updateTexture = function() { texture = createTileMap(gl, stitcher.atlas, 2) From d51606f256754c63554e1621224c721e985b7346 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 19:19:48 -0700 Subject: [PATCH 088/256] Generate mipmaps only once all textures are loaded. Closes GH-1 Update voxel-stitch deathcap/voxel-stitch@f368d5628a746726b69540a3f8767f04049ded2a Add addedAll event Commit message generated by https://github.com/deathcap/lmno-cl --- main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 9035a32..bec978b 100644 --- a/main.js +++ b/main.js @@ -64,7 +64,7 @@ shell.on("gl-init", function() { texture.minFilter = gl.LINEAR_MIPMAP_LINEAR texture.mipSamples = 4 } - stitcher.on('added', updateTexture) + stitcher.on('addedAll', updateTexture) stitcher.stitch() /* diff --git a/package.json b/package.json index 8fea163..c15d95b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "ao-mesher": "^0.2.9", "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git#3d69d8d2cde740b69855d92a02a8f9e23666ea40", - "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#8026d9e64fc0534a3eb3becf01e8363222af494d", + "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#f368d5628a746726b69540a3f8767f04049ded2a", "ao-shader": "^0.2.3", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", From 8469c1f59f3040c14b8c0459e1608b383669de33 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 19:21:41 -0700 Subject: [PATCH 089/256] Add missing sample blocks file --- lib/blocks.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/blocks.js diff --git a/lib/blocks.js b/lib/blocks.js new file mode 100644 index 0000000..2eba4fb --- /dev/null +++ b/lib/blocks.js @@ -0,0 +1,19 @@ +'use strict'; + +// sample blocks for demo.js TODO: move to voxel-land as a proper plugin, refactor with lib/examples.js terrain gen + +module.exports = function(game, opts) { + return new BlocksPlugin(game, opts); +}; + +function BlocksPlugin(game, opts) { + var registry = game.plugins.get('voxel-registry'); + + registry.registerBlock('dirt', {texture: 'dirt'}) + registry.registerBlock('stone', {texture: 'stone'}) + registry.registerBlock('cobblestone', {texture: 'cobblestone'}) + registry.registerBlock('lava', {texture: 'lava_still'}) + registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) + registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) +} + From d1448ea21729d5f3e026ce4f4e8d3e0703bca93a Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 20:45:51 -0700 Subject: [PATCH 090/256] Add voxel-drop plugin to demo, drop a resource pack to load textures --- README.md | 1 + demo.js | 2 ++ package.json | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b8ab2e1..4a55d12 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Click the canvas to interact. Added features: * Mouse and key controls (WASD, space, shift) using [game-shell-fps-camera](https://github.com/deathcap/game-shell-fps-camera) * Plugin support using [voxel-plugins](https://github.com/deathcap/voxel-plugins) +* Dynamic texture atlas using [voxel-stitch](https://github.com/deathcap/voxel-stitch) * ... --- diff --git a/demo.js b/demo.js index fa1715f..6298dba 100644 --- a/demo.js +++ b/demo.js @@ -8,6 +8,7 @@ require('voxel-plugins-ui'); require('voxel-registry'); require('voxel-stitch'); require('./lib/blocks.js'); +require('voxel-drop'); createShell({require: require, pluginOpts: { @@ -16,6 +17,7 @@ createShell({require: require, pluginOpts: 'voxel-plugins-ui': {gui: new createGUI.GUI()}, //'kb-bindings-ui': {gui: new createGUI.GUI()}, // TODO: add compatibility, game-shell bindings object is different than kb-bindings './lib/blocks.js': {}, + 'voxel-drop': {}, } }); diff --git a/package.json b/package.json index c15d95b..21dd096 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "voxel-plugins-ui": "^0.2.0", "voxel-registry": "^0.3.0", "beefy": "^1.1.0", - "browserify": "^3.38.0" + "browserify": "^3.38.0", + "voxel-drop": "^0.1.0" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", From 8900b7a4a3e32b65ed56435fe75bfe71b9c3c65b Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 20:48:29 -0700 Subject: [PATCH 091/256] Remove isabella-texture-pack --- main.js | 15 +-------------- package.json | 1 - 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/main.js b/main.js index bec978b..1b19e30 100644 --- a/main.js +++ b/main.js @@ -4,7 +4,6 @@ var createShell = require("gl-now") var createCamera = require("game-shell-fps-camera") var createTileMap = require("gl-tile-map") var ndarray = require("ndarray") -var terrain = require("isabella-texture-pack") var createWireShader = require("./lib/wireShader.js") var createAOShader = require("ao-shader") var examples = require("./lib/examples.js") @@ -15,7 +14,7 @@ var mat4 = glm.mat4 var createPlugins = require('voxel-plugins') //Tile size parameters -var TILE_SIZE = Math.floor(terrain.shape[0] / 16)|0 +var TILE_SIZE = 16 // TODO: heterogenous var main = function(opts) { opts = opts || {}; @@ -53,10 +52,6 @@ shell.on("gl-init", function() { wireShader = createWireShader(gl) //Create texture atlas - var tiles = ndarray(terrain.data, - [16,16,terrain.shape[0]>>4,terrain.shape[1]>>4,4], - [terrain.stride[0]*16, terrain.stride[1]*16, terrain.stride[0], terrain.stride[1], terrain.stride[2]], 0) - var stitcher = shell.plugins.get('voxel-stitch') // TODO: load not as a plugin? var updateTexture = function() { texture = createTileMap(gl, stitcher.atlas, 2) @@ -67,14 +62,6 @@ shell.on("gl-init", function() { stitcher.on('addedAll', updateTexture) stitcher.stitch() - /* - texture = createTileMap(gl, tiles, 2) - - texture.magFilter = gl.NEAREST - texture.minFilter = gl.LINEAR_MIPMAP_LINEAR - texture.mipSamples = 4 - */ - mesh = createVoxelMesh(shell.gl, 'Terrain', examples.Terrain) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) diff --git a/package.json b/package.json index 21dd096..a6ffd03 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "gl-shader": "^3.0.0", "gl-vao": "^1.1.2", "gl-tile-map": "^0.3.0", - "isabella-texture-pack": "^0.0.1", "lazy-property": "^0.0.2", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", From 111bca31aeddb214a5c6f5c981d0ab364e81686f Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 20:50:01 -0700 Subject: [PATCH 092/256] dat-gui is a devDependency --- demo.js | 2 +- package.json | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/demo.js b/demo.js index 6298dba..d1f183a 100644 --- a/demo.js +++ b/demo.js @@ -3,8 +3,8 @@ var createShell = require('./'); var createGUI = require('dat-gui'); -require('kb-bindings-ui'); require('voxel-plugins-ui'); +//require('kb-bindings-ui'); require('voxel-registry'); require('voxel-stitch'); require('./lib/blocks.js'); diff --git a/package.json b/package.json index a6ffd03..0554c56 100644 --- a/package.json +++ b/package.json @@ -19,12 +19,11 @@ "ndarray-fill": "^0.1.0", "ndarray-ops": "^1.2.1", "brfs": "^1.0.0", - "voxel-plugins": "^0.3.0", - "dat-gui": "^0.5.0" + "voxel-plugins": "^0.3.0" }, "devDependencies": { + "dat-gui": "^0.5.0", "kb-bindings": "^0.2.0", - "kb-bindings-ui": "^0.2.0", "voxel-plugins-ui": "^0.2.0", "voxel-registry": "^0.3.0", "beefy": "^1.1.0", From 18532ed9db4733f216629b3676c977eb6b156326 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 22:27:05 -0700 Subject: [PATCH 093/256] Change beefy port to 9999 Since I often have other beefy instances running, default 9966 conflicts --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0554c56..1be8c02 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "beefy demo.js" + "start": "beefy demo.js 9999" }, "repository": { "type": "git", From d4d70371a504c27a5f7c45267a63a9c5a1ee4418 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 4 Apr 2014 22:36:42 -0700 Subject: [PATCH 094/256] Update to game-shell-fps-camera and voxel-stitch ^0.1.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1be8c02..6ba7f43 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "main": "main.js", "dependencies": { "ao-mesher": "^0.2.9", - "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git#3d69d8d2cde740b69855d92a02a8f9e23666ea40", - "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#f368d5628a746726b69540a3f8767f04049ded2a", + "game-shell-fps-camera": "^0.1.0", + "voxel-stitch": "^0.1.0", "ao-shader": "^0.2.3", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", From b3a635001dca4f3248abafe0780d414ef8855eba Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 13:52:27 -0700 Subject: [PATCH 095/256] Update to ao-mesher with per-side textures --- lib/createMesh.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/createMesh.js b/lib/createMesh.js index ad6b0f2..bb41b45 100644 --- a/lib/createMesh.js +++ b/lib/createMesh.js @@ -9,13 +9,13 @@ var ops = require("ndarray-ops") var cached = {} //Creates a mesh from a set of voxels -function createVoxelMesh(gl, name, voxels) { +function createVoxelMesh(gl, name, voxels, voxelSideTextureIDs) { if(name in cached) { return cached[name] } //Create mesh - var vert_data = createAOMesh(voxels) + var vert_data = createAOMesh(voxels, voxelSideTextureIDs) //Upload triangle mesh to WebGL var triangleVertexCount = Math.floor(vert_data.length/8) @@ -70,4 +70,4 @@ function createVoxelMesh(gl, name, voxels) { return result } -module.exports = createVoxelMesh \ No newline at end of file +module.exports = createVoxelMesh diff --git a/package.json b/package.json index 6ba7f43..e003a35 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "ao-mesher": "^0.2.9", + "ao-mesher": "git://github.com/deathcap/ao-mesher.git#bfc352f8210d9538956ed658527e0810cd70a1e3", "game-shell-fps-camera": "^0.1.0", "voxel-stitch": "^0.1.0", "ao-shader": "^0.2.3", From d14171c4c3ee6a2d27f0dbfbe1141b12f3badc46 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 13:54:17 -0700 Subject: [PATCH 096/256] Add a multi-colored wool block for testing side textures --- lib/blocks.js | 1 + lib/examples.js | 4 ++++ main.js | 6 +++++- package.json | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/blocks.js b/lib/blocks.js index 2eba4fb..5d29a39 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -15,5 +15,6 @@ function BlocksPlugin(game, opts) { registry.registerBlock('lava', {texture: 'lava_still'}) registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) + registry.registerBlock('wool', {texture: ['wool_colored_gray', 'wool_colored_white', 'wool_colored_green', 'wool_colored_light_blue', 'wool_colored_red', 'wool_colored_green']}) } diff --git a/lib/examples.js b/lib/examples.js index 6fc821e..de2287e 100644 --- a/lib/examples.js +++ b/lib/examples.js @@ -15,6 +15,10 @@ function makeFill(name, size, func) { //Terrain makeFill("Terrain", [33,33,33], function(i,j,k) { + if (i===30 && j===30 && k===30) { + return (1<<15)+6; // wool + } + if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { return 0 // air } diff --git a/main.js b/main.js index 1b19e30..4d88d75 100644 --- a/main.js +++ b/main.js @@ -23,6 +23,10 @@ var main = function(opts) { var shell = createShell(opts); var camera = createCamera(shell); + /* + global.shell = shell + global.camera = camera + */ camera.position[0] = -20; camera.position[1] = -33; @@ -62,7 +66,7 @@ shell.on("gl-init", function() { stitcher.on('addedAll', updateTexture) stitcher.stitch() - mesh = createVoxelMesh(shell.gl, 'Terrain', examples.Terrain) + mesh = createVoxelMesh(shell.gl, 'Terrain', examples.Terrain, stitcher.voxelSideTextureIDs) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) diff --git a/package.json b/package.json index e003a35..39fad88 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "ao-mesher": "git://github.com/deathcap/ao-mesher.git#bfc352f8210d9538956ed658527e0810cd70a1e3", + "ao-mesher": "git://github.com/deathcap/ao-mesher.git#c4c9d8594bb10d6b77a9ae8ee2ab7c99a6328d13", "game-shell-fps-camera": "^0.1.0", "voxel-stitch": "^0.1.0", "ao-shader": "^0.2.3", From 7a70ebfaba8014804d616d17d3a8de0beae70419 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 15:10:23 -0700 Subject: [PATCH 097/256] Unique colors on each wool block face --- lib/blocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blocks.js b/lib/blocks.js index 5d29a39..0e01a75 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -15,6 +15,6 @@ function BlocksPlugin(game, opts) { registry.registerBlock('lava', {texture: 'lava_still'}) registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) - registry.registerBlock('wool', {texture: ['wool_colored_gray', 'wool_colored_white', 'wool_colored_green', 'wool_colored_light_blue', 'wool_colored_red', 'wool_colored_green']}) + registry.registerBlock('wool', {texture: ['wool_colored_gray', 'wool_colored_white', 'wool_colored_green', 'wool_colored_light_blue', 'wool_colored_red', 'wool_colored_yellow']}) } From 77b3549b4684adf17514160dd7164b4624153814 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 15:37:48 -0700 Subject: [PATCH 098/256] Update ao-mesher - fixed side calculation deathcap/ao-mesher@ec74a227b31329d82e882e1b37aeeae3ddac658d Fix side calculation precedence bug deathcap/ao-mesher@36f875779e887a2e492b68883822d9e965a7d85d Add missing newline at end of file deathcap/ao-mesher@c75747717e14af2e8f1280f670e5f51b9ce72032 If voxel side textures unspecified, fallback to voxel index for compatibility deathcap/ao-mesher@bfc352f8210d9538956ed658527e0810cd70a1e3 Texture voxels per side from voxelSideTextureIDs array --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 39fad88..6ca26dd 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "ao-mesher": "git://github.com/deathcap/ao-mesher.git#c4c9d8594bb10d6b77a9ae8ee2ab7c99a6328d13", + "ao-mesher": "git://github.com/deathcap/ao-mesher.git#ec74a227b31329d82e882e1b37aeeae3ddac658d", "game-shell-fps-camera": "^0.1.0", "voxel-stitch": "^0.1.0", "ao-shader": "^0.2.3", From 8a2754099a51d06bcf5d48115ab493a9041c191c Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 15:37:28 -0700 Subject: [PATCH 099/256] Add tree to terrain to show transparency --- lib/blocks.js | 2 ++ lib/examples.js | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/blocks.js b/lib/blocks.js index 0e01a75..d85f532 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -16,5 +16,7 @@ function BlocksPlugin(game, opts) { registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) registry.registerBlock('wool', {texture: ['wool_colored_gray', 'wool_colored_white', 'wool_colored_green', 'wool_colored_light_blue', 'wool_colored_red', 'wool_colored_yellow']}) + registry.registerBlock('logOak', {texture:['log_oak_top', 'log_oak_top', 'log_oak']}) + registry.registerBlock('leavesOak', {texture: 'leaves_oak'}) } diff --git a/lib/examples.js b/lib/examples.js index de2287e..a2d415a 100644 --- a/lib/examples.js +++ b/lib/examples.js @@ -22,10 +22,24 @@ makeFill("Terrain", [33,33,33], function(i,j,k) { if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { return 0 // air } - var h0 = 3.0 * Math.sin(Math.PI * i / 12.0 - Math.PI * k * 0.1) + 27 + + // tree + if (i===7 && k===8 && 21 h0+1) { return 0 // air } + // grassy surface with dirt if(h0 <= j) { return (1<<15)+5//0x19 // grass } @@ -33,6 +47,8 @@ makeFill("Terrain", [33,33,33], function(i,j,k) { if(h1 <= j) { return (1<<15)+0//0x20 // dirt } + + // stone with ores if(4 < j) { return Math.random() < 0.1 ? (1<<15)+4 : //0x23 : // diamond From a612262667cb29fda79df4f9d0d29cbec894db0f Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 15:42:33 -0700 Subject: [PATCH 100/256] Update to a-mesher ^0.2.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6ca26dd..0af894e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "ao-mesher": "git://github.com/deathcap/ao-mesher.git#ec74a227b31329d82e882e1b37aeeae3ddac658d", + "ao-mesher": "^0.2.10", "game-shell-fps-camera": "^0.1.0", "voxel-stitch": "^0.1.0", "ao-shader": "^0.2.3", From 81b6e9be70e93aa530dc255afaa02d0464284a22 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 20:14:21 -0700 Subject: [PATCH 101/256] Rename examples to terrain --- lib/{examples.js => terrain.js} | 0 main.js | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename lib/{examples.js => terrain.js} (100%) diff --git a/lib/examples.js b/lib/terrain.js similarity index 100% rename from lib/examples.js rename to lib/terrain.js diff --git a/main.js b/main.js index 4d88d75..729b2d7 100644 --- a/main.js +++ b/main.js @@ -6,7 +6,7 @@ var createTileMap = require("gl-tile-map") var ndarray = require("ndarray") var createWireShader = require("./lib/wireShader.js") var createAOShader = require("ao-shader") -var examples = require("./lib/examples.js") +var terrain = require("./lib/terrain.js") var createVoxelMesh = require("./lib/createMesh.js") var glm = require("gl-matrix") var mat4 = glm.mat4 @@ -66,7 +66,7 @@ shell.on("gl-init", function() { stitcher.on('addedAll', updateTexture) stitcher.stitch() - mesh = createVoxelMesh(shell.gl, 'Terrain', examples.Terrain, stitcher.voxelSideTextureIDs) + mesh = createVoxelMesh(shell.gl, 'Terrain', terrain.Terrain, stitcher.voxelSideTextureIDs) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) From 616687ed533b94c7fb7cd1833797a28f75e63add Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 20:15:55 -0700 Subject: [PATCH 102/256] Add OAPQUE in terrain.js for clarity --- lib/terrain.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/terrain.js b/lib/terrain.js index a2d415a..388a86c 100644 --- a/lib/terrain.js +++ b/lib/terrain.js @@ -13,10 +13,13 @@ function makeFill(name, size, func) { }, true) } +// bit to indicate voxel is opaque (transparent if not set) +var OPAQUE = 1<<15; + //Terrain makeFill("Terrain", [33,33,33], function(i,j,k) { if (i===30 && j===30 && k===30) { - return (1<<15)+6; // wool + return OPAQUE|6; // wool } if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { @@ -25,7 +28,7 @@ makeFill("Terrain", [33,33,33], function(i,j,k) { // tree if (i===7 && k===8 && 21 Date: Sat, 5 Apr 2014 20:17:22 -0700 Subject: [PATCH 103/256] Export only terrain --- lib/terrain.js | 6 +++--- main.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/terrain.js b/lib/terrain.js index 388a86c..0cf415d 100644 --- a/lib/terrain.js +++ b/lib/terrain.js @@ -5,8 +5,8 @@ var fill = require("ndarray-fill") var lazyProperty = require("lazy-property") //Fill ndarray with function -function makeFill(name, size, func) { - lazyProperty(exports, name, function() { +function makeFill(size, func) { + lazyProperty(module, 'exports', function(materials) { var result = ndarray(new Int32Array(size[0]*size[1]*size[2]), size) fill(result, func) return result @@ -17,7 +17,7 @@ function makeFill(name, size, func) { var OPAQUE = 1<<15; //Terrain -makeFill("Terrain", [33,33,33], function(i,j,k) { +makeFill([33,33,33], function(i,j,k) { if (i===30 && j===30 && k===30) { return OPAQUE|6; // wool } diff --git a/main.js b/main.js index 729b2d7..cd73a07 100644 --- a/main.js +++ b/main.js @@ -66,7 +66,7 @@ shell.on("gl-init", function() { stitcher.on('addedAll', updateTexture) stitcher.stitch() - mesh = createVoxelMesh(shell.gl, 'Terrain', terrain.Terrain, stitcher.voxelSideTextureIDs) + mesh = createVoxelMesh(shell.gl, 'Terrain', terrain, stitcher.voxelSideTextureIDs) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) From 39fcd2885deb586ad0bf902085a1b9028d92902d Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 20:37:45 -0700 Subject: [PATCH 104/256] Lookup block indices for terrain generation; change to export a function called with materials instead of lazy property --- lib/terrain.js | 102 ++++++++++++++++++++++++------------------------- main.js | 16 +++++++- package.json | 1 - 3 files changed, 63 insertions(+), 56 deletions(-) diff --git a/lib/terrain.js b/lib/terrain.js index 0cf415d..ffb2c22 100644 --- a/lib/terrain.js +++ b/lib/terrain.js @@ -2,62 +2,58 @@ var ndarray = require("ndarray") var fill = require("ndarray-fill") -var lazyProperty = require("lazy-property") - -//Fill ndarray with function -function makeFill(size, func) { - lazyProperty(module, 'exports', function(materials) { - var result = ndarray(new Int32Array(size[0]*size[1]*size[2]), size) - fill(result, func) - return result - }, true) -} // bit to indicate voxel is opaque (transparent if not set) var OPAQUE = 1<<15; -//Terrain -makeFill([33,33,33], function(i,j,k) { - if (i===30 && j===30 && k===30) { - return OPAQUE|6; // wool - } - - if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { - return 0 // air - } - - // tree - if (i===7 && k===8 && 21 h0+1) { - return 0 // air - } - // grassy surface with dirt - if(h0 <= j) { - return OPAQUE|5//0x19 // grass - } - var h1 = 2.0 * Math.sin(Math.PI * i * 0.25 - Math.PI * k * 0.3) + 20 - if(h1 <= j) { - return OPAQUE|0//0x20 // dirt - } - - // stone with ores - if(4 < j) { - return Math.random() < 0.1 ? - OPAQUE|4 : //0x23 : // diamond - OPAQUE|1 //0x10 // stone - } - return OPAQUE|3 // lava -}) +module.exports = function(materials) { + var size = [33,33,33] + var result = ndarray(new Int32Array(size[0]*size[1]*size[2]), size) + //Fill ndarray with function + fill(result, function(i,j,k) { + //Terrain + if (i===30 && j===30 && k===30) { + return OPAQUE|materials.wool; + } + + if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { + return 0 // air + } + + // tree + if (i===7 && k===8 && 21 h0+1) { + return 0 // air + } + // grassy surface with dirt + if(h0 <= j) { + return OPAQUE|materials.grass + } + var h1 = 2.0 * Math.sin(Math.PI * i * 0.25 - Math.PI * k * 0.3) + 20 + if(h1 <= j) { + return OPAQUE|materials.dirt + } + + // stone with ores + if(4 < j) { + return Math.random() < 0.1 ? + OPAQUE|materials.oreDiamond : + OPAQUE|materials.stone + } + return OPAQUE|materials.lava + }) + return result +} diff --git a/main.js b/main.js index cd73a07..a3e73ff 100644 --- a/main.js +++ b/main.js @@ -6,7 +6,7 @@ var createTileMap = require("gl-tile-map") var ndarray = require("ndarray") var createWireShader = require("./lib/wireShader.js") var createAOShader = require("ao-shader") -var terrain = require("./lib/terrain.js") +var createTerrain = require("./lib/terrain.js") // TODO: replace with shama's chunker mentioned in https://github.com/voxel/issues/issues/4#issuecomment-39644684 var createVoxelMesh = require("./lib/createMesh.js") var glm = require("gl-matrix") var mat4 = glm.mat4 @@ -66,7 +66,19 @@ shell.on("gl-init", function() { stitcher.on('addedAll', updateTexture) stitcher.stitch() - mesh = createVoxelMesh(shell.gl, 'Terrain', terrain, stitcher.voxelSideTextureIDs) + var registry = plugins.get('voxel-registry') + var materials = { // TODO: refactor + wool: registry.getBlockID('wool') - 1, + logOak: registry.getBlockID('logOak') - 1, + leavesOak: registry.getBlockID('leavesOak') - 1, + grass: registry.getBlockID('grass') - 1, + dirt: registry.getBlockID('dirt') - 1, + oreDiamond: registry.getBlockID('oreDiamond') - 1, + stone: registry.getBlockID('stone') - 1, + lava: registry.getBlockID('lava') - 1 + }; + + mesh = createVoxelMesh(shell.gl, 'Terrain', createTerrain(materials), stitcher.voxelSideTextureIDs) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) diff --git a/package.json b/package.json index 0af894e..0f4cb3f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "gl-shader": "^3.0.0", "gl-vao": "^1.1.2", "gl-tile-map": "^0.3.0", - "lazy-property": "^0.0.2", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "ndarray-ops": "^1.2.1", From 85932eb27ce4212f7997aee8bd2f500547040597 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 20:45:19 -0700 Subject: [PATCH 105/256] Refactor opaque bit to use 'transparent' block registry property --- lib/blocks.js | 2 +- lib/terrain.js | 19 ++++++++----------- main.js | 27 +++++++++++++++------------ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/blocks.js b/lib/blocks.js index d85f532..cf94b1a 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -17,6 +17,6 @@ function BlocksPlugin(game, opts) { registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) registry.registerBlock('wool', {texture: ['wool_colored_gray', 'wool_colored_white', 'wool_colored_green', 'wool_colored_light_blue', 'wool_colored_red', 'wool_colored_yellow']}) registry.registerBlock('logOak', {texture:['log_oak_top', 'log_oak_top', 'log_oak']}) - registry.registerBlock('leavesOak', {texture: 'leaves_oak'}) + registry.registerBlock('leavesOak', {texture: 'leaves_oak', transparent: true}) } diff --git a/lib/terrain.js b/lib/terrain.js index ffb2c22..d72c0c6 100644 --- a/lib/terrain.js +++ b/lib/terrain.js @@ -3,9 +3,6 @@ var ndarray = require("ndarray") var fill = require("ndarray-fill") -// bit to indicate voxel is opaque (transparent if not set) -var OPAQUE = 1<<15; - module.exports = function(materials) { var size = [33,33,33] var result = ndarray(new Int32Array(size[0]*size[1]*size[2]), size) @@ -13,7 +10,7 @@ module.exports = function(materials) { fill(result, function(i,j,k) { //Terrain if (i===30 && j===30 && k===30) { - return OPAQUE|materials.wool; + return materials.wool; } if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { @@ -22,13 +19,13 @@ module.exports = function(materials) { // tree if (i===7 && k===8 && 21 Date: Sat, 5 Apr 2014 20:47:07 -0700 Subject: [PATCH 106/256] Remove createVoxelMesh caching since it is now only called once --- lib/createMesh.js | 9 +-------- main.js | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/createMesh.js b/lib/createMesh.js index bb41b45..3da7181 100644 --- a/lib/createMesh.js +++ b/lib/createMesh.js @@ -6,14 +6,8 @@ var createVAO = require("gl-vao") var createAOMesh = require("ao-mesher") var ops = require("ndarray-ops") -var cached = {} - //Creates a mesh from a set of voxels -function createVoxelMesh(gl, name, voxels, voxelSideTextureIDs) { - if(name in cached) { - return cached[name] - } - +function createVoxelMesh(gl, voxels, voxelSideTextureIDs) { //Create mesh var vert_data = createAOMesh(voxels, voxelSideTextureIDs) @@ -66,7 +60,6 @@ function createVoxelMesh(gl, name, voxels, voxelSideTextureIDs) { center: [voxels.shape[0]>>1, voxels.shape[1]>>1, voxels.shape[2]>>1], radius: voxels.shape[2] } - cached[name] = result return result } diff --git a/main.js b/main.js index 3781fa1..b141f1e 100644 --- a/main.js +++ b/main.js @@ -81,7 +81,7 @@ shell.on("gl-init", function() { } } - mesh = createVoxelMesh(shell.gl, 'Terrain', createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs) + mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) From a68172d83340451776db1eee753dedb1e3ca98be Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 20:52:15 -0700 Subject: [PATCH 107/256] Change clear color to a light blue sky --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index b141f1e..b99edf1 100644 --- a/main.js +++ b/main.js @@ -18,7 +18,7 @@ var TILE_SIZE = 16 // TODO: heterogenous var main = function(opts) { opts = opts || {}; - opts.clearColor = [0,0,0,0]; + opts.clearColor = [0.75, 0.8, 0.9, 1.0] opts.pointerLock = true; var shell = createShell(opts); From b56e8bc4b342310e418bb4c622e8f8a2fa12f1d2 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 21:19:07 -0700 Subject: [PATCH 108/256] Fix voxel-stitch version, ^0.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0f4cb3f..fb0833e 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "ao-mesher": "^0.2.10", "game-shell-fps-camera": "^0.1.0", - "voxel-stitch": "^0.1.0", + "voxel-stitch": "^0.2.0", "ao-shader": "^0.2.3", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", From de1640560b282cc673538184a183ed1d5778ea82 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 21:39:29 -0700 Subject: [PATCH 109/256] Add a block with a high index (255) as a test --- lib/terrain.js | 7 +++++++ main.js | 3 +++ 2 files changed, 10 insertions(+) diff --git a/lib/terrain.js b/lib/terrain.js index d72c0c6..91bbad9 100644 --- a/lib/terrain.js +++ b/lib/terrain.js @@ -9,10 +9,17 @@ module.exports = function(materials) { //Fill ndarray with function fill(result, function(i,j,k) { //Terrain + if (i===30 && j===30 && k===30) { + // face texture test return materials.wool; } + if (i===25 && j===30 && k===30) { + // high block index test + return (1<<15)|255; + } + if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { return 0 // air } diff --git a/main.js b/main.js index b99edf1..8b25d42 100644 --- a/main.js +++ b/main.js @@ -81,6 +81,9 @@ shell.on("gl-init", function() { } } + for (var k = 0; k < 6; k++) + stitcher.voxelSideTextureIDs.set(255, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.stone-1, k)) + mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) From bd6694738485a3d078f2684335cbf2b98bbd7eeb Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 21:46:02 -0700 Subject: [PATCH 110/256] Increase block index from 8-bit to 15-bit (all but 1-bit opaque flag); update test Update ao-mesher deathcap/ao-mesher@b8aa6eb7e14603a1d6c888c763b90a77a070ddd7 Use all lower bits as voxel index, increasing max from 255 to 32767. Closes mikolalysenko/ao-mesher#2 Commit message generated by https://github.com/deathcap/lmno-cl --- lib/terrain.js | 4 ++-- main.js | 6 +++++- package.json | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/terrain.js b/lib/terrain.js index 91bbad9..d87fb1c 100644 --- a/lib/terrain.js +++ b/lib/terrain.js @@ -12,12 +12,12 @@ module.exports = function(materials) { if (i===30 && j===30 && k===30) { // face texture test - return materials.wool; + return materials.wool } if (i===25 && j===30 && k===30) { // high block index test - return (1<<15)|255; + return materials.highBlock } if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { diff --git a/main.js b/main.js index 8b25d42..a3b9b4a 100644 --- a/main.js +++ b/main.js @@ -81,8 +81,12 @@ shell.on("gl-init", function() { } } + // test manually assigned high block index - clone stone texture (if shows up as dirt, wrapped around) + // before https://github.com/mikolalysenko/ao-mesher/issues/2 max is 255, after max is 32767 + var highIndex = 32767 + terrainMaterials.highBlock = OPAQUE|highIndex for (var k = 0; k < 6; k++) - stitcher.voxelSideTextureIDs.set(255, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.stone-1, k)) + stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.stone-1, k)) mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs) var c = mesh.center diff --git a/package.json b/package.json index fb0833e..59a0795 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "ao-mesher": "^0.2.10", + "ao-mesher": "git://github.com/deathcap/ao-mesher.git#b8aa6eb7e14603a1d6c888c763b90a77a070ddd7", "game-shell-fps-camera": "^0.1.0", "voxel-stitch": "^0.2.0", "ao-shader": "^0.2.3", From 2018982ec9774c1d83bbf4b0488d0d4a1ac74180 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 22:42:21 -0700 Subject: [PATCH 111/256] Add glass, another transparency test --- lib/blocks.js | 1 + lib/terrain.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/blocks.js b/lib/blocks.js index cf94b1a..57ad2ef 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -13,6 +13,7 @@ function BlocksPlugin(game, opts) { registry.registerBlock('stone', {texture: 'stone'}) registry.registerBlock('cobblestone', {texture: 'cobblestone'}) registry.registerBlock('lava', {texture: 'lava_still'}) + registry.registerBlock('glass', {texture: 'glass', transparent: true}) registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) registry.registerBlock('wool', {texture: ['wool_colored_gray', 'wool_colored_white', 'wool_colored_green', 'wool_colored_light_blue', 'wool_colored_red', 'wool_colored_yellow']}) diff --git a/lib/terrain.js b/lib/terrain.js index d87fb1c..13243be 100644 --- a/lib/terrain.js +++ b/lib/terrain.js @@ -35,6 +35,14 @@ module.exports = function(materials) { return materials.leavesOak } + // modern art + x = i - 20 + y = j - 28 + z = k - 8 + if (x*x + y*y + z*z < 5.0) { + return materials.glass + } + // rolling hills var h0 = 3.0 * Math.sin(Math.PI * i / 12.0 - Math.PI * k * 0.1) + 22 if(j > h0+1) { From 7152f6679c41d26ff2aad794201180285760af2c Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 22:59:57 -0700 Subject: [PATCH 112/256] Add lake as a (failed) semi-transparent alpha blending test The water textures are not see-through, unlike with three.js/voxel-engine --- lib/blocks.js | 1 + lib/terrain.js | 10 +++++++++- main.js | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/blocks.js b/lib/blocks.js index 57ad2ef..ea963d9 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -13,6 +13,7 @@ function BlocksPlugin(game, opts) { registry.registerBlock('stone', {texture: 'stone'}) registry.registerBlock('cobblestone', {texture: 'cobblestone'}) registry.registerBlock('lava', {texture: 'lava_still'}) + registry.registerBlock('water', {texture: 'water_flow', transparent: true}) registry.registerBlock('glass', {texture: 'glass', transparent: true}) registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) diff --git a/lib/terrain.js b/lib/terrain.js index 13243be..038dde9 100644 --- a/lib/terrain.js +++ b/lib/terrain.js @@ -35,7 +35,7 @@ module.exports = function(materials) { return materials.leavesOak } - // modern art + // glass structure x = i - 20 y = j - 28 z = k - 8 @@ -43,6 +43,14 @@ module.exports = function(materials) { return materials.glass } + // lake + x = i - 5 + y = j - 24 + z = k - 19 + if (x*x + y*y + z*z < 3.0) { + return materials.water + } + // rolling hills var h0 = 3.0 * Math.sin(Math.PI * i / 12.0 - Math.PI * k * 0.1) + 22 if(j > h0+1) { diff --git a/main.js b/main.js index a3b9b4a..2404860 100644 --- a/main.js +++ b/main.js @@ -54,6 +54,16 @@ var OPAQUE = 1<<15; shell.on("gl-init", function() { var gl = shell.gl + /* TODO: fix alpha transparency, this has no effect - maybe need to change ao-shader? + //gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) + //gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA) + gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); + gl.enable(gl.BLEND) + */ + // premultiply alpha when loading textures, so can use gl.ONE blending, see http://stackoverflow.com/questions/11521035/blending-with-html-background-in-webgl + // TODO: move to gl-texture2d? + gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) + //Create shaders shader = createAOShader(gl) wireShader = createWireShader(gl) @@ -81,12 +91,12 @@ shell.on("gl-init", function() { } } - // test manually assigned high block index - clone stone texture (if shows up as dirt, wrapped around) + // test manually assigned high block index - clone wool texture (if shows up as dirt, wrapped around) // before https://github.com/mikolalysenko/ao-mesher/issues/2 max is 255, after max is 32767 var highIndex = 32767 terrainMaterials.highBlock = OPAQUE|highIndex for (var k = 0; k < 6; k++) - stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.stone-1, k)) + stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.wool-1, k)) mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs) var c = mesh.center From 136c58938217cb8b0d2e40551c7c488c04792f48 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 5 Apr 2014 23:48:54 -0700 Subject: [PATCH 113/256] Update ao-shader with alpha, re-enable alpha blending test --- main.js | 7 +++---- package.json | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 2404860..664d0f4 100644 --- a/main.js +++ b/main.js @@ -54,12 +54,11 @@ var OPAQUE = 1<<15; shell.on("gl-init", function() { var gl = shell.gl - /* TODO: fix alpha transparency, this has no effect - maybe need to change ao-shader? + // TODO: is this right? see https://github.com/mikolalysenko/ao-shader/issues/2 //gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) - //gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA) - gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); + gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA) + //gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); gl.enable(gl.BLEND) - */ // premultiply alpha when loading textures, so can use gl.ONE blending, see http://stackoverflow.com/questions/11521035/blending-with-html-background-in-webgl // TODO: move to gl-texture2d? gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) diff --git a/package.json b/package.json index 59a0795..e23bc63 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "ao-mesher": "git://github.com/deathcap/ao-mesher.git#b8aa6eb7e14603a1d6c888c763b90a77a070ddd7", "game-shell-fps-camera": "^0.1.0", "voxel-stitch": "^0.2.0", - "ao-shader": "^0.2.3", + "ao-shader": "git://github.com/deathcap/ao-shader.git#08b2f65fc072869a579d2ffd5eb15460e6de9ac6", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", "gl-now": "^1.0.1", From d06e1135bea1819205d3990487bd4ceae7cf721e Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 6 Apr 2014 13:12:59 -0700 Subject: [PATCH 114/256] Update to three.js 0.58.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bca35f5..caf86ab 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", "voxel-region-change": "0.1.0", "raf": "0.0.1", - "three": "0.58.9", + "three": "0.58.10", "pin-it": "0.0.1", "aabb-3d": "0.0.0", "inherits": "1.0.0", From 55c05c6bc632365fc9f61047e69fd7cb953fc2d3 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 6 Apr 2014 18:15:33 -0700 Subject: [PATCH 115/256] Update to artpacks ^0.3.1 and voxel-control --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index caf86ab..759e0e8 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,9 @@ "voxel-mesh": "git://github.com/deathcap/voxel-mesh.git#6a881552c2281648a8ad8f50e6dd71ff610ef770", "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", - "voxel-control": "git://github.com/deathcap/voxel-control.git#d9ac73b0423ec0deb0ebcd54711bf7c656f9ddb6", + "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", "voxel-texture": "0.5.8", - "artpacks": "git://github.com/deathcap/artpacks.git#326defb7dbb867456bd918a33143d3729b7ab2f9", + "artpacks": "^0.3.1", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", "voxel-region-change": "0.1.0", "raf": "0.0.1", From 3132e6843211639b331ce226e5b7824199a89614 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 6 Apr 2014 18:19:34 -0700 Subject: [PATCH 116/256] Update to three.js 0.66.2, ref GH-74 Required update to voxel-mesh: deathcap/voxel-mesh@b170a0f18977fb8eac571d445e9522fd6073a63d Replace Face4 with two Face3s, for three.js --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 759e0e8..386c9fd 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ ], "dependencies": { "voxel": "git://github.com/deathcap/voxel.git#4ce16e8b8d10362a0114483c21cc66777f5702f2", - "voxel-mesh": "git://github.com/deathcap/voxel-mesh.git#6a881552c2281648a8ad8f50e6dd71ff610ef770", + "voxel-mesh": "git://github.com/deathcap/voxel-mesh.git#b170a0f18977fb8eac571d445e9522fd6073a63d", "voxel-view": "git://github.com/deathcap/voxel-view.git#be8a36643ddc5de42c8506d6372510c16665f57c", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", @@ -22,7 +22,7 @@ "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", "voxel-region-change": "0.1.0", "raf": "0.0.1", - "three": "0.58.10", + "three": "0.66.2", "pin-it": "0.0.1", "aabb-3d": "0.0.0", "inherits": "1.0.0", From 8f4c30623042a653089c8e3850ccff8e66e47b9f Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 7 Apr 2014 19:14:35 -0700 Subject: [PATCH 117/256] Expose shell through game.shell, instead of using shell as game instance (keep it small) --- main.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index 664d0f4..9a8f1f9 100644 --- a/main.js +++ b/main.js @@ -16,6 +16,9 @@ var createPlugins = require('voxel-plugins') //Tile size parameters var TILE_SIZE = 16 // TODO: heterogenous +var game = {}; +global.game = game; // for debugging + var main = function(opts) { opts = opts || {}; opts.clearColor = [0.75, 0.8, 0.9, 1.0] @@ -23,22 +26,15 @@ var main = function(opts) { var shell = createShell(opts); var camera = createCamera(shell); - /* - global.shell = shell - global.camera = camera - */ camera.position[0] = -20; camera.position[1] = -33; camera.position[2] = -40; - var game = {}; game.isClient = true; - game.buttons = {}; - game.buttons.bindings = shell.bindings; + game.shell = shell; var plugins = createPlugins(game, {require: opts.require || require}); - shell.plugins = plugins; for (var name in opts.pluginOpts) { plugins.add(name, opts.pluginOpts[name]); @@ -68,7 +64,7 @@ shell.on("gl-init", function() { wireShader = createWireShader(gl) //Create texture atlas - var stitcher = shell.plugins.get('voxel-stitch') // TODO: load not as a plugin? + var stitcher = game.plugins.get('voxel-stitch') // TODO: load not as a plugin? var updateTexture = function() { texture = createTileMap(gl, stitcher.atlas, 2) texture.magFilter = gl.NEAREST From 604bff647cef5826caf8856f972f1a67162ec2cb Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 7 Apr 2014 19:36:56 -0700 Subject: [PATCH 118/256] Add working kb-bindings-ui plugin, configurable keybindings Added game-shell support in ^0.3.0 --- demo.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/demo.js b/demo.js index d1f183a..a7dcb41 100644 --- a/demo.js +++ b/demo.js @@ -4,7 +4,7 @@ var createShell = require('./'); var createGUI = require('dat-gui'); require('voxel-plugins-ui'); -//require('kb-bindings-ui'); +require('kb-bindings-ui'); require('voxel-registry'); require('voxel-stitch'); require('./lib/blocks.js'); @@ -15,7 +15,7 @@ createShell({require: require, pluginOpts: 'voxel-registry': {}, 'voxel-stitch': {}, 'voxel-plugins-ui': {gui: new createGUI.GUI()}, - //'kb-bindings-ui': {gui: new createGUI.GUI()}, // TODO: add compatibility, game-shell bindings object is different than kb-bindings + 'kb-bindings-ui': {}, './lib/blocks.js': {}, 'voxel-drop': {}, } diff --git a/package.json b/package.json index e23bc63..f3bbdc9 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "devDependencies": { "dat-gui": "^0.5.0", - "kb-bindings": "^0.2.0", + "kb-bindings-ui": "^0.3.0", "voxel-plugins-ui": "^0.2.0", "voxel-registry": "^0.3.0", "beefy": "^1.1.0", From 3068165268e62c0b67434acf4273c130bb70b48f Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 7 Apr 2014 19:58:55 -0700 Subject: [PATCH 119/256] Update to gl-now ^1.3.0, and misc patch fixes --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f3bbdc9..054764f 100644 --- a/package.json +++ b/package.json @@ -5,19 +5,19 @@ "main": "main.js", "dependencies": { "ao-mesher": "git://github.com/deathcap/ao-mesher.git#b8aa6eb7e14603a1d6c888c763b90a77a070ddd7", - "game-shell-fps-camera": "^0.1.0", + "game-shell-fps-camera": "^0.1.1", "voxel-stitch": "^0.2.0", "ao-shader": "git://github.com/deathcap/ao-shader.git#08b2f65fc072869a579d2ffd5eb15460e6de9ac6", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", - "gl-now": "^1.0.1", + "gl-now": "^1.3.0", "gl-shader": "^3.0.0", "gl-vao": "^1.1.2", "gl-tile-map": "^0.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "ndarray-ops": "^1.2.1", - "brfs": "^1.0.0", + "brfs": "^1.0.1", "voxel-plugins": "^0.3.0" }, "devDependencies": { @@ -27,7 +27,7 @@ "voxel-registry": "^0.3.0", "beefy": "^1.1.0", "browserify": "^3.38.0", - "voxel-drop": "^0.1.0" + "voxel-drop": "^0.1.1" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", From c9247d2ad4adeb6ceab11790dd63ac10e3bcc610 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 8 Apr 2014 19:23:04 -0700 Subject: [PATCH 120/256] Add voxel-keys plugin --- demo.js | 2 ++ package.json | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/demo.js b/demo.js index a7dcb41..db1ddcf 100644 --- a/demo.js +++ b/demo.js @@ -9,6 +9,7 @@ require('voxel-registry'); require('voxel-stitch'); require('./lib/blocks.js'); require('voxel-drop'); +require('voxel-keys'); createShell({require: require, pluginOpts: { @@ -18,6 +19,7 @@ createShell({require: require, pluginOpts: 'kb-bindings-ui': {}, './lib/blocks.js': {}, 'voxel-drop': {}, + 'voxel-keys': {}, } }); diff --git a/package.json b/package.json index 054764f..5e2b92b 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "voxel-registry": "^0.3.0", "beefy": "^1.1.0", "browserify": "^3.38.0", - "voxel-drop": "^0.1.1" + "voxel-drop": "^0.1.1", + "voxel-keys": "^0.1.0" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", From 8392e706e284ed2f65ba4ee2691a8779bfb87019 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 8 Apr 2014 19:51:03 -0700 Subject: [PATCH 121/256] Fix z-order, add voxel-artpacks for testing --- demo.js | 3 ++- main.js | 7 +++++++ package.json | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/demo.js b/demo.js index db1ddcf..07d1eed 100644 --- a/demo.js +++ b/demo.js @@ -10,6 +10,7 @@ require('voxel-stitch'); require('./lib/blocks.js'); require('voxel-drop'); require('voxel-keys'); +require('voxel-artpacks'); createShell({require: require, pluginOpts: { @@ -20,7 +21,7 @@ createShell({require: require, pluginOpts: './lib/blocks.js': {}, 'voxel-drop': {}, 'voxel-keys': {}, + 'voxel-artpacks': {} } }); -document.querySelector('.dg.ac').style.zIndex = 1; // fix datgui behind canvas diff --git a/main.js b/main.js index 9a8f1f9..58753fb 100644 --- a/main.js +++ b/main.js @@ -34,6 +34,7 @@ var main = function(opts) { game.isClient = true; game.shell = shell; + // TODO: should this be moved into gl-init?? see z-index note below var plugins = createPlugins(game, {require: opts.require || require}); for (var name in opts.pluginOpts) { @@ -50,6 +51,12 @@ var OPAQUE = 1<<15; shell.on("gl-init", function() { var gl = shell.gl + // since the plugins are loaded before gl-init, the element will be + // below other UI widgets in the DOM tree, so by default the z-order will cause + // the canvas to cover the other widgets - to fix this, set z-index below + shell.canvas.style.zIndex = '-1'; + shell.canvas.parentElement.style.zIndex = '-1'; + // TODO: is this right? see https://github.com/mikolalysenko/ao-shader/issues/2 //gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA) diff --git a/package.json b/package.json index 5e2b92b..21299c5 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "beefy": "^1.1.0", "browserify": "^3.38.0", "voxel-drop": "^0.1.1", - "voxel-keys": "^0.1.0" + "voxel-keys": "^0.1.0", + "voxel-artpacks": "git://github.com/deathcap/voxel-artpacks.git" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", From 7ec75fa7ab966ca331e0498061c65f98b5b813f3 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 9 Apr 2014 20:27:18 -0700 Subject: [PATCH 122/256] Update to voxel-artpacks ^0.1.0, more game-shell support --- main.js | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 58753fb..269a6e3 100644 --- a/main.js +++ b/main.js @@ -73,6 +73,7 @@ shell.on("gl-init", function() { //Create texture atlas var stitcher = game.plugins.get('voxel-stitch') // TODO: load not as a plugin? var updateTexture = function() { + console.log('updateTexture() calling createTileMap()') texture = createTileMap(gl, stitcher.atlas, 2) texture.magFilter = gl.NEAREST texture.minFilter = gl.LINEAR_MIPMAP_LINEAR diff --git a/package.json b/package.json index 21299c5..b21444d 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "browserify": "^3.38.0", "voxel-drop": "^0.1.1", "voxel-keys": "^0.1.0", - "voxel-artpacks": "git://github.com/deathcap/voxel-artpacks.git" + "voxel-artpacks": "^0.1.0" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", From 42159f79fde14c826c3ad01e4696d2183e2e51e7 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 10 Apr 2014 19:41:06 -0700 Subject: [PATCH 123/256] Update to voxel-stitch 0.2.2, texture pack changing fixes --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b21444d..ae268c9 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "ao-mesher": "git://github.com/deathcap/ao-mesher.git#b8aa6eb7e14603a1d6c888c763b90a77a070ddd7", "game-shell-fps-camera": "^0.1.1", - "voxel-stitch": "^0.2.0", + "voxel-stitch": "^0.2.2", "ao-shader": "git://github.com/deathcap/ao-shader.git#08b2f65fc072869a579d2ffd5eb15460e6de9ac6", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", From 648b64d36642284917592ccd1fe22734c6c3019e Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 12 Apr 2014 14:44:30 -0700 Subject: [PATCH 124/256] Start updating to use rect-mip-map --- main.js | 34 +++++++++++++++++++++++++++++++++- package.json | 6 ++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 269a6e3..29c3622 100644 --- a/main.js +++ b/main.js @@ -2,15 +2,18 @@ var createShell = require("gl-now") var createCamera = require("game-shell-fps-camera") -var createTileMap = require("gl-tile-map") var ndarray = require("ndarray") var createWireShader = require("./lib/wireShader.js") +var rectMipMap = require('rect-mip-map'); var createAOShader = require("ao-shader") var createTerrain = require("./lib/terrain.js") // TODO: replace with shama's chunker mentioned in https://github.com/voxel/issues/issues/4#issuecomment-39644684 var createVoxelMesh = require("./lib/createMesh.js") var glm = require("gl-matrix") var mat4 = glm.mat4 +var getPixels = require('get-pixels') +var createTexture = require('gl-texture2d') + var createPlugins = require('voxel-plugins') //Tile size parameters @@ -19,6 +22,29 @@ var TILE_SIZE = 16 // TODO: heterogenous var game = {}; global.game = game; // for debugging +// like https://github.com/mikolalysenko/gl-tile-map/blob/master/tilemap.js but uses rect-tile-map +var createTileMap = function(gl, atlas, cb) { + getPixels(atlas.canvas.toDataURL(), function(err, array) { + if (err) throw new Error('get-pixels failed: '+err); + + var pyramid = rectTileMap(array, atlas); + console.log('pyramid=',pyramid); + + var tex = createTexture(gl, pyramid[0]); + tex.generateMipmap(); // TODO + + for (var i = 1; i < pyramid.length; ++i) { + tex.setPixels(pyramid[i], 0, 0, i); + } + + tex.magFilter = gl.NEAREST + tex.minFilter = gl.LINEAR_MIPMAP_LINEAR + tex.mipSamples = 4 + + cb(tex); + }); +}; + var main = function(opts) { opts = opts || {}; opts.clearColor = [0.75, 0.8, 0.9, 1.0] @@ -74,10 +100,16 @@ shell.on("gl-init", function() { var stitcher = game.plugins.get('voxel-stitch') // TODO: load not as a plugin? var updateTexture = function() { console.log('updateTexture() calling createTileMap()') + createTileMap(gl, atlas, function(tex) { + texture = tex; + }); + + /* texture = createTileMap(gl, stitcher.atlas, 2) texture.magFilter = gl.NEAREST texture.minFilter = gl.LINEAR_MIPMAP_LINEAR texture.mipSamples = 4 + */ } stitcher.on('addedAll', updateTexture) stitcher.stitch() diff --git a/package.json b/package.json index ae268c9..855e022 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "ao-mesher": "git://github.com/deathcap/ao-mesher.git#b8aa6eb7e14603a1d6c888c763b90a77a070ddd7", "game-shell-fps-camera": "^0.1.1", - "voxel-stitch": "^0.2.2", + "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#7415457267fb9bc995139fef8c9cb58282236ee5", "ao-shader": "git://github.com/deathcap/ao-shader.git#08b2f65fc072869a579d2ffd5eb15460e6de9ac6", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", @@ -18,7 +18,9 @@ "ndarray-fill": "^0.1.0", "ndarray-ops": "^1.2.1", "brfs": "^1.0.1", - "voxel-plugins": "^0.3.0" + "voxel-plugins": "^0.3.0", + "get-pixels": "^1.0.1", + "gl-texture2d": "^1.0.1" }, "devDependencies": { "dat-gui": "^0.5.0", From 459ac76ae8a790b612820a0da13fdfba6e57882a Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 12 Apr 2014 14:58:43 -0700 Subject: [PATCH 125/256] Move texture2d creation to voxel-stitch --- main.js | 44 ++++++-------------------------------------- package.json | 6 ++---- 2 files changed, 8 insertions(+), 42 deletions(-) diff --git a/main.js b/main.js index 29c3622..b299f4c 100644 --- a/main.js +++ b/main.js @@ -4,16 +4,12 @@ var createShell = require("gl-now") var createCamera = require("game-shell-fps-camera") var ndarray = require("ndarray") var createWireShader = require("./lib/wireShader.js") -var rectMipMap = require('rect-mip-map'); var createAOShader = require("ao-shader") var createTerrain = require("./lib/terrain.js") // TODO: replace with shama's chunker mentioned in https://github.com/voxel/issues/issues/4#issuecomment-39644684 var createVoxelMesh = require("./lib/createMesh.js") var glm = require("gl-matrix") var mat4 = glm.mat4 -var getPixels = require('get-pixels') -var createTexture = require('gl-texture2d') - var createPlugins = require('voxel-plugins') //Tile size parameters @@ -22,29 +18,6 @@ var TILE_SIZE = 16 // TODO: heterogenous var game = {}; global.game = game; // for debugging -// like https://github.com/mikolalysenko/gl-tile-map/blob/master/tilemap.js but uses rect-tile-map -var createTileMap = function(gl, atlas, cb) { - getPixels(atlas.canvas.toDataURL(), function(err, array) { - if (err) throw new Error('get-pixels failed: '+err); - - var pyramid = rectTileMap(array, atlas); - console.log('pyramid=',pyramid); - - var tex = createTexture(gl, pyramid[0]); - tex.generateMipmap(); // TODO - - for (var i = 1; i < pyramid.length; ++i) { - tex.setPixels(pyramid[i], 0, 0, i); - } - - tex.magFilter = gl.NEAREST - tex.minFilter = gl.LINEAR_MIPMAP_LINEAR - tex.mipSamples = 4 - - cb(tex); - }); -}; - var main = function(opts) { opts = opts || {}; opts.clearColor = [0.75, 0.8, 0.9, 1.0] @@ -99,17 +72,12 @@ shell.on("gl-init", function() { //Create texture atlas var stitcher = game.plugins.get('voxel-stitch') // TODO: load not as a plugin? var updateTexture = function() { - console.log('updateTexture() calling createTileMap()') - createTileMap(gl, atlas, function(tex) { - texture = tex; - }); - - /* - texture = createTileMap(gl, stitcher.atlas, 2) - texture.magFilter = gl.NEAREST - texture.minFilter = gl.LINEAR_MIPMAP_LINEAR - texture.mipSamples = 4 - */ + console.log('updateTexture() calling createGLTexture()') + + stitcher.createGLTexture(gl, function(err, tex) { + if (err) throw new Error('stitcher createGLTexture error: ' + err) + texture = tex + }) } stitcher.on('addedAll', updateTexture) stitcher.stitch() diff --git a/package.json b/package.json index 855e022..5843da8 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "ao-mesher": "git://github.com/deathcap/ao-mesher.git#b8aa6eb7e14603a1d6c888c763b90a77a070ddd7", "game-shell-fps-camera": "^0.1.1", - "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#7415457267fb9bc995139fef8c9cb58282236ee5", + "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#2c3eae2417c48e038ea72902bfb239884e116b9d", "ao-shader": "git://github.com/deathcap/ao-shader.git#08b2f65fc072869a579d2ffd5eb15460e6de9ac6", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", @@ -18,9 +18,7 @@ "ndarray-fill": "^0.1.0", "ndarray-ops": "^1.2.1", "brfs": "^1.0.1", - "voxel-plugins": "^0.3.0", - "get-pixels": "^1.0.1", - "gl-texture2d": "^1.0.1" + "voxel-plugins": "^0.3.0" }, "devDependencies": { "dat-gui": "^0.5.0", From c25bbe52910fce16f1e56e0f1416647738ba1d6d Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 12 Apr 2014 17:18:37 -0700 Subject: [PATCH 126/256] Create mesh in updateTexture(), when voxelSideTextureIDs is available Would have liked to create the mesh before setting the texture so the general terrain outline shows untextured before the textures load later, but voxel-stitch now calculates updateTextureSideIDs() after 'addedAll', and emits 'updateTexture'. The voxelSideTextureIDs array is only populated after the atlaspack textures are added, since the texture sizes cannot be known until then, and only then can the UVs -> indexes be calculated for ao-mesher. --- main.js | 30 +++++++++++++++++------------- package.json | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/main.js b/main.js index b299f4c..d7b42da 100644 --- a/main.js +++ b/main.js @@ -78,8 +78,12 @@ shell.on("gl-init", function() { if (err) throw new Error('stitcher createGLTexture error: ' + err) texture = tex }) + + mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs) + var c = mesh.center + camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) } - stitcher.on('addedAll', updateTexture) + stitcher.on('updateTexture', updateTexture) stitcher.stitch() //Lookup voxel materials for terrain generation @@ -101,10 +105,6 @@ shell.on("gl-init", function() { for (var k = 0; k < 6; k++) stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.wool-1, k)) - mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs) - var c = mesh.center - camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) - shell.bind('wireframe', 'F') }) @@ -139,10 +139,12 @@ shell.on("gl-render", function(t) { shader.uniforms.model = model shader.uniforms.tileSize = TILE_SIZE if (texture) shader.uniforms.tileMap = texture.bind() // texture might not have loaded yet - - mesh.triangleVAO.bind() - gl.drawArrays(gl.TRIANGLES, 0, mesh.triangleVertexCount) - mesh.triangleVAO.unbind() + + if(mesh) { + mesh.triangleVAO.bind() + gl.drawArrays(gl.TRIANGLES, 0, mesh.triangleVertexCount) + mesh.triangleVAO.unbind() + } if(shell.wasDown('wireframe')) { //Bind the wire shader @@ -151,10 +153,12 @@ shell.on("gl-render", function(t) { wireShader.uniforms.projection = projection wireShader.uniforms.model = model wireShader.uniforms.view = view - - mesh.wireVAO.bind() - gl.drawArrays(gl.LINES, 0, mesh.wireVertexCount) - mesh.wireVAO.unbind() + + if(mesh) { + mesh.wireVAO.bind() + gl.drawArrays(gl.LINES, 0, mesh.wireVertexCount) + mesh.wireVAO.unbind() + } } }) } diff --git a/package.json b/package.json index 5843da8..2f78148 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "ao-mesher": "git://github.com/deathcap/ao-mesher.git#b8aa6eb7e14603a1d6c888c763b90a77a070ddd7", "game-shell-fps-camera": "^0.1.1", - "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#2c3eae2417c48e038ea72902bfb239884e116b9d", + "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#a448370e3bda7da71d1b2cdbb62d09f56ae92923", "ao-shader": "git://github.com/deathcap/ao-shader.git#08b2f65fc072869a579d2ffd5eb15460e6de9ac6", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", From 2f475fba1a6dd725f50a6f1a1bb025c5b14f75ee Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 12 Apr 2014 19:45:13 -0700 Subject: [PATCH 127/256] Working voxel-stitch with rect-tile-map --- demo.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/demo.js b/demo.js index 07d1eed..341339e 100644 --- a/demo.js +++ b/demo.js @@ -15,7 +15,7 @@ require('voxel-artpacks'); createShell({require: require, pluginOpts: { 'voxel-registry': {}, - 'voxel-stitch': {}, + 'voxel-stitch': {debug: false}, 'voxel-plugins-ui': {gui: new createGUI.GUI()}, 'kb-bindings-ui': {}, './lib/blocks.js': {}, diff --git a/package.json b/package.json index 2f78148..9276744 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "ao-mesher": "git://github.com/deathcap/ao-mesher.git#b8aa6eb7e14603a1d6c888c763b90a77a070ddd7", "game-shell-fps-camera": "^0.1.1", - "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#a448370e3bda7da71d1b2cdbb62d09f56ae92923", + "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#5546e94e3c7234856178229ad6bbd3fe8f72ea6d", "ao-shader": "git://github.com/deathcap/ao-shader.git#08b2f65fc072869a579d2ffd5eb15460e6de9ac6", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", From 839d5efd8b121522e4f8d74e364fad67fcfe2580 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 12 Apr 2014 19:55:53 -0700 Subject: [PATCH 128/256] Fix high block test wool cloned texture, need to set after voxelSideTextureIDs is populated --- main.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index d7b42da..a4ecba4 100644 --- a/main.js +++ b/main.js @@ -79,6 +79,10 @@ shell.on("gl-init", function() { texture = tex }) + // for highBlock, clone wool texture (if shows up as dirt, wrapped around) + for (var k = 0; k < 6; k++) + stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.wool-1, k)) + mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) @@ -98,12 +102,10 @@ shell.on("gl-init", function() { } } - // test manually assigned high block index - clone wool texture (if shows up as dirt, wrapped around) + // test manually assigned high block index // before https://github.com/mikolalysenko/ao-mesher/issues/2 max is 255, after max is 32767 var highIndex = 32767 terrainMaterials.highBlock = OPAQUE|highIndex - for (var k = 0; k < 6; k++) - stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.wool-1, k)) shell.bind('wireframe', 'F') }) From 86249528a3c2eff76631ad32497214d6e682a00a Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 12 Apr 2014 20:30:13 -0700 Subject: [PATCH 129/256] Update to voxel-stitch ^0.3.0, atlaspack + rect-tile-map > gl-tile-map + mip-tile-map --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9276744..a113550 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "ao-mesher": "git://github.com/deathcap/ao-mesher.git#b8aa6eb7e14603a1d6c888c763b90a77a070ddd7", "game-shell-fps-camera": "^0.1.1", - "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#5546e94e3c7234856178229ad6bbd3fe8f72ea6d", + "voxel-stitch": "^0.3.0", "ao-shader": "git://github.com/deathcap/ao-shader.git#08b2f65fc072869a579d2ffd5eb15460e6de9ac6", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", From ae41edc4d398fb874bf15270c71fdb7eab846717 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 12 Apr 2014 20:32:07 -0700 Subject: [PATCH 130/256] Lava is transparent, too --- lib/blocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blocks.js b/lib/blocks.js index ea963d9..f7b0a64 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -12,7 +12,7 @@ function BlocksPlugin(game, opts) { registry.registerBlock('dirt', {texture: 'dirt'}) registry.registerBlock('stone', {texture: 'stone'}) registry.registerBlock('cobblestone', {texture: 'cobblestone'}) - registry.registerBlock('lava', {texture: 'lava_still'}) + registry.registerBlock('lava', {texture: 'lava_still', transparent: true}) registry.registerBlock('water', {texture: 'water_flow', transparent: true}) registry.registerBlock('glass', {texture: 'glass', transparent: true}) registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) From 36bb64fef69ce1f1990daa12e39b42b0d6b82ff7 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 12 Apr 2014 22:52:45 -0700 Subject: [PATCH 131/256] Set tileCount uniform for ao-shader Corresponds to https://github.com/deathcap/voxel-mipmap-demo/commits/tilecount --- main.js | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index a4ecba4..52c404d 100644 --- a/main.js +++ b/main.js @@ -47,6 +47,8 @@ var texture, shader, mesh, wireShader // bit in voxel array to indicate voxel is opaque (transparent if not set) var OPAQUE = 1<<15; +var TILE_COUNT = null; + shell.on("gl-init", function() { var gl = shell.gl @@ -71,6 +73,7 @@ shell.on("gl-init", function() { //Create texture atlas var stitcher = game.plugins.get('voxel-stitch') // TODO: load not as a plugin? + TILE_COUNT = stitcher.tileCount // set for shader below (never changes) var updateTexture = function() { console.log('updateTexture() calling createGLTexture()') @@ -140,6 +143,7 @@ shell.on("gl-render", function(t) { shader.uniforms.view = view shader.uniforms.model = model shader.uniforms.tileSize = TILE_SIZE + shader.uniforms.tileCount = TILE_COUNT if (texture) shader.uniforms.tileMap = texture.bind() // texture might not have loaded yet if(mesh) { diff --git a/package.json b/package.json index a113550..754dede 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "ao-mesher": "git://github.com/deathcap/ao-mesher.git#b8aa6eb7e14603a1d6c888c763b90a77a070ddd7", "game-shell-fps-camera": "^0.1.1", "voxel-stitch": "^0.3.0", - "ao-shader": "git://github.com/deathcap/ao-shader.git#08b2f65fc072869a579d2ffd5eb15460e6de9ac6", + "ao-shader": "git://github.com/deathcap/ao-shader.git#19c1eac2a1da842c96f62905ef0032770a9c31a5", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", "gl-now": "^1.3.0", From 5bf0a602fd587053a3ba517be4639cf9dbf8a134 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 15:49:59 -0700 Subject: [PATCH 132/256] Update to use voxel-shader, voxel-mesher > ao-shader, ao-mesher --- lib/createMesh.js | 2 +- main.js | 2 +- package.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/createMesh.js b/lib/createMesh.js index 3da7181..970134b 100644 --- a/lib/createMesh.js +++ b/lib/createMesh.js @@ -3,7 +3,7 @@ var ndarray = require("ndarray") var createBuffer = require("gl-buffer") var createVAO = require("gl-vao") -var createAOMesh = require("ao-mesher") +var createAOMesh = require("voxel-mesher") var ops = require("ndarray-ops") //Creates a mesh from a set of voxels diff --git a/main.js b/main.js index 52c404d..a00160c 100644 --- a/main.js +++ b/main.js @@ -4,7 +4,7 @@ var createShell = require("gl-now") var createCamera = require("game-shell-fps-camera") var ndarray = require("ndarray") var createWireShader = require("./lib/wireShader.js") -var createAOShader = require("ao-shader") +var createAOShader = require("voxel-shader") var createTerrain = require("./lib/terrain.js") // TODO: replace with shama's chunker mentioned in https://github.com/voxel/issues/issues/4#issuecomment-39644684 var createVoxelMesh = require("./lib/createMesh.js") var glm = require("gl-matrix") diff --git a/package.json b/package.json index 754dede..ec4200f 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "ao-mesher": "git://github.com/deathcap/ao-mesher.git#b8aa6eb7e14603a1d6c888c763b90a77a070ddd7", + "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#56ab4142c5068abdf14aa6596eb620f7267db511", + "voxel-shader": "git://github.com/deathcap/voxel-shader.git#39eb693d97e6c347aec05f3f9d523754bd4341a5", "game-shell-fps-camera": "^0.1.1", "voxel-stitch": "^0.3.0", - "ao-shader": "git://github.com/deathcap/ao-shader.git#19c1eac2a1da842c96f62905ef0032770a9c31a5", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", "gl-now": "^1.3.0", From 92635fbee71d9b5d2c2f7c2076cef5e28358d62a Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 16:27:26 -0700 Subject: [PATCH 133/256] Update mesher, shader, stitch - 16-bit tex IDs + 2k atlas --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ec4200f..32c0ffa 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#56ab4142c5068abdf14aa6596eb620f7267db511", - "voxel-shader": "git://github.com/deathcap/voxel-shader.git#39eb693d97e6c347aec05f3f9d523754bd4341a5", + "voxel-mesher": "^0.3.0", + "voxel-shader": "^0.4.0", "game-shell-fps-camera": "^0.1.1", - "voxel-stitch": "^0.3.0", + "voxel-stitch": "^0.4.0", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", "gl-now": "^1.3.0", From 106e5e556587ff59284cf1c2b3745ae64cb0661f Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 17:14:23 -0700 Subject: [PATCH 134/256] Update mesher, shader, stitch - high-res/mixed texture support (>16x16) --- lib/createMesh.js | 4 ++-- main.js | 6 +----- package.json | 6 +++--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/createMesh.js b/lib/createMesh.js index 970134b..9cb4c98 100644 --- a/lib/createMesh.js +++ b/lib/createMesh.js @@ -7,9 +7,9 @@ var createAOMesh = require("voxel-mesher") var ops = require("ndarray-ops") //Creates a mesh from a set of voxels -function createVoxelMesh(gl, voxels, voxelSideTextureIDs) { +function createVoxelMesh(gl, voxels, voxelSideTextureIDs, voxelSideTextureSizes) { //Create mesh - var vert_data = createAOMesh(voxels, voxelSideTextureIDs) + var vert_data = createAOMesh(voxels, voxelSideTextureIDs, voxelSideTextureSizes) //Upload triangle mesh to WebGL var triangleVertexCount = Math.floor(vert_data.length/8) diff --git a/main.js b/main.js index a00160c..26c1f58 100644 --- a/main.js +++ b/main.js @@ -12,9 +12,6 @@ var mat4 = glm.mat4 var createPlugins = require('voxel-plugins') -//Tile size parameters -var TILE_SIZE = 16 // TODO: heterogenous - var game = {}; global.game = game; // for debugging @@ -86,7 +83,7 @@ shell.on("gl-init", function() { for (var k = 0; k < 6; k++) stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.wool-1, k)) - mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs) + mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs, stitcher.voxelSideTextureSizes) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) } @@ -142,7 +139,6 @@ shell.on("gl-render", function(t) { shader.uniforms.projection = projection shader.uniforms.view = view shader.uniforms.model = model - shader.uniforms.tileSize = TILE_SIZE shader.uniforms.tileCount = TILE_COUNT if (texture) shader.uniforms.tileMap = texture.bind() // texture might not have loaded yet diff --git a/package.json b/package.json index 32c0ffa..d547d2e 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "voxel-mesher": "^0.3.0", - "voxel-shader": "^0.4.0", + "voxel-mesher": "^0.4.0", + "voxel-shader": "^0.5.0", "game-shell-fps-camera": "^0.1.1", - "voxel-stitch": "^0.4.0", + "voxel-stitch": "^0.5.0", "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", "gl-now": "^1.3.0", From 2e2ded614bf85f29195fd49c95b8a86fe0d7cab9 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 19:36:20 -0700 Subject: [PATCH 135/256] Remove voxel-mesh --- index.js | 3 ++- package.json | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index fa4dbb1..1ffd8da 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ var voxel = require('voxel') -var voxelMesh = require('voxel-mesh') var ray = require('voxel-raycast') var texture = require('voxel-texture') var artpacks = require('artpacks'); @@ -568,6 +567,7 @@ Game.prototype.showChunk = function(chunk) { var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position) var scale = new THREE.Vector3(1, 1, 1) var transparentTypes = this.materials.getTransparentVoxelTypes ? this.materials.getTransparentVoxelTypes() : {}; + /* TODO var mesh = voxelMesh(chunk, this.mesher, scale, this.THREE, {transparentTypes: transparentTypes}) this.voxels.chunks[chunkIndex] = chunk if (this.voxels.meshes[chunkIndex]) { @@ -583,6 +583,7 @@ Game.prototype.showChunk = function(chunk) { mesh.addToScene(this.scene) this.emit('renderChunk', chunk) return mesh + */ } // # Debugging methods diff --git a/package.json b/package.json index 445cc4c..855fb04 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ ], "dependencies": { "voxel": "git://github.com/deathcap/voxel#ndarray", - "voxel-mesh": "git://github.com/deathcap/voxel-mesh#ndarray", "voxel-view": "0.0.6", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", From 63526ff8efa4cb9c7d09993af3925618ddd9d6d1 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 19:39:21 -0700 Subject: [PATCH 136/256] Remove texture --- index.js | 15 --------------- package.json | 2 -- 2 files changed, 17 deletions(-) diff --git a/index.js b/index.js index 1ffd8da..e5a01af 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,5 @@ var voxel = require('voxel') var ray = require('voxel-raycast') -var texture = require('voxel-texture') -var artpacks = require('artpacks'); var control = require('voxel-control') var voxelView = require('voxel-view') var THREE = require('three') @@ -45,7 +43,6 @@ function Game(opts) { this.arrayType = opts.arrayType || {1:Uint8Array, 2:Uint16Array, 4:Uint32Array}[opts.arrayTypeSize] || Uint8Array this.cubeSize = 1 // backwards compat this.chunkSize = opts.chunkSize || 32 - this.texture_modules = opts.texture_modules || [texture]; // chunkDistance and removeDistance should not be set to the same thing // as it causes lag when you go back and forth on a chunk boundary @@ -57,9 +54,6 @@ function Game(opts) { this.playerHeight = opts.playerHeight || 1.62 this.meshType = opts.meshType || 'surfaceMesh' this.mesher = opts.mesher || voxel.meshers.transgreedy - //this.materialType = opts.materialType || THREE.MeshLambertMaterial - //this.materialParams = opts.materialParams || {} - //this.materialTransparentTypes = opts.materialTransparentTypes || {} // TODO: automatically get from voxel-texture this.items = [] this.voxels = voxel(this) this.scene = new THREE.Scene() @@ -98,15 +92,6 @@ function Game(opts) { this.pendingChunks = [] if (this.isClient) { - /*this.materials = this.texture_modules[0](this.texture_opts = { - useAtlas: (opts.useAtlas === undefined) ? false : opts.useAtlas, - texturePath: opts.texturePath || './textures/', - artPacks: artpacks(opts.artPacks), - materialType: opts.materialType || THREE.MeshLambertMaterial, - materialParams: opts.materialParams || {}, - materialFlatColor: opts.materialFlatColor === true, - game: this - })*/ if (opts.appendDocument) this.appendTo(document.body) if (opts.exposeGlobal) window.game = window.g = this } diff --git a/package.json b/package.json index 855fb04..14c9952 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,6 @@ "voxel-view": "0.0.6", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", - "voxel-texture": "0.5.8", - "artpacks": "^0.3.1", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", "voxel-region-change": "0.1.0", "raf": "0.0.1", From bfb60b63ad256feac81bede0dfc64fce02ae304f Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 20:19:10 -0700 Subject: [PATCH 137/256] Expose camera as property on shell --- main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/main.js b/main.js index 26c1f58..e537c90 100644 --- a/main.js +++ b/main.js @@ -22,6 +22,7 @@ var main = function(opts) { var shell = createShell(opts); var camera = createCamera(shell); + shell.camera = camera; camera.position[0] = -20; camera.position[1] = -33; From 41bc9528ccb79026b002e274ba0e3e5fdae4d364 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 20:20:11 -0700 Subject: [PATCH 138/256] Remove voxel-view, throw error on accessing removed properties --- index.js | 50 +++++++++++++++++++------------------------------- package.json | 2 +- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index e5a01af..933eb6c 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ var voxel = require('voxel') var ray = require('voxel-raycast') var control = require('voxel-control') -var voxelView = require('voxel-view') +var createShell = require('game-shell-voxel') var THREE = require('three') var Stats = require('./lib/stats') var Detector = require('./lib/detector') @@ -56,20 +56,20 @@ function Game(opts) { this.mesher = opts.mesher || voxel.meshers.transgreedy this.items = [] this.voxels = voxel(this) - this.scene = new THREE.Scene() - this.view = opts.view || new voxelView(THREE, { - width: this.width, - height: this.height, - skyColor: this.skyColor, - antialias: this.antialias - }) - this.view.bindToScene(this.scene) - this.camera = this.view.getCamera() - if (!opts.lightsDisabled) this.addLights(this.scene) - - this.fogScale = opts.fogScale || 32 - if (!opts.fogDisabled) this.scene.fog = new THREE.Fog( this.skyColor, 0.00025, this.worldWidth() * this.fogScale ) - + + // was a THREE.Scene instance, mainly used for scene.add(), objects, lights TODO: scene graph replacement? + Object.defineProperty(this, 'scene', {get:function() { throw new Error('voxel-engine "scene" property removed') }}) + + // hooked up THREE.Scene, created THREE.PerspectiveCamera, added to element + // TODO: add this.view.cameraPosition(), this.view.cameraVector()? -> [x,y,z] to game-shell-fps-camera, very useful + Object.defineProperty(this, 'view', {get:function() { throw new Error('voxel-engine "view" property removed') }}) + + // used to be a THREE.PerspectiveCamera set by voxel-view; see also basic-camera but API not likely compatible (TODO: make it compatible?) + Object.defineProperty(this, 'camera', {get:function() { throw new Error('voxel-engine "camera" property removed') }}) + + // handles all rendering + this.shell = createShell({require: opts.require || require, pluginOpts: opts.pluginOpts}) + this.collideVoxels = collisions( this.getBlock.bind(this), 1, @@ -92,7 +92,6 @@ function Game(opts) { this.pendingChunks = [] if (this.isClient) { - if (opts.appendDocument) this.appendTo(document.body) if (opts.exposeGlobal) window.game = window.g = this } @@ -137,11 +136,13 @@ Game.prototype.voxelPosition = function(gamePosition) { } Game.prototype.cameraPosition = function() { - return this.view.cameraPosition() + return this.shell.camera.position } +var _cameraVector = vector.create(); Game.prototype.cameraVector = function() { - return this.view.cameraVector() + this.shell.camera.getCameraVector(_cameraVector) + return _cameraVector } Game.prototype.makePhysical = function(target, envelope, blocksCreation) { @@ -273,10 +274,6 @@ Game.prototype.createAdjacent = function(hit, val) { this.createBlock(hit.adjacent, val) } -Game.prototype.appendTo = function (element) { - this.view.appendTo(element) -} - // # Defaults/options parsing Game.prototype.gravity = [0, -0.0000036, 0] @@ -424,15 +421,6 @@ Game.prototype.addStats = function() { document.body.appendChild( stats.domElement ) } -Game.prototype.addLights = function(scene) { - var ambientLight, directionalLight - ambientLight = new THREE.AmbientLight(0xcccccc) - scene.add(ambientLight) - var light = new THREE.DirectionalLight( 0xffffff , 1) - light.position.set( 1, 1, 0.5 ).normalize() - scene.add( light ) -} - // # Chunk related methods Game.prototype.configureChunkLoading = function(opts) { diff --git a/package.json b/package.json index 14c9952..5f8fbc4 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "Deathcap (https://github.com/deathcap)" ], "dependencies": { + "game-shell-voxel": "git://github.com/deathcap/game-shell-voxel.git", "voxel": "git://github.com/deathcap/voxel#ndarray", - "voxel-view": "0.0.6", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", From 0cc10d5f5428fb96de685007bf40399aec956ae0 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 20:24:03 -0700 Subject: [PATCH 139/256] Remove WebGL capability checks; the shell should handle it --- index.js | 51 +----------------------------------------- lib/detector.js | 59 ------------------------------------------------- 2 files changed, 1 insertion(+), 109 deletions(-) delete mode 100644 lib/detector.js diff --git a/index.js b/index.js index 933eb6c..2e4ac55 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,6 @@ function Game(opts) { if (!(this instanceof Game)) return new Game(opts) var self = this if (!opts) opts = {} - if (process.browser && this.notCapable(opts)) return // is this a client or a headless server this.isClient = Boolean( (typeof opts.isClient !== 'undefined') ? opts.isClient : process.browser ) @@ -61,7 +60,7 @@ function Game(opts) { Object.defineProperty(this, 'scene', {get:function() { throw new Error('voxel-engine "scene" property removed') }}) // hooked up THREE.Scene, created THREE.PerspectiveCamera, added to element - // TODO: add this.view.cameraPosition(), this.view.cameraVector()? -> [x,y,z] to game-shell-fps-camera, very useful + // note: instead of this.view.cameraPosition()/cameraVector(), use this.cameraPosition()/cameraVector() Object.defineProperty(this, 'view', {get:function() { throw new Error('voxel-engine "view" property removed') }}) // used to be a THREE.PerspectiveCamera set by voxel-view; see also basic-camera but API not likely compatible (TODO: make it compatible?) @@ -110,7 +109,6 @@ function Game(opts) { if (!this.isClient) return this.paused = true - this.initializeRendering(opts) this.showAllChunks() @@ -326,30 +324,6 @@ Game.prototype.setDimensions = function(opts) { } } -Game.prototype.notCapable = function(opts) { - var self = this - if( !Detector().webgl ) { - this.view = { - appendTo: function(el) { - el.appendChild(self.notCapableMessage()) - } - } - return true - } - return false -} - -Game.prototype.notCapableMessage = function() { - var wrapper = document.createElement('div') - wrapper.className = "errorMessage" - var a = document.createElement('a') - a.title = "You need WebGL and Pointer Lock (Chrome 23/Firefox 14) to play this game. Click here for more information." - a.innerHTML = a.title - a.href = "http://get.webgl.org" - wrapper.appendChild(a) - return wrapper -} - Game.prototype.onWindowResize = function() { var width = window.innerWidth var height = window.innerHeight @@ -629,10 +603,6 @@ Game.prototype.tick = function(delta) { this.spatial.emit('position', playerPos, playerPos) } -Game.prototype.render = function(delta) { - this.view.render(this.scene) -} - Game.prototype.initializeTimer = function(rate) { var self = this var accum = 0 @@ -667,25 +637,6 @@ Game.prototype.initializeTimer = function(rate) { } } -Game.prototype.initializeRendering = function(opts) { - var self = this - - if (!opts.statsDisabled) self.addStats() - - window.addEventListener('resize', self.onWindowResize.bind(self), false) - - requestAnimationFrame(window).on('data', function(dt) { - self.emit('prerender', dt) - self.render(dt) - self.emit('postrender', dt) - }) - if (typeof stats !== 'undefined') { - self.on('postrender', function() { - stats.update() - }) - } -} - Game.prototype.initializeControls = function(opts) { // player control this.keybindings = opts.keybindings || this.defaultButtons diff --git a/lib/detector.js b/lib/detector.js deleted file mode 100644 index 31f19a2..0000000 --- a/lib/detector.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * @author alteredq / http://alteredqualia.com/ - * @author mr.doob / http://mrdoob.com/ - */ - -module.exports = function() { - return { - canvas : !! window.CanvasRenderingContext2D, - webgl : ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(), - workers : !! window.Worker, - fileapi : window.File && window.FileReader && window.FileList && window.Blob, - - getWebGLErrorMessage : function () { - - var domElement = document.createElement( 'div' ); - - domElement.style.fontFamily = 'monospace'; - domElement.style.fontSize = '13px'; - domElement.style.textAlign = 'center'; - domElement.style.background = '#eee'; - domElement.style.color = '#000'; - domElement.style.padding = '1em'; - domElement.style.width = '475px'; - domElement.style.margin = '5em auto 0'; - - if ( ! this.webgl ) { - - domElement.innerHTML = window.WebGLRenderingContext ? [ - 'Your graphics card does not seem to support WebGL.
', - 'Find out how to get it here.' - ].join( '\n' ) : [ - 'Your browser does not seem to support WebGL.
', - 'Find out how to get it here.' - ].join( '\n' ); - - } - - return domElement; - - }, - - addGetWebGLMessage : function ( parameters ) { - - var parent, id, domElement; - - parameters = parameters || {}; - - parent = parameters.parent !== undefined ? parameters.parent : document.body; - id = parameters.id !== undefined ? parameters.id : 'oldie'; - - domElement = Detector.getWebGLErrorMessage(); - domElement.id = id; - - parent.appendChild( domElement ); - - } - - }; -} From e612062169f88bbf090ba0ff319ee46b7c661bd8 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 20:32:16 -0700 Subject: [PATCH 140/256] Remove controls --- index.js | 76 +++++----------------------------------------------- package.json | 3 --- 2 files changed, 6 insertions(+), 73 deletions(-) diff --git a/index.js b/index.js index 2e4ac55..c118010 100644 --- a/index.js +++ b/index.js @@ -8,15 +8,12 @@ var Detector = require('./lib/detector') var inherits = require('inherits') var path = require('path') var EventEmitter = require('events').EventEmitter -if (process.browser) var interact = require('interact') -var requestAnimationFrame = require('raf') var collisions = require('collide-3d-tilemap') var aabb = require('aabb-3d') var glMatrix = require('gl-matrix') var vector = glMatrix.vec3 var SpatialEventEmitter = require('spatial-events') var regionChange = require('voxel-region-change') -var kb = require('kb-bindings') var physical = require('voxel-physical') var pin = require('pin-it') var tic = require('tic')() @@ -116,7 +113,12 @@ function Game(opts) { self.asyncChunkGeneration = 'asyncChunkGeneration' in opts ? opts.asyncChunkGeneration : true }, 2000) - this.initializeControls(opts) + // initializeControls() + // player control + // game-shell handles controls now TODO: provide some compatibility layer? as not covered by https://github.com/deathcap/voxel-keys + Object.defineProperty(this, 'keybindings', {get:function() { throw new Error('voxel-engine "keybindings" property removed') }}) + Object.defineProperty(this, 'buttons', {get:function() { throw new Error('voxel-engine "buttons" property removed') }}) // especially for this one (polling interface) + Object.defineProperty(this, 'interact', {get:function() { throw new Error('voxel-engine "interact" property removed') }}) } inherits(Game, EventEmitter) @@ -279,23 +281,6 @@ Game.prototype.friction = 0.3 Game.prototype.epilson = 1e-8 Game.prototype.terminalVelocity = [0.9, 0.1, 0.9] -Game.prototype.defaultButtons = { - 'W': 'forward' -, 'A': 'left' -, 'S': 'backward' -, 'D': 'right' -, '': 'forward' -, '': 'left' -, '': 'backward' -, '': 'right' -, '': 'fire' -, '': 'firealt' -, '': 'jump' -, '': 'crouch' -, '': 'alt' -, '': 'sprint' -} - // used in methods that have identity function(pos) {} Game.prototype.parseVectorArguments = function(args) { if (!args) return false @@ -324,16 +309,6 @@ Game.prototype.setDimensions = function(opts) { } } -Game.prototype.onWindowResize = function() { - var width = window.innerWidth - var height = window.innerHeight - if (this.container) { - width = this.container.clientWidth - height = this.container.clientHeight - } - this.view.resizeWindow(width, height) -} - // # Physics/collision related methods Game.prototype.control = function(target) { @@ -561,22 +536,6 @@ Game.prototype.pin = pin // # Misc internal methods -Game.prototype.onControlChange = function(gained, stream) { - this.paused = false - - if (!gained && !this.optout) { - this.buttons.disable() - return - } - - this.buttons.enable() - stream.pipe(this.controls.createWriteRotationStream()) -} - -Game.prototype.onControlOptOut = function() { - this.optout = true -} - Game.prototype.onFire = function(state) { this.emit('fire', this.controlling, state) } @@ -637,29 +596,6 @@ Game.prototype.initializeTimer = function(rate) { } } -Game.prototype.initializeControls = function(opts) { - // player control - this.keybindings = opts.keybindings || this.defaultButtons - this.buttons = kb(document.body, this.keybindings) - this.buttons.disable() - this.optout = false - this.interact = interact(opts.interactElement || this.view.element, opts.interactMouseDrag) - this.interact - .on('attain', this.onControlChange.bind(this, true)) - .on('release', this.onControlChange.bind(this, false)) - .on('opt-out', this.onControlOptOut.bind(this)) - this.hookupControls(this.buttons, opts) -} - -Game.prototype.hookupControls = function(buttons, opts) { - opts = opts || {} - opts.controls = opts.controls || {} - opts.controls.onfire = this.onFire.bind(this) - this.controls = control(buttons, opts.controls) - this.items.push(this.controls) - this.controlling = null -} - Game.prototype.handleChunkGeneration = function() { var self = this this.voxels.on('missingChunk', function(chunkPos) { diff --git a/package.json b/package.json index 5f8fbc4..b37d089 100644 --- a/package.json +++ b/package.json @@ -18,14 +18,11 @@ "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", "voxel-region-change": "0.1.0", - "raf": "0.0.1", "three": "0.66.2", "pin-it": "0.0.1", "aabb-3d": "0.0.0", "inherits": "1.0.0", - "interact": "0.0.2", "gl-matrix": "2.0.0", - "kb-bindings": "0.2.0", "spatial-events": "0.0.1", "spatial-trigger": "0.0.0", "collide-3d-tilemap": "0.0.1", From 91dd6b8154ad327bcb3116b7e0277fd24896f088 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 20:33:16 -0700 Subject: [PATCH 141/256] Missed removing this detector require --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index c118010..f42c457 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,6 @@ var control = require('voxel-control') var createShell = require('game-shell-voxel') var THREE = require('three') var Stats = require('./lib/stats') -var Detector = require('./lib/detector') var inherits = require('inherits') var path = require('path') var EventEmitter = require('events').EventEmitter From 90b55542f678c2a3f73e60d86671114f7938a70d Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 20:44:14 -0700 Subject: [PATCH 142/256] Stub appendTo and notCapable for compatibility --- index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/index.js b/index.js index f42c457..3297e62 100644 --- a/index.js +++ b/index.js @@ -273,6 +273,10 @@ Game.prototype.createAdjacent = function(hit, val) { this.createBlock(hit.adjacent, val) } +Game.prototype.appendTo = function (element) { + // no-op; game-shell to append itself +} + // # Defaults/options parsing Game.prototype.gravity = [0, -0.0000036, 0] @@ -308,6 +312,11 @@ Game.prototype.setDimensions = function(opts) { } } +Game.prototype.notCapable = function(opts) { + // TODO: wire up capability check in game-shell-voxel? maybe restore the capability check here? + return false +} + // # Physics/collision related methods Game.prototype.control = function(target) { From 3c167d725265bc7b51c614ba447777bd7659a32f Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 20:45:37 -0700 Subject: [PATCH 143/256] Revert "Remove WebGL capability checks" This reverts commit 0cc10d5f5428fb96de685007bf40399aec956ae0. Conflicts: index.js --- index.js | 30 ++++++++++++++++++++++--- lib/detector.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 lib/detector.js diff --git a/index.js b/index.js index 3297e62..38b4057 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,7 @@ function Game(opts) { if (!(this instanceof Game)) return new Game(opts) var self = this if (!opts) opts = {} + if (process.browser && this.notCapable(opts)) return // is this a client or a headless server this.isClient = Boolean( (typeof opts.isClient !== 'undefined') ? opts.isClient : process.browser ) @@ -56,7 +57,7 @@ function Game(opts) { Object.defineProperty(this, 'scene', {get:function() { throw new Error('voxel-engine "scene" property removed') }}) // hooked up THREE.Scene, created THREE.PerspectiveCamera, added to element - // note: instead of this.view.cameraPosition()/cameraVector(), use this.cameraPosition()/cameraVector() + // TODO: add this.view.cameraPosition(), this.view.cameraVector()? -> [x,y,z] to game-shell-fps-camera, very useful Object.defineProperty(this, 'view', {get:function() { throw new Error('voxel-engine "view" property removed') }}) // used to be a THREE.PerspectiveCamera set by voxel-view; see also basic-camera but API not likely compatible (TODO: make it compatible?) @@ -105,6 +106,7 @@ function Game(opts) { if (!this.isClient) return this.paused = true + this.initializeRendering(opts) this.showAllChunks() @@ -313,10 +315,29 @@ Game.prototype.setDimensions = function(opts) { } Game.prototype.notCapable = function(opts) { - // TODO: wire up capability check in game-shell-voxel? maybe restore the capability check here? + var self = this + if( !Detector().webgl ) { + this.view = { + appendTo: function(el) { + el.appendChild(self.notCapableMessage()) + } + } + return true + } return false } +Game.prototype.notCapableMessage = function() { + var wrapper = document.createElement('div') + wrapper.className = "errorMessage" + var a = document.createElement('a') + a.title = "You need WebGL and Pointer Lock (Chrome 23/Firefox 14) to play this game. Click here for more information." + a.innerHTML = a.title + a.href = "http://get.webgl.org" + wrapper.appendChild(a) + return wrapper +} + // # Physics/collision related methods Game.prototype.control = function(target) { @@ -570,6 +591,10 @@ Game.prototype.tick = function(delta) { this.spatial.emit('position', playerPos, playerPos) } +Game.prototype.render = function(delta) { + this.view.render(this.scene) +} + Game.prototype.initializeTimer = function(rate) { var self = this var accum = 0 @@ -603,7 +628,6 @@ Game.prototype.initializeTimer = function(rate) { self.frameUpdated = true } } - Game.prototype.handleChunkGeneration = function() { var self = this this.voxels.on('missingChunk', function(chunkPos) { diff --git a/lib/detector.js b/lib/detector.js new file mode 100644 index 0000000..31f19a2 --- /dev/null +++ b/lib/detector.js @@ -0,0 +1,59 @@ +/** + * @author alteredq / http://alteredqualia.com/ + * @author mr.doob / http://mrdoob.com/ + */ + +module.exports = function() { + return { + canvas : !! window.CanvasRenderingContext2D, + webgl : ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(), + workers : !! window.Worker, + fileapi : window.File && window.FileReader && window.FileList && window.Blob, + + getWebGLErrorMessage : function () { + + var domElement = document.createElement( 'div' ); + + domElement.style.fontFamily = 'monospace'; + domElement.style.fontSize = '13px'; + domElement.style.textAlign = 'center'; + domElement.style.background = '#eee'; + domElement.style.color = '#000'; + domElement.style.padding = '1em'; + domElement.style.width = '475px'; + domElement.style.margin = '5em auto 0'; + + if ( ! this.webgl ) { + + domElement.innerHTML = window.WebGLRenderingContext ? [ + 'Your graphics card does not seem to support WebGL.
', + 'Find out how to get it here.' + ].join( '\n' ) : [ + 'Your browser does not seem to support WebGL.
', + 'Find out how to get it here.' + ].join( '\n' ); + + } + + return domElement; + + }, + + addGetWebGLMessage : function ( parameters ) { + + var parent, id, domElement; + + parameters = parameters || {}; + + parent = parameters.parent !== undefined ? parameters.parent : document.body; + id = parameters.id !== undefined ? parameters.id : 'oldie'; + + domElement = Detector.getWebGLErrorMessage(); + domElement.id = id; + + parent.appendChild( domElement ); + + } + + }; +} From 78c86b1de566fef2a82e4f591ed9afcb4937f04b Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 20:46:00 -0700 Subject: [PATCH 144/256] Revert "Missed removing this detector require" This reverts commit 91dd6b8154ad327bcb3116b7e0277fd24896f088. --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 38b4057..c5fdf5d 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ var control = require('voxel-control') var createShell = require('game-shell-voxel') var THREE = require('three') var Stats = require('./lib/stats') +var Detector = require('./lib/detector') var inherits = require('inherits') var path = require('path') var EventEmitter = require('events').EventEmitter From a8a9243810c249cd16d951aedcb8bb9a524b4b30 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 20:47:42 -0700 Subject: [PATCH 145/256] Fix spurious initializeRendering call --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index c5fdf5d..031e2bd 100644 --- a/index.js +++ b/index.js @@ -107,7 +107,6 @@ function Game(opts) { if (!this.isClient) return this.paused = true - this.initializeRendering(opts) this.showAllChunks() From f822dcaf8fcba5a864d93e539bd95f009f170e02 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 21:09:29 -0700 Subject: [PATCH 146/256] Warn if voxel-stitch or voxel-registry plugins not found, instead of erroring out --- main.js | 67 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/main.js b/main.js index e537c90..6e6d43d 100644 --- a/main.js +++ b/main.js @@ -71,43 +71,50 @@ shell.on("gl-init", function() { //Create texture atlas var stitcher = game.plugins.get('voxel-stitch') // TODO: load not as a plugin? - TILE_COUNT = stitcher.tileCount // set for shader below (never changes) - var updateTexture = function() { - console.log('updateTexture() calling createGLTexture()') - - stitcher.createGLTexture(gl, function(err, tex) { - if (err) throw new Error('stitcher createGLTexture error: ' + err) - texture = tex - }) - - // for highBlock, clone wool texture (if shows up as dirt, wrapped around) - for (var k = 0; k < 6; k++) - stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.wool-1, k)) - - mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs, stitcher.voxelSideTextureSizes) - var c = mesh.center - camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) + if (stitcher) { + TILE_COUNT = stitcher.tileCount // set for shader below (never changes) + var updateTexture = function() { + console.log('updateTexture() calling createGLTexture()') + + stitcher.createGLTexture(gl, function(err, tex) { + if (err) throw new Error('stitcher createGLTexture error: ' + err) + texture = tex + }) + + // for highBlock, clone wool texture (if shows up as dirt, wrapped around) + for (var k = 0; k < 6; k++) + stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.wool-1, k)) + + mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs, stitcher.voxelSideTextureSizes) + var c = mesh.center + camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) + } + stitcher.on('updateTexture', updateTexture) + stitcher.stitch() + } else { + console.warn('voxel-stitch plugin not found, expect no textures') } - stitcher.on('updateTexture', updateTexture) - stitcher.stitch() //Lookup voxel materials for terrain generation var registry = plugins.get('voxel-registry') - var terrainMaterials = {}; - for (var blockName in registry.blockName2Index) { - var blockIndex = registry.blockName2Index[blockName]; - if (registry.getProp(blockName, 'transparent')) { - terrainMaterials[blockName] = blockIndex - 1 - } else { - terrainMaterials[blockName] = OPAQUE|(blockIndex - 1) // TODO: separate arrays? https://github.com/mikolalysenko/ao-mesher/issues/2 + if (registry) { + var terrainMaterials = {}; + for (var blockName in registry.blockName2Index) { + var blockIndex = registry.blockName2Index[blockName]; + if (registry.getProp(blockName, 'transparent')) { + terrainMaterials[blockName] = blockIndex - 1 + } else { + terrainMaterials[blockName] = OPAQUE|(blockIndex - 1) // TODO: separate arrays? https://github.com/mikolalysenko/ao-mesher/issues/2 + } } + // test manually assigned high block index + // before https://github.com/mikolalysenko/ao-mesher/issues/2 max is 255, after max is 32767 + var highIndex = 32767 + terrainMaterials.highBlock = OPAQUE|highIndex + } else { + console.warn('voxel-registry plugin not found, expect no textures') } - // test manually assigned high block index - // before https://github.com/mikolalysenko/ao-mesher/issues/2 max is 255, after max is 32767 - var highIndex = 32767 - terrainMaterials.highBlock = OPAQUE|highIndex - shell.bind('wireframe', 'F') }) From 0ffc391826bf084d5cddde25f468775d83fdcd16 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Apr 2014 21:14:01 -0700 Subject: [PATCH 147/256] module.exports() returns shell instance --- main.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.js b/main.js index 6e6d43d..a55e1fa 100644 --- a/main.js +++ b/main.js @@ -171,6 +171,8 @@ shell.on("gl-render", function(t) { } } }) + + return shell // TODO: fix indenting } module.exports = main From 12ef940097debd58496e7ebafceb4a4970336b5b Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 14 Apr 2014 19:29:21 -0700 Subject: [PATCH 148/256] Move createVoxelMesh to voxel-mesher --- lib/createMesh.js | 66 ----------------------------------------------- main.js | 2 +- package.json | 6 +---- 3 files changed, 2 insertions(+), 72 deletions(-) delete mode 100644 lib/createMesh.js diff --git a/lib/createMesh.js b/lib/createMesh.js deleted file mode 100644 index 9cb4c98..0000000 --- a/lib/createMesh.js +++ /dev/null @@ -1,66 +0,0 @@ -"use strict" - -var ndarray = require("ndarray") -var createBuffer = require("gl-buffer") -var createVAO = require("gl-vao") -var createAOMesh = require("voxel-mesher") -var ops = require("ndarray-ops") - -//Creates a mesh from a set of voxels -function createVoxelMesh(gl, voxels, voxelSideTextureIDs, voxelSideTextureSizes) { - //Create mesh - var vert_data = createAOMesh(voxels, voxelSideTextureIDs, voxelSideTextureSizes) - - //Upload triangle mesh to WebGL - var triangleVertexCount = Math.floor(vert_data.length/8) - var vert_buf = createBuffer(gl, vert_data) - var triangleVAO = createVAO(gl, [ - { "buffer": vert_buf, - "type": gl.UNSIGNED_BYTE, - "size": 4, - "offset": 0, - "stride": 8, - "normalized": false - }, - { "buffer": vert_buf, - "type": gl.UNSIGNED_BYTE, - "size": 4, - "offset": 4, - "stride": 8, - "normalized": false - } - ]) - - //Create wire mesh - var wireVertexCount = 2 * triangleVertexCount - var wireVertexArray = ndarray(new Uint8Array(wireVertexCount * 3), [triangleVertexCount, 2, 3]) - var trianglePositions = ndarray(vert_data, [triangleVertexCount, 3], [8, 1], 0) - ops.assign(wireVertexArray.pick(undefined, 0, undefined), trianglePositions) - var wires = wireVertexArray.pick(undefined, 1, undefined) - for(var i=0; i<3; ++i) { - ops.assign(wires.lo(i).step(3), trianglePositions.lo((i+1)%3).step(3)) - } - var wireBuf = createBuffer(gl, wireVertexArray.data) - var wireVAO = createVAO(gl, [ - { "buffer": wireBuf, - "type": gl.UNSIGNED_BYTE, - "size": 3, - "offset": 0, - "stride": 3, - "normalized": false - } - ]) - - //Bundle result and return - var result = { - triangleVertexCount: triangleVertexCount, - triangleVAO: triangleVAO, - wireVertexCount: wireVertexCount, - wireVAO: wireVAO, - center: [voxels.shape[0]>>1, voxels.shape[1]>>1, voxels.shape[2]>>1], - radius: voxels.shape[2] - } - return result -} - -module.exports = createVoxelMesh diff --git a/main.js b/main.js index a55e1fa..51027b0 100644 --- a/main.js +++ b/main.js @@ -6,7 +6,7 @@ var ndarray = require("ndarray") var createWireShader = require("./lib/wireShader.js") var createAOShader = require("voxel-shader") var createTerrain = require("./lib/terrain.js") // TODO: replace with shama's chunker mentioned in https://github.com/voxel/issues/issues/4#issuecomment-39644684 -var createVoxelMesh = require("./lib/createMesh.js") +var createVoxelMesh = require("voxel-mesher") var glm = require("gl-matrix") var mat4 = glm.mat4 diff --git a/package.json b/package.json index d547d2e..b574d79 100644 --- a/package.json +++ b/package.json @@ -4,19 +4,15 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "voxel-mesher": "^0.4.0", + "voxel-mesher": "^0.5.0", "voxel-shader": "^0.5.0", "game-shell-fps-camera": "^0.1.1", "voxel-stitch": "^0.5.0", - "gl-buffer": "^2.0.6", "gl-matrix": "^2.2.1", "gl-now": "^1.3.0", "gl-shader": "^3.0.0", - "gl-vao": "^1.1.2", - "gl-tile-map": "^0.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", - "ndarray-ops": "^1.2.1", "brfs": "^1.0.1", "voxel-plugins": "^0.3.0" }, From 677c73d9c9e4421110d379976d1e50f7a8430694 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 14 Apr 2014 19:40:01 -0700 Subject: [PATCH 149/256] Load materials before textures --- main.js | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/main.js b/main.js index 51027b0..29d1708 100644 --- a/main.js +++ b/main.js @@ -69,8 +69,28 @@ shell.on("gl-init", function() { shader = createAOShader(gl) wireShader = createWireShader(gl) + //Lookup voxel materials for terrain generation + var registry = plugins.get('voxel-registry') + if (registry) { + var terrainMaterials = {}; + for (var blockName in registry.blockName2Index) { + var blockIndex = registry.blockName2Index[blockName]; + if (registry.getProp(blockName, 'transparent')) { + terrainMaterials[blockName] = blockIndex - 1 + } else { + terrainMaterials[blockName] = OPAQUE|(blockIndex - 1) // TODO: separate arrays? https://github.com/mikolalysenko/ao-mesher/issues/2 + } + } + // test manually assigned high block index + // before https://github.com/mikolalysenko/ao-mesher/issues/2 max is 255, after max is 32767 + var highIndex = 32767 + terrainMaterials.highBlock = OPAQUE|highIndex + } else { + console.warn('voxel-registry plugin not found, expect no textures') + } + //Create texture atlas - var stitcher = game.plugins.get('voxel-stitch') // TODO: load not as a plugin? + var stitcher = game.plugins.get('voxel-stitch') if (stitcher) { TILE_COUNT = stitcher.tileCount // set for shader below (never changes) var updateTexture = function() { @@ -85,6 +105,7 @@ shell.on("gl-init", function() { for (var k = 0; k < 6; k++) stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.wool-1, k)) + // the voxels! mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs, stitcher.voxelSideTextureSizes) var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) @@ -95,26 +116,6 @@ shell.on("gl-init", function() { console.warn('voxel-stitch plugin not found, expect no textures') } - //Lookup voxel materials for terrain generation - var registry = plugins.get('voxel-registry') - if (registry) { - var terrainMaterials = {}; - for (var blockName in registry.blockName2Index) { - var blockIndex = registry.blockName2Index[blockName]; - if (registry.getProp(blockName, 'transparent')) { - terrainMaterials[blockName] = blockIndex - 1 - } else { - terrainMaterials[blockName] = OPAQUE|(blockIndex - 1) // TODO: separate arrays? https://github.com/mikolalysenko/ao-mesher/issues/2 - } - } - // test manually assigned high block index - // before https://github.com/mikolalysenko/ao-mesher/issues/2 max is 255, after max is 32767 - var highIndex = 32767 - terrainMaterials.highBlock = OPAQUE|highIndex - } else { - console.warn('voxel-registry plugin not found, expect no textures') - } - shell.bind('wireframe', 'F') }) From 7ee278a5708ed698601c0ec6b8d4e2cb5d7a6d05 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 14 Apr 2014 20:18:26 -0700 Subject: [PATCH 150/256] Move wireframe into voxel-wireframe plugin. Closes GH-3 --- demo.js | 4 +++- lib/wireShader.js | 16 ---------------- main.js | 27 ++++++++------------------- package.json | 2 +- 4 files changed, 12 insertions(+), 37 deletions(-) delete mode 100644 lib/wireShader.js diff --git a/demo.js b/demo.js index 341339e..19acc8a 100644 --- a/demo.js +++ b/demo.js @@ -11,6 +11,7 @@ require('./lib/blocks.js'); require('voxel-drop'); require('voxel-keys'); require('voxel-artpacks'); +require('voxel-wireframe'); createShell({require: require, pluginOpts: { @@ -21,7 +22,8 @@ createShell({require: require, pluginOpts: './lib/blocks.js': {}, 'voxel-drop': {}, 'voxel-keys': {}, - 'voxel-artpacks': {} + 'voxel-artpacks': {}, + 'voxel-wireframe': {}, } }); diff --git a/lib/wireShader.js b/lib/wireShader.js deleted file mode 100644 index fbef92a..0000000 --- a/lib/wireShader.js +++ /dev/null @@ -1,16 +0,0 @@ -"use strict" -var createShader = require("gl-shader") - -module.exports = function(gl) { - return createShader(gl, -"attribute vec3 position;\ -uniform mat4 projection;\ -uniform mat4 view;\ -uniform mat4 model;\ -void main() {\ - gl_Position=projection * view * model * vec4(position, 1.0);\ -}", -"void main() {\ - gl_FragColor = vec4(0, 1, 0, 1);\ -}") -} \ No newline at end of file diff --git a/main.js b/main.js index 29d1708..b577326 100644 --- a/main.js +++ b/main.js @@ -3,7 +3,6 @@ var createShell = require("gl-now") var createCamera = require("game-shell-fps-camera") var ndarray = require("ndarray") -var createWireShader = require("./lib/wireShader.js") var createAOShader = require("voxel-shader") var createTerrain = require("./lib/terrain.js") // TODO: replace with shama's chunker mentioned in https://github.com/voxel/issues/issues/4#issuecomment-39644684 var createVoxelMesh = require("voxel-mesher") @@ -40,7 +39,7 @@ var main = function(opts) { plugins.loadAll(); //Config variables -var texture, shader, mesh, wireShader +var texture, shader, mesh // bit in voxel array to indicate voxel is opaque (transparent if not set) var OPAQUE = 1<<15; @@ -67,7 +66,6 @@ shell.on("gl-init", function() { //Create shaders shader = createAOShader(gl) - wireShader = createWireShader(gl) //Lookup voxel materials for terrain generation var registry = plugins.get('voxel-registry') @@ -107,6 +105,7 @@ shell.on("gl-init", function() { // the voxels! mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs, stitcher.voxelSideTextureSizes) + shell.mesh = mesh // for voxel-wireframe TODO: refactor var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) } @@ -137,7 +136,12 @@ shell.on("gl-render", function(t) { var projection = mat4.perspective(new Float32Array(16), Math.PI/4.0, shell.width/shell.height, 1.0, 1000.0) var model = mat4.identity(new Float32Array(16)) var view = camera.view() - + + // for voxel-wireframe rendering TODO: refactor + shell.projection = projection + shell.model = model + shell.view = view + gl.enable(gl.CULL_FACE) gl.enable(gl.DEPTH_TEST) @@ -156,21 +160,6 @@ shell.on("gl-render", function(t) { gl.drawArrays(gl.TRIANGLES, 0, mesh.triangleVertexCount) mesh.triangleVAO.unbind() } - - if(shell.wasDown('wireframe')) { - //Bind the wire shader - wireShader.bind() - wireShader.attributes.position.location = 0 - wireShader.uniforms.projection = projection - wireShader.uniforms.model = model - wireShader.uniforms.view = view - - if(mesh) { - mesh.wireVAO.bind() - gl.drawArrays(gl.LINES, 0, mesh.wireVertexCount) - mesh.wireVAO.unbind() - } - } }) return shell // TODO: fix indenting diff --git a/package.json b/package.json index b574d79..8faf776 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,13 @@ "voxel-stitch": "^0.5.0", "gl-matrix": "^2.2.1", "gl-now": "^1.3.0", - "gl-shader": "^3.0.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", "voxel-plugins": "^0.3.0" }, "devDependencies": { + "voxel-wireframe": "^0.1.0", "dat-gui": "^0.5.0", "kb-bindings-ui": "^0.3.0", "voxel-plugins-ui": "^0.2.0", From edb990343575384a21c87ac5692941a27ac296e6 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 14 Apr 2014 23:45:26 -0700 Subject: [PATCH 151/256] Remove redundant bind, ref GH-3 --- main.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.js b/main.js index b577326..4d6f2c0 100644 --- a/main.js +++ b/main.js @@ -114,8 +114,6 @@ shell.on("gl-init", function() { } else { console.warn('voxel-stitch plugin not found, expect no textures') } - - shell.bind('wireframe', 'F') }) shell.on("gl-error", function(err) { From 2c0eee7b873a74348283c8e0d7aad4c8177d6f7d Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 12:39:39 -0700 Subject: [PATCH 152/256] Add missing loadAfter voxel-registry in lib/blocks plugin --- lib/blocks.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/blocks.js b/lib/blocks.js index f7b0a64..ac0bb9f 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -5,6 +5,9 @@ module.exports = function(game, opts) { return new BlocksPlugin(game, opts); }; +module.exports.pluginInfo = { + loadAfter: ['voxel-registry'] +}; function BlocksPlugin(game, opts) { var registry = game.plugins.get('voxel-registry'); From e698d2bdb00e43f415ffe574bf7472ecfd5d939e Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 12:41:21 -0700 Subject: [PATCH 153/256] Change registry and stitch plugins to proper dependencies ('built-in' plugins) Makes more sense to include voxel-registry and voxel-stitch as actual dependencies, instead of letting the caller provide them, since game-shell-voxel explicitly uses them (in gl-init handler, setting up blocks and textures). Introduces concept of BUILTIN_PLUGINS. Callers can provide custom options to these plugins, or they default to '{}' (but they cannot currently override these plugins with their own versions). --- demo.js | 5 +---- main.js | 27 +++++++++++++++++++++++---- package.json | 4 ++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/demo.js b/demo.js index 19acc8a..0ff1200 100644 --- a/demo.js +++ b/demo.js @@ -5,8 +5,6 @@ var createGUI = require('dat-gui'); require('voxel-plugins-ui'); require('kb-bindings-ui'); -require('voxel-registry'); -require('voxel-stitch'); require('./lib/blocks.js'); require('voxel-drop'); require('voxel-keys'); @@ -15,8 +13,7 @@ require('voxel-wireframe'); createShell({require: require, pluginOpts: { - 'voxel-registry': {}, - 'voxel-stitch': {debug: false}, + //'voxel-stitch': {debug: true}, 'voxel-plugins-ui': {gui: new createGUI.GUI()}, 'kb-bindings-ui': {}, './lib/blocks.js': {}, diff --git a/main.js b/main.js index 4d6f2c0..fa45ff3 100644 --- a/main.js +++ b/main.js @@ -10,6 +10,10 @@ var glm = require("gl-matrix") var mat4 = glm.mat4 var createPlugins = require('voxel-plugins') +require('voxel-registry') +require('voxel-stitch') + +var BUILTIN_PLUGINS = ['voxel-registry', 'voxel-stitch']; var game = {}; global.game = game; // for debugging @@ -30,11 +34,26 @@ var main = function(opts) { game.isClient = true; game.shell = shell; - // TODO: should this be moved into gl-init?? see z-index note below - var plugins = createPlugins(game, {require: opts.require || require}); + // TODO: should plugin creation this be moved into gl-init?? see z-index note below + + var plugins = createPlugins(game, {require: function(name) { + // we provide the built-in plugins ourselves; otherwise check caller's require, if any + // TODO: allow caller to override built-ins? better way to do this? + if (BUILTIN_PLUGINS.indexOf(name) !== -1) { + return require(name); + } else { + return opts.require ? opts.require(name) : require(name); + } + }}); + + var pluginOpts = opts.pluginOpts || {}; // TODO: persist + + BUILTIN_PLUGINS.forEach(function(name) { + opts.pluginOpts[name] = opts.pluginOpts[name] || {}; + }); - for (var name in opts.pluginOpts) { - plugins.add(name, opts.pluginOpts[name]); + for (var name in pluginOpts) { + plugins.add(name, pluginOpts[name]); } plugins.loadAll(); diff --git a/package.json b/package.json index 8faf776..ddae4c9 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,13 @@ "voxel-mesher": "^0.5.0", "voxel-shader": "^0.5.0", "game-shell-fps-camera": "^0.1.1", - "voxel-stitch": "^0.5.0", "gl-matrix": "^2.2.1", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", + "voxel-stitch": "^0.5.0", + "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0" }, "devDependencies": { @@ -20,7 +21,6 @@ "dat-gui": "^0.5.0", "kb-bindings-ui": "^0.3.0", "voxel-plugins-ui": "^0.2.0", - "voxel-registry": "^0.3.0", "beefy": "^1.1.0", "browserify": "^3.38.0", "voxel-drop": "^0.1.1", From 7b108d50dfd368f3845be989bddededfc2782955 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 12:59:15 -0700 Subject: [PATCH 154/256] Add list of meshes --- main.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index fa45ff3..d56609a 100644 --- a/main.js +++ b/main.js @@ -26,6 +26,7 @@ var main = function(opts) { var shell = createShell(opts); var camera = createCamera(shell); shell.camera = camera; + shell.meshes = []; // populated below TODO: move to voxels.meshes camera.position[0] = -20; camera.position[1] = -33; @@ -58,7 +59,7 @@ var main = function(opts) { plugins.loadAll(); //Config variables -var texture, shader, mesh +var texture, shader // bit in voxel array to indicate voxel is opaque (transparent if not set) var OPAQUE = 1<<15; @@ -123,8 +124,8 @@ shell.on("gl-init", function() { stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.wool-1, k)) // the voxels! - mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs, stitcher.voxelSideTextureSizes) - shell.mesh = mesh // for voxel-wireframe TODO: refactor + var mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs, stitcher.voxelSideTextureSizes) + shell.meshes = [mesh] // for voxel-wireframe TODO: refactor var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) } @@ -172,7 +173,8 @@ shell.on("gl-render", function(t) { shader.uniforms.tileCount = TILE_COUNT if (texture) shader.uniforms.tileMap = texture.bind() // texture might not have loaded yet - if(mesh) { + for (var i = 0; i < shell.meshes.length; ++i) { + var mesh = shell.meshes[i]; mesh.triangleVAO.bind() gl.drawArrays(gl.TRIANGLES, 0, mesh.triangleVertexCount) mesh.triangleVAO.unbind() From 02bd1d87725f1df51f9808d97672f733a48ab486 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 19:07:54 -0700 Subject: [PATCH 155/256] Remove high block ID test Know it works --- lib/terrain.js | 5 ----- main.js | 8 -------- 2 files changed, 13 deletions(-) diff --git a/lib/terrain.js b/lib/terrain.js index 038dde9..9acedb6 100644 --- a/lib/terrain.js +++ b/lib/terrain.js @@ -15,11 +15,6 @@ module.exports = function(materials) { return materials.wool } - if (i===25 && j===30 && k===30) { - // high block index test - return materials.highBlock - } - if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { return 0 // air } diff --git a/main.js b/main.js index d56609a..2613e8a 100644 --- a/main.js +++ b/main.js @@ -99,10 +99,6 @@ shell.on("gl-init", function() { terrainMaterials[blockName] = OPAQUE|(blockIndex - 1) // TODO: separate arrays? https://github.com/mikolalysenko/ao-mesher/issues/2 } } - // test manually assigned high block index - // before https://github.com/mikolalysenko/ao-mesher/issues/2 max is 255, after max is 32767 - var highIndex = 32767 - terrainMaterials.highBlock = OPAQUE|highIndex } else { console.warn('voxel-registry plugin not found, expect no textures') } @@ -119,10 +115,6 @@ shell.on("gl-init", function() { texture = tex }) - // for highBlock, clone wool texture (if shows up as dirt, wrapped around) - for (var k = 0; k < 6; k++) - stitcher.voxelSideTextureIDs.set(highIndex, k, stitcher.voxelSideTextureIDs.get(registry.blockName2Index.wool-1, k)) - // the voxels! var mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs, stitcher.voxelSideTextureSizes) shell.meshes = [mesh] // for voxel-wireframe TODO: refactor From 3798d445fd00d091b1ae6b58ff2d547e34272fcc Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 19:45:58 -0700 Subject: [PATCH 156/256] Move shader setup to voxel-shader plugin --- main.js | 48 ++++-------------------------------------------- package.json | 3 +-- 2 files changed, 5 insertions(+), 46 deletions(-) diff --git a/main.js b/main.js index 2613e8a..a85a1aa 100644 --- a/main.js +++ b/main.js @@ -3,17 +3,15 @@ var createShell = require("gl-now") var createCamera = require("game-shell-fps-camera") var ndarray = require("ndarray") -var createAOShader = require("voxel-shader") var createTerrain = require("./lib/terrain.js") // TODO: replace with shama's chunker mentioned in https://github.com/voxel/issues/issues/4#issuecomment-39644684 var createVoxelMesh = require("voxel-mesher") -var glm = require("gl-matrix") -var mat4 = glm.mat4 var createPlugins = require('voxel-plugins') require('voxel-registry') require('voxel-stitch') +require('voxel-shader') -var BUILTIN_PLUGINS = ['voxel-registry', 'voxel-stitch']; +var BUILTIN_PLUGINS = ['voxel-registry', 'voxel-stitch', 'voxel-shader']; var game = {}; global.game = game; // for debugging @@ -25,7 +23,7 @@ var main = function(opts) { var shell = createShell(opts); var camera = createCamera(shell); - shell.camera = camera; + shell.camera = camera; // TODO: move to a plugin instead of hanging off shell instance? shell.meshes = []; // populated below TODO: move to voxels.meshes camera.position[0] = -20; @@ -58,14 +56,9 @@ var main = function(opts) { } plugins.loadAll(); -//Config variables -var texture, shader - // bit in voxel array to indicate voxel is opaque (transparent if not set) var OPAQUE = 1<<15; -var TILE_COUNT = null; - shell.on("gl-init", function() { var gl = shell.gl @@ -84,9 +77,6 @@ shell.on("gl-init", function() { // TODO: move to gl-texture2d? gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) - //Create shaders - shader = createAOShader(gl) - //Lookup voxel materials for terrain generation var registry = plugins.get('voxel-registry') if (registry) { @@ -106,13 +96,12 @@ shell.on("gl-init", function() { //Create texture atlas var stitcher = game.plugins.get('voxel-stitch') if (stitcher) { - TILE_COUNT = stitcher.tileCount // set for shader below (never changes) var updateTexture = function() { console.log('updateTexture() calling createGLTexture()') stitcher.createGLTexture(gl, function(err, tex) { if (err) throw new Error('stitcher createGLTexture error: ' + err) - texture = tex + stitcher.texture = tex // TODO: fix this awkward roundaboutness. voxel-shader uses this }) // the voxels! @@ -142,35 +131,6 @@ shell.on("gl-error", function(err) { shell.on("gl-render", function(t) { var gl = shell.gl - //Calculation projection matrix - var projection = mat4.perspective(new Float32Array(16), Math.PI/4.0, shell.width/shell.height, 1.0, 1000.0) - var model = mat4.identity(new Float32Array(16)) - var view = camera.view() - - // for voxel-wireframe rendering TODO: refactor - shell.projection = projection - shell.model = model - shell.view = view - - gl.enable(gl.CULL_FACE) - gl.enable(gl.DEPTH_TEST) - - //Bind the shader - shader.bind() - shader.attributes.attrib0.location = 0 - shader.attributes.attrib1.location = 1 - shader.uniforms.projection = projection - shader.uniforms.view = view - shader.uniforms.model = model - shader.uniforms.tileCount = TILE_COUNT - if (texture) shader.uniforms.tileMap = texture.bind() // texture might not have loaded yet - - for (var i = 0; i < shell.meshes.length; ++i) { - var mesh = shell.meshes[i]; - mesh.triangleVAO.bind() - gl.drawArrays(gl.TRIANGLES, 0, mesh.triangleVertexCount) - mesh.triangleVAO.unbind() - } }) return shell // TODO: fix indenting diff --git a/package.json b/package.json index ddae4c9..b190e9f 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,8 @@ "main": "main.js", "dependencies": { "voxel-mesher": "^0.5.0", - "voxel-shader": "^0.5.0", + "voxel-shader": "^0.6.0", "game-shell-fps-camera": "^0.1.1", - "gl-matrix": "^2.2.1", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", From 6479d8ec9797d70d1d81055d5f1fc2d245e85179 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 19:48:08 -0700 Subject: [PATCH 157/256] Remove now-unused gl-render --- main.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main.js b/main.js index a85a1aa..48276c2 100644 --- a/main.js +++ b/main.js @@ -128,11 +128,6 @@ shell.on("gl-error", function(err) { document.body.appendChild(a) }) -shell.on("gl-render", function(t) { - var gl = shell.gl - -}) - return shell // TODO: fix indenting } From 635b3a1cf0dae668b3cdad1c8feb98b4204db18a Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 20:15:15 -0700 Subject: [PATCH 158/256] Fix not capable message for view removal --- index.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 031e2bd..afdaa83 100644 --- a/index.js +++ b/index.js @@ -317,11 +317,8 @@ Game.prototype.setDimensions = function(opts) { Game.prototype.notCapable = function(opts) { var self = this if( !Detector().webgl ) { - this.view = { - appendTo: function(el) { - el.appendChild(self.notCapableMessage()) - } - } + if (!this.reportedNotCapable) document.body.appendChild(self.notCapableMessage()) + this.reportedNotCapable = true // only once return true } return false From 70f13504324b03e348057cdcbdbd89ac8ec8e665 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 20:24:25 -0700 Subject: [PATCH 159/256] Less friendly gl-error reporting; let voxel-engine handle compatible browser detection --- main.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/main.js b/main.js index 48276c2..1977a3c 100644 --- a/main.js +++ b/main.js @@ -118,14 +118,7 @@ shell.on("gl-init", function() { }) shell.on("gl-error", function(err) { - var a = document.createElement('a') - a.textContent = 'You need a modern WebGL browser (Chrome/Firefox) to play this game. Click here for more information. (WebGL error: ' + err + ')' - a.style.webkitUserSelect = '' - a.href = 'http://get.webgl.org/'; - - while(document.body.firstChild) document.body.removeChild(document.body.firstChild) - - document.body.appendChild(a) + document.body.appendChild(document.createTextNode('Fatal WebGL error: ' + err)) }) return shell // TODO: fix indenting From c6ee3a039a1237da59cca542b1680f7d8f461fb8 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 20:27:43 -0700 Subject: [PATCH 160/256] Refactor built-in plugin opts --- main.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 1977a3c..5dde811 100644 --- a/main.js +++ b/main.js @@ -11,7 +11,11 @@ require('voxel-registry') require('voxel-stitch') require('voxel-shader') -var BUILTIN_PLUGINS = ['voxel-registry', 'voxel-stitch', 'voxel-shader']; +var BUILTIN_PLUGIN_OPTS = { + 'voxel-registry': {}, + 'voxel-stitch': {}, + 'voxel-shader': {} +}; var game = {}; global.game = game; // for debugging @@ -38,7 +42,7 @@ var main = function(opts) { var plugins = createPlugins(game, {require: function(name) { // we provide the built-in plugins ourselves; otherwise check caller's require, if any // TODO: allow caller to override built-ins? better way to do this? - if (BUILTIN_PLUGINS.indexOf(name) !== -1) { + if (name in BUILTIN_PLUGIN_OPTS) { return require(name); } else { return opts.require ? opts.require(name) : require(name); @@ -47,9 +51,9 @@ var main = function(opts) { var pluginOpts = opts.pluginOpts || {}; // TODO: persist - BUILTIN_PLUGINS.forEach(function(name) { - opts.pluginOpts[name] = opts.pluginOpts[name] || {}; - }); + for (var name in BUILTIN_PLUGIN_OPTS) { + opts.pluginOpts[name] = opts.pluginOpts[name] || BUILTIN_PLUGIN_OPTS[name]; + } for (var name in pluginOpts) { plugins.add(name, pluginOpts[name]); From 7f48d017fd56b6b3144bff27f9731692fcda0a86 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 20:33:56 -0700 Subject: [PATCH 161/256] Remove stitcher.stitch() call since voxel-stitch now calls it itself --- main.js | 1 - package.json | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 5dde811..9be1786 100644 --- a/main.js +++ b/main.js @@ -115,7 +115,6 @@ shell.on("gl-init", function() { camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) } stitcher.on('updateTexture', updateTexture) - stitcher.stitch() } else { console.warn('voxel-stitch plugin not found, expect no textures') } diff --git a/package.json b/package.json index b190e9f..d096d23 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,13 @@ "main": "main.js", "dependencies": { "voxel-mesher": "^0.5.0", - "voxel-shader": "^0.6.0", + "voxel-shader": "git://github.com/deathcap/voxel-shader.git#bcaae88e1e57adf0d499f3225ddb64bc9eec1d61", "game-shell-fps-camera": "^0.1.1", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", - "voxel-stitch": "^0.5.0", + "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#41cc9714a440890685f233f22af027dd9090c7e0", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0" }, From 2382a4649bef9b0625de202a1352bce85dbce337 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 20:50:16 -0700 Subject: [PATCH 162/256] Move GL texture creation to voxel-shader; show voxels on 'updatedSides' event Update voxel-shader, voxel-stitch deathcap/voxel-shader@612a72c8551df75f8329a31020cd4a76d49ad63a Set texture on updateTexture event from voxel-stitch deathcap/voxel-stitch@e2f981afed46dcbaace478449faef4a3565e1511 Emit updatedSides (was updateTexture), create GL texture and then emit updateTexture Commit message generated by https://github.com/deathcap/lmno-cl --- main.js | 12 ++---------- package.json | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/main.js b/main.js index 9be1786..e7a7d02 100644 --- a/main.js +++ b/main.js @@ -100,21 +100,13 @@ shell.on("gl-init", function() { //Create texture atlas var stitcher = game.plugins.get('voxel-stitch') if (stitcher) { - var updateTexture = function() { - console.log('updateTexture() calling createGLTexture()') - - stitcher.createGLTexture(gl, function(err, tex) { - if (err) throw new Error('stitcher createGLTexture error: ' + err) - stitcher.texture = tex // TODO: fix this awkward roundaboutness. voxel-shader uses this - }) - - // the voxels! + var addVoxels = function() { var mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs, stitcher.voxelSideTextureSizes) shell.meshes = [mesh] // for voxel-wireframe TODO: refactor var c = mesh.center camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) } - stitcher.on('updateTexture', updateTexture) + stitcher.on('updatedSides', addVoxels) } else { console.warn('voxel-stitch plugin not found, expect no textures') } diff --git a/package.json b/package.json index d096d23..787485e 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,13 @@ "main": "main.js", "dependencies": { "voxel-mesher": "^0.5.0", - "voxel-shader": "git://github.com/deathcap/voxel-shader.git#bcaae88e1e57adf0d499f3225ddb64bc9eec1d61", + "voxel-shader": "git://github.com/deathcap/voxel-shader.git#612a72c8551df75f8329a31020cd4a76d49ad63a", "game-shell-fps-camera": "^0.1.1", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", - "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#41cc9714a440890685f233f22af027dd9090c7e0", + "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#e2f981afed46dcbaace478449faef4a3565e1511", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0" }, From 9fa48fcab1d57dd53d0d30e488c50f49746b53f5 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 20:53:06 -0700 Subject: [PATCH 163/256] Move blending settings to voxel-shader Update voxel-shader deathcap/voxel-shader@fa7d12388aa9df49dc159a08e47cb58af67d270d Add blending function setting from game-shell-voxel Commit message generated by https://github.com/deathcap/lmno-cl --- main.js | 9 --------- package.json | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/main.js b/main.js index e7a7d02..a73289a 100644 --- a/main.js +++ b/main.js @@ -72,15 +72,6 @@ shell.on("gl-init", function() { shell.canvas.style.zIndex = '-1'; shell.canvas.parentElement.style.zIndex = '-1'; - // TODO: is this right? see https://github.com/mikolalysenko/ao-shader/issues/2 - //gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA) - //gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - gl.enable(gl.BLEND) - // premultiply alpha when loading textures, so can use gl.ONE blending, see http://stackoverflow.com/questions/11521035/blending-with-html-background-in-webgl - // TODO: move to gl-texture2d? - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) - //Lookup voxel materials for terrain generation var registry = plugins.get('voxel-registry') if (registry) { diff --git a/package.json b/package.json index 787485e..661b06e 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "main.js", "dependencies": { "voxel-mesher": "^0.5.0", - "voxel-shader": "git://github.com/deathcap/voxel-shader.git#612a72c8551df75f8329a31020cd4a76d49ad63a", + "voxel-shader": "git://github.com/deathcap/voxel-shader.git#fa7d12388aa9df49dc159a08e47cb58af67d270d", "game-shell-fps-camera": "^0.1.1", "gl-now": "^1.3.0", "ndarray": "^1.0.10", From ec17ebcc6678012bc6c4a06e69dc83178c598a47 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 15 Apr 2014 21:37:41 -0700 Subject: [PATCH 164/256] Move meshes to voxel-mesher, now loaded as plugin --- main.js | 21 +++++++-------------- package.json | 12 ++++++------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/main.js b/main.js index a73289a..0c13807 100644 --- a/main.js +++ b/main.js @@ -4,17 +4,18 @@ var createShell = require("gl-now") var createCamera = require("game-shell-fps-camera") var ndarray = require("ndarray") var createTerrain = require("./lib/terrain.js") // TODO: replace with shama's chunker mentioned in https://github.com/voxel/issues/issues/4#issuecomment-39644684 -var createVoxelMesh = require("voxel-mesher") var createPlugins = require('voxel-plugins') require('voxel-registry') require('voxel-stitch') require('voxel-shader') +require('voxel-mesher') var BUILTIN_PLUGIN_OPTS = { 'voxel-registry': {}, 'voxel-stitch': {}, - 'voxel-shader': {} + 'voxel-shader': {}, + 'voxel-mesher': {}, }; var game = {}; @@ -88,18 +89,10 @@ shell.on("gl-init", function() { console.warn('voxel-registry plugin not found, expect no textures') } - //Create texture atlas - var stitcher = game.plugins.get('voxel-stitch') - if (stitcher) { - var addVoxels = function() { - var mesh = createVoxelMesh(shell.gl, createTerrain(terrainMaterials), stitcher.voxelSideTextureIDs, stitcher.voxelSideTextureSizes) - shell.meshes = [mesh] // for voxel-wireframe TODO: refactor - var c = mesh.center - camera.lookAt([c[0]+mesh.radius*2, c[1], c[2]], c, [0,1,0]) - } - stitcher.on('updatedSides', addVoxels) - } else { - console.warn('voxel-stitch plugin not found, expect no textures') + // add voxels + var mesher = plugins.get('voxel-mesher'); + if (mesher) { + mesher.addVoxelArray(createTerrain(terrainMaterials)); } }) diff --git a/package.json b/package.json index 661b06e..1440721 100644 --- a/package.json +++ b/package.json @@ -4,27 +4,27 @@ "description": "Demonstration of mipmapping for voxel terrain", "main": "main.js", "dependencies": { - "voxel-mesher": "^0.5.0", - "voxel-shader": "git://github.com/deathcap/voxel-shader.git#fa7d12388aa9df49dc159a08e47cb58af67d270d", + "voxel-mesher": "^0.6.0", + "voxel-shader": "^0.7.0", "game-shell-fps-camera": "^0.1.1", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", - "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#e2f981afed46dcbaace478449faef4a3565e1511", + "voxel-stitch": "^0.6.0", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0" }, "devDependencies": { - "voxel-wireframe": "^0.1.0", + "voxel-wireframe": "^0.2.0", "dat-gui": "^0.5.0", "kb-bindings-ui": "^0.3.0", "voxel-plugins-ui": "^0.2.0", "beefy": "^1.1.0", "browserify": "^3.38.0", - "voxel-drop": "^0.1.1", + "voxel-drop": "^0.1.2", "voxel-keys": "^0.1.0", - "voxel-artpacks": "^0.1.0" + "voxel-artpacks": "^0.1.1" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", From d71ee2382da7b9c53f02328abb07870f68a5b7c2 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 16 Apr 2014 12:06:26 -0700 Subject: [PATCH 165/256] Load terrain as a plugin; move blocks to built-in for now --- demo.js | 2 -- lib/terrain.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++-- main.js | 27 ++++---------------------- 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/demo.js b/demo.js index 0ff1200..36d28f9 100644 --- a/demo.js +++ b/demo.js @@ -5,7 +5,6 @@ var createGUI = require('dat-gui'); require('voxel-plugins-ui'); require('kb-bindings-ui'); -require('./lib/blocks.js'); require('voxel-drop'); require('voxel-keys'); require('voxel-artpacks'); @@ -16,7 +15,6 @@ createShell({require: require, pluginOpts: //'voxel-stitch': {debug: true}, 'voxel-plugins-ui': {gui: new createGUI.GUI()}, 'kb-bindings-ui': {}, - './lib/blocks.js': {}, 'voxel-drop': {}, 'voxel-keys': {}, 'voxel-artpacks': {}, diff --git a/lib/terrain.js b/lib/terrain.js index 9acedb6..3fc3ebc 100644 --- a/lib/terrain.js +++ b/lib/terrain.js @@ -3,7 +3,55 @@ var ndarray = require("ndarray") var fill = require("ndarray-fill") -module.exports = function(materials) { +// TODO: refactor with voxel-land +module.exports = function(game, opts) { + return new TerrainPlugin(game, opts); +}; +module.exports.pluginInfo = { + loadAfter: ['voxel-registry', 'voxel-mesher'] +}; + +function TerrainPlugin(game, opts) { + this.shell = game.shell; + + this.registry = game.plugins.get('voxel-registry'); + if (!this.registry) throw new Error('lib/terrain requires voxel-registry plugin'); + + this.mesher = game.plugins.get('voxel-mesher'); + if (!this.mesher) throw new Error('lib/terrain requires voxel-mesher plugin'); + + this.enable(); +}; + +TerrainPlugin.prototype.enable = function() { + // once the game is about to initialize, gather all registered materials and build voxels + // TODO: this doesn't really have to be done on gl-init, only when the blocks are ready. refactor with lib/blocks.js + this.shell.on('gl-init', this.onInit = this.addVoxels.bind(this)); +}; + +TerrainPlugin.prototype.disable = function() { + this.shell.removeListener('gl-init', this.onInit); +}; + +// bit in voxel array to indicate voxel is opaque (transparent if not set) +var OPAQUE = 1<<15; + +TerrainPlugin.prototype.addVoxels = function() { + var terrainMaterials = {}; + for (var blockName in this.registry.blockName2Index) { + var blockIndex = this.registry.blockName2Index[blockName]; + if (this.registry.getProp(blockName, 'transparent')) { + terrainMaterials[blockName] = blockIndex - 1 // TODO: remove -1 offset? leave 0 as 'air' (unused) in texture arrays? + } else { + terrainMaterials[blockName] = OPAQUE|(blockIndex - 1) // TODO: separate arrays? https://github.com/mikolalysenko/ao-mesher/issues/2 + } + } + + // add voxels + this.mesher.addVoxelArray(createTerrain(terrainMaterials)); +}; + +var createTerrain = function(materials) { var size = [33,33,33] var result = ndarray(new Int32Array(size[0]*size[1]*size[2]), size) //Fill ndarray with function @@ -69,6 +117,6 @@ module.exports = function(materials) { return materials.lava }) return result -} +}; diff --git a/main.js b/main.js index 0c13807..b8238ee 100644 --- a/main.js +++ b/main.js @@ -10,12 +10,16 @@ require('voxel-registry') require('voxel-stitch') require('voxel-shader') require('voxel-mesher') +require('./lib/blocks.js') // temporary +require('./lib/terrain.js') // temporary var BUILTIN_PLUGIN_OPTS = { 'voxel-registry': {}, 'voxel-stitch': {}, 'voxel-shader': {}, 'voxel-mesher': {}, + './lib/blocks.js': {}, + './lib/terrain.js': {}, }; var game = {}; @@ -61,9 +65,6 @@ var main = function(opts) { } plugins.loadAll(); -// bit in voxel array to indicate voxel is opaque (transparent if not set) -var OPAQUE = 1<<15; - shell.on("gl-init", function() { var gl = shell.gl @@ -74,26 +75,6 @@ shell.on("gl-init", function() { shell.canvas.parentElement.style.zIndex = '-1'; //Lookup voxel materials for terrain generation - var registry = plugins.get('voxel-registry') - if (registry) { - var terrainMaterials = {}; - for (var blockName in registry.blockName2Index) { - var blockIndex = registry.blockName2Index[blockName]; - if (registry.getProp(blockName, 'transparent')) { - terrainMaterials[blockName] = blockIndex - 1 - } else { - terrainMaterials[blockName] = OPAQUE|(blockIndex - 1) // TODO: separate arrays? https://github.com/mikolalysenko/ao-mesher/issues/2 - } - } - } else { - console.warn('voxel-registry plugin not found, expect no textures') - } - - // add voxels - var mesher = plugins.get('voxel-mesher'); - if (mesher) { - mesher.addVoxelArray(createTerrain(terrainMaterials)); - } }) shell.on("gl-error", function(err) { From 56c3972eab91248c8845b98ae8c26d46a1191b40 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 16 Apr 2014 18:06:50 -0700 Subject: [PATCH 166/256] Fix indentation --- main.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/main.js b/main.js index b8238ee..c41029c 100644 --- a/main.js +++ b/main.js @@ -65,23 +65,23 @@ var main = function(opts) { } plugins.loadAll(); -shell.on("gl-init", function() { - var gl = shell.gl + shell.on("gl-init", function() { + var gl = shell.gl - // since the plugins are loaded before gl-init, the element will be - // below other UI widgets in the DOM tree, so by default the z-order will cause - // the canvas to cover the other widgets - to fix this, set z-index below - shell.canvas.style.zIndex = '-1'; - shell.canvas.parentElement.style.zIndex = '-1'; + // since the plugins are loaded before gl-init, the element will be + // below other UI widgets in the DOM tree, so by default the z-order will cause + // the canvas to cover the other widgets - to fix this, set z-index below + shell.canvas.style.zIndex = '-1'; + shell.canvas.parentElement.style.zIndex = '-1'; - //Lookup voxel materials for terrain generation -}) + //Lookup voxel materials for terrain generation + }) -shell.on("gl-error", function(err) { - document.body.appendChild(document.createTextNode('Fatal WebGL error: ' + err)) -}) + shell.on("gl-error", function(err) { + document.body.appendChild(document.createTextNode('Fatal WebGL error: ' + err)) + }) - return shell // TODO: fix indenting + return shell } module.exports = main From 357c97d1c5618ff38c86f669180fd4b289b16ecb Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 16 Apr 2014 18:43:12 -0700 Subject: [PATCH 167/256] Move camera to new voxel-camera plugin --- main.js | 12 ++---------- package.json | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/main.js b/main.js index c41029c..454fefb 100644 --- a/main.js +++ b/main.js @@ -1,15 +1,13 @@ "use strict" var createShell = require("gl-now") -var createCamera = require("game-shell-fps-camera") -var ndarray = require("ndarray") -var createTerrain = require("./lib/terrain.js") // TODO: replace with shama's chunker mentioned in https://github.com/voxel/issues/issues/4#issuecomment-39644684 var createPlugins = require('voxel-plugins') require('voxel-registry') require('voxel-stitch') require('voxel-shader') require('voxel-mesher') +require('voxel-camera') require('./lib/blocks.js') // temporary require('./lib/terrain.js') // temporary @@ -18,6 +16,7 @@ var BUILTIN_PLUGIN_OPTS = { 'voxel-stitch': {}, 'voxel-shader': {}, 'voxel-mesher': {}, + 'voxel-camera': {}, './lib/blocks.js': {}, './lib/terrain.js': {}, }; @@ -31,13 +30,6 @@ var main = function(opts) { opts.pointerLock = true; var shell = createShell(opts); - var camera = createCamera(shell); - shell.camera = camera; // TODO: move to a plugin instead of hanging off shell instance? - shell.meshes = []; // populated below TODO: move to voxels.meshes - - camera.position[0] = -20; - camera.position[1] = -33; - camera.position[2] = -40; game.isClient = true; game.shell = shell; diff --git a/package.json b/package.json index 1440721..38502c3 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,11 @@ "dependencies": { "voxel-mesher": "^0.6.0", "voxel-shader": "^0.7.0", - "game-shell-fps-camera": "^0.1.1", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", + "voxel-camera": "git://github.com/deathcap/voxel-camera.git", "voxel-stitch": "^0.6.0", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0" From 1f3419bbbab88de3dac5bcaeccd4c8a049775aee Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 16 Apr 2014 19:00:06 -0700 Subject: [PATCH 168/256] =?UTF-8?q?Update=20game-shell-fps-camera,=20now?= =?UTF-8?q?=20loaded=20as=20a=20plugin=20(=E2=89=88=20voxel-camera)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 4 ++-- package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 454fefb..985dab5 100644 --- a/main.js +++ b/main.js @@ -7,7 +7,7 @@ require('voxel-registry') require('voxel-stitch') require('voxel-shader') require('voxel-mesher') -require('voxel-camera') +require('game-shell-fps-camera') require('./lib/blocks.js') // temporary require('./lib/terrain.js') // temporary @@ -16,7 +16,7 @@ var BUILTIN_PLUGIN_OPTS = { 'voxel-stitch': {}, 'voxel-shader': {}, 'voxel-mesher': {}, - 'voxel-camera': {}, + 'game-shell-fps-camera': {}, './lib/blocks.js': {}, './lib/terrain.js': {}, }; diff --git a/package.json b/package.json index 38502c3..8f58a00 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,12 @@ "main": "main.js", "dependencies": { "voxel-mesher": "^0.6.0", - "voxel-shader": "^0.7.0", + "voxel-shader": "^0.8.0", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", - "voxel-camera": "git://github.com/deathcap/voxel-camera.git", + "game-shell-fps-camera": "^0.2.0", "voxel-stitch": "^0.6.0", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0" From 4e0d73973d608915c1435e88be1f0303be49add1 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 16 Apr 2014 19:11:15 -0700 Subject: [PATCH 169/256] Minor cleanup --- main.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index 985dab5..938700c 100644 --- a/main.js +++ b/main.js @@ -26,16 +26,14 @@ global.game = game; // for debugging var main = function(opts) { opts = opts || {}; - opts.clearColor = [0.75, 0.8, 0.9, 1.0] - opts.pointerLock = true; + opts.clearColor = opts.clearColor || [0.75, 0.8, 0.9, 1.0] + opts.pointerLock = opts.pointerLock !== undefined ? opts.pointerLock : true; var shell = createShell(opts); game.isClient = true; game.shell = shell; - // TODO: should plugin creation this be moved into gl-init?? see z-index note below - var plugins = createPlugins(game, {require: function(name) { // we provide the built-in plugins ourselves; otherwise check caller's require, if any // TODO: allow caller to override built-ins? better way to do this? @@ -46,7 +44,7 @@ var main = function(opts) { } }}); - var pluginOpts = opts.pluginOpts || {}; // TODO: persist + var pluginOpts = opts.pluginOpts || {}; for (var name in BUILTIN_PLUGIN_OPTS) { opts.pluginOpts[name] = opts.pluginOpts[name] || BUILTIN_PLUGIN_OPTS[name]; @@ -62,11 +60,9 @@ var main = function(opts) { // since the plugins are loaded before gl-init, the element will be // below other UI widgets in the DOM tree, so by default the z-order will cause - // the canvas to cover the other widgets - to fix this, set z-index below + // the canvas to cover the other widgets - to allow plugins to cover the canvas, + // we lower the z-index of the canvas below shell.canvas.style.zIndex = '-1'; - shell.canvas.parentElement.style.zIndex = '-1'; - - //Lookup voxel materials for terrain generation }) shell.on("gl-error", function(err) { From 18a1112a56b5c8946f2675cef057016dbfb5d775 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 16 Apr 2014 19:15:19 -0700 Subject: [PATCH 170/256] Move lib/blocks, lib/terrain back to demo --- demo.js | 4 ++++ main.js | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/demo.js b/demo.js index 36d28f9..fe3fd3c 100644 --- a/demo.js +++ b/demo.js @@ -9,6 +9,8 @@ require('voxel-drop'); require('voxel-keys'); require('voxel-artpacks'); require('voxel-wireframe'); +require('./lib/blocks.js'); +require('./lib/terrain.js'); createShell({require: require, pluginOpts: { @@ -19,6 +21,8 @@ createShell({require: require, pluginOpts: 'voxel-keys': {}, 'voxel-artpacks': {}, 'voxel-wireframe': {}, + './lib/blocks.js': {}, + './lib/terrain.js': {}, } }); diff --git a/main.js b/main.js index 938700c..d3007aa 100644 --- a/main.js +++ b/main.js @@ -8,8 +8,6 @@ require('voxel-stitch') require('voxel-shader') require('voxel-mesher') require('game-shell-fps-camera') -require('./lib/blocks.js') // temporary -require('./lib/terrain.js') // temporary var BUILTIN_PLUGIN_OPTS = { 'voxel-registry': {}, @@ -17,8 +15,6 @@ var BUILTIN_PLUGIN_OPTS = { 'voxel-shader': {}, 'voxel-mesher': {}, 'game-shell-fps-camera': {}, - './lib/blocks.js': {}, - './lib/terrain.js': {}, }; var game = {}; From 7b3ed0f140b54524292fcceac8bacd00489b257c Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 16 Apr 2014 19:54:06 -0700 Subject: [PATCH 171/256] Merge game-shell-voxel main.js into index.js --- index.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++--- main.js | 72 -------------------------------------------------------- 2 files changed, 60 insertions(+), 75 deletions(-) delete mode 100644 main.js diff --git a/index.js b/index.js index afdaa83..3b396ba 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +'use strict' var voxel = require('voxel') var ray = require('voxel-raycast') var control = require('voxel-control') @@ -17,9 +18,25 @@ var regionChange = require('voxel-region-change') var physical = require('voxel-physical') var pin = require('pin-it') var tic = require('tic')() +var createShell = require('gl-now') + +var createPlugins = require('voxel-plugins') +require('voxel-registry') +require('voxel-stitch') +require('voxel-shader') +require('voxel-mesher') +require('game-shell-fps-camera') module.exports = Game +var BUILTIN_PLUGIN_OPTS = { + 'voxel-registry': {}, + 'voxel-stitch': {}, + 'voxel-shader': {}, + 'voxel-mesher': {}, + 'game-shell-fps-camera': {}, +}; + function Game(opts) { if (!(this instanceof Game)) return new Game(opts) var self = this @@ -46,7 +63,7 @@ function Game(opts) { this.chunkDistance = opts.chunkDistance || 2 this.removeDistance = opts.removeDistance || this.chunkDistance + 1 - this.skyColor = opts.skyColor || 0xBFD1E5 + this.skyColor = opts.skyColor || 0xBFD1E5 // TODO: ≈ clearColor array this.antialias = opts.antialias this.playerHeight = opts.playerHeight || 1.62 this.meshType = opts.meshType || 'surfaceMesh' @@ -64,8 +81,48 @@ function Game(opts) { // used to be a THREE.PerspectiveCamera set by voxel-view; see also basic-camera but API not likely compatible (TODO: make it compatible?) Object.defineProperty(this, 'camera', {get:function() { throw new Error('voxel-engine "camera" property removed') }}) - // handles all rendering - this.shell = createShell({require: opts.require || require, pluginOpts: opts.pluginOpts}) + // the game-shell + var shellOpts = shellOpts || {} + shellOpts.clearColor = opts.clearColor || [0.75, 0.8, 0.9, 1.0] // TODO: take from skyColor, packed hex + shellOpts.pointerLock = opts.pointerLock !== undefined ? opts.pointerLock : true + var shell = createShell(shellOpts) + shell.on('gl-init', function() { + // since the plugins are loaded before gl-init, the element will be + // below other UI widgets in the DOM tree, so by default the z-order will cause + // the canvas to cover the other widgets - to allow plugins to cover the canvas, + // we lower the z-index of the canvas below + shell.canvas.style.zIndex = '-1' + }) + + shell.on('gl-error', function(err) { + // normally not reached; notCapable() checks for WebGL compatibility first + document.body.appendChild(document.createTextNode('Fatal WebGL error: ' + err)) + }) + + this.shell = shell + + // setup plugins + var plugins = createPlugins(this, {require: function(name) { + // we provide the built-in plugins ourselves; otherwise check caller's require, if any + // TODO: allow caller to override built-ins? better way to do this? + if (name in BUILTIN_PLUGIN_OPTS) { + return require(name) + } else { + return opts.require ? opts.require(name) : require(name) + } + }}) + + var pluginOpts = opts.pluginOpts || {} + + for (var name in BUILTIN_PLUGIN_OPTS) { + opts.pluginOpts[name] = opts.pluginOpts[name] || BUILTIN_PLUGIN_OPTS[name] + } + + for (var name in pluginOpts) { + plugins.add(name, pluginOpts[name]) + } + plugins.loadAll() + this.collideVoxels = collisions( this.getBlock.bind(this), diff --git a/main.js b/main.js deleted file mode 100644 index d3007aa..0000000 --- a/main.js +++ /dev/null @@ -1,72 +0,0 @@ -"use strict" - -var createShell = require("gl-now") - -var createPlugins = require('voxel-plugins') -require('voxel-registry') -require('voxel-stitch') -require('voxel-shader') -require('voxel-mesher') -require('game-shell-fps-camera') - -var BUILTIN_PLUGIN_OPTS = { - 'voxel-registry': {}, - 'voxel-stitch': {}, - 'voxel-shader': {}, - 'voxel-mesher': {}, - 'game-shell-fps-camera': {}, -}; - -var game = {}; -global.game = game; // for debugging - -var main = function(opts) { - opts = opts || {}; - opts.clearColor = opts.clearColor || [0.75, 0.8, 0.9, 1.0] - opts.pointerLock = opts.pointerLock !== undefined ? opts.pointerLock : true; - - var shell = createShell(opts); - - game.isClient = true; - game.shell = shell; - - var plugins = createPlugins(game, {require: function(name) { - // we provide the built-in plugins ourselves; otherwise check caller's require, if any - // TODO: allow caller to override built-ins? better way to do this? - if (name in BUILTIN_PLUGIN_OPTS) { - return require(name); - } else { - return opts.require ? opts.require(name) : require(name); - } - }}); - - var pluginOpts = opts.pluginOpts || {}; - - for (var name in BUILTIN_PLUGIN_OPTS) { - opts.pluginOpts[name] = opts.pluginOpts[name] || BUILTIN_PLUGIN_OPTS[name]; - } - - for (var name in pluginOpts) { - plugins.add(name, pluginOpts[name]); - } - plugins.loadAll(); - - shell.on("gl-init", function() { - var gl = shell.gl - - // since the plugins are loaded before gl-init, the element will be - // below other UI widgets in the DOM tree, so by default the z-order will cause - // the canvas to cover the other widgets - to allow plugins to cover the canvas, - // we lower the z-index of the canvas below - shell.canvas.style.zIndex = '-1'; - }) - - shell.on("gl-error", function(err) { - document.body.appendChild(document.createTextNode('Fatal WebGL error: ' + err)) - }) - - return shell -} - -module.exports = main - From 2617554c579b0855c78e163591b4984d7370ad72 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 16 Apr 2014 22:51:38 -0700 Subject: [PATCH 172/256] Set game-shell clearColor from voxel-engine opts.skyColor --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3b396ba..0616a03 100644 --- a/index.js +++ b/index.js @@ -63,7 +63,7 @@ function Game(opts) { this.chunkDistance = opts.chunkDistance || 2 this.removeDistance = opts.removeDistance || this.chunkDistance + 1 - this.skyColor = opts.skyColor || 0xBFD1E5 // TODO: ≈ clearColor array + this.skyColor = opts.skyColor || 0xBFD1E5 this.antialias = opts.antialias this.playerHeight = opts.playerHeight || 1.62 this.meshType = opts.meshType || 'surfaceMesh' @@ -83,7 +83,10 @@ function Game(opts) { // the game-shell var shellOpts = shellOpts || {} - shellOpts.clearColor = opts.clearColor || [0.75, 0.8, 0.9, 1.0] // TODO: take from skyColor, packed hex + shellOpts.clearColor = [ + (this.skyColor >> 16) / 255.0, + ((this.skyColor >> 8) & 0xff) / 255.0, + (this.skyColor & 0xff) / 255.0] shellOpts.pointerLock = opts.pointerLock !== undefined ? opts.pointerLock : true var shell = createShell(shellOpts) shell.on('gl-init', function() { From 5d09d07a25b973ce4b3d1bc71fe42fa187dd865d Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 17 Apr 2014 19:22:06 -0700 Subject: [PATCH 173/256] Start integrating showChunk() with voxel-mesher.. some voxels show up --- index.js | 68 +++++++++++++++++++++++++++++++--------------------- package.json | 4 ++-- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/index.js b/index.js index 0616a03..bbb000e 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,7 @@ var physical = require('voxel-physical') var pin = require('pin-it') var tic = require('tic')() var createShell = require('gl-now') +var ndarray = require('ndarray') var createPlugins = require('voxel-plugins') require('voxel-registry') @@ -67,7 +68,10 @@ function Game(opts) { this.antialias = opts.antialias this.playerHeight = opts.playerHeight || 1.62 this.meshType = opts.meshType || 'surfaceMesh' - this.mesher = opts.mesher || voxel.meshers.transgreedy + + // was a 'voxel' module meshers object, now using voxel-mesher(ao-mesher) + Object.defineProperty(this, 'mesher', {get:function() { throw new Error('voxel-engine "mesher" property removed') }}) + this.items = [] this.voxels = voxel(this) @@ -126,6 +130,7 @@ function Game(opts) { } plugins.loadAll() + this.mesherPlugin = plugins.get('voxel-mesher') this.collideVoxels = collisions( this.getBlock.bind(this), @@ -152,27 +157,31 @@ function Game(opts) { if (opts.exposeGlobal) window.game = window.g = this } - //this.materialNames = opts.materials || [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'] - this.materials = opts.materials - + self.chunkRegion.on('change', function(newChunk) { self.removeFarChunks() }) - //if (this.isClient) this.materials.load(this.materialNames) - - if (this.generateChunks) this.handleChunkGeneration() - // client side only after this point if (!this.isClient) return - - this.paused = true + + // materials + //this.materialNames = opts.materials || [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'] + this.materials = opts.materials - this.showAllChunks() + // textures loaded, now can render chunks + var stitcher = plugins.get('voxel-stitch') + stitcher.on('updatedSides', function() { + if (self.generateChunks) self.handleChunkGeneration() + self.showAllChunks() + + // TODO: ? + setTimeout(function() { + self.asyncChunkGeneration = 'asyncChunkGeneration' in opts ? opts.asyncChunkGeneration : true + }, 2000) + }) - setTimeout(function() { - self.asyncChunkGeneration = 'asyncChunkGeneration' in opts ? opts.asyncChunkGeneration : true - }, 2000) + this.paused = true // initializeControls() // player control @@ -573,25 +582,30 @@ Game.prototype.showAllChunks = function() { Game.prototype.showChunk = function(chunk) { var chunkIndex = chunk.position.join('|') var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position) - var scale = new THREE.Vector3(1, 1, 1) - var transparentTypes = this.materials.getTransparentVoxelTypes ? this.materials.getTransparentVoxelTypes() : {}; - /* TODO - var mesh = voxelMesh(chunk, this.mesher, scale, this.THREE, {transparentTypes: transparentTypes}) + + var voxelArray = ndarray(chunk.voxels, chunk.dims) // TODO: detect and use ndarray natively if passed in (isndarray) + var mesh = this.mesherPlugin.createMesh(voxelArray) + if (!mesh) { + // no voxels + // TODO: not quite right - this occurs if all the voxels are the _same_ (a superset of + // whether all the voxels are air). If a chunk is solid stone, we still need to render it; + // I guess this is why mikolalysenko made the chunks 33,33,33 in voxel-mipmap-demo. We could + // leave the edges empty (air) so solid chunks always render (unless entirely air). + // But for now, skip these chunks. + return null; + } + this.voxels.chunks[chunkIndex] = chunk if (this.voxels.meshes[chunkIndex]) { - if (this.voxels.meshes[chunkIndex].surfaceMesh) this.scene.remove(this.voxels.meshes[chunkIndex].surfaceMesh) - if (this.voxels.meshes[chunkIndex].wireMesh) this.scene.remove(this.voxels.meshes[chunkIndex].wireMesh) + // TODO: remove mesh if exists + //if (this.voxels.meshes[chunkIndex].surfaceMesh) this.scene.remove(this.voxels.meshes[chunkIndex].surfaceMesh) + //if (this.voxels.meshes[chunkIndex].wireMesh) this.scene.remove(this.voxels.meshes[chunkIndex].wireMesh) } this.voxels.meshes[chunkIndex] = mesh - if (this.isClient) { - if (this.meshType === 'wireMesh') mesh.createWireMesh() - else mesh.createSurfaceMesh(this.materials) - } - mesh.setPosition(bounds[0][0], bounds[0][1], bounds[0][2]) - mesh.addToScene(this.scene) + //mesh.setPosition(bounds[0][0], bounds[0][1], bounds[0][2]) // TODO: chunk position + //mesh.addToScene(this.scene) // TODO: something this.emit('renderChunk', chunk) return mesh - */ } // # Debugging methods diff --git a/package.json b/package.json index 59e6e80..024e409 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "^0.6.0", - "voxel-shader": "^0.8.0", + "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#5e574c650f2735a2c5b51d5c380e7cfc2c3a6fac", + "voxel-shader": "git://github.com/deathcap/voxel-shader.git#d1a6b9616685ffba85d268660a77bc157eb81eef", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", From edb9ddb25cadeeb526242e2213803013319db24c Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 17 Apr 2014 20:59:55 -0700 Subject: [PATCH 174/256] Accept ndarray to showChunk(), alternative to {voxels, dims, position} --- index.js | 8 ++++++-- package.json | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index bbb000e..0dcd3d5 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ var pin = require('pin-it') var tic = require('tic')() var createShell = require('gl-now') var ndarray = require('ndarray') +var isndarray = require('isndarray') var createPlugins = require('voxel-plugins') require('voxel-registry') @@ -579,11 +580,13 @@ Game.prototype.showAllChunks = function() { } } -Game.prototype.showChunk = function(chunk) { +Game.prototype.showChunk = function(chunk, optionalPosition) { + if (optionalPosition) chunk.position = optionalPosition + var chunkIndex = chunk.position.join('|') var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position) - var voxelArray = ndarray(chunk.voxels, chunk.dims) // TODO: detect and use ndarray natively if passed in (isndarray) + var voxelArray = isndarray(chunk) ? chunk : ndarray(chunk.voxels, chunk.dims) var mesh = this.mesherPlugin.createMesh(voxelArray) if (!mesh) { // no voxels @@ -592,6 +595,7 @@ Game.prototype.showChunk = function(chunk) { // I guess this is why mikolalysenko made the chunks 33,33,33 in voxel-mipmap-demo. We could // leave the edges empty (air) so solid chunks always render (unless entirely air). // But for now, skip these chunks. + console.log('Skipping empty/solid chunk',chunk.position) return null; } diff --git a/package.json b/package.json index 024e409..822810d 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "spatial-events": "0.0.1", "spatial-trigger": "0.0.0", "collide-3d-tilemap": "0.0.1", - "tic": "0.2.1" + "tic": "0.2.1", + "isndarray": "^0.1.0" }, "devDependencies": { "tape": "0.2.2" From d04e17a1435094c05bc9534c627f26978eeac72f Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 17 Apr 2014 21:20:47 -0700 Subject: [PATCH 175/256] Update game-shell-fps-camera - initial position/rotation options --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 822810d..4741385 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", - "game-shell-fps-camera": "^0.2.0", + "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git#b0df4a2c639065e7c6b83c7402668e77c6a79ac8", "voxel-stitch": "^0.6.0", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", From e6c49c648744d36d5db73bfb955340771033b213 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 18 Apr 2014 18:12:37 -0700 Subject: [PATCH 176/256] Disable asyncChunkGeneration for now, fixes refreshing chunks --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0dcd3d5..1a9f671 100644 --- a/index.js +++ b/index.js @@ -176,9 +176,9 @@ function Game(opts) { if (self.generateChunks) self.handleChunkGeneration() self.showAllChunks() - // TODO: ? + // TODO: fix async chunk gen, loadPendingChunks() may load 1 even if this.pendingChunks empty setTimeout(function() { - self.asyncChunkGeneration = 'asyncChunkGeneration' in opts ? opts.asyncChunkGeneration : true + self.asyncChunkGeneration = 'asyncChunkGeneration' in opts ? opts.asyncChunkGeneration : false }, 2000) }) From ca23b489b584bd452a74f3a4e52f02bcd76398fa Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 18 Apr 2014 20:35:13 -0700 Subject: [PATCH 177/256] Pass position to mesher for chunking Update voxel-mesher, voxel-shader deathcap/voxel-mesher@fc59631fe3ab7df470bdd2b2dd9dbff99db07591 Scale position by chunk size deathcap/voxel-mesher@6a55e26a20b3665d885869c6df70a8248f3d2c79 Allow more than one mesh, for chunking deathcap/voxel-mesher@c30974a43606fff619dda754c4328265a3686d79 Remove unused this.voxelArrays deathcap/voxel-mesher@bedea261e3af006ba9cd13e097147118cb07797a Calculate model matrix, translate by position deathcap/voxel-shader@424946b4f05d95a5498942729e68fe91ae48ff68 Set model matrix from mesh (for chunking, rendered translated) Commit message generated by https://github.com/deathcap/lmno-cl --- index.js | 8 +++++--- package.json | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1a9f671..72d615f 100644 --- a/index.js +++ b/index.js @@ -587,7 +587,7 @@ Game.prototype.showChunk = function(chunk, optionalPosition) { var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position) var voxelArray = isndarray(chunk) ? chunk : ndarray(chunk.voxels, chunk.dims) - var mesh = this.mesherPlugin.createMesh(voxelArray) + var mesh = this.mesherPlugin.createMesh(voxelArray, chunk.position) if (!mesh) { // no voxels // TODO: not quite right - this occurs if all the voxels are the _same_ (a superset of @@ -595,8 +595,10 @@ Game.prototype.showChunk = function(chunk, optionalPosition) { // I guess this is why mikolalysenko made the chunks 33,33,33 in voxel-mipmap-demo. We could // leave the edges empty (air) so solid chunks always render (unless entirely air). // But for now, skip these chunks. - console.log('Skipping empty/solid chunk',chunk.position) - return null; + //console.log('Skipping empty/solid chunk',chunk.position) + return null + } else { + console.log('Mesh for ',chunkIndex,'=',mesh) } this.voxels.chunks[chunkIndex] = chunk diff --git a/package.json b/package.json index 4741385..38e124e 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#5e574c650f2735a2c5b51d5c380e7cfc2c3a6fac", - "voxel-shader": "git://github.com/deathcap/voxel-shader.git#d1a6b9616685ffba85d268660a77bc157eb81eef", + "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#fc59631fe3ab7df470bdd2b2dd9dbff99db07591", + "voxel-shader": "git://github.com/deathcap/voxel-shader.git#424946b4f05d95a5498942729e68fe91ae48ff68", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", @@ -23,7 +23,7 @@ "voxel-stitch": "^0.6.0", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", - "voxel": "git://github.com/deathcap/voxel#ndarray", + "voxel": "git://github.com/deathcap/voxel#005cefa451d6acf11359959ac2890f19fe57ada7", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", From 6ad35277ea1ef55db46cd1b6264557a5cbca3451 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 18 Apr 2014 21:58:43 -0700 Subject: [PATCH 178/256] Move mesh storage to voxels.meshes, keyed by chunk index Now same as the three.js-based voxel-engine, instead of having a separate plugin (voxel-mesher) store the meshes in an array itself. Update voxel-mesher, voxel-shader deathcap/voxel-mesher@0e5adaae6ac7d6a96dc32056e956b25a283be4a5 Remove this.meshes; let voxel-engine store it per chunk (via voxels.meshes) deathcap/voxel-shader@eb5e9bbf9d6f0fd5e24621732b6ac8d8c80a0823 Add required 'meshes' option, keyed by chunk index (= voxel-engine this.voxels.meshes) Commit message generated by https://github.com/deathcap/lmno-cl --- index.js | 1 + package.json | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 72d615f..bdf3d8c 100644 --- a/index.js +++ b/index.js @@ -75,6 +75,7 @@ function Game(opts) { this.items = [] this.voxels = voxel(this) + BUILTIN_PLUGIN_OPTS['voxel-shader'].meshes = this.voxels.meshes // was a THREE.Scene instance, mainly used for scene.add(), objects, lights TODO: scene graph replacement? Object.defineProperty(this, 'scene', {get:function() { throw new Error('voxel-engine "scene" property removed') }}) diff --git a/package.json b/package.json index 38e124e..557f21e 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#fc59631fe3ab7df470bdd2b2dd9dbff99db07591", - "voxel-shader": "git://github.com/deathcap/voxel-shader.git#424946b4f05d95a5498942729e68fe91ae48ff68", + "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#0e5adaae6ac7d6a96dc32056e956b25a283be4a5", + "voxel-shader": "git://github.com/deathcap/voxel-shader.git#eb5e9bbf9d6f0fd5e24621732b6ac8d8c80a0823", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", @@ -23,7 +23,7 @@ "voxel-stitch": "^0.6.0", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", - "voxel": "git://github.com/deathcap/voxel#005cefa451d6acf11359959ac2890f19fe57ada7", + "voxel": "git://github.com/deathcap/voxel#4ce16e8b8d10362a0114483c21cc66777f5702f2", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", From ba2012528f9dff6f03d6a12e2d350233a0e249f1 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 18 Apr 2014 22:08:43 -0700 Subject: [PATCH 179/256] Update for non-pluginized voxel-mesh (createVoxelMesh) Update voxel-mesher deathcap/voxel-mesher@edbe93a7b76549bd40fa48c560de4edfae9c7691 Remove plugin, export createVoxelMesh directly Commit message generated by https://github.com/deathcap/lmno-cl --- index.js | 12 +++++------- package.json | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index bdf3d8c..020e56e 100644 --- a/index.js +++ b/index.js @@ -21,12 +21,12 @@ var tic = require('tic')() var createShell = require('gl-now') var ndarray = require('ndarray') var isndarray = require('isndarray') +var createVoxelMesh = require('voxel-mesher') var createPlugins = require('voxel-plugins') require('voxel-registry') require('voxel-stitch') require('voxel-shader') -require('voxel-mesher') require('game-shell-fps-camera') module.exports = Game @@ -35,7 +35,6 @@ var BUILTIN_PLUGIN_OPTS = { 'voxel-registry': {}, 'voxel-stitch': {}, 'voxel-shader': {}, - 'voxel-mesher': {}, 'game-shell-fps-camera': {}, }; @@ -132,8 +131,6 @@ function Game(opts) { } plugins.loadAll() - this.mesherPlugin = plugins.get('voxel-mesher') - this.collideVoxels = collisions( this.getBlock.bind(this), 1, @@ -172,8 +169,8 @@ function Game(opts) { this.materials = opts.materials // textures loaded, now can render chunks - var stitcher = plugins.get('voxel-stitch') - stitcher.on('updatedSides', function() { + this.stitcher = plugins.get('voxel-stitch') + this.stitcher.on('updatedSides', function() { if (self.generateChunks) self.handleChunkGeneration() self.showAllChunks() @@ -588,7 +585,8 @@ Game.prototype.showChunk = function(chunk, optionalPosition) { var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position) var voxelArray = isndarray(chunk) ? chunk : ndarray(chunk.voxels, chunk.dims) - var mesh = this.mesherPlugin.createMesh(voxelArray, chunk.position) + var mesh = createVoxelMesh(this.shell.gl, voxelArray, this.stitcher.voxelSideTextureIDs, this.stitcher.voxelSideTextureSizes, chunk.position) + if (!mesh) { // no voxels // TODO: not quite right - this occurs if all the voxels are the _same_ (a superset of diff --git a/package.json b/package.json index 557f21e..12c4102 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#0e5adaae6ac7d6a96dc32056e956b25a283be4a5", + "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#edbe93a7b76549bd40fa48c560de4edfae9c7691", "voxel-shader": "git://github.com/deathcap/voxel-shader.git#eb5e9bbf9d6f0fd5e24621732b6ac8d8c80a0823", "gl-now": "^1.3.0", "ndarray": "^1.0.10", From c318ba24cddeacd886c347ee899e2cf81994dea9 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 19 Apr 2014 09:49:14 -0700 Subject: [PATCH 180/256] Remove unused (now integrated) game-shell-voxel require() --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 020e56e..858b51c 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,6 @@ var voxel = require('voxel') var ray = require('voxel-raycast') var control = require('voxel-control') -var createShell = require('game-shell-voxel') var THREE = require('three') var Stats = require('./lib/stats') var Detector = require('./lib/detector') From 43581b50f329d39d1c93da6662a2dec56936b71e Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 19 Apr 2014 09:58:29 -0700 Subject: [PATCH 181/256] Use sphere world generator in voxel module by default instead of including our own --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index 858b51c..bbc84db 100644 --- a/index.js +++ b/index.js @@ -469,9 +469,7 @@ Game.prototype.configureChunkLoading = function(opts) { var self = this if (!opts.generateChunks) return if (!opts.generate) { - this.generate = function(x,y,z) { - return x*x+y*y+z*z <= 15*15 ? 1 + (1<<15) : 0 // sphere world - } + this.generate = voxel.generator.Sphere } else { this.generate = opts.generate } From d38f3030489f5844e237f750deca8691fd8855ba Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 19 Apr 2014 11:39:55 -0700 Subject: [PATCH 182/256] Accept a string value for opts.generate, indexed to voxel.generator Allows demos to use the simple voxel generator methods in the 'voxel' module, without having to include it themselves (and ensure it is the correct version with ndarray support and so on). --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index bbc84db..a4a2784 100644 --- a/index.js +++ b/index.js @@ -470,6 +470,8 @@ Game.prototype.configureChunkLoading = function(opts) { if (!opts.generateChunks) return if (!opts.generate) { this.generate = voxel.generator.Sphere + } else if (typeof opts.generate === 'string') { + this.generate = voxel.generator[opts.generate] } else { this.generate = opts.generate } From 7b8db7212ed2f86e072023d8ebcae9a8ead04c6f Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 19 Apr 2014 11:43:17 -0700 Subject: [PATCH 183/256] Remove mesh debug log --- index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.js b/index.js index a4a2784..87fc0f2 100644 --- a/index.js +++ b/index.js @@ -595,8 +595,6 @@ Game.prototype.showChunk = function(chunk, optionalPosition) { // But for now, skip these chunks. //console.log('Skipping empty/solid chunk',chunk.position) return null - } else { - console.log('Mesh for ',chunkIndex,'=',mesh) } this.voxels.chunks[chunkIndex] = chunk From 245ac6cd6abdd889e5b30c75445be5c8c716ab90 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 19 Apr 2014 11:45:31 -0700 Subject: [PATCH 184/256] Update voxel, voxel-mesher - chunking fixes deathcap/voxel@005cefa451d6acf11359959ac2890f19fe57ada7 Remove deprecated API, voxelIndex/voxelVector deathcap/voxel@bd2ff15f0ac44e10ebf543b9b0cbecc53c6f1a3d Remove meshers in favor of ao-mesher deathcap/voxel@414e96cc0e79a7bf8f82e2b910d64309ae9ef3b7 Merge branch 'deathcap/master' into ndarray deathcap/voxel@792b8b2c406f6f4721b77e1bad7027d0fe6d1a0f Pad voxel generate deathcap/voxel@dbccd51529e339d3eb6827be32257f8a53d8c203 Converting to ndarray deathcap/voxel-mesher@05ed980d31b0d1d0a4c5444876613ac0b3ccbc44 Fix translation vector ordering and offset Commit message generated by https://github.com/deathcap/lmno-cl --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 12c4102..8277c4f 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#edbe93a7b76549bd40fa48c560de4edfae9c7691", + "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#05ed980d31b0d1d0a4c5444876613ac0b3ccbc44", "voxel-shader": "git://github.com/deathcap/voxel-shader.git#eb5e9bbf9d6f0fd5e24621732b6ac8d8c80a0823", "gl-now": "^1.3.0", "ndarray": "^1.0.10", @@ -23,7 +23,7 @@ "voxel-stitch": "^0.6.0", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", - "voxel": "git://github.com/deathcap/voxel#4ce16e8b8d10362a0114483c21cc66777f5702f2", + "voxel": "git://github.com/deathcap/voxel#005cefa451d6acf11359959ac2890f19fe57ada7", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", From ade3d5e051179df5ae41b5f75412b2766345292c Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 19 Apr 2014 11:50:12 -0700 Subject: [PATCH 185/256] Remove demo - moved to voexl-example https://github.com/deathcap/voxel-example --- demo.js | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 demo.js diff --git a/demo.js b/demo.js deleted file mode 100644 index fe3fd3c..0000000 --- a/demo.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var createShell = require('./'); -var createGUI = require('dat-gui'); - -require('voxel-plugins-ui'); -require('kb-bindings-ui'); -require('voxel-drop'); -require('voxel-keys'); -require('voxel-artpacks'); -require('voxel-wireframe'); -require('./lib/blocks.js'); -require('./lib/terrain.js'); - -createShell({require: require, pluginOpts: - { - //'voxel-stitch': {debug: true}, - 'voxel-plugins-ui': {gui: new createGUI.GUI()}, - 'kb-bindings-ui': {}, - 'voxel-drop': {}, - 'voxel-keys': {}, - 'voxel-artpacks': {}, - 'voxel-wireframe': {}, - './lib/blocks.js': {}, - './lib/terrain.js': {}, - } -}); - From 409ec9d54eaef030c6a1b91e3b4d777a21a31242 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 19 Apr 2014 11:59:30 -0700 Subject: [PATCH 186/256] Remove three.js dependency --- index.js | 22 ++++++---------------- package.json | 1 - 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 87fc0f2..0b9ada1 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,6 @@ var voxel = require('voxel') var ray = require('voxel-raycast') var control = require('voxel-control') -var THREE = require('three') var Stats = require('./lib/stats') var Detector = require('./lib/detector') var inherits = require('inherits') @@ -51,7 +50,7 @@ function Game(opts) { this.setConfigurablePositions(opts) this.configureChunkLoading(opts) this.setDimensions(opts) - this.THREE = THREE + Object.defineProperty(this, 'THREE', {get:function() { throw new Error('voxel-engine "THREE property removed') }}) this.vector = vector this.glMatrix = glMatrix this.arrayType = opts.arrayType || {1:Uint8Array, 2:Uint16Array, 4:Uint32Array}[opts.arrayTypeSize] || Uint8Array @@ -75,14 +74,14 @@ function Game(opts) { this.voxels = voxel(this) BUILTIN_PLUGIN_OPTS['voxel-shader'].meshes = this.voxels.meshes - // was a THREE.Scene instance, mainly used for scene.add(), objects, lights TODO: scene graph replacement? + // was a three.js Scene instance, mainly used for scene.add(), objects, lights TODO: scene graph replacement? or can do without? Object.defineProperty(this, 'scene', {get:function() { throw new Error('voxel-engine "scene" property removed') }}) - // hooked up THREE.Scene, created THREE.PerspectiveCamera, added to element + // hooked up three.js Scene, created three.js PerspectiveCamera, added to element // TODO: add this.view.cameraPosition(), this.view.cameraVector()? -> [x,y,z] to game-shell-fps-camera, very useful Object.defineProperty(this, 'view', {get:function() { throw new Error('voxel-engine "view" property removed') }}) - // used to be a THREE.PerspectiveCamera set by voxel-view; see also basic-camera but API not likely compatible (TODO: make it compatible?) + // used to be a three.js PerspectiveCamera set by voxel-view; see also basic-camera but API not likely compatible (TODO: make it compatible?) Object.defineProperty(this, 'camera', {get:function() { throw new Error('voxel-engine "camera" property removed') }}) // the game-shell @@ -613,20 +612,11 @@ Game.prototype.showChunk = function(chunk, optionalPosition) { // # Debugging methods Game.prototype.addMarker = function(position) { - var geometry = new THREE.SphereGeometry( 0.1, 10, 10 ) - var material = new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading } ) - var mesh = new THREE.Mesh( geometry, material ) - mesh.position.copy(position) - this.scene.add(mesh) + throw new Error('voxel-engine addMarker not yet implemented TODO: figure out how to fit this into the rendering pipeline') } Game.prototype.addAABBMarker = function(aabb, color) { - var geometry = new THREE.CubeGeometry(aabb.width(), aabb.height(), aabb.depth()) - var material = new THREE.MeshBasicMaterial({ color: color || 0xffffff, wireframe: true, transparent: true, opacity: 0.5, side: THREE.DoubleSide }) - var mesh = new THREE.Mesh(geometry, material) - mesh.position.set(aabb.x0() + aabb.width() / 2, aabb.y0() + aabb.height() / 2, aabb.z0() + aabb.depth() / 2) - this.scene.add(mesh) - return mesh + throw new Error('voxel-engine addAABBMarker not yet implemented TODO') } Game.prototype.addVoxelMarker = function(x, y, z, color) { diff --git a/package.json b/package.json index 8277c4f..f50156f 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", "voxel-region-change": "0.1.0", - "three": "0.66.2", "pin-it": "0.0.1", "aabb-3d": "0.0.0", "inherits": "1.0.0", From fc0d68213ce8c8196b2e2bbbacfdda15fd765540 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 19 Apr 2014 12:08:30 -0700 Subject: [PATCH 187/256] Update voxel-shader - meshes from game.voxels.meshes instead of option deathcap/voxel-shader@ef900c1d1830773fd86f896936686860dc63bfe7 Get meshes from game.voxels.meshes if available Commit message generated by https://github.com/deathcap/lmno-cl --- index.js | 1 - package.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 0b9ada1..a5bc767 100644 --- a/index.js +++ b/index.js @@ -72,7 +72,6 @@ function Game(opts) { this.items = [] this.voxels = voxel(this) - BUILTIN_PLUGIN_OPTS['voxel-shader'].meshes = this.voxels.meshes // was a three.js Scene instance, mainly used for scene.add(), objects, lights TODO: scene graph replacement? or can do without? Object.defineProperty(this, 'scene', {get:function() { throw new Error('voxel-engine "scene" property removed') }}) diff --git a/package.json b/package.json index f50156f..cc5fc9a 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ ], "dependencies": { "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#05ed980d31b0d1d0a4c5444876613ac0b3ccbc44", - "voxel-shader": "git://github.com/deathcap/voxel-shader.git#eb5e9bbf9d6f0fd5e24621732b6ac8d8c80a0823", + "voxel-shader": "git://github.com/deathcap/voxel-shader.git#ef900c1d1830773fd86f896936686860dc63bfe7", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", From 961e2f2c03a18b2f7d933fa73cc02d126d4e6b08 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 19 Apr 2014 12:09:24 -0700 Subject: [PATCH 188/256] Add missing .git extension to voxel dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cc5fc9a..260a094 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "voxel-stitch": "^0.6.0", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", - "voxel": "git://github.com/deathcap/voxel#005cefa451d6acf11359959ac2890f19fe57ada7", + "voxel": "git://github.com/deathcap/voxel.git#005cefa451d6acf11359959ac2890f19fe57ada7", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", From 264693469bacac7ee0106014aa3f7b266d818f75 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 23 Apr 2014 18:48:02 -0700 Subject: [PATCH 189/256] Back to loading voxel-mesher as a plugin Update voxel, voxel-mesher deathcap/voxel@03c82f4ea95809110fe9afce98c2fa65ca9e8417 Merge branch 'upstream' into ndarray deathcap/voxel-mesher@c4550ef120564518cd8a000657587328038f1736 Remove unnecessary plugin code deathcap/voxel-mesher@b75fd51b6be3671a0f1f37f781e21ce8174f145e Revert "Remove plugin, export createVoxelMesh directly" Commit message generated by https://github.com/deathcap/lmno-cl --- index.js | 6 ++++-- package.json | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a5bc767..b14b1f3 100644 --- a/index.js +++ b/index.js @@ -19,12 +19,12 @@ var tic = require('tic')() var createShell = require('gl-now') var ndarray = require('ndarray') var isndarray = require('isndarray') -var createVoxelMesh = require('voxel-mesher') var createPlugins = require('voxel-plugins') require('voxel-registry') require('voxel-stitch') require('voxel-shader') +require('voxel-mesher') require('game-shell-fps-camera') module.exports = Game @@ -33,6 +33,7 @@ var BUILTIN_PLUGIN_OPTS = { 'voxel-registry': {}, 'voxel-stitch': {}, 'voxel-shader': {}, + 'voxel-mesher': {}, 'game-shell-fps-camera': {}, }; @@ -176,6 +177,7 @@ function Game(opts) { self.asyncChunkGeneration = 'asyncChunkGeneration' in opts ? opts.asyncChunkGeneration : false }, 2000) }) + this.mesherPlugin = plugins.get('voxel-mesher') this.paused = true @@ -582,7 +584,7 @@ Game.prototype.showChunk = function(chunk, optionalPosition) { var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position) var voxelArray = isndarray(chunk) ? chunk : ndarray(chunk.voxels, chunk.dims) - var mesh = createVoxelMesh(this.shell.gl, voxelArray, this.stitcher.voxelSideTextureIDs, this.stitcher.voxelSideTextureSizes, chunk.position) + var mesh = this.mesherPlugin.createVoxelMesh(this.shell.gl, voxelArray, this.stitcher.voxelSideTextureIDs, this.stitcher.voxelSideTextureSizes, chunk.position) if (!mesh) { // no voxels diff --git a/package.json b/package.json index 260a094..ded8734 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#05ed980d31b0d1d0a4c5444876613ac0b3ccbc44", + "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#c4550ef120564518cd8a000657587328038f1736", "voxel-shader": "git://github.com/deathcap/voxel-shader.git#ef900c1d1830773fd86f896936686860dc63bfe7", "gl-now": "^1.3.0", "ndarray": "^1.0.10", @@ -23,7 +23,7 @@ "voxel-stitch": "^0.6.0", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", - "voxel": "git://github.com/deathcap/voxel.git#005cefa451d6acf11359959ac2890f19fe57ada7", + "voxel": "git://github.com/deathcap/voxel.git#03c82f4ea95809110fe9afce98c2fa65ca9e8417", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", From 46dcbbcafa6f535a7e718b1dec58bb29dace6084 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 23 Apr 2014 20:26:14 -0700 Subject: [PATCH 190/256] Update voxel-mesher, voxel-shader, voxel-stitch - wireframe and cube side refactor deathcap/voxel-stitch@996b0240b10052a0694591275b6f9ca0e796c4fd Move texture name expansion to new cube-side-array module. Closes https://github.com/deathcap/voxel-mesher/issues/2 deathcap/voxel-mesher@0b8e2542f527535e715de0fb24f54563d0d4fe82 Emit 'meshed' event, wire mesh creation to voxel-wireframe. Closes deathcap/voxel-mesher#3 deathcap/voxel-mesher@3bd93426fc2e6d6c91ed88d7a91dd0baa83aae41 Remove unnecessary plugin code deathcap/voxel-mesher@0ac12f8d3b042a4d57102c8c55839c1560c9184b Revert "Remove plugin, export createVoxelMesh directly" deathcap/voxel-mesher@e69b5fa61f22229806da1f3b25b98361c2b5e2eb Fix reversed chunk shape multiplication deathcap/voxel-shader@0cbaded092e01380fc49cf5de85ef5f4eab52e2d Get meshes from game.voxels.meshes if available deathcap/voxel-shader@74c6a74427429377badb5fcf5032738c7f82c835 Fix markdown link Commit message generated by https://github.com/deathcap/lmno-cl --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ded8734..9650d97 100644 --- a/package.json +++ b/package.json @@ -13,14 +13,14 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#c4550ef120564518cd8a000657587328038f1736", - "voxel-shader": "git://github.com/deathcap/voxel-shader.git#ef900c1d1830773fd86f896936686860dc63bfe7", + "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#0b8e2542f527535e715de0fb24f54563d0d4fe82", + "voxel-shader": "git://github.com/deathcap/voxel-shader.git#0cbaded092e01380fc49cf5de85ef5f4eab52e2d", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git#b0df4a2c639065e7c6b83c7402668e77c6a79ac8", - "voxel-stitch": "^0.6.0", + "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#996b0240b10052a0694591275b6f9ca0e796c4fd", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", "voxel": "git://github.com/deathcap/voxel.git#03c82f4ea95809110fe9afce98c2fa65ca9e8417", From 8c303d22d747dc6b2e7e94e4936536527cfd7c0d Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 24 Apr 2014 22:07:45 -0700 Subject: [PATCH 191/256] Update cameraPosition, cameraVector to use game-shell-fps-camera --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b14b1f3..fabbce8 100644 --- a/index.js +++ b/index.js @@ -179,6 +179,8 @@ function Game(opts) { }) this.mesherPlugin = plugins.get('voxel-mesher') + this.cameraPlugin = plugins.get('game-shell-fps-camera') // TODO: support other plugins implementing same API + this.paused = true // initializeControls() @@ -204,12 +206,12 @@ Game.prototype.voxelPosition = function(gamePosition) { } Game.prototype.cameraPosition = function() { - return this.shell.camera.position + return this.cameraPlugin.camera.position } var _cameraVector = vector.create(); Game.prototype.cameraVector = function() { - this.shell.camera.getCameraVector(_cameraVector) + this.cameraPlugin.camera.getCameraVector(_cameraVector) return _cameraVector } From 68eb2190606c662d4a1ce9bff4c2145f3d118855 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 24 Apr 2014 22:24:04 -0700 Subject: [PATCH 192/256] playerPosition() returns cameraPosition(), for now --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index fabbce8..d4033ac 100644 --- a/index.js +++ b/index.js @@ -424,11 +424,14 @@ Game.prototype.potentialCollisionSet = function() { */ Game.prototype.playerPosition = function() { + return this.cameraPosition() + /* TODO: cameraPosition != playerPosition? var target = this.controls.target() var position = target ? target.avatar.position : this.camera.localToWorld(this.camera.position.clone()) return [position.x, position.y, position.z] + */ } Game.prototype.playerAABB = function(position) { From 281e9bac86e66661f0ea5c32366d9ac318a4c6e7 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 24 Apr 2014 23:40:38 -0700 Subject: [PATCH 193/256] Re-enable async chunk gen, start unpaused, and generate chunks even without game.controls --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d4033ac..635061b 100644 --- a/index.js +++ b/index.js @@ -174,14 +174,14 @@ function Game(opts) { // TODO: fix async chunk gen, loadPendingChunks() may load 1 even if this.pendingChunks empty setTimeout(function() { - self.asyncChunkGeneration = 'asyncChunkGeneration' in opts ? opts.asyncChunkGeneration : false + self.asyncChunkGeneration = 'asyncChunkGeneration' in opts ? opts.asyncChunkGeneration : true }, 2000) }) this.mesherPlugin = plugins.get('voxel-mesher') this.cameraPlugin = plugins.get('game-shell-fps-camera') // TODO: support other plugins implementing same API - this.paused = true + //this.paused = true // TODO: should it start paused, then unpause when pointer lock is acquired? // initializeControls() // player control @@ -553,6 +553,8 @@ Game.prototype.updateDirtyChunks = function() { Game.prototype.loadPendingChunks = function(count) { var pendingChunks = this.pendingChunks + console.log('loadPendingChunks=',pendingChunks) + if (!this.asyncChunkGeneration) { count = pendingChunks.length } else { @@ -655,7 +657,7 @@ Game.prototype.tick = function(delta) { this.emit('tick', delta) - if (!this.controls) return + //if (!this.controls) return // this.controls removed; still load chunks var playerPos = this.playerPosition() this.spatial.emit('position', playerPos, playerPos) } @@ -664,6 +666,7 @@ Game.prototype.render = function(delta) { this.view.render(this.scene) } +// TODO: merge with game-shell render loop? Game.prototype.initializeTimer = function(rate) { var self = this var accum = 0 @@ -700,6 +703,7 @@ Game.prototype.initializeTimer = function(rate) { Game.prototype.handleChunkGeneration = function() { var self = this this.voxels.on('missingChunk', function(chunkPos) { + console.log('handleChunkGeneration missingChunk',chunkPos) self.pendingChunks.push(chunkPos.join('|')) }) this.voxels.requestMissingChunks(this.worldOrigin) From c2e4ab5f0404ef97f0a84284cfb4fb36b2b3f852 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 26 Apr 2014 20:34:41 -0700 Subject: [PATCH 194/256] Log voxel types for debugging generation (chunkDensity) --- index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/index.js b/index.js index 635061b..8583f29 100644 --- a/index.js +++ b/index.js @@ -584,11 +584,30 @@ Game.prototype.showAllChunks = function() { } } +// Calculate fraction of each voxel type in chunk, for debugging +var chunkDensity = function(chunk) { + var counts = {}; + var length = chunk.data.length; + for (var i = 0; i < length; i += 1) { + var val = chunk.data[i] + if (!(val in counts)) counts[val] = 0 + + counts[val] += 1 + } + + var densities = {} + for (var val in counts) { + densities[val] = counts[val] / length + } + return densities +} + Game.prototype.showChunk = function(chunk, optionalPosition) { if (optionalPosition) chunk.position = optionalPosition var chunkIndex = chunk.position.join('|') var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position) + console.log('showChunk',chunkIndex,'density=',JSON.stringify(chunkDensity(chunk))) var voxelArray = isndarray(chunk) ? chunk : ndarray(chunk.voxels, chunk.dims) var mesh = this.mesherPlugin.createVoxelMesh(this.shell.gl, voxelArray, this.stitcher.voxelSideTextureIDs, this.stitcher.voxelSideTextureSizes, chunk.position) From cbaee6dc22398edad28609fdbbf31fb27d5008cd Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 26 Apr 2014 21:26:11 -0700 Subject: [PATCH 195/256] Negate cameraPosition to fix +Y/-Y mismatch; new chunks now generate --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 8583f29..5d4736d 100644 --- a/index.js +++ b/index.js @@ -206,7 +206,11 @@ Game.prototype.voxelPosition = function(gamePosition) { } Game.prototype.cameraPosition = function() { - return this.cameraPlugin.camera.position + var p = this.cameraPlugin.camera.position + + // Negate since basic-camera consides -Y up, but we use +Y for up + // TODO: do X and Z need to be negated too? + return [-p[0], -p[1], -p[2]] } var _cameraVector = vector.create(); @@ -607,7 +611,7 @@ Game.prototype.showChunk = function(chunk, optionalPosition) { var chunkIndex = chunk.position.join('|') var bounds = this.voxels.getBounds.apply(this.voxels, chunk.position) - console.log('showChunk',chunkIndex,'density=',JSON.stringify(chunkDensity(chunk))) + //console.log('showChunk',chunkIndex,'density=',JSON.stringify(chunkDensity(chunk))) var voxelArray = isndarray(chunk) ? chunk : ndarray(chunk.voxels, chunk.dims) var mesh = this.mesherPlugin.createVoxelMesh(this.shell.gl, voxelArray, this.stitcher.voxelSideTextureIDs, this.stitcher.voxelSideTextureSizes, chunk.position) From 9f2b57bbf0970960effd4dc755b29fb7edc9d765 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 27 Apr 2014 10:26:31 -0700 Subject: [PATCH 196/256] Move cameraPosition negation to game-shell-fps-camera getPosition() Update game-shell-fps-camera deathcap/game-shell-fps-camera@06a101f8517a3cb6180bb33bcf87cc44173a74f2 Add _getPosition(), returns camera position but accounts for inverted axes Commit message generated by https://github.com/deathcap/lmno-cl --- index.js | 7 +++---- package.json | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 5d4736d..c608e1f 100644 --- a/index.js +++ b/index.js @@ -205,12 +205,11 @@ Game.prototype.voxelPosition = function(gamePosition) { return v } +var _position = new Array(3) Game.prototype.cameraPosition = function() { - var p = this.cameraPlugin.camera.position + this.cameraPlugin.getPosition(_position) - // Negate since basic-camera consides -Y up, but we use +Y for up - // TODO: do X and Z need to be negated too? - return [-p[0], -p[1], -p[2]] + return _position } var _cameraVector = vector.create(); diff --git a/package.json b/package.json index 9650d97..9733a83 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", - "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git#b0df4a2c639065e7c6b83c7402668e77c6a79ac8", + "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git#06a101f8517a3cb6180bb33bcf87cc44173a74f2", "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#996b0240b10052a0694591275b6f9ca0e796c4fd", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", From 5746b254c8af731303449b3037620f0561329089 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 27 Apr 2014 16:24:43 -0700 Subject: [PATCH 197/256] Update dependencies - voxel-mesher/shader ^0.9.0 --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9733a83..76358eb 100644 --- a/package.json +++ b/package.json @@ -13,14 +13,14 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "git://github.com/deathcap/voxel-mesher.git#0b8e2542f527535e715de0fb24f54563d0d4fe82", - "voxel-shader": "git://github.com/deathcap/voxel-shader.git#0cbaded092e01380fc49cf5de85ef5f4eab52e2d", + "voxel-mesher": "^0.9.0", + "voxel-shader": "^0.9.0", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", - "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git#06a101f8517a3cb6180bb33bcf87cc44173a74f2", - "voxel-stitch": "git://github.com/deathcap/voxel-stitch.git#996b0240b10052a0694591275b6f9ca0e796c4fd", + "game-shell-fps-camera": "^0.3.0", + "voxel-stitch": "^0.6.2", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", "voxel": "git://github.com/deathcap/voxel.git#03c82f4ea95809110fe9afce98c2fa65ca9e8417", From 5efc028bfae1ffe155fd6d6beca7e4bce163f731 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 27 Apr 2014 16:50:40 -0700 Subject: [PATCH 198/256] Update to g-s-fps-camera ^0.3.1, with position fix. Chunks now load consistently. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 76358eb..7345117 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", - "game-shell-fps-camera": "^0.3.0", + "game-shell-fps-camera": "^0.3.1", "voxel-stitch": "^0.6.2", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", From 854e502848b9974127dd386785fdb6865adfbf9b Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 29 Apr 2014 18:49:51 -0700 Subject: [PATCH 199/256] Update removeFarChunks to dispose of gl-vao meshes, fixes far chunk unloading --- index.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index c608e1f..eb73659 100644 --- a/index.js +++ b/index.js @@ -519,21 +519,14 @@ Game.prototype.removeFarChunks = function(playerPosition) { if (!chunk) return var chunkPosition = chunk.position if (mesh) { - if (mesh.surfaceMesh) { - self.scene.remove(mesh.surfaceMesh) - //mesh.surfaceMesh.geometry.dispose() - } - if (mesh.wireMesh) { - mesh.wireMesh.geometry.dispose() - //self.scene.remove(mesh.wireMesh) - } - delete mesh.data - delete mesh.geometry - delete mesh.meshed - delete mesh.surfaceMesh - delete mesh.wireMesh + // dispose of the gl-vao meshes + // TODO: refactor so each plugin is responsible, instead of having to list each here + if (mesh.triangleVAO) mesh.triangleVAO.dispose() // voxel-mesher + if (mesh.wireVAO) mesh.wireVAO.dispose() // voxel-wireframe + if (mesh.borderVAO) mesh.borderVAO.dispose() // voxel-chunkborder } delete self.voxels.chunks[chunkIndex] + delete self.voxels.meshes[chunkIndex] self.emit('removeChunk', chunkPosition) }) self.voxels.requestMissingChunks(playerPosition) From ac277b2d1ae5f03b36631ec2179b77677747727d Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 29 Apr 2014 18:56:10 -0700 Subject: [PATCH 200/256] Remove chunk logging --- index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.js b/index.js index eb73659..2e6bc11 100644 --- a/index.js +++ b/index.js @@ -549,8 +549,6 @@ Game.prototype.updateDirtyChunks = function() { Game.prototype.loadPendingChunks = function(count) { var pendingChunks = this.pendingChunks - console.log('loadPendingChunks=',pendingChunks) - if (!this.asyncChunkGeneration) { count = pendingChunks.length } else { @@ -718,7 +716,6 @@ Game.prototype.initializeTimer = function(rate) { Game.prototype.handleChunkGeneration = function() { var self = this this.voxels.on('missingChunk', function(chunkPos) { - console.log('handleChunkGeneration missingChunk',chunkPos) self.pendingChunks.push(chunkPos.join('|')) }) this.voxels.requestMissingChunks(this.worldOrigin) From fd6ef6bf3bf78eceb51a5435ce2f74049ff5d774 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 29 Apr 2014 19:14:49 -0700 Subject: [PATCH 201/256] Update voxel - fixes setBlock() with ndarray chunks deathcap/voxel@c2f35f1ea2c3395252aa508423119a85a5571bb4 Use ndarray get/set in voxelAtCoordinates; remove voxelIndexFromCoordinates Commit message generated by https://github.com/deathcap/lmno-cl --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7345117..56a4a62 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "voxel-stitch": "^0.6.2", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", - "voxel": "git://github.com/deathcap/voxel.git#03c82f4ea95809110fe9afce98c2fa65ca9e8417", + "voxel": "git://github.com/deathcap/voxel.git#c2f35f1ea2c3395252aa508423119a85a5571bb4", "voxel-raycast": "0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", From 2ab6150b5e84d559d4f633192ada0ddcda85d426 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 1 May 2014 21:12:07 -0700 Subject: [PATCH 202/256] Re-add hookupControls() --- index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/index.js b/index.js index 2e6bc11..13ce693 100644 --- a/index.js +++ b/index.js @@ -189,6 +189,9 @@ function Game(opts) { Object.defineProperty(this, 'keybindings', {get:function() { throw new Error('voxel-engine "keybindings" property removed') }}) Object.defineProperty(this, 'buttons', {get:function() { throw new Error('voxel-engine "buttons" property removed') }}) // especially for this one (polling interface) Object.defineProperty(this, 'interact', {get:function() { throw new Error('voxel-engine "interact" property removed') }}) + + var buttons = {}; // TODO: this is a state object (key => boolean), but game-shell has .wasDown(key) => boolean instead + this.hookupControls(buttons, opts) } inherits(Game, EventEmitter) @@ -713,6 +716,16 @@ Game.prototype.initializeTimer = function(rate) { self.frameUpdated = true } } + +Game.prototype.hookupControls = function(buttons, opts) { + opts = opts || {} + opts.controls = opts.controls || {} + opts.controls.onfire = this.onFire.bind(this) + this.controls = control(buttons, opts.controls) + this.items.push(this.controls) + this.controlling = null +} + Game.prototype.handleChunkGeneration = function() { var self = this this.voxels.on('missingChunk', function(chunkPos) { From 471230e886cb719d25d90e24f1b78e5e5d842682 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 3 May 2014 18:22:31 -0700 Subject: [PATCH 203/256] Fix pluginOpts defaulting --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 13ce693..6b5b1da 100644 --- a/index.js +++ b/index.js @@ -121,7 +121,7 @@ function Game(opts) { var pluginOpts = opts.pluginOpts || {} for (var name in BUILTIN_PLUGIN_OPTS) { - opts.pluginOpts[name] = opts.pluginOpts[name] || BUILTIN_PLUGIN_OPTS[name] + pluginOpts[name] = pluginOpts[name] || BUILTIN_PLUGIN_OPTS[name] } for (var name in pluginOpts) { From d1470e5a1eb1f4b6aaaf6b73b3bfb38d8be639a2 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 3 May 2014 21:02:42 -0700 Subject: [PATCH 204/256] Check if no camera plugin loaded in cameraVector(), cameraPosition() --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6b5b1da..eadb79f 100644 --- a/index.js +++ b/index.js @@ -210,14 +210,19 @@ Game.prototype.voxelPosition = function(gamePosition) { var _position = new Array(3) Game.prototype.cameraPosition = function() { - this.cameraPlugin.getPosition(_position) + if (this.cameraPlugin) { + this.cameraPlugin.getPosition(_position) + } return _position } var _cameraVector = vector.create(); Game.prototype.cameraVector = function() { - this.cameraPlugin.camera.getCameraVector(_cameraVector) + if (this.cameraPlugin) { + this.cameraPlugin.camera.getCameraVector(_cameraVector) + } + return _cameraVector } From 1091cddc1d454b0f8a842c1e3fcb6f4081b3ee57 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 4 May 2014 11:07:41 -0700 Subject: [PATCH 205/256] Replace hardcoded mesh disposal with vertexArrayObjects iteration See: deathcap/voxel-mesher@dc0f31ff3d01e62bc30c8d46932a2b7ec9b8f805 deathcap/voxel-shader@aacf86064ad63a4f26545e1247fa7358ab61fad8 deathcap/voxel-wireframe@4d8744de249ce9a246f5518cc77ad6d1f7603b33 deathcap/voxel-chunkborder@19d53ad7e256db4507b5f4aa265595d9b365d28b --- index.js | 7 +++---- package.json | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index eadb79f..9e825bd 100644 --- a/index.js +++ b/index.js @@ -528,10 +528,9 @@ Game.prototype.removeFarChunks = function(playerPosition) { var chunkPosition = chunk.position if (mesh) { // dispose of the gl-vao meshes - // TODO: refactor so each plugin is responsible, instead of having to list each here - if (mesh.triangleVAO) mesh.triangleVAO.dispose() // voxel-mesher - if (mesh.wireVAO) mesh.wireVAO.dispose() // voxel-wireframe - if (mesh.borderVAO) mesh.borderVAO.dispose() // voxel-chunkborder + for (var key in mesh.vertexArrayObjects) { + mesh.vertexArrayObjects[key].dispose() + } } delete self.voxels.chunks[chunkIndex] delete self.voxels.meshes[chunkIndex] diff --git a/package.json b/package.json index 56a4a62..f7e97d8 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "^0.9.0", - "voxel-shader": "^0.9.0", + "voxel-mesher": "^0.10.0", + "voxel-shader": "^0.10.0", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", From 6fdd7047ba5c2bf9ffc430aa20e92c6b6f32bcec Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 5 May 2014 12:47:39 -0700 Subject: [PATCH 206/256] Proxy game-shell wasDown() to game.buttons properties for compatibility --- index.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 9e825bd..81b8435 100644 --- a/index.js +++ b/index.js @@ -187,11 +187,10 @@ function Game(opts) { // player control // game-shell handles controls now TODO: provide some compatibility layer? as not covered by https://github.com/deathcap/voxel-keys Object.defineProperty(this, 'keybindings', {get:function() { throw new Error('voxel-engine "keybindings" property removed') }}) - Object.defineProperty(this, 'buttons', {get:function() { throw new Error('voxel-engine "buttons" property removed') }}) // especially for this one (polling interface) Object.defineProperty(this, 'interact', {get:function() { throw new Error('voxel-engine "interact" property removed') }}) - var buttons = {}; // TODO: this is a state object (key => boolean), but game-shell has .wasDown(key) => boolean instead - this.hookupControls(buttons, opts) + this.proxyButtons() // sets this.buttons TODO: refresh when shell.bindings changes (bind/unbind) + this.hookupControls(this.buttons, opts) } inherits(Game, EventEmitter) @@ -721,6 +720,21 @@ Game.prototype.initializeTimer = function(rate) { } } +// Create the buttons state object (binding => state), proxying to game-shell .wasDown(binding) +Game.prototype.proxyButtons = function() { + var self = this + + self.buttons = {} + + Object.keys(this.shell.bindings).forEach(function(name) { + Object.defineProperty(self.buttons, name, {get: + function() { + return self.shell.wasDown(name) + } + }) + }) +} + Game.prototype.hookupControls = function(buttons, opts) { opts = opts || {} opts.controls = opts.controls || {} From 4f581ce575af53ccd1867984daa392dbeafa3c6e Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 5 May 2014 20:10:41 -0700 Subject: [PATCH 207/256] Support keybindings option, passes each to game-shell bind(); re-add initializeControls, defaultButtons --- index.js | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 81b8435..1e052b4 100644 --- a/index.js +++ b/index.js @@ -183,14 +183,7 @@ function Game(opts) { //this.paused = true // TODO: should it start paused, then unpause when pointer lock is acquired? - // initializeControls() - // player control - // game-shell handles controls now TODO: provide some compatibility layer? as not covered by https://github.com/deathcap/voxel-keys - Object.defineProperty(this, 'keybindings', {get:function() { throw new Error('voxel-engine "keybindings" property removed') }}) - Object.defineProperty(this, 'interact', {get:function() { throw new Error('voxel-engine "interact" property removed') }}) - - this.proxyButtons() // sets this.buttons TODO: refresh when shell.bindings changes (bind/unbind) - this.hookupControls(this.buttons, opts) + this.initializeControls(opts) } inherits(Game, EventEmitter) @@ -365,6 +358,23 @@ Game.prototype.friction = 0.3 Game.prototype.epilson = 1e-8 Game.prototype.terminalVelocity = [0.9, 0.1, 0.9] +Game.prototype.defaultButtons = { + 'W': 'forward' +, 'A': 'left' +, 'S': 'backward' +, 'D': 'right' +, '': 'forward' +, '': 'left' +, '': 'backward' +, '': 'right' +, '': 'fire' +, '': 'firealt' +, '': 'jump' +, '': 'crouch' +, '': 'alt' +, '': 'sprint' +} + // used in methods that have identity function(pos) {} Game.prototype.parseVectorArguments = function(args) { if (!args) return false @@ -735,6 +745,24 @@ Game.prototype.proxyButtons = function() { }) } +Game.prototype.initializeControls = function(opts) { + // player control - game-shell handles most controls now + + // initial keybindings passed in from options, bind in game-shell + Object.defineProperty(this, 'keybindings', {get:function() { throw new Error('voxel-engine "keybindings" property removed') }}) + var keybindings = opts.keybindings || this.defaultButtons + for (var key in keybindings) { + var name = keybindings[key] + + this.shell.bind(name, key) + } + + Object.defineProperty(this, 'interact', {get:function() { throw new Error('voxel-engine "interact" property removed') }}) + + this.proxyButtons() // sets this.buttons TODO: refresh when shell.bindings changes (bind/unbind) + this.hookupControls(this.buttons, opts) +} + Game.prototype.hookupControls = function(buttons, opts) { opts = opts || {} opts.controls = opts.controls || {} From 10a470949307adb4e858548590947cf71d5eaf4b Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 5 May 2014 20:15:16 -0700 Subject: [PATCH 208/256] Remove angle brackets for game-shell virtual key name compatibility --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 1e052b4..ee6e300 100644 --- a/index.js +++ b/index.js @@ -748,12 +748,15 @@ Game.prototype.proxyButtons = function() { Game.prototype.initializeControls = function(opts) { // player control - game-shell handles most controls now - // initial keybindings passed in from options, bind in game-shell + // initial keybindings passed in from options Object.defineProperty(this, 'keybindings', {get:function() { throw new Error('voxel-engine "keybindings" property removed') }}) var keybindings = opts.keybindings || this.defaultButtons for (var key in keybindings) { var name = keybindings[key] + // translate name for game-shell + key = key.replace('<', '').replace('>', '') + this.shell.bind(name, key) } From a06350f77fd370f424a0f75ea6cfcd5ecab3fe46 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 5 May 2014 20:29:28 -0700 Subject: [PATCH 209/256] Fix mouse keys, fire - add filtered_vkey matching game-shell (spaces to -) --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ee6e300..d7edb5e 100644 --- a/index.js +++ b/index.js @@ -745,6 +745,15 @@ Game.prototype.proxyButtons = function() { }) } +// cleanup key name - based on https://github.com/mikolalysenko/game-shell/blob/master/shell.js +var filtered_vkey = function(k) { + if(k.charAt(0) === '<' && k.charAt(k.length-1) === '>') { + k = k.substring(1, k.length-1) + } + k = k.replace(/\s/g, "-") + return k +} + Game.prototype.initializeControls = function(opts) { // player control - game-shell handles most controls now @@ -755,7 +764,7 @@ Game.prototype.initializeControls = function(opts) { var name = keybindings[key] // translate name for game-shell - key = key.replace('<', '').replace('>', '') + key = filtered_vkey(key) this.shell.bind(name, key) } From 902f20e65085402202ae251247e79fe25e63417c Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 5 May 2014 20:53:04 -0700 Subject: [PATCH 210/256] Simulate three.js player object --- index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.js b/index.js index d7edb5e..33a6eb8 100644 --- a/index.js +++ b/index.js @@ -782,6 +782,20 @@ Game.prototype.hookupControls = function(buttons, opts) { this.controls = control(buttons, opts.controls) this.items.push(this.controls) this.controlling = null + + // control calls controls.target(x), required for controls to function + // normally called by voxel-player game.control(player), but requires three.js :( + // use a fake object for now TODO + var player = { + velocity: {x:0, y:0, z:0}, + position: {x:0, y:0, z:0}, + atRestY: function() { + return true // TODO + }, + rotation: {x:0, y:0, z:0}, + yaw: 0, pitch: 0, roll: 0 + } + this.control(player) } Game.prototype.handleChunkGeneration = function() { From 4648457154fb2c5464605b8a0f8865f049bb3b20 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 5 May 2014 21:03:11 -0700 Subject: [PATCH 211/256] Update g-s-fps-camera, now using matching keybinding names --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f7e97d8..b33d4de 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", - "game-shell-fps-camera": "^0.3.1", + "game-shell-fps-camera": "^0.4.0", "voxel-stitch": "^0.6.2", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", From ef8c0eeb875b378e0267f385d5db1011eed072f4 Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 6 May 2014 09:00:40 -0700 Subject: [PATCH 212/256] Negate and flip camera vector - partially fixes raycasting, https://github.com/deathcap/voxel-example/issues/2 --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 33a6eb8..e9781a0 100644 --- a/index.js +++ b/index.js @@ -213,6 +213,9 @@ var _cameraVector = vector.create(); Game.prototype.cameraVector = function() { if (this.cameraPlugin) { this.cameraPlugin.camera.getCameraVector(_cameraVector) + _cameraVector[0] = -_cameraVector[2] + _cameraVector[1] = -_cameraVector[1] + _cameraVector[2] = -_cameraVector[0] } return _cameraVector From 25096cf237c2460a9ecbc35602d40943e12b6dcc Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 7 May 2014 22:03:27 -0700 Subject: [PATCH 213/256] Load plugins after setting up controls Moved plugin setup down as far as possible, but before initializing the required built-in plugins. --- index.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index e9781a0..eaee42a 100644 --- a/index.js +++ b/index.js @@ -118,17 +118,6 @@ function Game(opts) { } }}) - var pluginOpts = opts.pluginOpts || {} - - for (var name in BUILTIN_PLUGIN_OPTS) { - pluginOpts[name] = pluginOpts[name] || BUILTIN_PLUGIN_OPTS[name] - } - - for (var name in pluginOpts) { - plugins.add(name, pluginOpts[name]) - } - plugins.loadAll() - this.collideVoxels = collisions( this.getBlock.bind(this), 1, @@ -166,6 +155,23 @@ function Game(opts) { //this.materialNames = opts.materials || [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'] this.materials = opts.materials + //this.paused = true // TODO: should it start paused, then unpause when pointer lock is acquired? + + this.initializeControls(opts) + + // setup plugins + var pluginOpts = opts.pluginOpts || {} + + for (var name in BUILTIN_PLUGIN_OPTS) { + pluginOpts[name] = pluginOpts[name] || BUILTIN_PLUGIN_OPTS[name] + } + + for (var name in pluginOpts) { + plugins.add(name, pluginOpts[name]) + } + plugins.loadAll() + + // textures loaded, now can render chunks this.stitcher = plugins.get('voxel-stitch') this.stitcher.on('updatedSides', function() { @@ -181,9 +187,7 @@ function Game(opts) { this.cameraPlugin = plugins.get('game-shell-fps-camera') // TODO: support other plugins implementing same API - //this.paused = true // TODO: should it start paused, then unpause when pointer lock is acquired? - this.initializeControls(opts) } inherits(Game, EventEmitter) From e3b65d420c08b5f7e285d859de2fe2874b8006a1 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 8 May 2014 19:10:38 -0700 Subject: [PATCH 214/256] Update to voxel-stitch ^0.7.0, texture array improvements --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b33d4de..1ca3f78 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", "game-shell-fps-camera": "^0.4.0", - "voxel-stitch": "^0.6.2", + "voxel-stitch": "^0.7.0", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", "voxel": "git://github.com/deathcap/voxel.git#c2f35f1ea2c3395252aa508423119a85a5571bb4", From b25666470d28a49b86c3197f3edc306e548e6534 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 8 May 2014 19:36:44 -0700 Subject: [PATCH 215/256] Remove lib/blocks.js, lib/terrain.js - moved to voxel-example --- lib/blocks.js | 27 ----------- lib/terrain.js | 122 ------------------------------------------------- 2 files changed, 149 deletions(-) delete mode 100644 lib/blocks.js delete mode 100644 lib/terrain.js diff --git a/lib/blocks.js b/lib/blocks.js deleted file mode 100644 index ac0bb9f..0000000 --- a/lib/blocks.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -// sample blocks for demo.js TODO: move to voxel-land as a proper plugin, refactor with lib/examples.js terrain gen - -module.exports = function(game, opts) { - return new BlocksPlugin(game, opts); -}; -module.exports.pluginInfo = { - loadAfter: ['voxel-registry'] -}; - -function BlocksPlugin(game, opts) { - var registry = game.plugins.get('voxel-registry'); - - registry.registerBlock('dirt', {texture: 'dirt'}) - registry.registerBlock('stone', {texture: 'stone'}) - registry.registerBlock('cobblestone', {texture: 'cobblestone'}) - registry.registerBlock('lava', {texture: 'lava_still', transparent: true}) - registry.registerBlock('water', {texture: 'water_flow', transparent: true}) - registry.registerBlock('glass', {texture: 'glass', transparent: true}) - registry.registerBlock('oreDiamond', {texture: 'diamond_ore'}) - registry.registerBlock('grass', {texture: ['grass_top', 'dirt', 'grass_side']}) - registry.registerBlock('wool', {texture: ['wool_colored_gray', 'wool_colored_white', 'wool_colored_green', 'wool_colored_light_blue', 'wool_colored_red', 'wool_colored_yellow']}) - registry.registerBlock('logOak', {texture:['log_oak_top', 'log_oak_top', 'log_oak']}) - registry.registerBlock('leavesOak', {texture: 'leaves_oak', transparent: true}) -} - diff --git a/lib/terrain.js b/lib/terrain.js deleted file mode 100644 index 3fc3ebc..0000000 --- a/lib/terrain.js +++ /dev/null @@ -1,122 +0,0 @@ -"use strict" - -var ndarray = require("ndarray") -var fill = require("ndarray-fill") - -// TODO: refactor with voxel-land -module.exports = function(game, opts) { - return new TerrainPlugin(game, opts); -}; -module.exports.pluginInfo = { - loadAfter: ['voxel-registry', 'voxel-mesher'] -}; - -function TerrainPlugin(game, opts) { - this.shell = game.shell; - - this.registry = game.plugins.get('voxel-registry'); - if (!this.registry) throw new Error('lib/terrain requires voxel-registry plugin'); - - this.mesher = game.plugins.get('voxel-mesher'); - if (!this.mesher) throw new Error('lib/terrain requires voxel-mesher plugin'); - - this.enable(); -}; - -TerrainPlugin.prototype.enable = function() { - // once the game is about to initialize, gather all registered materials and build voxels - // TODO: this doesn't really have to be done on gl-init, only when the blocks are ready. refactor with lib/blocks.js - this.shell.on('gl-init', this.onInit = this.addVoxels.bind(this)); -}; - -TerrainPlugin.prototype.disable = function() { - this.shell.removeListener('gl-init', this.onInit); -}; - -// bit in voxel array to indicate voxel is opaque (transparent if not set) -var OPAQUE = 1<<15; - -TerrainPlugin.prototype.addVoxels = function() { - var terrainMaterials = {}; - for (var blockName in this.registry.blockName2Index) { - var blockIndex = this.registry.blockName2Index[blockName]; - if (this.registry.getProp(blockName, 'transparent')) { - terrainMaterials[blockName] = blockIndex - 1 // TODO: remove -1 offset? leave 0 as 'air' (unused) in texture arrays? - } else { - terrainMaterials[blockName] = OPAQUE|(blockIndex - 1) // TODO: separate arrays? https://github.com/mikolalysenko/ao-mesher/issues/2 - } - } - - // add voxels - this.mesher.addVoxelArray(createTerrain(terrainMaterials)); -}; - -var createTerrain = function(materials) { - var size = [33,33,33] - var result = ndarray(new Int32Array(size[0]*size[1]*size[2]), size) - //Fill ndarray with function - fill(result, function(i,j,k) { - //Terrain - - if (i===30 && j===30 && k===30) { - // face texture test - return materials.wool - } - - if(i <=1 || i>=31 || j <= 1 || j >= 31 || k <= 1 || k >= 31) { - return 0 // air - } - - // tree - if (i===7 && k===8 && 21 h0+1) { - return 0 // air - } - // grassy surface with dirt - if(h0 <= j) { - return materials.grass - } - var h1 = 2.0 * Math.sin(Math.PI * i * 0.25 - Math.PI * k * 0.3) + 20 - if(h1 <= j) { - return materials.dirt - } - - // stone with ores - if(4 < j) { - return Math.random() < 0.1 ? - materials.oreDiamond : - materials.stone - } - return materials.lava - }) - return result -}; - - From dfc16f12d879d227ab6ddef6aa7d01c9df2e5131 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 9 May 2014 18:31:07 -0700 Subject: [PATCH 216/256] Set _parent node_ of canvas zIndex to -1, fixes unclickable datgui plugins --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index eaee42a..a1ab204 100644 --- a/index.js +++ b/index.js @@ -97,7 +97,7 @@ function Game(opts) { // below other UI widgets in the DOM tree, so by default the z-order will cause // the canvas to cover the other widgets - to allow plugins to cover the canvas, // we lower the z-index of the canvas below - shell.canvas.style.zIndex = '-1' + shell.canvas.parentElement.style.zIndex = '-1' }) shell.on('gl-error', function(err) { From 8d5355e6cddb5d4776924f8b6e63f8b9e554db5b Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 7 May 2014 19:17:51 -0700 Subject: [PATCH 217/256] Support voxel-engine 'plugin' for top-level options Conflicts: index.js package.json --- index.js | 4 +++- package.json | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a1ab204..b298089 100644 --- a/index.js +++ b/index.js @@ -21,6 +21,7 @@ var ndarray = require('ndarray') var isndarray = require('isndarray') var createPlugins = require('voxel-plugins') +var extend = require('extend') require('voxel-registry') require('voxel-stitch') require('voxel-shader') @@ -41,8 +42,9 @@ function Game(opts) { if (!(this instanceof Game)) return new Game(opts) var self = this if (!opts) opts = {} + if (opts.pluginOpts && opts.pluginOpts['voxel-engine']) opts = extend(opts, opts.pluginOpts['voxel-engine']) if (process.browser && this.notCapable(opts)) return - + // is this a client or a headless server this.isClient = Boolean( (typeof opts.isClient !== 'undefined') ? opts.isClient : process.browser ) diff --git a/package.json b/package.json index 1ca3f78..d945ad4 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "spatial-trigger": "0.0.0", "collide-3d-tilemap": "0.0.1", "tic": "0.2.1", - "isndarray": "^0.1.0" + "isndarray": "^0.1.0", + "extend": "^1.2.1" }, "devDependencies": { "tape": "0.2.2" From 104ef59f709c5d070d87ef146736aee6a8f82403 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 9 May 2014 21:29:51 -0700 Subject: [PATCH 218/256] Update to voxel-stitch ^0.7.1, fixes item textures with voxel-registry --- index.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b298089..1b11ed2 100644 --- a/index.js +++ b/index.js @@ -155,7 +155,7 @@ function Game(opts) { // materials //this.materialNames = opts.materials || [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'] - this.materials = opts.materials + this.materialNames = opts.materials //this.paused = true // TODO: should it start paused, then unpause when pointer lock is acquired? diff --git a/package.json b/package.json index d945ad4..130312c 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", "game-shell-fps-camera": "^0.4.0", - "voxel-stitch": "^0.7.0", + "voxel-stitch": "^0.7.1", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", "voxel": "git://github.com/deathcap/voxel.git#c2f35f1ea2c3395252aa508423119a85a5571bb4", From 348bdafd3bbdb485d74968a8bc63a614aa627450 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 10 May 2014 22:50:23 -0700 Subject: [PATCH 219/256] Update to voxel-shader ^0.11.0, includes camera options --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 130312c..d066f10 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ ], "dependencies": { "voxel-mesher": "^0.10.0", - "voxel-shader": "^0.10.0", + "voxel-shader": "^0.11.0", "gl-now": "^1.3.0", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", From 216be651f223ff896067239e2907dbb0361112c9 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 25 May 2014 18:48:05 -0700 Subject: [PATCH 220/256] Add chunkPad option, update to voxel-mesher ^0.11.0 --- index.js | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1b11ed2..f32781c 100644 --- a/index.js +++ b/index.js @@ -59,6 +59,7 @@ function Game(opts) { this.arrayType = opts.arrayType || {1:Uint8Array, 2:Uint16Array, 4:Uint32Array}[opts.arrayTypeSize] || Uint8Array this.cubeSize = 1 // backwards compat this.chunkSize = opts.chunkSize || 32 + this.chunkPad = opts.chunkPad || 4 // chunkDistance and removeDistance should not be set to the same thing // as it causes lag when you go back and forth on a chunk boundary @@ -629,7 +630,7 @@ Game.prototype.showChunk = function(chunk, optionalPosition) { //console.log('showChunk',chunkIndex,'density=',JSON.stringify(chunkDensity(chunk))) var voxelArray = isndarray(chunk) ? chunk : ndarray(chunk.voxels, chunk.dims) - var mesh = this.mesherPlugin.createVoxelMesh(this.shell.gl, voxelArray, this.stitcher.voxelSideTextureIDs, this.stitcher.voxelSideTextureSizes, chunk.position) + var mesh = this.mesherPlugin.createVoxelMesh(this.shell.gl, voxelArray, this.stitcher.voxelSideTextureIDs, this.stitcher.voxelSideTextureSizes, chunk.position, this.chunkPad) if (!mesh) { // no voxels diff --git a/package.json b/package.json index d066f10..1e4f686 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "^0.10.0", + "voxel-mesher": "^0.11.0", "voxel-shader": "^0.11.0", "gl-now": "^1.3.0", "ndarray": "^1.0.10", From b1c019f7b7432e6a873d430be6e593b4b290e356 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 28 May 2014 18:51:11 -0700 Subject: [PATCH 221/256] Fix camera vector reflection, corrects voxel raycasting Missing temporary variable assignment was overwriting the axes..oops. Closes https://github.com/deathcap/voxpopuli/issues/45 --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index f32781c..6b92f19 100644 --- a/index.js +++ b/index.js @@ -216,13 +216,11 @@ Game.prototype.cameraPosition = function() { return _position } -var _cameraVector = vector.create(); +var _cameraVector = vector.create() Game.prototype.cameraVector = function() { if (this.cameraPlugin) { this.cameraPlugin.camera.getCameraVector(_cameraVector) - _cameraVector[0] = -_cameraVector[2] - _cameraVector[1] = -_cameraVector[1] - _cameraVector[2] = -_cameraVector[0] + vector.set(_cameraVector, -_cameraVector[2], -_cameraVector[1], -_cameraVector[0]) } return _cameraVector From d683c9bc998e8ca2f92d22497391b0d1b631c992 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 30 May 2014 22:43:13 -0700 Subject: [PATCH 222/256] Remove this.control(player) and fake player in hookupControls Moved to deathcap/game-shell-fps-camera@f12cdd0b371e8ed3e476d43ad98a3f9ee2301386 --- index.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/index.js b/index.js index 6b92f19..dd2aa4a 100644 --- a/index.js +++ b/index.js @@ -790,20 +790,6 @@ Game.prototype.hookupControls = function(buttons, opts) { this.controls = control(buttons, opts.controls) this.items.push(this.controls) this.controlling = null - - // control calls controls.target(x), required for controls to function - // normally called by voxel-player game.control(player), but requires three.js :( - // use a fake object for now TODO - var player = { - velocity: {x:0, y:0, z:0}, - position: {x:0, y:0, z:0}, - atRestY: function() { - return true // TODO - }, - rotation: {x:0, y:0, z:0}, - yaw: 0, pitch: 0, roll: 0 - } - this.control(player) } Game.prototype.handleChunkGeneration = function() { From 37282de27a816e392d62dffc23762e6ce0404ea1 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 31 May 2014 18:03:11 -0700 Subject: [PATCH 223/256] Fix collideVoxels vector i_end NaN infinite loop, vector object/array structure --- index.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index dd2aa4a..38cc1f7 100644 --- a/index.js +++ b/index.js @@ -474,15 +474,13 @@ Game.prototype.playerAABB = function(position) { Game.prototype.collideTerrain = function(other, bbox, vec, resting) { var self = this - var axes = ['x', 'y', 'z'] - var vec3 = [vec.x, vec.y, vec.z] - this.collideVoxels(bbox, vec3, function hit(axis, tile, coords, dir, edge) { + this.collideVoxels(bbox, vec, function hit(axis, tile, coords, dir, edge) { if (!tile) return - if (Math.abs(vec3[axis]) < Math.abs(edge)) return - vec3[axis] = vec[axes[axis]] = edge - other.acceleration[axes[axis]] = 0 - resting[axes[axis]] = dir - other.friction[axes[(axis + 1) % 3]] = other.friction[axes[(axis + 2) % 3]] = axis === 1 ? self.friction : 1 + if (Math.abs(vec[axis]) < Math.abs(edge)) return + vec[axis] = edge + other.acceleration[axis] = 0 + //TODO: fix jittering resting[{0:'x',1:'y',2:'z'}[axis]] = dir // TODO: change to glm vec3 array + other.friction[(axis + 1) % 3] = other.friction[(axis + 2) % 3] = axis === 1 ? self.friction : 1 return true }) } From 2b4054b5363a982ed266cbe961a03ac501c0ba36 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 1 Jun 2014 19:32:19 -0700 Subject: [PATCH 224/256] Re-enable setting resting variable in terrain collision Ref https://github.com/deathcap/voxpopuli/issues/46 --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 38cc1f7..6943162 100644 --- a/index.js +++ b/index.js @@ -479,7 +479,7 @@ Game.prototype.collideTerrain = function(other, bbox, vec, resting) { if (Math.abs(vec[axis]) < Math.abs(edge)) return vec[axis] = edge other.acceleration[axis] = 0 - //TODO: fix jittering resting[{0:'x',1:'y',2:'z'}[axis]] = dir // TODO: change to glm vec3 array + resting[{0:'x',1:'y',2:'z'}[axis]] = dir // TODO: change to glm vec3 array other.friction[(axis + 1) % 3] = other.friction[(axis + 2) % 3] = axis === 1 ? self.friction : 1 return true }) From b82feb2c37dc1a644f42ae50064041b69f954019 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 5 Jun 2014 20:48:00 -0700 Subject: [PATCH 225/256] Simplify resting property setting --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 6943162..0ac4d25 100644 --- a/index.js +++ b/index.js @@ -479,7 +479,7 @@ Game.prototype.collideTerrain = function(other, bbox, vec, resting) { if (Math.abs(vec[axis]) < Math.abs(edge)) return vec[axis] = edge other.acceleration[axis] = 0 - resting[{0:'x',1:'y',2:'z'}[axis]] = dir // TODO: change to glm vec3 array + resting[['x','y','z'][axis]] = dir // TODO: change to glm vec3 array? other.friction[(axis + 1) % 3] = other.friction[(axis + 2) % 3] = axis === 1 ? self.friction : 1 return true }) From 44f711d3cf7fa3cee456d1d2e604727cae584fea Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 5 Jun 2014 21:11:43 -0700 Subject: [PATCH 226/256] playerPosition() now returns avatar position, if player under control --- index.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 0ac4d25..b9702bd 100644 --- a/index.js +++ b/index.js @@ -452,14 +452,10 @@ Game.prototype.potentialCollisionSet = function() { */ Game.prototype.playerPosition = function() { - return this.cameraPosition() - /* TODO: cameraPosition != playerPosition? + if (!target) return this.cameraPosition() var target = this.controls.target() - var position = target - ? target.avatar.position - : this.camera.localToWorld(this.camera.position.clone()) + var position = target.avatar.position return [position.x, position.y, position.z] - */ } Game.prototype.playerAABB = function(position) { From aca9bc943f89fdec3166841d98c44466768f09b2 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 5 Jun 2014 21:15:33 -0700 Subject: [PATCH 227/256] Update voxel, voxel-control, voxel-physical - fix collision oscillation Ref https://github.com/deathcap/voxpopuli/issues/46 deathcap/game-shell-fps-camera@72bbb6e6994f793f5cb865f31e55f905adff0010 Negate player position in proxy instead of voxel-physics; fixes oscillation deathcap/voxel@dbedb222b13ac542c44954270abb92c3fd442df3 Change default chunkPad to 0 for backwards-compatibility (voxel-engine) deathcap/voxel-control@a38a9acc0ef8e933722bcaaac8640328fa293101 Merge branch 'master' of github.com:deathcap/voxel-control deathcap/voxel-control@44811572b62060a9896e44008382e5cf2de295fd Update readme: target also requires .rotation deathcap/voxel-physical@2680d8667e8cb4f70e8b8689002dea41deeea2c0 Remove bounding box hacks Commit message generated by https://github.com/deathcap/lmno-cl --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 1e4f686..0d9f87a 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,14 @@ "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", - "game-shell-fps-camera": "^0.4.0", + "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git#72bbb6e6994f793f5cb865f31e55f905adff0010", "voxel-stitch": "^0.7.1", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", - "voxel": "git://github.com/deathcap/voxel.git#c2f35f1ea2c3395252aa508423119a85a5571bb4", + "voxel": "git://github.com/deathcap/voxel.git#dbedb222b13ac542c44954270abb92c3fd442df3", "voxel-raycast": "0.2.1", - "voxel-control": "git://github.com/deathcap/voxel-control.git#44540136f963b7aa0dda1363b837540e6b6bcb1e", - "voxel-physical": "git://github.com/deathcap/voxel-physical.git#4deb6d93aca18aa8b12a813aedd457a451eec2bd", + "voxel-control": "git://github.com/deathcap/voxel-control.git#a38a9acc0ef8e933722bcaaac8640328fa293101", + "voxel-physical": "git://github.com/deathcap/voxel-physical.git#2680d8667e8cb4f70e8b8689002dea41deeea2c0", "voxel-region-change": "0.1.0", "pin-it": "0.0.1", "aabb-3d": "0.0.0", From ff3d46049b57d90ea0ca9b84c9351f74bde96d0d Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 6 Jun 2014 22:23:48 -0700 Subject: [PATCH 228/256] Update to gs-fps-camera ^0.5.0, adds voxel-control/physics integration --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0d9f87a..5b95d58 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", "brfs": "^1.0.1", - "game-shell-fps-camera": "git://github.com/deathcap/game-shell-fps-camera.git#72bbb6e6994f793f5cb865f31e55f905adff0010", + "game-shell-fps-camera": "^0.5.0", "voxel-stitch": "^0.7.1", "voxel-registry": "^0.3.0", "voxel-plugins": "^0.3.0", From c3aa0e75d878780bb71787e46e81ff1bf450c725 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 7 Jun 2014 16:52:21 -0700 Subject: [PATCH 229/256] Remove obsolete comment in showChunk, solid chunks generate a mesh now that they are padded --- index.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/index.js b/index.js index b9702bd..4d9e39c 100644 --- a/index.js +++ b/index.js @@ -626,12 +626,6 @@ Game.prototype.showChunk = function(chunk, optionalPosition) { if (!mesh) { // no voxels - // TODO: not quite right - this occurs if all the voxels are the _same_ (a superset of - // whether all the voxels are air). If a chunk is solid stone, we still need to render it; - // I guess this is why mikolalysenko made the chunks 33,33,33 in voxel-mipmap-demo. We could - // leave the edges empty (air) so solid chunks always render (unless entirely air). - // But for now, skip these chunks. - //console.log('Skipping empty/solid chunk',chunk.position) return null } @@ -642,8 +636,6 @@ Game.prototype.showChunk = function(chunk, optionalPosition) { //if (this.voxels.meshes[chunkIndex].wireMesh) this.scene.remove(this.voxels.meshes[chunkIndex].wireMesh) } this.voxels.meshes[chunkIndex] = mesh - //mesh.setPosition(bounds[0][0], bounds[0][1], bounds[0][2]) // TODO: chunk position - //mesh.addToScene(this.scene) // TODO: something this.emit('renderChunk', chunk) return mesh } From 1d6a587f09fc59149e8924a5e88798202ffaff1c Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 9 Jun 2014 18:14:48 -0700 Subject: [PATCH 230/256] Update dependencies --- package.json | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 5b95d58..f02f81b 100644 --- a/package.json +++ b/package.json @@ -14,33 +14,32 @@ ], "dependencies": { "voxel-mesher": "^0.11.0", - "voxel-shader": "^0.11.0", - "gl-now": "^1.3.0", + "voxel-shader": "^0.12.0", + "gl-now": "^1.3.1", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", - "brfs": "^1.0.1", "game-shell-fps-camera": "^0.5.0", - "voxel-stitch": "^0.7.1", - "voxel-registry": "^0.3.0", - "voxel-plugins": "^0.3.0", + "voxel-stitch": "^0.9.0", + "voxel-registry": "^0.6.0", + "voxel-plugins": "^0.3.2", "voxel": "git://github.com/deathcap/voxel.git#dbedb222b13ac542c44954270abb92c3fd442df3", - "voxel-raycast": "0.2.1", + "voxel-raycast": "^0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#a38a9acc0ef8e933722bcaaac8640328fa293101", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#2680d8667e8cb4f70e8b8689002dea41deeea2c0", - "voxel-region-change": "0.1.0", - "pin-it": "0.0.1", - "aabb-3d": "0.0.0", - "inherits": "1.0.0", - "gl-matrix": "2.0.0", - "spatial-events": "0.0.1", - "spatial-trigger": "0.0.0", - "collide-3d-tilemap": "0.0.1", - "tic": "0.2.1", + "voxel-region-change": "^0.1.0", + "pin-it": "^0.0.1", + "aabb-3d": "^0.1.0", + "inherits": "^2.0.1", + "gl-matrix": "^2.2.1", + "spatial-events": "^1.1.0", + "spatial-trigger": "^0.0.0", + "collide-3d-tilemap": "^0.0.1", + "tic": "^0.2.1", "isndarray": "^0.1.0", "extend": "^1.2.1" }, "devDependencies": { - "tape": "0.2.2" + "tape": "^2.13.2" }, "scripts": { "test": "node test.js" From 26f5099c12c3f8b1dc6216e596f4cf070c8ba318 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 9 Jun 2014 18:38:33 -0700 Subject: [PATCH 231/256] Add missing alpha channel to skyColor -> clearColor Closes https://github.com/deathcap/voxpopuli/issues/48 --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4d9e39c..253ae31 100644 --- a/index.js +++ b/index.js @@ -92,7 +92,8 @@ function Game(opts) { shellOpts.clearColor = [ (this.skyColor >> 16) / 255.0, ((this.skyColor >> 8) & 0xff) / 255.0, - (this.skyColor & 0xff) / 255.0] + (this.skyColor & 0xff) / 255.0, + 1.0] shellOpts.pointerLock = opts.pointerLock !== undefined ? opts.pointerLock : true var shell = createShell(shellOpts) shell.on('gl-init', function() { From f9f5f2c1e61d7e900fac99064d6a3a2dcb096075 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 14 Jun 2014 00:00:02 -0700 Subject: [PATCH 232/256] Update to voxel-mesher/shader 0.13.0 - model rendering enhancements --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f02f81b..288c50d 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "^0.11.0", - "voxel-shader": "^0.12.0", + "voxel-mesher": "^0.13.0", + "voxel-shader": "^0.13.0", "gl-now": "^1.3.1", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", From 6a81ddfb7d6df8334b4bfc2cd66746163d0df519 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 14 Jun 2014 12:32:34 -0700 Subject: [PATCH 233/256] Update to use camera getVector(), fixes XYZ coordinate reversal The orientations now match the three.js-based voxel-engine: N +Z North ^ ^ +z -Z South W <--o--> E | +X East v +---> +x -X West S Z and X are no longer swapped. (from deathcap/game-shell-fps-camera@bfb7b233657fd82a330dd6696e84979011153e66) + Update voxel: deathcap/voxel@2a92d917199aedc89267c60eb0687d3472a7ce2f Fix chunk array inconsistency, indices now ordered XYZ Commit message generated by https://github.com/deathcap/lmno-cl --- index.js | 3 +-- package.json | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 253ae31..1e84d0c 100644 --- a/index.js +++ b/index.js @@ -220,8 +220,7 @@ Game.prototype.cameraPosition = function() { var _cameraVector = vector.create() Game.prototype.cameraVector = function() { if (this.cameraPlugin) { - this.cameraPlugin.camera.getCameraVector(_cameraVector) - vector.set(_cameraVector, -_cameraVector[2], -_cameraVector[1], -_cameraVector[0]) + this.cameraPlugin.getVector(_cameraVector) } return _cameraVector diff --git a/package.json b/package.json index 288c50d..cfdc6e3 100644 --- a/package.json +++ b/package.json @@ -13,16 +13,16 @@ "Mikola Lysenko (https://github.com/mikolalysenko/)" ], "dependencies": { - "voxel-mesher": "^0.13.0", + "voxel-mesher": "^0.14.0", "voxel-shader": "^0.13.0", "gl-now": "^1.3.1", "ndarray": "^1.0.10", "ndarray-fill": "^0.1.0", - "game-shell-fps-camera": "^0.5.0", + "game-shell-fps-camera": "^0.6.0", "voxel-stitch": "^0.9.0", "voxel-registry": "^0.6.0", "voxel-plugins": "^0.3.2", - "voxel": "git://github.com/deathcap/voxel.git#dbedb222b13ac542c44954270abb92c3fd442df3", + "voxel": "git://github.com/deathcap/voxel.git#2a92d917199aedc89267c60eb0687d3472a7ce2f", "voxel-raycast": "^0.2.1", "voxel-control": "git://github.com/deathcap/voxel-control.git#a38a9acc0ef8e933722bcaaac8640328fa293101", "voxel-physical": "git://github.com/deathcap/voxel-physical.git#2680d8667e8cb4f70e8b8689002dea41deeea2c0", From ed04bf46c765b7daf094fe73b7207b43b2ec40b0 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 15 Jun 2014 15:09:07 -0700 Subject: [PATCH 234/256] Only report game.buttons down if pointerLock acquired Fixes inconsistency where the game is controllable with the keyboard, but not the mouse since the user hasn't clicked to acquire pointerlock. Restores compatible behavior with pre-ndarray voxel-engine. Closes https://github.com/deathcap/voxpopuli/issues/50 --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 1e84d0c..6e2d339 100644 --- a/index.js +++ b/index.js @@ -733,7 +733,7 @@ Game.prototype.proxyButtons = function() { Object.keys(this.shell.bindings).forEach(function(name) { Object.defineProperty(self.buttons, name, {get: function() { - return self.shell.wasDown(name) + return self.shell.pointerLock && self.shell.wasDown(name) } }) }) From 9385712b62742b17bc1361d0f5e3ac0abbbefaf5 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 15 Jun 2014 18:39:14 -0700 Subject: [PATCH 235/256] Create container for game-shell, remove canvas z-index hack The game-shell container is now created in createContainer(), ensuring it is the first element in the document, then passed in the 'element' shell option. If omitted, game-shell will create its own container, but this will occur after plugins are loaded, which makes it difficult to provide UI elements on top of the canvas since it is later in the DOM tree, which was previously fixed by lowering the z-index but that causes issues with fullscreen mode (see https://github.com/deathcap/voxel-fullscreen/issues/1). Creating the container ourselves solves all these problems. --- index.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 6e2d339..9958402 100644 --- a/index.js +++ b/index.js @@ -95,14 +95,8 @@ function Game(opts) { (this.skyColor & 0xff) / 255.0, 1.0] shellOpts.pointerLock = opts.pointerLock !== undefined ? opts.pointerLock : true + shellOpts.element = this.createContainer(opts) var shell = createShell(shellOpts) - shell.on('gl-init', function() { - // since the plugins are loaded before gl-init, the element will be - // below other UI widgets in the DOM tree, so by default the z-order will cause - // the canvas to cover the other widgets - to allow plugins to cover the canvas, - // we lower the z-index of the canvas below - shell.canvas.parentElement.style.zIndex = '-1' - }) shell.on('gl-error', function(err) { // normally not reached; notCapable() checks for WebGL compatibility first @@ -397,6 +391,25 @@ Game.prototype.setConfigurablePositions = function(opts) { this.worldOrigin = wo || [0, 0, 0] } +Game.prototype.createContainer = function(opts) { + if (opts.container) return opts.container + + // based on game-shell makeDefaultContainer() + var container = document.createElement("div") + container.tabindex = 1 + container.style.position = "absolute" + container.style.left = "0px" + container.style.right = "0px" + container.style.top = "0px" + container.style.bottom = "0px" + container.style.height = "100%" + container.style.overflow = "hidden" + document.body.appendChild(container) + document.body.style.overflow = "hidden" //Prevent bounce + document.body.style.height = "100%" + return container +} + Game.prototype.setDimensions = function(opts) { if (opts.container) this.container = opts.container if (opts.container && opts.container.clientHeight) { From 8aaf8b60ded0ea98d2594b161f2d6102af1a0087 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 26 Jun 2014 21:45:03 -0700 Subject: [PATCH 236/256] Update to use voxel-controls/physicals forks for ndarray compatibility Includes changes from: https://github.com/chrisdickinson/voxel-control/pull/9 https://github.com/chrisdickinson/voxel-physical/pull/11 --- index.js | 4 ++-- package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 9958402..32a291d 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ 'use strict' var voxel = require('voxel') var ray = require('voxel-raycast') -var control = require('voxel-control') +var control = require('voxel-controls') var Stats = require('./lib/stats') var Detector = require('./lib/detector') var inherits = require('inherits') @@ -13,7 +13,7 @@ var glMatrix = require('gl-matrix') var vector = glMatrix.vec3 var SpatialEventEmitter = require('spatial-events') var regionChange = require('voxel-region-change') -var physical = require('voxel-physical') +var physical = require('voxel-physicals') var pin = require('pin-it') var tic = require('tic')() var createShell = require('gl-now') diff --git a/package.json b/package.json index cfdc6e3..6520064 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,8 @@ "voxel-plugins": "^0.3.2", "voxel": "git://github.com/deathcap/voxel.git#2a92d917199aedc89267c60eb0687d3472a7ce2f", "voxel-raycast": "^0.2.1", - "voxel-control": "git://github.com/deathcap/voxel-control.git#a38a9acc0ef8e933722bcaaac8640328fa293101", - "voxel-physical": "git://github.com/deathcap/voxel-physical.git#2680d8667e8cb4f70e8b8689002dea41deeea2c0", + "voxel-controls": "^0.1.0", + "voxel-physicals": "^0.2.0", "voxel-region-change": "^0.1.0", "pin-it": "^0.0.1", "aabb-3d": "^0.1.0", From 83565b0343185c7d22d51584891b851815359a53 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 3 Jul 2014 20:58:13 -0700 Subject: [PATCH 237/256] Minor stylistic cleanup (semicolons) --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 32a291d..2976657 100644 --- a/index.js +++ b/index.js @@ -36,7 +36,7 @@ var BUILTIN_PLUGIN_OPTS = { 'voxel-shader': {}, 'voxel-mesher': {}, 'game-shell-fps-camera': {}, -}; +} function Game(opts) { if (!(this instanceof Game)) return new Game(opts) @@ -611,8 +611,8 @@ Game.prototype.showAllChunks = function() { // Calculate fraction of each voxel type in chunk, for debugging var chunkDensity = function(chunk) { - var counts = {}; - var length = chunk.data.length; + var counts = {} + var length = chunk.data.length for (var i = 0; i < length; i += 1) { var val = chunk.data[i] if (!(val in counts)) counts[val] = 0 From 9998d9ea7920c73144913d4e520b99413f2e668d Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 7 Jul 2014 21:29:19 -0700 Subject: [PATCH 238/256] Update to voxel-registry ^0.8.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6520064..ff2ada9 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "ndarray-fill": "^0.1.0", "game-shell-fps-camera": "^0.6.0", "voxel-stitch": "^0.9.0", - "voxel-registry": "^0.6.0", + "voxel-registry": "^0.8.1", "voxel-plugins": "^0.3.2", "voxel": "git://github.com/deathcap/voxel.git#2a92d917199aedc89267c60eb0687d3472a7ce2f", "voxel-raycast": "^0.2.1", From 82023105dab9eccb3aab1c6e81431cf239be4473 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 13 Jul 2014 21:06:18 -0700 Subject: [PATCH 239/256] Update dependencies --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ff2ada9..dc9f1e8 100644 --- a/package.json +++ b/package.json @@ -14,12 +14,12 @@ ], "dependencies": { "voxel-mesher": "^0.14.0", - "voxel-shader": "^0.13.0", + "voxel-shader": "^0.13.1", "gl-now": "^1.3.1", - "ndarray": "^1.0.10", - "ndarray-fill": "^0.1.0", + "ndarray": "^1.0.15", + "ndarray-fill": "^1.0.1", "game-shell-fps-camera": "^0.6.0", - "voxel-stitch": "^0.9.0", + "voxel-stitch": "^0.9.1", "voxel-registry": "^0.8.1", "voxel-plugins": "^0.3.2", "voxel": "git://github.com/deathcap/voxel.git#2a92d917199aedc89267c60eb0687d3472a7ce2f", From 65957754759bc878848b23dc2e6f3ec93a6df77d Mon Sep 17 00:00:00 2001 From: Georg Zoeller Date: Thu, 15 Jan 2015 12:17:58 +0800 Subject: [PATCH 240/256] game-shell should not load on the server game-shell is now gated by isClient as it internally references document. and will crash when running on a headless server. --- index.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 2976657..49c6cec 100644 --- a/index.js +++ b/index.js @@ -87,23 +87,28 @@ function Game(opts) { // used to be a three.js PerspectiveCamera set by voxel-view; see also basic-camera but API not likely compatible (TODO: make it compatible?) Object.defineProperty(this, 'camera', {get:function() { throw new Error('voxel-engine "camera" property removed') }}) - // the game-shell - var shellOpts = shellOpts || {} - shellOpts.clearColor = [ - (this.skyColor >> 16) / 255.0, - ((this.skyColor >> 8) & 0xff) / 255.0, - (this.skyColor & 0xff) / 255.0, - 1.0] - shellOpts.pointerLock = opts.pointerLock !== undefined ? opts.pointerLock : true - shellOpts.element = this.createContainer(opts) - var shell = createShell(shellOpts) - - shell.on('gl-error', function(err) { - // normally not reached; notCapable() checks for WebGL compatibility first - document.body.appendChild(document.createTextNode('Fatal WebGL error: ' + err)) - }) - this.shell = shell + + // the game-shell + if (this.isClient) /*GZ: Do not load on server, as document element is missing*/ + { + var shellOpts = shellOpts || {} + shellOpts.clearColor = [ + (this.skyColor >> 16) / 255.0, + ((this.skyColor >> 8) & 0xff) / 255.0, + (this.skyColor & 0xff) / 255.0, + 1.0] + shellOpts.pointerLock = opts.pointerLock !== undefined ? opts.pointerLock : true + shellOpts.element = this.createContainer(opts) + var shell = createShell(shellOpts) + + shell.on('gl-error', function(err) { + // normally not reached; notCapable() checks for WebGL compatibility first + document.body.appendChild(document.createTextNode('Fatal WebGL error: ' + err)) + }) + + this.shell = shell + } // setup plugins var plugins = createPlugins(this, {require: function(name) { From a041f9393a3967520a091a30d17cc2bbe7108b7f Mon Sep 17 00:00:00 2001 From: Georg Zoeller Date: Thu, 15 Jan 2015 12:41:05 +0800 Subject: [PATCH 241/256] fix gl-now crash on require on headless server Moved require into the isClient check as gl-now crashes when trying to access document.ready on a headless server --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 49c6cec..031b4a6 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,6 @@ var regionChange = require('voxel-region-change') var physical = require('voxel-physicals') var pin = require('pin-it') var tic = require('tic')() -var createShell = require('gl-now') var ndarray = require('ndarray') var isndarray = require('isndarray') @@ -92,6 +91,7 @@ function Game(opts) { // the game-shell if (this.isClient) /*GZ: Do not load on server, as document element is missing*/ { + var createShell = require('gl-now') var shellOpts = shellOpts || {} shellOpts.clearColor = [ (this.skyColor >> 16) / 255.0, From 2ab1c098a8e4b8ca6fbc345677f2aa768b9d77e3 Mon Sep 17 00:00:00 2001 From: Georg Zoeller Date: Thu, 15 Jan 2015 15:23:50 +0800 Subject: [PATCH 242/256] fixed safety check on valid in .playerPosition() only check for invalid target after declaring it. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 031b4a6..b83fb6f 100644 --- a/index.js +++ b/index.js @@ -470,8 +470,8 @@ Game.prototype.potentialCollisionSet = function() { */ Game.prototype.playerPosition = function() { - if (!target) return this.cameraPosition() var target = this.controls.target() + if (!target) return this.cameraPosition() var position = target.avatar.position return [position.x, position.y, position.z] } From eb914d62a5184e56d62ece30136abe35063bec97 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 5 Feb 2015 19:56:14 -0800 Subject: [PATCH 243/256] Update readme for voxel-example, ndarray-based analogue to voxel-hello-world --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2ab27bc..e40e393 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,13 @@ Learn more at http://voxeljs.com Write a voxel.js game in browser: http://voxel-creator.jit.su -hello world template repo: http://github.com/maxogden/voxel-hello-world +hello world template repo: http://github.com/deathcap/voxel-example # example ``` js -var createGame = require('voxel-engine') +var createGame = require('voxel-example') var game = createGame() -game.appendTo(document.body) ``` ### contributing From 396146c37f10520aeab12f63a34497833e368494 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 5 Feb 2015 21:12:33 -0800 Subject: [PATCH 244/256] Throw error on using unsupported 'materials' option --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index b83fb6f..b3d29e0 100644 --- a/index.js +++ b/index.js @@ -155,8 +155,7 @@ function Game(opts) { if (!this.isClient) return // materials - //this.materialNames = opts.materials || [['grass', 'dirt', 'grass_dirt'], 'brick', 'dirt'] - this.materialNames = opts.materials + if ('materials' in opts) throw new Error('opts.materials replaced with voxel-registry registerBlock()') // TODO: bridge? //this.paused = true // TODO: should it start paused, then unpause when pointer lock is acquired? From d88bff98784e286908a3a9644e2d6e15bcf3a059 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 5 Feb 2015 22:51:33 -0800 Subject: [PATCH 245/256] Update to voxel-stitch ^0.10.0; major performance fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dc9f1e8..c07c943 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ndarray": "^1.0.15", "ndarray-fill": "^1.0.1", "game-shell-fps-camera": "^0.6.0", - "voxel-stitch": "^0.9.1", + "voxel-stitch": "^0.10.0", "voxel-registry": "^0.8.1", "voxel-plugins": "^0.3.2", "voxel": "git://github.com/deathcap/voxel.git#2a92d917199aedc89267c60eb0687d3472a7ce2f", From 641158bfeefbce73a97e0d640f2013f3d21c5648 Mon Sep 17 00:00:00 2001 From: deathcap Date: Fri, 6 Feb 2015 21:07:45 -0800 Subject: [PATCH 246/256] Update to game-shell-fps-camera ^0.7.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c07c943..20b424f 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "gl-now": "^1.3.1", "ndarray": "^1.0.15", "ndarray-fill": "^1.0.1", - "game-shell-fps-camera": "^0.6.0", + "game-shell-fps-camera": "^0.7.0", "voxel-stitch": "^0.10.0", "voxel-registry": "^0.8.1", "voxel-plugins": "^0.3.2", From e98df9820a7c8b3907f3b627d77d7adea170952c Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 7 Feb 2015 12:58:09 -0800 Subject: [PATCH 247/256] Update to voxel-shader ^0.14.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 20b424f..9107e55 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ ], "dependencies": { "voxel-mesher": "^0.14.0", - "voxel-shader": "^0.13.1", + "voxel-shader": "^0.14.0", "gl-now": "^1.3.1", "ndarray": "^1.0.15", "ndarray-fill": "^1.0.1", From df9afb3c4c976969c2b431a23fac78c33ddacab6 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 11 Feb 2015 20:33:09 -0800 Subject: [PATCH 248/256] Remove unused pin-it module --- index.js | 3 --- package.json | 1 - 2 files changed, 4 deletions(-) diff --git a/index.js b/index.js index b3d29e0..cbd9da6 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,6 @@ var vector = glMatrix.vec3 var SpatialEventEmitter = require('spatial-events') var regionChange = require('voxel-region-change') var physical = require('voxel-physicals') -var pin = require('pin-it') var tic = require('tic')() var ndarray = require('ndarray') var isndarray = require('isndarray') @@ -672,8 +671,6 @@ Game.prototype.addVoxelMarker = function(x, y, z, color) { return this.addAABBMarker(bbox, color) } -Game.prototype.pin = pin - // # Misc internal methods Game.prototype.onFire = function(state) { diff --git a/package.json b/package.json index 9107e55..e987f6f 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "voxel-controls": "^0.1.0", "voxel-physicals": "^0.2.0", "voxel-region-change": "^0.1.0", - "pin-it": "^0.0.1", "aabb-3d": "^0.1.0", "inherits": "^2.0.1", "gl-matrix": "^2.2.1", From 0296e526d9e0404cfc646f3ec627bb6c0fbb09d9 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 11 Feb 2015 20:35:02 -0800 Subject: [PATCH 249/256] Replace gl-matrix/vec3 with gl-vec3 --- index.js | 5 ++--- package.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index cbd9da6..713d744 100644 --- a/index.js +++ b/index.js @@ -9,8 +9,7 @@ var path = require('path') var EventEmitter = require('events').EventEmitter var collisions = require('collide-3d-tilemap') var aabb = require('aabb-3d') -var glMatrix = require('gl-matrix') -var vector = glMatrix.vec3 +var vector = require('gl-vec3') var SpatialEventEmitter = require('spatial-events') var regionChange = require('voxel-region-change') var physical = require('voxel-physicals') @@ -53,7 +52,7 @@ function Game(opts) { this.setDimensions(opts) Object.defineProperty(this, 'THREE', {get:function() { throw new Error('voxel-engine "THREE property removed') }}) this.vector = vector - this.glMatrix = glMatrix + Object.defineProperty(this, 'glMatrix', {get:function() { throw new Error('voxel-engine "glMatrix" property removed, include your own') }}) this.arrayType = opts.arrayType || {1:Uint8Array, 2:Uint16Array, 4:Uint32Array}[opts.arrayTypeSize] || Uint8Array this.cubeSize = 1 // backwards compat this.chunkSize = opts.chunkSize || 32 diff --git a/package.json b/package.json index e987f6f..ae6ae56 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "voxel-region-change": "^0.1.0", "aabb-3d": "^0.1.0", "inherits": "^2.0.1", - "gl-matrix": "^2.2.1", + "gl-vec3": "^1.0.3", "spatial-events": "^1.1.0", "spatial-trigger": "^0.0.0", "collide-3d-tilemap": "^0.0.1", From 60de3a9a7f033dd1e91a5c91a8aaeacd3ba31a0b Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 11 Feb 2015 20:44:12 -0800 Subject: [PATCH 250/256] Mark removed properties with obsolete() --- index.js | 21 +++++++++++++-------- package.json | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 713d744..a9fd850 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ var physical = require('voxel-physicals') var tic = require('tic')() var ndarray = require('ndarray') var isndarray = require('isndarray') +var obsolete = require('obsolete') var createPlugins = require('voxel-plugins') var extend = require('extend') @@ -50,9 +51,9 @@ function Game(opts) { this.setConfigurablePositions(opts) this.configureChunkLoading(opts) this.setDimensions(opts) - Object.defineProperty(this, 'THREE', {get:function() { throw new Error('voxel-engine "THREE property removed') }}) + obsolete(this, 'THREE') this.vector = vector - Object.defineProperty(this, 'glMatrix', {get:function() { throw new Error('voxel-engine "glMatrix" property removed, include your own') }}) + obsolete(this, 'glMatrix', 'use your own gl-matrix, gl-vec3, or gl-vec4') this.arrayType = opts.arrayType || {1:Uint8Array, 2:Uint16Array, 4:Uint32Array}[opts.arrayTypeSize] || Uint8Array this.cubeSize = 1 // backwards compat this.chunkSize = opts.chunkSize || 32 @@ -69,20 +70,20 @@ function Game(opts) { this.meshType = opts.meshType || 'surfaceMesh' // was a 'voxel' module meshers object, now using voxel-mesher(ao-mesher) - Object.defineProperty(this, 'mesher', {get:function() { throw new Error('voxel-engine "mesher" property removed') }}) + obsolete(this, 'mesher', 'replaced by voxel-mesher') this.items = [] this.voxels = voxel(this) // was a three.js Scene instance, mainly used for scene.add(), objects, lights TODO: scene graph replacement? or can do without? - Object.defineProperty(this, 'scene', {get:function() { throw new Error('voxel-engine "scene" property removed') }}) + obsolete(this, 'scene') // hooked up three.js Scene, created three.js PerspectiveCamera, added to element // TODO: add this.view.cameraPosition(), this.view.cameraVector()? -> [x,y,z] to game-shell-fps-camera, very useful - Object.defineProperty(this, 'view', {get:function() { throw new Error('voxel-engine "view" property removed') }}) + obsolete(this, 'view') // used to be a three.js PerspectiveCamera set by voxel-view; see also basic-camera but API not likely compatible (TODO: make it compatible?) - Object.defineProperty(this, 'camera', {get:function() { throw new Error('voxel-engine "camera" property removed') }}) + obsolete(this, 'camera') @@ -192,6 +193,10 @@ function Game(opts) { inherits(Game, EventEmitter) +Game.prototype.toString = function() { + return 'voxel-engine' +} + // # External API Game.prototype.voxelPosition = function(gamePosition) { @@ -765,7 +770,7 @@ Game.prototype.initializeControls = function(opts) { // player control - game-shell handles most controls now // initial keybindings passed in from options - Object.defineProperty(this, 'keybindings', {get:function() { throw new Error('voxel-engine "keybindings" property removed') }}) + obsolete(this, 'keybindings') var keybindings = opts.keybindings || this.defaultButtons for (var key in keybindings) { var name = keybindings[key] @@ -776,7 +781,7 @@ Game.prototype.initializeControls = function(opts) { this.shell.bind(name, key) } - Object.defineProperty(this, 'interact', {get:function() { throw new Error('voxel-engine "interact" property removed') }}) + obsolete(this, 'interact') this.proxyButtons() // sets this.buttons TODO: refresh when shell.bindings changes (bind/unbind) this.hookupControls(this.buttons, opts) diff --git a/package.json b/package.json index ae6ae56..191589e 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "collide-3d-tilemap": "^0.0.1", "tic": "^0.2.1", "isndarray": "^0.1.0", + "obsolete": "^0.1.0", "extend": "^1.2.1" }, "devDependencies": { From 402d3d0463ad95608cf7b205babe8cd20380c7b9 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 12 Feb 2015 18:45:48 -0800 Subject: [PATCH 251/256] Update to voxel ^0.5.0 ndarray release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 191589e..a1ffc83 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "voxel-stitch": "^0.10.0", "voxel-registry": "^0.8.1", "voxel-plugins": "^0.3.2", - "voxel": "git://github.com/deathcap/voxel.git#2a92d917199aedc89267c60eb0687d3472a7ce2f", + "voxel": "^0.5.0", "voxel-raycast": "^0.2.1", "voxel-controls": "^0.1.0", "voxel-physicals": "^0.2.0", From 7db79ada0289466a5c739de4c3fa521d649d94b9 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 16 Feb 2015 21:40:55 -0800 Subject: [PATCH 252/256] Remove unused ndarray-fill dependency --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index a1ffc83..8bf7a1a 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "voxel-shader": "^0.14.0", "gl-now": "^1.3.1", "ndarray": "^1.0.15", - "ndarray-fill": "^1.0.1", "game-shell-fps-camera": "^0.7.0", "voxel-stitch": "^0.10.0", "voxel-registry": "^0.8.1", From e9b8f6b3dac1bb38d1df2f631a0b8126274a5b0e Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 25 Mar 2015 13:51:51 -0700 Subject: [PATCH 253/256] Remove stats FPS counter - use browser built-in FPS meter instead For Chrome, see http://stackoverflow.com/questions/22038065/show-fps-meter-chrome-33 --- index.js | 10 ---- lib/stats.js | 145 --------------------------------------------------- 2 files changed, 155 deletions(-) delete mode 100644 lib/stats.js diff --git a/index.js b/index.js index a9fd850..b32b732 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,6 @@ var voxel = require('voxel') var ray = require('voxel-raycast') var control = require('voxel-controls') -var Stats = require('./lib/stats') var Detector = require('./lib/detector') var inherits = require('inherits') var path = require('path') @@ -501,15 +500,6 @@ Game.prototype.collideTerrain = function(other, bbox, vec, resting) { }) } -// # Three.js specific methods - -Game.prototype.addStats = function() { - stats = new Stats() - stats.domElement.style.position = 'absolute' - stats.domElement.style.bottom = '0px' - document.body.appendChild( stats.domElement ) -} - // # Chunk related methods Game.prototype.configureChunkLoading = function(opts) { diff --git a/lib/stats.js b/lib/stats.js deleted file mode 100644 index a871df0..0000000 --- a/lib/stats.js +++ /dev/null @@ -1,145 +0,0 @@ -/** - * @author mrdoob / http://mrdoob.com/ - */ - -var Stats = function () { - - var startTime = Date.now(), prevTime = startTime; - var ms = 0, msMin = Infinity, msMax = 0; - var fps = 0, fpsMin = Infinity, fpsMax = 0; - var frames = 0, mode = 0; - - var container = document.createElement( 'div' ); - container.id = 'stats'; - container.addEventListener( 'mousedown', function ( event ) { event.preventDefault(); setMode( ++ mode % 2 ) }, false ); - container.style.cssText = 'width:80px;opacity:0.9;cursor:pointer'; - - var fpsDiv = document.createElement( 'div' ); - fpsDiv.id = 'fps'; - fpsDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#002'; - container.appendChild( fpsDiv ); - - var fpsText = document.createElement( 'div' ); - fpsText.id = 'fpsText'; - fpsText.style.cssText = 'color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px'; - fpsText.innerHTML = 'FPS'; - fpsDiv.appendChild( fpsText ); - - var fpsGraph = document.createElement( 'div' ); - fpsGraph.id = 'fpsGraph'; - fpsGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0ff'; - fpsDiv.appendChild( fpsGraph ); - - while ( fpsGraph.children.length < 74 ) { - - var bar = document.createElement( 'span' ); - bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#113'; - fpsGraph.appendChild( bar ); - - } - - var msDiv = document.createElement( 'div' ); - msDiv.id = 'ms'; - msDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#020;display:none'; - container.appendChild( msDiv ); - - var msText = document.createElement( 'div' ); - msText.id = 'msText'; - msText.style.cssText = 'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px'; - msText.innerHTML = 'MS'; - msDiv.appendChild( msText ); - - var msGraph = document.createElement( 'div' ); - msGraph.id = 'msGraph'; - msGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0f0'; - msDiv.appendChild( msGraph ); - - while ( msGraph.children.length < 74 ) { - - var bar = document.createElement( 'span' ); - bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#131'; - msGraph.appendChild( bar ); - - } - - var setMode = function ( value ) { - - mode = value; - - switch ( mode ) { - - case 0: - fpsDiv.style.display = 'block'; - msDiv.style.display = 'none'; - break; - case 1: - fpsDiv.style.display = 'none'; - msDiv.style.display = 'block'; - break; - } - - } - - var updateGraph = function ( dom, value ) { - - var child = dom.appendChild( dom.firstChild ); - child.style.height = value + 'px'; - - } - - return { - - REVISION: 11, - - domElement: container, - - setMode: setMode, - - begin: function () { - - startTime = Date.now(); - - }, - - end: function () { - - var time = Date.now(); - - ms = time - startTime; - msMin = Math.min( msMin, ms ); - msMax = Math.max( msMax, ms ); - - msText.textContent = ms + ' MS (' + msMin + '-' + msMax + ')'; - updateGraph( msGraph, Math.min( 30, 30 - ( ms / 200 ) * 30 ) ); - - frames ++; - - if ( time > prevTime + 1000 ) { - - fps = Math.round( ( frames * 1000 ) / ( time - prevTime ) ); - fpsMin = Math.min( fpsMin, fps ); - fpsMax = Math.max( fpsMax, fps ); - - fpsText.textContent = fps + ' FPS (' + fpsMin + '-' + fpsMax + ')'; - updateGraph( fpsGraph, Math.min( 30, 30 - ( fps / 100 ) * 30 ) ); - - prevTime = time; - frames = 0; - - } - - return time; - - }, - - update: function () { - - startTime = this.end(); - - } - - } - -}; - -module.exports = Stats \ No newline at end of file From 6b5c9531183c40aafcb476b31d31ee0f456fb701 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 28 Mar 2015 13:18:34 -0700 Subject: [PATCH 254/256] Emit engine-init event at the very end of the constructor This allows plugins to perform actions which require all plugins to be initialized (for example, calling showChunk which requires the mesher and stitcher and shader to have loaded, and set in the game instance). --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b32b732..d73613b 100644 --- a/index.js +++ b/index.js @@ -187,7 +187,7 @@ function Game(opts) { this.cameraPlugin = plugins.get('game-shell-fps-camera') // TODO: support other plugins implementing same API - + this.emit('engine-init', this); } inherits(Game, EventEmitter) From 3273959e753a0adbabdb4b8d7a6ca1d253f8cbd6 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 29 Mar 2015 15:21:12 -0700 Subject: [PATCH 255/256] raycastVoxels() default normal to top face if hits inside voxel voxel-raycast can return a hit normal of [0,0,0] if, for example, the starting position is within a voxel, but this is not a valid normal vector. If this happens, instead default to [0,1,0], the top face. --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index d73613b..3f2c4e9 100644 --- a/index.js +++ b/index.js @@ -280,6 +280,12 @@ Game.prototype.raycastVoxels = function(start, direction, maxDistance, epilson) var adjacentPosition = [0, 0, 0] var voxelPosition = this.voxelPosition(hitPosition) vector.add(adjacentPosition, voxelPosition, hitNormal) + + if (Math.abs(hitNormal[0] + hitNormal[1] + hitNormal[2]) !== 1) { + hitNormal[0] = 0 + hitNormal[1] = 1 + hitNormal[2] = 0 + } return { position: hitPosition, From 038c12f07ea1fa6b70a0f2df0502f59b8559bddc Mon Sep 17 00:00:00 2001 From: Morgan Herlocker Date: Mon, 16 Mar 2015 21:49:52 -0400 Subject: [PATCH 256/256] 'renderChunk' typo - missing quote --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e40e393..c1de578 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,7 @@ emits when you move between voxels. pos has x, y, and z voxel coordinates of the emits when you move between chunks. pos has x, y, and z chunk coordinates of the chunk you just entered -### `game.on('renderChunk, function(chunk) {})` +### `game.on('renderChunk', function(chunk) {})` emits when a chunk is drawn (using the `showChunk` method). `chunk` is the full chunk object, which has the voxel data and a `.position` and `.dims`