Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Last active December 12, 2015 03:59
Show Gist options
  • Save max-mapper/4711236 to your computer and use it in GitHub Desktop.
Save max-mapper/4711236 to your computer and use it in GitHub Desktop.
voxel.js game
var createEngine = require('voxel-engine')
window.game = createEngine({ lightsDisabled: true })
game.scene.add(new game.THREE.HemisphereLight(0x408CFF, 0xFFC880, 0.6))
game.on('mousedown', function(pos) {
var light = new game.THREE.PointLight( 0xffffff, 1, 500 )
var direction = game.camera.matrixWorld.multiplyVector3(new game.THREE.Vector3(0,0,-1))
var diff = direction.subSelf(game.controls.yawObject.position.clone()).normalize()
diff.multiplySelf({x: 20, y: 20, z: 20})
var position = pos.clone().subSelf(diff)
light.position.copy(position)
game.addMarker(position)
game.scene.add(light)
updateAllVoxels()
})
function updateAllVoxels() {
Object.keys(game.voxels.meshes).map(function(key){
var mesh = game.voxels.meshes[key]
mesh.surfaceMesh.material.materials.map(function(material) {
material.needsUpdate = true
})
})
}
// rotate camera to look straight up
game.controls.pitchObject.rotation.x = -1.5
var container = document.body
game.appendTo(container)
game.setupPointerLock(container)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment