Skip to content

Commit b69d7c7

Browse files
authored
Merge pull request #13341 from MiiBond/gltf_khr_lights_v2
Rough update to KHR_lights support to match current spec
2 parents 6234d0a + f45894b commit b69d7c7

File tree

5 files changed

+4583
-31
lines changed

5 files changed

+4583
-31
lines changed

examples/js/loaders/GLTFLoader.js

+15-28
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ THREE.GLTFLoader = ( function () {
252252

253253
case 'directional':
254254
lightNode = new THREE.DirectionalLight( color );
255-
lightNode.position.set( 0, 0, 1 );
255+
lightNode.target.position.set( 0, 0, 1 );
256+
lightNode.add( lightNode.target );
256257
break;
257258

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

262263
case 'spot':
263264
lightNode = new THREE.SpotLight( color );
264-
lightNode.position.set( 0, 0, 1 );
265+
// Handle spotlight properties.
266+
light.spot = light.spot || {};
267+
light.spot.innerConeAngle = light.spot.innerConeAngle !== undefined ? light.spot.innerConeAngle : 0;
268+
light.spot.outerConeAngle = light.spot.outerConeAngle !== undefined ? light.spot.outerConeAngle : Math.PI / 4.0;
269+
lightNode.angle = light.spot.outerConeAngle;
270+
lightNode.penumbra = 1.0 - light.spot.innerConeAngle / light.spot.outerConeAngle;
271+
lightNode.target.position.set( 0, 0, 1 );
272+
lightNode.add( lightNode.target );
265273
break;
266274

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

273281
if ( lightNode ) {
274282

275-
if ( light.constantAttenuation !== undefined ) {
283+
lightNode.decay = 2;
276284

277-
lightNode.intensity = light.constantAttenuation;
285+
if ( light.intensity !== undefined ) {
278286

279-
}
280-
281-
if ( light.linearAttenuation !== undefined ) {
282-
283-
lightNode.distance = 1 / light.linearAttenuation;
284-
285-
}
286-
287-
if ( light.quadraticAttenuation !== undefined ) {
288-
289-
lightNode.decay = light.quadraticAttenuation;
290-
291-
}
292-
293-
if ( light.fallOffAngle !== undefined ) {
294-
295-
lightNode.angle = light.fallOffAngle;
296-
297-
}
298-
299-
if ( light.fallOffExponent !== undefined ) {
300-
301-
console.warn( 'THREE.GLTFLoader:: light.fallOffExponent not currently supported.' );
287+
lightNode.intensity = light.intensity;
302288

303289
}
304290

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

25962582
'mesh',
25972583
'skin',
2598-
'camera'
2584+
'camera',
2585+
'light'
25992586

26002587
] ).then( function ( dependencies ) {
26012588

0 commit comments

Comments
 (0)