-
Notifications
You must be signed in to change notification settings - Fork 2
/
StartingCode-withLights.html
112 lines (88 loc) · 2.98 KB
/
StartingCode-withLights.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<html>
<head>
<title>Starting Code for 1st Project 2017 - with lights and textures</title>
<style>
body {
font-family: Monospace;
background-color: #f0f0f0;
margin: 0px;
overflow: hidden;
}
canvas {
width: 100%;
height: 100%;
}
</style>
<script src="lib/three.min.js"></script>
<script src="lib/stats.min.js"></script>
<script src="lib/Coordinates.js"></script>
<script src="lib/OrbitControls.js"></script>
</head>
<body>
<script>
var scene, camera, renderer, controls, stats;
function Start() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
renderer = new THREE.WebGLRenderer( {antialias: true} );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0xf0f0f0 );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.gammaInput = true;
renderer.gammaOutput = true;
renderer.shadowMap.enabled = true;
document.body.appendChild( renderer.domElement );
camera.position.set(2,2,2);
camera.lookAt( new THREE.Vector3(0,0,0));
var geometry = new THREE.BoxGeometry(1,1,1);
var texture = THREE.ImageUtils.loadTexture('textures/11635.jpg');
var material = new THREE.MeshPhongMaterial( { map: texture } );
var cube = new THREE.Mesh( geometry, material );
cube.castShadow = true;
cube.receiveShadow = true;
scene.add( cube );
hemiLight = new THREE.HemisphereLight( 0xffffff, 0xffffff, 0.6 );
hemiLight.color.setHSL( 0.6, 1, 0.6 );
hemiLight.groundColor.setHSL( 0.095, 1, 0.75 );
hemiLight.position.set( 0, 500, 0 );
scene.add( hemiLight );
dirLight = new THREE.DirectionalLight( 0xffffff, 1 );
dirLight.color.setHSL( 0.1, 1, 0.95 );
dirLight.position.set( -1, 1.75, 1 );
dirLight.position.multiplyScalar( 50 );
scene.add( dirLight );
dirLight.castShadow = true;
dirLight.shadow.mapSize.width = 1024;
dirLight.shadow.mapSize.height = 1024;
// GROUND
var groundGeo = new THREE.PlaneBufferGeometry( 10000, 10000 );
var groundMat = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x050505 } );
groundMat.color.setHSL( 0.095, 1, 0.75 );
var ground = new THREE.Mesh( groundGeo, groundMat );
ground.position.y = -0.5;
ground.rotation.x = -Math.PI/2;
scene.add( ground );
ground.receiveShadow = true;
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
document.body.appendChild( stats.domElement );
// uncomment if you need to draw coordinate axes when building the scene
//Coordinates.drawAllAxes();
controls = new THREE.OrbitControls( camera );
controls.addEventListener( 'change', Render );
}
function Update() {
requestAnimationFrame( Update );
controls.update();
stats.update();
Render();
}
function Render() {
renderer.render(scene, camera);
}
Start();
Update();
</script>
</body>
</html>