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

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

GUI front-end to server base plus web page content

File size: 1.5 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.SpotLightHelper = function ( light ) {
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 var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
18
19 geometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, -0.5, 0 ) );
20 geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
21
22 var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
23
24 this.cone = new THREE.Mesh( geometry, material );
25 this.add( this.cone );
26
27 this.update();
28
29};
30
31THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
32
33THREE.SpotLightHelper.prototype.dispose = function () {
34 this.cone.geometry.dispose();
35 this.cone.material.dispose();
36};
37
38THREE.SpotLightHelper.prototype.update = function () {
39
40 var vector = new THREE.Vector3();
41 var vector2 = new THREE.Vector3();
42
43 return function () {
44
45 var coneLength = this.light.distance ? this.light.distance : 10000;
46 var coneWidth = coneLength * Math.tan( this.light.angle );
47
48 this.cone.scale.set( coneWidth, coneWidth, coneLength );
49
50 vector.setFromMatrixPosition( this.light.matrixWorld );
51 vector2.setFromMatrixPosition( this.light.target.matrixWorld );
52
53 this.cone.lookAt( vector2.sub( vector ) );
54
55 this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
56
57 };
58
59}();
Note: See TracBrowser for help on using the repository browser.