summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/app.js
blob: 3cafecafe5019b587cfb673e93c2b0a2163d7960 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
if (is_mobile) {
	$("html").addClass("mobile")
}
else {
  $("html").addClass("desktop")
}


var scene, cam, map;

var app = new function(){}

app.mode = { editor: false, builder: false }
  
app.init = function () {
	app.tube = new Tube ()
	app.router = new SiteRouter ()
}

app.launch = function () {
  if ($.browser.msie || ! has3d()) { return app.fallback() }
  
	var last_t = 0
	function animate (t) {
		var dt = t - last_t
		last_t = t
		requestAnimationFrame(animate)
		environment.update(t, dt)
	}

	var loader = new Loader(function(){
		$("#loader").hide()
		window.environment && window.environment.init()
		// window.editor && window.editor.init()
		// window.path && window.path.init()
		animate()
	})
	
	// loader.preloadImages([])
	loader.ready()

	window.scrollTo(0,0)
}

app.fallback = function(){
  app.unsupported = true
  var msg = "Sorry, your browser is not supported.<br><br>" +
            "Please use <a href='http://chrome.com/'>Chrome</a> or <a href='https://www.apple.com/safari/'>Safari</a> or <a href='http://getfirefox.com/'>Firefox</a>."
  var $fallback = $("<div>")
  $fallback.attr('id', 'fallback')
  $fallback.html(msg)
  $('body').append($fallback)
  $("#keyhint").hide()
  $("#editorView").hide()
}

app.on = function(){
	app.tube.on.apply(app.tube, arguments)
}

app.off = function(){
	app.tube.off.apply(app.tube, arguments)
}

app.position = function(obj){
	var pos = {
		x: obj.x,
		y: obj.y,
		z: obj.z,
		rotationX: obj.rotationX,
		rotationY: obj.rotationY
	}
	if (obj.scale !== 1) {
		pos.scale = obj.scale
	}
	return pos
}

document.addEventListener('DOMContentLoaded', app.init)