Skip to content

Rough update to KHR_lights support to match current spec #13341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
var spot = light.spot || {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about doing this instead?

var spot = light.spot || { innerConeAngle: 0, outerConeAngle: Math.PI / 4.0 };
lightNode.angle = spot.outerConeAngle;
lightNode.penumbra = 1.0 - ( spot.innerConeAngle / spot.outerConeAngle );
lightNode.target.position.set( 0, 0, 1 );
lightNode.add( lightNode.target );

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

innerConeAngle and outerConeAngle are not required to be present, so their default values must be set independently. @MiiBond is the spot property required? Perhaps:

light.spot = light.spot || {};
light.spot.innerConeAngle = light.spot.innerConeAngle !== undefined ? light.spot.innerConeAngle : 0;
light.spot.outerConeAngle = light.spot.innerConeAngle !== undefined ? light.spot.innerConeAngle : Math.PI / 4.0;
// ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spot isn't required, no.

I'm not sure I follow what you're suggesting with your change. Are you just suggesting to get rid of the variable declarations within the case statement?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is the idea; i'm happy with or without that change.

var innerConeAngle = spot.innerConeAngle !== undefined ? spot.innerConeAngle : 0;
var outerConeAngle = spot.outerConeAngle !== undefined ? spot.outerConeAngle : Math.PI / 4.0;
lightNode.angle = outerConeAngle;
lightNode.penumbra = 1.0 - innerConeAngle / outerConeAngle;
lightNode.target.position.set( 0, 0, 1 );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target of a spot is 0, 0, 1 by default?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local direction of the glTF light is always +Z; the only way to rotate it is by rotating the object or its parents in the scene graph.

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 @@ -2546,7 +2532,8 @@ THREE.GLTFLoader = ( function () {

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

] ).then( function ( dependencies ) {

Expand Down
Loading