|
@@ -14,34 +14,25 @@ THREE.DirectionalLightHelper = function ( light, size ) {
|
|
|
this.matrix = light.matrixWorld;
|
|
|
this.matrixAutoUpdate = false;
|
|
|
|
|
|
- size = size || 1;
|
|
|
+ if ( size === undefined ) size = 1;
|
|
|
|
|
|
- var geometry = new THREE.Geometry();
|
|
|
- geometry.vertices.push(
|
|
|
- new THREE.Vector3( - size, size, 0 ),
|
|
|
- new THREE.Vector3( size, size, 0 ),
|
|
|
- new THREE.Vector3( size, - size, 0 ),
|
|
|
- new THREE.Vector3( - size, - size, 0 ),
|
|
|
- new THREE.Vector3( - size, size, 0 )
|
|
|
- );
|
|
|
+ var geometry = new THREE.BufferGeometry();
|
|
|
+ geometry.addAttribute( 'position', new THREE.Float32Attribute( [
|
|
|
+ - size, size, 0,
|
|
|
+ size, size, 0,
|
|
|
+ size, - size, 0,
|
|
|
+ - size, - size, 0,
|
|
|
+ - size, size, 0
|
|
|
+ ], 3 ) );
|
|
|
|
|
|
var material = new THREE.LineBasicMaterial( { fog: false } );
|
|
|
- material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
|
|
|
|
|
- this.lightPlane = new THREE.Line( geometry, material );
|
|
|
- this.add( this.lightPlane );
|
|
|
+ this.add( new THREE.Line( geometry, material ) );
|
|
|
|
|
|
- geometry = new THREE.Geometry();
|
|
|
- geometry.vertices.push(
|
|
|
- new THREE.Vector3(),
|
|
|
- new THREE.Vector3()
|
|
|
- );
|
|
|
+ geometry = new THREE.BufferGeometry();
|
|
|
+ geometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
|
|
|
|
|
|
- material = new THREE.LineBasicMaterial( { fog: false } );
|
|
|
- material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
|
|
-
|
|
|
- this.targetLine = new THREE.Line( geometry, material );
|
|
|
- this.add( this.targetLine );
|
|
|
+ this.add( new THREE.Line( geometry, material ));
|
|
|
|
|
|
this.update();
|
|
|
|
|
@@ -52,10 +43,13 @@ THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelpe
|
|
|
|
|
|
THREE.DirectionalLightHelper.prototype.dispose = function () {
|
|
|
|
|
|
- this.lightPlane.geometry.dispose();
|
|
|
- this.lightPlane.material.dispose();
|
|
|
- this.targetLine.geometry.dispose();
|
|
|
- this.targetLine.material.dispose();
|
|
|
+ var lightPlane = this.children[ 0 ];
|
|
|
+ var targetLine = this.children[ 1 ];
|
|
|
+
|
|
|
+ lightPlane.geometry.dispose();
|
|
|
+ lightPlane.material.dispose();
|
|
|
+ targetLine.geometry.dispose();
|
|
|
+ targetLine.material.dispose();
|
|
|
|
|
|
};
|
|
|
|
|
@@ -71,12 +65,14 @@ THREE.DirectionalLightHelper.prototype.update = function () {
|
|
|
v2.setFromMatrixPosition( this.light.target.matrixWorld );
|
|
|
v3.subVectors( v2, v1 );
|
|
|
|
|
|
- this.lightPlane.lookAt( v3 );
|
|
|
- this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
|
|
+ var lightPlane = this.children[ 0 ];
|
|
|
+ var targetLine = this.children[ 1 ];
|
|
|
+
|
|
|
+ lightPlane.lookAt( v3 );
|
|
|
+ lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
|
|
|
|
|
- this.targetLine.geometry.vertices[ 1 ].copy( v3 );
|
|
|
- this.targetLine.geometry.verticesNeedUpdate = true;
|
|
|
- this.targetLine.material.color.copy( this.lightPlane.material.color );
|
|
|
+ targetLine.lookAt( v3 );
|
|
|
+ targetLine.scale.z = v3.length();
|
|
|
|
|
|
};
|
|
|
|