source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/src/extras/helpers/DirectionalLightHelper.js

Last change on this file was 28897, checked in by davidb, 10 years ago

GUI front-end to server base plus web page content

File size: 2.0 KB
Line 
1/**
2 * @author alteredq / http://alteredqualia.com/
3 * @author mrdoob / http://mrdoob.com/
4 * @author WestLangley / http://github.com/WestLangley
5 */
6
7THREE.DirectionalLightHelper = function ( light, size ) {
8
9 THREE.Object3D.call( this );
10
11 this.light = light;
12 this.light.updateMatrixWorld();
13
14 this.matrixWorld = light.matrixWorld;
15 this.matrixAutoUpdate = false;
16
17 size = size || 1;
18 var geometry = new THREE.PlaneGeometry( size, size );
19 var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
20 material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
21
22 this.lightPlane = new THREE.Mesh( geometry, material );
23 this.add( this.lightPlane );
24
25 geometry = new THREE.Geometry();
26 geometry.vertices.push( new THREE.Vector3() );
27 geometry.vertices.push( new THREE.Vector3() );
28
29 material = new THREE.LineBasicMaterial( { fog: false } );
30 material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
31
32 this.targetLine = new THREE.Line( geometry, material );
33 this.add( this.targetLine );
34
35 this.update();
36
37};
38
39THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
40
41THREE.DirectionalLightHelper.prototype.dispose = function () {
42
43 this.lightPlane.geometry.dispose();
44 this.lightPlane.material.dispose();
45 this.targetLine.geometry.dispose();
46 this.targetLine.material.dispose();
47};
48
49THREE.DirectionalLightHelper.prototype.update = function () {
50
51 var v1 = new THREE.Vector3();
52 var v2 = new THREE.Vector3();
53 var v3 = new THREE.Vector3();
54
55 return function () {
56
57 v1.setFromMatrixPosition( this.light.matrixWorld );
58 v2.setFromMatrixPosition( this.light.target.matrixWorld );
59 v3.subVectors( v2, v1 );
60
61 this.lightPlane.lookAt( v3 );
62 this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
63
64 this.targetLine.geometry.vertices[ 1 ].copy( v3 );
65 this.targetLine.geometry.verticesNeedUpdate = true;
66 this.targetLine.material.color.copy( this.lightPlane.material.color );
67
68 }
69
70}();
71
Note: See TracBrowser for help on using the repository browser.