-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (44 loc) · 1.51 KB
/
index.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
var scene, camera, renderer, container, sceneSize, audioContext, masterGain, masterAnalyzer;
var constraints = { audio: true };
function successCallback (stream) {
console.log("success");
mediaStreamSource = audioContext.createMediaStreamSource(stream);
init();
}
function errorCallback () {
console.log("err", arguments);
}
function initAudio () {
audioContext = new webkitAudioContext();
masterGain = audioContext.createGainNode();
masterAnalyser = audioContext.createAnalyser();
masterAnalyser.connect(masterGain);
masterGain.connect(audioContext.destination);
navigator.webkitGetUserMedia(constraints, successCallback, errorCallback); // todo: make non-webkit-specific
}
function init () {
sceneSize = 100;
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(
50,
window.innerWidth / window.innerHeight,
sceneSize / 1000,
sceneSize * 20
);
camera.position.z = sceneSize;
var geometry = new THREE.SphereGeometry(sceneSize / 20, 20, 20);
var material = new THREE.MeshNormalMaterial();
var mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
container = document.createElement('div');
document.body.appendChild(container);
container.appendChild(renderer.domElement);
animate();
}
function animate () {
window.requestAnimationFrame(animate); // ensures this function gets called once every 60 seconds
renderer.render(scene, camera);
}
initAudio();