-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcubular-system.js
63 lines (49 loc) · 1.85 KB
/
cubular-system.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
58
59
60
61
62
63
/* global THREE */
var solarSystem;
function init() {
var scene = new THREE.Scene();
var clock = new THREE.Clock();
var gui = new dat.GUI();
solarSystem = SolarSystem.heliocentric(new CelestialMaterial('./texture/'), scene);
//solarSystem = SolarSystem.geocentric(new CelestialMaterial('./texture/'), scene);
var light = new THREE.AmbientLight(0x404040, 0.5);
scene.add(light);
var f = gui.addFolder('Ambient light');
f.add(light, 'intensity', 0, 1);
f.open();
// camera
var camera = new THREE.PerspectiveCamera(
45, // field of view
window.innerWidth / window.innerHeight, // aspect ratio
1, // near clipping plane
1000 // far clipping plane
);
camera.position.x = -24;
camera.position.y = 74;
camera.position.z = 74;
camera.lookAt(new THREE.Vector3(0, 0, 0));
// renderer
var renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
document.getElementById('webgl').appendChild(renderer.domElement);
var controls = new THREE.OrbitControls(camera, renderer.domElement);
update(renderer, scene, camera, controls, clock);
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener('resize', onWindowResize, false);
return scene;
}
function update(renderer, scene, camera, controls, clock) {
var timeDelta = clock.getDelta();
solarSystem.animate(timeDelta);
controls.update();
renderer.render(scene, camera);
requestAnimationFrame(function () {
update(renderer, scene, camera, controls, clock);
});
}
var scene = init();