Skip to content

Commit

Permalink
Merge pull request #13341 from MiiBond/gltf_khr_lights_v2
Browse files Browse the repository at this point in the history
Rough update to KHR_lights support to match current spec
  • Loading branch information
mrdoob committed Apr 6, 2018
2 parents 6234d0a + f45894b commit b69d7c7
Show file tree
Hide file tree
Showing 5 changed files with 4,583 additions and 31 deletions.
43 changes: 15 additions & 28 deletions examples/js/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ THREE.GLTFLoader = ( function () {

case 'directional':
lightNode = new THREE.DirectionalLight( color );
lightNode.position.set( 0, 0, 1 );
lightNode.target.position.set( 0, 0, 1 );
lightNode.add( lightNode.target );
break;

case 'point':
Expand All @@ -261,7 +262,14 @@ THREE.GLTFLoader = ( function () {

case 'spot':
lightNode = new THREE.SpotLight( color );
lightNode.position.set( 0, 0, 1 );
// 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;
lightNode.target.position.set( 0, 0, 1 );
lightNode.add( lightNode.target );
break;

case 'ambient':
Expand All @@ -272,33 +280,11 @@ THREE.GLTFLoader = ( function () {

if ( lightNode ) {

if ( light.constantAttenuation !== undefined ) {
lightNode.decay = 2;

lightNode.intensity = light.constantAttenuation;
if ( light.intensity !== undefined ) {

}

if ( light.linearAttenuation !== undefined ) {

lightNode.distance = 1 / light.linearAttenuation;

}

if ( light.quadraticAttenuation !== undefined ) {

lightNode.decay = light.quadraticAttenuation;

}

if ( light.fallOffAngle !== undefined ) {

lightNode.angle = light.fallOffAngle;

}

if ( light.fallOffExponent !== undefined ) {

console.warn( 'THREE.GLTFLoader:: light.fallOffExponent not currently supported.' );
lightNode.intensity = light.intensity;

}

Expand Down Expand Up @@ -2595,7 +2581,8 @@ THREE.GLTFLoader = ( function () {

'mesh',
'skin',
'camera'
'camera',
'light'

] ).then( function ( dependencies ) {

Expand Down
Loading

0 comments on commit b69d7c7

Please sign in to comment.