Permalink
Browse files

Merge branch 'master' of https://github.com/rantecki/voxel-mesh into …

…rantecki_20130325
  • Loading branch information...
2 parents f4e00d5 + 1416a15 commit 5647fb80a9b1bfd0478ae8e88e8ad9e0cc81313c @rantecki rantecki committed Mar 25, 2013
Showing with 22 additions and 5 deletions.
  1. +19 −2 index.js
  2. +3 −3 package.json
View
@@ -30,18 +30,35 @@ function Mesh(data, mesher, scaleFactor, three) {
if (q.length === 5) {
var f = new this.THREE.Face4(q[0], q[1], q[2], q[3])
f.color = new this.THREE.Color(q[4])
- f.vertexColors = [f.color,f.color,f.color,f.color]
geometry.faces.push(f)
} else if (q.length == 4) {
var f = new this.THREE.Face3(q[0], q[1], q[2])
f.color = new this.THREE.Color(q[3])
- f.vertexColors = [f.color,f.color,f.color]
geometry.faces.push(f)
}
}
geometry.computeFaceNormals()
+ // compute vertex colors for ambient occlusion
+ var light = new THREE.Color(0xffffff)
+ var shadow = new THREE.Color(0x505050)
+ for (var i = 0; i < geometry.faces.length; ++i) {
+ var face = geometry.faces[i]
+ // facing up
+ if (face.normal.y === 1) face.vertexColors = [light, light, light, light]
+ // facing down
+ else if (face.normal.y === -1) face.vertexColors = [shadow, shadow, shadow, shadow]
+ // facing right
+ else if (face.normal.x === 1) face.vertexColors = [shadow, light, light, shadow]
+ // facing left
+ else if (face.normal.x === -1) face.vertexColors = [shadow, shadow, light, light]
+ // facing backward
+ else if (face.normal.z === 1) face.vertexColors = [shadow, shadow, light, light]
+ // facing forward
+ else face.vertexColors = [shadow, light, light, shadow]
+ }
+
geometry.verticesNeedUpdate = true
geometry.elementsNeedUpdate = true
geometry.normalsNeedUpdate = true
View
@@ -1,7 +1,7 @@
{
"name": "voxel-mesh",
"description": "generate a three.js mesh from voxel data",
- "version": "0.2.0",
+ "version": "0.2.1",
"main": "index.js",
"repository": {
"type": "git",
@@ -12,8 +12,8 @@
"email": "max@maxogden.com"
},
"license": "MIT",
- "dependencies": {
- "three": "0.56.0"
+ "peerDependencies": {
+ "three": "*"
},
"engine": {
"node": ">=0.6.0"

0 comments on commit 5647fb8

Please sign in to comment.