UNPKG

943 BJavaScriptView Raw
1import { Light } from './Light.js';
2
3class RectAreaLight extends Light {
4
5 constructor( color, intensity, width = 10, height = 10 ) {
6
7 super( color, intensity );
8
9 this.type = 'RectAreaLight';
10
11 this.width = width;
12 this.height = height;
13
14 }
15
16 get power() {
17
18 // compute the light's luminous power (in lumens) from its intensity (in nits)
19 return this.intensity * this.width * this.height * Math.PI;
20
21 }
22
23 set power( power ) {
24
25 // set the light's intensity (in nits) from the desired luminous power (in lumens)
26 this.intensity = power / ( this.width * this.height * Math.PI );
27
28 }
29
30 copy( source ) {
31
32 super.copy( source );
33
34 this.width = source.width;
35 this.height = source.height;
36
37 return this;
38
39 }
40
41 toJSON( meta ) {
42
43 const data = super.toJSON( meta );
44
45 data.object.width = this.width;
46 data.object.height = this.height;
47
48 return data;
49
50 }
51
52}
53
54RectAreaLight.prototype.isRectAreaLight = true;
55
56export { RectAreaLight };