Skip to content

Commit c7d3c71

Browse files
committed
SpotLight: Convert to ES6 class
1 parent 7b518ca commit c7d3c71

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

src/lights/SpotLight.js

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,49 @@ import { Light } from './Light.js';
22
import { SpotLightShadow } from './SpotLightShadow.js';
33
import { Object3D } from '../core/Object3D.js';
44

5-
function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
5+
class SpotLight extends Light {
66

7-
Light.call( this, color, intensity );
7+
constructor( color, intensity, distance = 0, angle = Math.PI / 3, penumbra = 0, decay = 1 ) {
88

9-
this.type = 'SpotLight';
9+
super( color, intensity );
1010

11-
this.position.copy( Object3D.DefaultUp );
12-
this.updateMatrix();
11+
Object.defineProperty( this, 'isSpotLight', { value: true } );
1312

14-
this.target = new Object3D();
13+
this.type = 'SpotLight';
1514

16-
Object.defineProperty( this, 'power', {
17-
get: function () {
15+
this.position.copy( Object3D.DefaultUp );
16+
this.updateMatrix();
1817

19-
// intensity = power per solid angle.
20-
// ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
21-
return this.intensity * Math.PI;
18+
this.target = new Object3D();
2219

23-
},
24-
set: function ( power ) {
20+
this.distance = distance;
21+
this.angle = angle;
22+
this.penumbra = penumbra;
23+
this.decay = decay; // for physically correct lights, should be 2.
2524

26-
// intensity = power per solid angle.
27-
// ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
28-
this.intensity = power / Math.PI;
25+
this.shadow = new SpotLightShadow();
2926

30-
}
31-
} );
27+
}
3228

33-
this.distance = ( distance !== undefined ) ? distance : 0;
34-
this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
35-
this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
36-
this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
29+
get power() {
3730

38-
this.shadow = new SpotLightShadow();
31+
// intensity = power per solid angle.
32+
// ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
33+
return this.intensity * Math.PI;
3934

40-
}
35+
}
4136

42-
SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
37+
set power( power ) {
4338

44-
constructor: SpotLight,
39+
// intensity = power per solid angle.
40+
// ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
41+
this.intensity = power / Math.PI;
4542

46-
isSpotLight: true,
43+
}
4744

48-
copy: function ( source ) {
45+
copy( source ) {
4946

50-
Light.prototype.copy.call( this, source );
47+
super.copy( source );
5148

5249
this.distance = source.distance;
5350
this.angle = source.angle;
@@ -62,7 +59,6 @@ SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
6259

6360
}
6461

65-
} );
66-
62+
}
6763

6864
export { SpotLight };

0 commit comments

Comments
 (0)