1 | /**
|
---|
2 | * @author alteredq / http://alteredqualia.com/
|
---|
3 | * @author mrdoob / http://mrdoob.com/
|
---|
4 | * @author WestLangley / http://github.com/WestLangley
|
---|
5 | */
|
---|
6 |
|
---|
7 | THREE.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 |
|
---|
31 | THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
|
---|
32 |
|
---|
33 | THREE.SpotLightHelper.prototype.dispose = function () {
|
---|
34 | this.cone.geometry.dispose();
|
---|
35 | this.cone.material.dispose();
|
---|
36 | };
|
---|
37 |
|
---|
38 | THREE.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 | }();
|
---|