9
9
< script type ="text/javascript " src ="../libs/stats.js "> </ script >
10
10
< script type ="text/javascript " src ="../libs/dat.gui.js "> </ script >
11
11
< style >
12
- body {
12
+ body {
13
13
/* set margin to 0 and overflow to hidden, to go fullscreen */
14
14
margin : 0 ;
15
15
overflow : hidden;
43
43
44
44
renderer . setClearColorHex ( 0xEEEEEE , 1.0 ) ;
45
45
renderer . setSize ( window . innerWidth , window . innerHeight ) ;
46
- // renderer.shadowMapEnabled = true;
46
+ // renderer.shadowMapEnabled = true;
47
47
48
48
// create the ground plane
49
- var planeGeometry = new THREE . PlaneGeometry ( 60 , 20 , 1 , 1 ) ;
50
- var planeMaterial = new THREE . MeshLambertMaterial ( { color : 0xffffff } ) ;
51
- var plane = new THREE . Mesh ( planeGeometry , planeMaterial ) ;
49
+ var planeGeometry = new THREE . PlaneGeometry ( 60 , 20 , 1 , 1 ) ;
50
+ var planeMaterial = new THREE . MeshLambertMaterial ( { color : 0xffffff } ) ;
51
+ var plane = new THREE . Mesh ( planeGeometry , planeMaterial ) ;
52
52
//plane.receiveShadow = true;
53
53
54
54
// rotate and position the plane
55
- plane . rotation . x = - 0.5 * Math . PI ;
56
- plane . position . x = 15
57
- plane . position . y = 0
58
- plane . position . z = 0
55
+ plane . rotation . x = - 0.5 * Math . PI ;
56
+ plane . position . x = 15
57
+ plane . position . y = 0
58
+ plane . position . z = 0
59
59
60
60
// add the plane to the scene
61
61
scene . add ( plane ) ;
62
62
63
63
// create a cube
64
- var cubeGeometry = new THREE . CubeGeometry ( 4 , 4 , 4 ) ;
64
+ var cubeGeometry = new THREE . CubeGeometry ( 4 , 4 , 4 ) ;
65
65
var cubeMaterial = new THREE . MeshLambertMaterial ( { color : 0xff7777 } ) ;
66
66
var cube = new THREE . Mesh ( cubeGeometry , cubeMaterial ) ;
67
67
cube . castShadow = true ;
68
68
69
69
// position the cube
70
- cube . position . x = - 4 ;
71
- cube . position . y = 3 ;
72
- cube . position . z = 0 ;
70
+ cube . position . x = - 4 ;
71
+ cube . position . y = 3 ;
72
+ cube . position . z = 0 ;
73
73
74
74
// add the cube to the scene
75
75
scene . add ( cube ) ;
76
76
77
- var sphereGeometry = new THREE . SphereGeometry ( 4 , 20 , 20 ) ;
77
+ var sphereGeometry = new THREE . SphereGeometry ( 4 , 20 , 20 ) ;
78
78
var sphereMaterial = new THREE . MeshLambertMaterial ( { color : 0x7777ff } ) ;
79
- var sphere = new THREE . Mesh ( sphereGeometry , sphereMaterial ) ;
79
+ var sphere = new THREE . Mesh ( sphereGeometry , sphereMaterial ) ;
80
80
81
81
// position the sphere
82
- sphere . position . x = 20 ;
83
- sphere . position . y = 0 ;
84
- sphere . position . z = 2 ;
85
- sphere . castShadow = true ;
82
+ sphere . position . x = 20 ;
83
+ sphere . position . y = 0 ;
84
+ sphere . position . z = 2 ;
85
+ sphere . castShadow = true ;
86
86
87
87
// add the sphere to the scene
88
88
scene . add ( sphere ) ;
91
91
camera . position . x = - 25 ;
92
92
camera . position . y = 30 ;
93
93
camera . position . z = 25 ;
94
- camera . lookAt ( new THREE . Vector3 ( 10 , 0 , 0 ) ) ;
94
+ camera . lookAt ( new THREE . Vector3 ( 10 , 0 , 0 ) ) ;
95
95
96
96
// add subtle ambient lighting
97
97
var ambiColor = "#0c0c0c" ;
100
100
101
101
// add spotlight for the shadows
102
102
// add spotlight for the shadows
103
- var spotLight = new THREE . SpotLight ( 0xffffff ) ;
104
- spotLight . position . set ( - 40 , 60 , - 10 ) ;
103
+ var spotLight = new THREE . SpotLight ( 0xffffff ) ;
104
+ spotLight . position . set ( - 40 , 60 , - 10 ) ;
105
105
spotLight . castShadow = true ;
106
- // scene.add( spotLight );
106
+ // scene.add( spotLight );
107
107
108
- var pointColor = "#ccffcc" ;
108
+ var pointColor = "#ccffcc" ;
109
109
var pointLight = new THREE . PointLight ( pointColor ) ;
110
- pointLight . distance = 100 ;
110
+ pointLight . distance = 100 ;
111
111
scene . add ( pointLight ) ;
112
112
113
113
117
117
var sphereLightMesh = new THREE . Mesh ( sphereLight , sphereLightMaterial ) ;
118
118
sphereLightMesh . castShadow = true ;
119
119
120
- sphereLightMesh . position = new THREE . Vector3 ( 3 , 5 , 3 ) ;
120
+ sphereLightMesh . position = new THREE . Vector3 ( 3 , 5 , 3 ) ;
121
121
scene . add ( sphereLightMesh ) ;
122
122
123
123
124
124
// add the output of the renderer to the html element
125
125
$ ( "#WebGL-output" ) . append ( renderer . domElement ) ;
126
126
127
127
// call the render function
128
- var step = 0 ;
128
+ var step = 0 ;
129
129
130
130
// used to determine the switch point for the light animation
131
- var invert = 1 ;
132
- var phase = 0 ;
131
+ var invert = 1 ;
132
+ var phase = 0 ;
133
133
134
- var controls = new function ( ) {
134
+ var controls = new function ( ) {
135
135
this . rotationSpeed = 0.03 ;
136
136
this . bouncingSpeed = 0.03 ;
137
137
this . ambientColor = ambiColor ;
138
138
this . pointColor = pointColor ;
139
139
this . intensity = 1 ;
140
- this . distance = 100 ;
140
+ this . distance = 100 ;
141
141
}
142
142
143
143
var gui = new dat . GUI ( ) ;
144
- gui . addColor ( controls , 'ambientColor' ) . onChange ( function ( e ) {
144
+ gui . addColor ( controls , 'ambientColor' ) . onChange ( function ( e ) {
145
145
ambientLight . color = new THREE . Color ( e ) ;
146
146
} ) ;
147
147
148
- gui . addColor ( controls , 'pointColor' ) . onChange ( function ( e ) {
148
+ gui . addColor ( controls , 'pointColor' ) . onChange ( function ( e ) {
149
149
pointLight . color = new THREE . Color ( e ) ;
150
150
} ) ;
151
151
152
- gui . add ( controls , 'intensity' , 0 , 3 ) . onChange ( function ( e ) {
152
+ gui . add ( controls , 'intensity' , 0 , 3 ) . onChange ( function ( e ) {
153
153
pointLight . intensity = e ;
154
154
} ) ;
155
155
156
- gui . add ( controls , 'distance' , 0 , 100 ) . onChange ( function ( e ) {
156
+ gui . add ( controls , 'distance' , 0 , 100 ) . onChange ( function ( e ) {
157
157
pointLight . distance = e ;
158
158
} ) ;
159
159
168
168
cube . rotation . z += controls . rotationSpeed ;
169
169
170
170
// bounce the sphere up and down
171
- step += controls . bouncingSpeed ;
172
- sphere . position . x = 20 + ( 10 * ( Math . cos ( step ) ) ) ;
173
- sphere . position . y = 2 + ( 10 * Math . abs ( Math . sin ( step ) ) ) ;
171
+ step += controls . bouncingSpeed ;
172
+ sphere . position . x = 20 + ( 10 * ( Math . cos ( step ) ) ) ;
173
+ sphere . position . y = 2 + ( 10 * Math . abs ( Math . sin ( step ) ) ) ;
174
174
175
175
// move the light simulation
176
- if ( phase > 2 * Math . PI ) {
177
- invert = invert * - 1 ;
178
- phase -= 2 * Math . PI ;
176
+ if ( phase > 2 * Math . PI ) {
177
+ invert = invert * - 1 ;
178
+ phase -= 2 * Math . PI ;
179
179
} else {
180
- phase += controls . rotationSpeed ;
180
+ phase += controls . rotationSpeed ;
181
181
}
182
- sphereLightMesh . position . z = + ( 7 * ( Math . sin ( phase ) ) ) ;
183
- sphereLightMesh . position . x = + ( 14 * ( Math . cos ( phase ) ) ) ;
182
+ sphereLightMesh . position . z = + ( 7 * ( Math . sin ( phase ) ) ) ;
183
+ sphereLightMesh . position . x = + ( 14 * ( Math . cos ( phase ) ) ) ;
184
184
185
- if ( invert < 0 ) {
185
+ if ( invert < 0 ) {
186
186
var pivot = 14 ;
187
- sphereLightMesh . position . x = ( invert * ( sphereLightMesh . position . x - pivot ) ) + pivot ;
187
+ sphereLightMesh . position . x = ( invert * ( sphereLightMesh . position . x - pivot ) ) + pivot ;
188
188
}
189
189
190
190
pointLight . position = sphereLightMesh . position ;
205
205
stats . domElement . style . left = '0px' ;
206
206
stats . domElement . style . top = '0px' ;
207
207
208
- $ ( "#Stats-output" ) . append ( stats . domElement ) ;
208
+ $ ( "#Stats-output" ) . append ( stats . domElement ) ;
209
209
210
210
return stats ;
211
211
}
212
212
} ) ;
213
213
214
214
215
-
216
215
</ script >
217
216
</ body >
218
217
</ html >
0 commit comments