未验证 提交 db4dda8b 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #14515 from donmccurdy/bug-gltfloader-lights-array

GLTFLoader: Fix lights list iterator.
......@@ -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 );
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册