Skip to content

Commit aa0f1fd

Browse files
committed
Nicer SpotLightHelper.
1 parent 492e6a1 commit aa0f1fd

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/extras/helpers/SpotLightHelper.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,35 @@ THREE.SpotLightHelper = function ( light ) {
1414
this.matrix = light.matrixWorld;
1515
this.matrixAutoUpdate = false;
1616

17-
var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
17+
var geometry = new THREE.BufferGeometry();
1818

19-
geometry.translate( 0, - 0.5, 0 );
20-
geometry.rotateX( - Math.PI / 2 );
19+
var positions = [];
2120

22-
var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
21+
positions.push(
22+
0, 0, 0, 0, 0, 1,
23+
0, 0, 0, 1, 0, 1,
24+
0, 0, 0, - 1, 0, 1,
25+
0, 0, 0, 0, 1, 1,
26+
0, 0, 0, 0, - 1, 1
27+
);
2328

24-
this.cone = new THREE.Mesh( geometry, material );
29+
var length = 32;
30+
31+
for ( var i = 0; i < length; i ++ ) {
32+
33+
var p1 = ( i / length ) * Math.PI * 2;
34+
var p2 = ( ( i + 1 ) / length ) * Math.PI * 2;
35+
36+
positions.push( Math.cos( p1 ), Math.sin( p1 ), 1 );
37+
positions.push( Math.cos( p2 ), Math.sin( p2 ), 1 );
38+
39+
}
40+
41+
geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
42+
43+
var material = new THREE.LineBasicMaterial( { fog: false } );
44+
45+
this.cone = new THREE.LineSegments( geometry, material );
2546
this.add( this.cone );
2647

2748
this.update();
@@ -45,7 +66,7 @@ THREE.SpotLightHelper.prototype.update = function () {
4566

4667
return function () {
4768

48-
var coneLength = this.light.distance ? this.light.distance : 10000;
69+
var coneLength = this.light.distance ? this.light.distance : 1000;
4970
var coneWidth = coneLength * Math.tan( this.light.angle );
5071

5172
this.cone.scale.set( coneWidth, coneWidth, coneLength );

0 commit comments

Comments
 (0)