-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
50 lines (35 loc) · 1.31 KB
/
helpers.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
// Some helper functions and variables
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
// Add examplepath to all file paths in code that you copied from threejs.org/examples/
var examplepath = 'https://threejs.org/examples/';
var stats = new Stats();
// Quickly turn on/off stats & gui
var statsOn = true;
var guiOn = true;
function initRenderer() {
container = document.createElement( 'div' );
document.body.appendChild( container );
if(statsOn) container.appendChild( stats.dom );
var canvasWidth = window.innerWidth;
var canvasHeight = window.innerHeight;
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 80000 );
// RENDERER
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setClearColor( 0xAAAAAA );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( canvasWidth, canvasHeight );
renderer.gammaInput = true;
renderer.gammaOutput = true;
container.appendChild( renderer.domElement );
// EVENTS
window.addEventListener( 'resize', onWindowResize, false );
}
// EVENT HANDLERS
function onWindowResize() {
var canvasWidth = window.innerWidth;
var canvasHeight = window.innerHeight;
renderer.setSize( canvasWidth, canvasHeight );
camera.aspect = canvasWidth / canvasHeight;
camera.updateProjectionMatrix();
render();
}