Skip to content

Commit 6d0ea9b

Browse files
committed
Clean up.
1 parent 102d038 commit 6d0ea9b

File tree

3 files changed

+37
-72
lines changed

3 files changed

+37
-72
lines changed

examples/webgl_animation_cloth.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
/* testing cloth simulation */
9292

9393
var pinsFormation = [];
94-
var pins = [6];
94+
var pins = [ 6 ];
9595

9696
pinsFormation.push( pins );
9797

@@ -112,7 +112,7 @@
112112

113113
function togglePins() {
114114

115-
pins = pinsFormation[ ~~( Math.random() * pinsFormation.length ) ];
115+
pins = pinsFormation[ ~~ ( Math.random() * pinsFormation.length ) ];
116116

117117
}
118118

@@ -165,10 +165,10 @@
165165

166166
var d = 300;
167167

168-
light.shadow.camera.left = -d;
168+
light.shadow.camera.left = - d;
169169
light.shadow.camera.right = d;
170170
light.shadow.camera.top = d;
171-
light.shadow.camera.bottom = -d;
171+
light.shadow.camera.bottom = - d;
172172

173173
light.shadow.camera.far = 1000;
174174

@@ -230,7 +230,7 @@
230230
var groundMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, map: groundTexture } );
231231

232232
var mesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 20000, 20000 ), groundMaterial );
233-
mesh.position.y = -250;
233+
mesh.position.y = - 250;
234234
mesh.rotation.x = - Math.PI / 2;
235235
mesh.receiveShadow = true;
236236
scene.add( mesh );
@@ -241,37 +241,37 @@
241241
var poleMat = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, shininess: 100 } );
242242

243243
var mesh = new THREE.Mesh( poleGeo, poleMat );
244-
mesh.position.x = -125;
245-
mesh.position.y = -62;
244+
mesh.position.x = - 125;
245+
mesh.position.y = - 62;
246246
mesh.receiveShadow = true;
247247
mesh.castShadow = true;
248248
scene.add( mesh );
249249

250250
var mesh = new THREE.Mesh( poleGeo, poleMat );
251251
mesh.position.x = 125;
252-
mesh.position.y = -62;
252+
mesh.position.y = - 62;
253253
mesh.receiveShadow = true;
254254
mesh.castShadow = true;
255255
scene.add( mesh );
256256

257257
var mesh = new THREE.Mesh( new THREE.BoxGeometry( 255, 5, 5 ), poleMat );
258-
mesh.position.y = -250 + 750/2;
258+
mesh.position.y = - 250 + ( 750 / 2 );
259259
mesh.position.x = 0;
260260
mesh.receiveShadow = true;
261261
mesh.castShadow = true;
262262
scene.add( mesh );
263263

264264
var gg = new THREE.BoxGeometry( 10, 10, 10 );
265265
var mesh = new THREE.Mesh( gg, poleMat );
266-
mesh.position.y = -250;
266+
mesh.position.y = - 250;
267267
mesh.position.x = 125;
268268
mesh.receiveShadow = true;
269269
mesh.castShadow = true;
270270
scene.add( mesh );
271271

272272
var mesh = new THREE.Mesh( gg, poleMat );
273-
mesh.position.y = -250;
274-
mesh.position.x = -125;
273+
mesh.position.y = - 250;
274+
mesh.position.x = - 125;
275275
mesh.receiveShadow = true;
276276
mesh.castShadow = true;
277277
scene.add( mesh );
@@ -301,7 +301,7 @@
301301

302302
window.addEventListener( 'resize', onWindowResize, false );
303303

304-
sphere.visible = !true
304+
sphere.visible = ! true
305305

306306
}
307307

@@ -327,7 +327,7 @@
327327
windStrength = Math.cos( time / 7000 ) * 20 + 40;
328328
windForce.set( Math.sin( time / 2000 ), Math.cos( time / 3000 ), Math.sin( time / 1000 ) ).normalize().multiplyScalar( windStrength );
329329

330-
simulate(time);
330+
simulate( time );
331331
render();
332332
stats.update();
333333

examples/webgl_shadowmap.html

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<script src="js/controls/FirstPersonControls.js"></script>
3838

3939
<script src="js/shaders/UnpackDepthRGBAShader.js"></script>
40+
<script src="js/utils/ShadowMapViewer.js"></script>
4041

4142
<script src="js/Detector.js"></script>
4243
<script src="js/libs/stats.min.js"></script>
@@ -51,18 +52,17 @@
5152

5253
var SCREEN_WIDTH = window.innerWidth;
5354
var SCREEN_HEIGHT = window.innerHeight;
54-
var FLOOR = -250;
55+
var FLOOR = - 250;
5556

5657
var camera, controls, scene, renderer;
5758
var container, stats;
5859

5960
var NEAR = 10, FAR = 3000;
6061

61-
var sceneHUD, cameraOrtho, hudMesh;
62-
6362
var mixer, morphs = [];
6463

6564
var light;
65+
var lightShadowMapViewer;
6666

6767
var clock = new THREE.Clock();
6868

@@ -167,64 +167,30 @@
167167

168168
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
169169

170-
var aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
171-
cameraOrtho.left = - aspect;
172-
cameraOrtho.right = aspect;
173-
cameraOrtho.top = 1;
174-
cameraOrtho.bottom = - 1;
175-
cameraOrtho.updateProjectionMatrix();
176-
177-
hudMesh.position.x = cameraOrtho.left + HUD_MARGIN;
178-
hudMesh.position.y = cameraOrtho.bottom + HUD_MARGIN;
179-
180170
controls.handleResize();
181171

182172
}
183173

184174
function onKeyDown ( event ) {
185175

186-
switch( event.keyCode ) {
176+
switch ( event.keyCode ) {
187177

188-
case 84: /*t*/ showHUD = !showHUD; break;
178+
case 84: /*t*/
179+
showHUD = ! showHUD;
180+
break;
189181

190182
}
191183

192184
}
193185

194186
function createHUD() {
195187

196-
var aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
197-
198-
cameraOrtho = new THREE.OrthographicCamera( - aspect, aspect, 1, - 1, 1, 10 );
199-
cameraOrtho.position.z = 5;
200-
201-
var shader = THREE.UnpackDepthRGBAShader;
202-
var uniforms = new THREE.UniformsUtils.clone( shader.uniforms );
203-
204-
uniforms.tDiffuse.value = light.shadowMap;
205-
206-
var hudMaterial = new THREE.ShaderMaterial( {
207-
uniforms: uniforms,
208-
vertexShader: shader.vertexShader,
209-
fragmentShader: shader.fragmentShader
210-
} );
211-
212-
var hudHeight = 2 / 3;
213-
214-
var hudWidth = hudHeight * SHADOW_MAP_WIDTH / SHADOW_MAP_HEIGHT;
215-
216-
var hudGeo = new THREE.PlaneBufferGeometry( hudWidth, hudHeight );
217-
hudGeo.translate( hudWidth / 2, hudHeight / 2, 0 );
218-
219-
hudMesh = new THREE.Mesh( hudGeo, hudMaterial );
220-
221-
hudMesh.position.x = cameraOrtho.left + HUD_MARGIN;
222-
hudMesh.position.y = cameraOrtho.bottom + HUD_MARGIN;
223-
224-
sceneHUD = new THREE.Scene();
225-
sceneHUD.add( hudMesh );
226-
227-
cameraOrtho.lookAt( sceneHUD.position );
188+
lightShadowMapViewer = new THREE.ShadowMapViewer( light );
189+
lightShadowMapViewer.position.x = 10;
190+
lightShadowMapViewer.position.y = SCREEN_HEIGHT - ( SHADOW_MAP_HEIGHT / 4 ) - 10;
191+
lightShadowMapViewer.size.width = SHADOW_MAP_WIDTH / 4;
192+
lightShadowMapViewer.size.height = SHADOW_MAP_HEIGHT / 4;
193+
lightShadowMapViewer.update();
228194

229195
}
230196

@@ -263,10 +229,10 @@
263229
bevelSize: 5,
264230
bevelEnabled: true
265231

266-
});
232+
} );
267233

268234
textGeo.computeBoundingBox();
269-
var centerOffset = -0.5 * ( textGeo.boundingBox.max.x - textGeo.boundingBox.min.x );
235+
var centerOffset = - 0.5 * ( textGeo.boundingBox.max.x - textGeo.boundingBox.min.x );
270236

271237
var textMaterial = new THREE.MeshPhongMaterial( { color: 0xff0000, specular: 0xffffff } );
272238

@@ -329,7 +295,7 @@
329295
play();
330296

331297
mesh.position.set( x, y, z );
332-
mesh.rotation.y = Math.PI/2;
298+
mesh.rotation.y = Math.PI / 2;
333299

334300
mesh.castShadow = true;
335301
mesh.receiveShadow = true;
@@ -348,9 +314,9 @@
348314
addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, 450, true );
349315
addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, 600, true );
350316

351-
addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, -300, true );
352-
addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, -450, true );
353-
addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, -600, true );
317+
addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, - 300, true );
318+
addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, - 450, true );
319+
addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, - 600, true );
354320

355321
} );
356322

@@ -397,7 +363,7 @@
397363

398364
if ( morph.position.x > 2000 ) {
399365

400-
morph.position.x = -1000 - Math.random() * 500;
366+
morph.position.x = - 1000 - Math.random() * 500;
401367

402368
}
403369

@@ -412,8 +378,7 @@
412378

413379
if ( showHUD ) {
414380

415-
renderer.clearDepth();
416-
renderer.render( sceneHUD, cameraOrtho );
381+
lightShadowMapViewer.render( renderer );
417382

418383
}
419384

examples/webgl_shadowmap_viewer.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@
9191
dirLight.shadowCameraNear = 1;
9292
dirLight.shadowCameraFar = 10;
9393
dirLight.shadowCameraRight = 15;
94-
dirLight.shadowCameraLeft = -15;
94+
dirLight.shadowCameraLeft = - 15;
9595
dirLight.shadowCameraTop = 15;
96-
dirLight.shadowCameraBottom = -15;
96+
dirLight.shadowCameraBottom = - 15;
9797
dirLight.shadowMapWidth = 1024;
9898
dirLight.shadowMapHeight = 1024;
9999
scene.add( dirLight );

0 commit comments

Comments
 (0)