forked from troffmo5/voxel-oculus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.js
64 lines (50 loc) · 1.82 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var createGame = require('voxel-engine')
var voxel = require('voxel')
var skin = require('minecraft-skin')
var oculus = require('./voxel-oculus')
var url = require('url')
// default values
var separation = 5
var distortion = 0.2
var aspectFactor = 1
var parsedURL = url.parse(window.location.href, true)
if (parsedURL.query) {
if (parsedURL.query.separation !== undefined) separation = parsedURL.query.separation;
if (parsedURL.query.distortion !== undefined) distortion = parsedURL.query.distortion;
if (parsedURL.query.aspectFactor !== undefined) aspectFactor = parsedURL.query.aspectFactor;
}
var game = createGame({
generate: voxel.generator['Valley'],
startingPosition: [185, 100, 0],
texturePath: 'textures/',
statsDisabled: true // not working :-(
})
window.game = game // for debugging
var container = document.body
game.appendTo(container)
container.addEventListener('click', function() {
game.requestPointerLock(container)
})
// rotate camera left so it points at the characters
game.controls.yawObject.rotation.y = 1.5
var maxogden = skin(game.THREE, 'textures/maxogden.png').createPlayerObject()
maxogden.position.set(0, 62, 20)
game.scene.add(maxogden)
var substack = skin(game.THREE, 'textures/substack.png').createPlayerObject()
substack.position.set(0, 62, -20)
game.scene.add(substack)
var currentMaterial = 1
game.on('mousedown', function (pos) {
if (erase) game.setBlock(pos, 0)
else game.createBlock(pos, currentMaterial)
})
var erase = true
window.addEventListener('keydown', function (ev) {
if (ev.keyCode === 'X'.charCodeAt(0)) {
erase = !erase
}
})
function ctrlToggle (ev) { erase = !ev.ctrlKey }
window.addEventListener('keyup', ctrlToggle)
window.addEventListener('keydown', ctrlToggle)
var effect = new oculus(game, {distortion: distortion, separation: separation, aspectFactor: aspectFactor});