Browse Source

Allow overrideColor to be changed after construction in HemisphereLightHelper

Lewy Blue 8 years ago
parent
commit
560441c879
1 changed files with 21 additions and 11 deletions
  1. 21 11
      src/helpers/HemisphereLightHelper.js

+ 21 - 11
src/helpers/HemisphereLightHelper.js

@@ -23,18 +23,20 @@ function HemisphereLightHelper( light, size, overrideColor ) {
 	this.matrix = light.matrixWorld;
 	this.matrixAutoUpdate = false;
 
+	this.overrideColor = overrideColor;
+
 	var geometry = new OctahedronBufferGeometry( size );
 	geometry.rotateY( Math.PI * 0.5 );
 
-	var material = new MeshBasicMaterial( { wireframe: true, fog: false, color: this.overrideColor } );
-	if ( ! overrideColor ) material.vertexColors = VertexColors;
+	this.material = new MeshBasicMaterial( { wireframe: true, fog: false, color: this.overrideColor } );
+	if ( ! overrideColor ) this.material.vertexColors = VertexColors;
 
 	var position = geometry.getAttribute( 'position' );
 	var colors = new Float32Array( position.count * 3 );
 
 	geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
 
-	this.add( new Mesh( geometry, material ) );
+	this.add( new Mesh( geometry, this.material ) );
 
 	this.update();
 
@@ -61,23 +63,31 @@ HemisphereLightHelper.prototype.update = function () {
 
 		var mesh = this.children[ 0 ];
 
-		var colors = mesh.geometry.getAttribute( 'color' );
+		if ( this.overrideColor ) {
+
+			this.material.color.set( this.overrideColor );
+
+		} else {
+
+			var colors = mesh.geometry.getAttribute( 'color' );
 
-		color1.copy( this.light.color );
-		color2.copy( this.light.groundColor );
+			color1.copy( this.light.color );
+			color2.copy( this.light.groundColor );
 
-		for ( var i = 0, l = colors.count; i < l; i ++ ) {
+			for ( var i = 0, l = colors.count; i < l; i ++ ) {
 
-			var color = ( i < ( l / 2 ) ) ? color1 : color2;
+				var color = ( i < ( l / 2 ) ) ? color1 : color2;
 
-			colors.setXYZ( i, color.r, color.g, color.b );
+				colors.setXYZ( i, color.r, color.g, color.b );
+
+			}
+
+			colors.needsUpdate = true;
 
 		}
 
 		mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
 
-		colors.needsUpdate = true;
-
 	};
 
 }();