diff --git a/examples/js/loaders/GLTFLoader.js b/examples/js/loaders/GLTFLoader.js index 8946d295adebc2..de59ed86843929 100644 --- a/examples/js/loaders/GLTFLoader.js +++ b/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 lightId in lights ) { + for ( var i = 0; i < lightDefs.length; i ++ ) { - var light = lights[ lightId ]; + var lightDef = lightDefs[ i ]; 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_' + lightId ); - this.lights[ lightId ] = lightNode; + lightNode.name = lightDef.name || ( 'light_' + i ); - } + this.lights.push( lightNode ); }