Browse Source

GLTFLoader: Clean up KHR_lights_punctual impl.

Don McCurdy 7 years ago
parent
commit
c7a988af7a
1 changed files with 19 additions and 29 deletions
  1. 19 29
      examples/js/loaders/GLTFLoader.js

+ 19 - 29
examples/js/loaders/GLTFLoader.js

@@ -272,28 +272,22 @@ THREE.GLTFLoader = ( function () {
 
 		this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
 
-		this.lights = {};
+		this.lights = [];
 
 		var extension = ( json.extensions && json.extensions[ EXTENSIONS.KHR_LIGHTS_PUNCTUAL ] ) || {};
-		var lights = extension.lights || {};
+		var lightDefs = extension.lights || [];
 
-		for ( var lightIndex = 0; lightIndex < lights.length; ++ lightIndex ) {
+		for ( var lightIndex = 0; lightIndex < lightDefs.length; ++ lightIndex ) {
 
-			var light = lights[ lightIndex ];
+			var lightDef = lightDefs[ lightIndex ];
 			var lightNode;
 
-			// the color default value is [1, 1, 1]
 			var color = new THREE.Color( 0xffffff );
-			if ( light.color !== undefined ) {
-				color.fromArray( light.color )
-			}
+			if ( lightDef.color !== undefined ) color.fromArray( lightDef.color );
 
-			var range = 0;
-			if ( light.range !== undefined ) {
-				range = light.range;
-			}
+			var range = lightDef.range !== undefined ? lightDef.range : 0;
 
-			switch ( light.type ) {
+			switch ( lightDef.type ) {
 
 				case 'directional':
 					lightNode = new THREE.DirectionalLight( color );
@@ -310,31 +304,27 @@ THREE.GLTFLoader = ( function () {
 					lightNode = new THREE.SpotLight( color );
 					lightNode.distance = range;
 					// Handle spotlight properties.
-					light.spot = light.spot || {};
-					light.spot.innerConeAngle = light.spot.innerConeAngle !== undefined ? light.spot.innerConeAngle : 0;
-					light.spot.outerConeAngle = light.spot.outerConeAngle !== undefined ? light.spot.outerConeAngle : Math.PI / 4.0;
-					lightNode.angle = light.spot.outerConeAngle;
-					lightNode.penumbra = 1.0 - light.spot.innerConeAngle / light.spot.outerConeAngle;
+					lightDef.spot = lightDef.spot || {};
+					lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
+					lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
+					lightNode.angle = lightDef.spot.outerConeAngle;
+					lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
 					lightNode.target.position.set( 0, 0, 1 );
 					lightNode.add( lightNode.target );
 					break;
 
-			}
-
-			if ( lightNode ) {
-
-				lightNode.decay = 2;
+				default:
+					throw new Error( 'THREE.GLTFLoader: Unexpected light type, "' + lightDef.type + '".' );
 
-				if ( light.intensity !== undefined ) {
+			}
 
-					lightNode.intensity = light.intensity;
+			lightNode.decay = 2;
 
-				}
+			if ( lightDef.intensity !== undefined ) lightNode.intensity = lightDef.intensity;
 
-				lightNode.name = light.name || ( 'light_' + lightIndex );
-				this.lights[ lightIndex ] = lightNode;
+			lightNode.name = lightDef.name || ( 'light_' + lightIndex );
 
-			}
+			this.lights.push( lightNode );
 
 		}