File size: 1,273 Bytes
0b12ad4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import {
  loadObjects
} from './components/objects/objects.js';
import {
  createCamera
} from './components/camera.js';
import {
  createLights
} from './components/lights.js';
import {
  createScene
} from './components/scene.js';

import {
  FaceTracker
} from './components/geometry/geometry.js';

import {
  createRenderer
} from './systems/renderer.js';
import {
  Resizer
} from './systems/Resizer.js';
import {
  Loop
} from './systems/Loop.js';

let camera;
let renderer;
let scene;
let loop;

class World {
  constructor(container) {
    camera = createCamera(0, 1);
    renderer = createRenderer();
    scene = createScene();
    container.append(renderer.domElement);

    const {
      ambientLight,
      mainLight
    } = createLights();

    scene.add(ambientLight, mainLight);
    loop = new Loop(camera, scene, renderer, new FaceTracker());
    const resizer = new Resizer(container, camera, renderer, loop);
  }

  async init() {
    const object = await loadObjects();

    if (typeof (object.tick) == "function") {
      loop.updatables.push(object);
    }
    scene.add(object);
    await loop.init();
  }

  render() {
    renderer.render(scene, camera);
  }

  start() {
    loop.start();
  }

  stop() {
    loop.stop();
  }
}

export {
  World
};