-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
52 lines (42 loc) · 1.45 KB
/
main.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
require(['three', 'third-party/FlyControls', 'webcam-texture'], function (THREE, FlyControls, webcamTexture) {
'use strict';
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100000);
camera.position.z = 1000;
var clock = new THREE.Clock();
var updates = [];
var controls = new FlyControls(camera);
controls.movementSpeed = 500;
controls.rollSpeed = Math.PI / 20;
controls.dragToLook = true;
updates.push(function(delta) {
controls.update(delta);
});
webcamTexture.start(function(material) {
updates.push(webcamTexture.update);
var geometry = new THREE.SphereGeometry(500, 256, 256);
var globe = new THREE.Mesh(geometry, material);
globe.rotation.y = 3.0;
scene.add(globe);
updates.push(function(delta) {
globe.rotation.y += 0.01;
});
});
window.addEventListener('resize', function() {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
});
function render() {
var delta = clock.getDelta();
updates.forEach(function(update) {
update(delta);
})
renderer.render(scene, camera);
requestAnimationFrame(render);
}
requestAnimationFrame(render);
});