Browse Source

Merge branch 'dev-dlhelper' of https://github.com/WestLangley/three.js into dev

Mr.doob 11 years ago
parent
commit
cc7b66ad78
1 changed files with 10 additions and 5 deletions
  1. 10 5
      src/extras/helpers/DirectionalLightHelper.js

+ 10 - 5
src/extras/helpers/DirectionalLightHelper.js

@@ -1,6 +1,7 @@
 /**
  * @author alteredq / http://alteredqualia.com/
  * @author mrdoob / http://mrdoob.com/
+ * @author WestLangley / http://github.com/WestLangley
  */
 
 THREE.DirectionalLightHelper = function ( light, size ) {
@@ -13,6 +14,7 @@ THREE.DirectionalLightHelper = function ( light, size ) {
 	this.matrixWorld = light.matrixWorld;
 	this.matrixAutoUpdate = false;
 
+	size = size || 1;
 	var geometry = new THREE.PlaneGeometry( size, size );
 	var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
 	material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
@@ -23,7 +25,6 @@ THREE.DirectionalLightHelper = function ( light, size ) {
 	geometry = new THREE.Geometry();
 	geometry.vertices.push( new THREE.Vector3() );
 	geometry.vertices.push( new THREE.Vector3() );
-	geometry.computeLineDistances();
 
 	material = new THREE.LineBasicMaterial( { fog: false } );
 	material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
@@ -47,16 +48,20 @@ THREE.DirectionalLightHelper.prototype.dispose = function () {
 
 THREE.DirectionalLightHelper.prototype.update = function () {
 
-	var vector = new THREE.Vector3();
+	var v1 = new THREE.Vector3();
+	var v2 = new THREE.Vector3();
+	var v3 = new THREE.Vector3();
 
 	return function () {
 
-		vector.getPositionFromMatrix( this.light.matrixWorld ).negate();
+		v1.getPositionFromMatrix( this.light.matrixWorld );
+		v2.getPositionFromMatrix( this.light.target.matrixWorld );
+		v3.subVectors( v2, v1 );
 
-		this.lightPlane.lookAt( vector );
+		this.lightPlane.lookAt( v3 );
 		this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
 
-		this.targetLine.geometry.vertices[ 1 ].copy( vector );
+		this.targetLine.geometry.vertices[ 1 ].copy( v3 );
 		this.targetLine.geometry.verticesNeedUpdate = true;
 		this.targetLine.material.color.copy( this.lightPlane.material.color );