UNPKG

1.73 kBJavaScriptView Raw
1import { Light } from './Light.js';
2import { SpotLightShadow } from './SpotLightShadow.js';
3import { Object3D } from '../core/Object3D.js';
4
5/**
6 * @author alteredq / http://alteredqualia.com/
7 */
8
9function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
10
11 Light.call( this, color, intensity );
12
13 this.type = 'SpotLight';
14
15 this.position.copy( Object3D.DefaultUp );
16 this.updateMatrix();
17
18 this.target = new Object3D();
19
20 Object.defineProperty( this, 'power', {
21 get: function () {
22
23 // intensity = power per solid angle.
24 // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
25 return this.intensity * Math.PI;
26
27 },
28 set: function ( power ) {
29
30 // intensity = power per solid angle.
31 // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
32 this.intensity = power / Math.PI;
33
34 }
35 } );
36
37 this.distance = ( distance !== undefined ) ? distance : 0;
38 this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
39 this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
40 this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
41
42 this.shadow = new SpotLightShadow();
43
44}
45
46SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
47
48 constructor: SpotLight,
49
50 isSpotLight: true,
51
52 copy: function ( source ) {
53
54 Light.prototype.copy.call( this, source );
55
56 this.distance = source.distance;
57 this.angle = source.angle;
58 this.penumbra = source.penumbra;
59 this.decay = source.decay;
60
61 this.target = source.target.clone();
62
63 this.shadow = source.shadow.clone();
64
65 return this;
66
67 }
68
69} );
70
71
72export { SpotLight };