-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathexample-scene.js
81 lines (71 loc) · 2.2 KB
/
example-scene.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var scene, root, renderer, camera, controls;
init();
createScene();
animate();
function init () {
scene = new THREE.Scene();
root = new THREE.Object3D();
scene.add( root );
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.shadowMap.enabled = true;
document.body.appendChild( renderer.domElement );
camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000.0
);
camera.position.z = 50.0;
controls = new THREE.OrbitControls( camera );
controls.addEventListener( "change", render );
}
function animate () {
requestAnimationFrame( animate );
controls.update();
render();
}
function render () {
renderer.render( scene, camera );
}
function createScene () {
// Create the objects
// In this case z+ is north, y- is the gravity.
var ground = createBox( 50.0, 1.0, 50.0, 0x99ff99 );
ground.position.set( 0.0, 0.0, 0.0 );
root.add( ground );
// Cube in the middle
var cube = createBox( 5.0, 5.0, 5.0 );
cube.position.set( 0.0, 5.0, 0.0 );
root.add( cube );
// North pole indicator
var northIndicator = createBox( 2.0, 2.0, 8.0, 0xff0000 );
northIndicator.position.set( 0.0, 1.0, 20.0 );
root.add( northIndicator );
// Add an ambient light
root.add( new THREE.AmbientLight( 0x333333) );
// Create the sun light and add it to the scene
var sunLight = new SunLight(
// Oulu
new THREE.Vector2( 65.05, 25.47 ),
new THREE.Vector3( 0.0, 0.0, 1.0 ),
new THREE.Vector3( -1.0, 0.0, 0.0 ),
new THREE.Vector3( 0.0, -1.0, 0.0 )
);
root.add( sunLight );
sunLight.updateOrientation(true);
sunLight.updateDirectionalLight();
// Adjust the directional light's shadow camera dimensions
sunLight.directionalLight.shadow.camera.right = 30.0;
sunLight.directionalLight.shadow.camera.left = -30.0;
sunLight.directionalLight.shadow.camera.top = 30.0;
sunLight.directionalLight.shadow.camera.bottom = -30.0;
}
function createBox ( width_, height_, depth_, color_ = 0xffffff ) {
var geometry = new THREE.BoxGeometry( width_, height_, depth_ );
var material = new THREE.MeshPhongMaterial( { color: color_ } );
var cube = new THREE.Mesh( geometry, material );
cube.castShadow = true;
cube.receiveShadow = true;
return cube;
}