summaryrefslogtreecommitdiff
path: root/js/lib/app.js
blob: b9dd0f773fbd503e1033f26cb037bd987d9cc70e (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
var scene, cam, controls

var app = (function() {

  var app = {}
  var last_t = 0, initial_t = 0

  app.init = function() {
    app.bind()
    app.build()
    // check if we're in an iframe
    // if (window.self === window.top) {
    app.ready()
    //}
  }

  app.bind = function() {
    $(window).resize(app.resize)
  }

  app.build = function() {
    if ($.browser.msie || ! has3d()) { return app.fallback() }
  
    scene = new MX.Scene().addTo('#scene')
    cam = scene.camera

    app.resize()

    window.scrollTo(0,0)
    environment.init()
  }

  app.ready = function() {
    if (last_t) return
    setTimeout(function () {
      $("html").removeClass("loading")
    }, 100)
    app.animate(0)
  }

  app.animate = function (t) {
    requestAnimationFrame(app.animate)
    if (! initial_t) {
      initial_t = t
      return
    }
    t -= initial_t
    var dt = t - last_t
    last_t = t
    environment.update(t, dt)
  }

  app.resize = function () {
    scene.width = window.innerWidth
    scene.height = window.innerHeight
    scene.perspective = Math.min(window.innerWidth, scene.height)
    scene.update()
  }

  app.fallback = function(){
    $('body').addClass('fallback')
  }

  return app

})()

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