Skip to content

Commit

Permalink
Move wireframe into voxel-wireframe plugin. Closes max-mapperGH-3
Browse files Browse the repository at this point in the history
  • Loading branch information
deathcap committed Apr 15, 2014
1 parent 677c73d commit 7ee278a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 37 deletions.
4 changes: 3 additions & 1 deletion demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require('./lib/blocks.js');
require('voxel-drop');
require('voxel-keys');
require('voxel-artpacks');
require('voxel-wireframe');

createShell({require: require, pluginOpts:
{
Expand All @@ -21,7 +22,8 @@ createShell({require: require, pluginOpts:
'./lib/blocks.js': {},
'voxel-drop': {},
'voxel-keys': {},
'voxel-artpacks': {}
'voxel-artpacks': {},
'voxel-wireframe': {},
}
});

16 changes: 0 additions & 16 deletions lib/wireShader.js

This file was deleted.

27 changes: 8 additions & 19 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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;
Expand All @@ -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')
Expand Down Expand Up @@ -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])
}
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7ee278a

Please sign in to comment.