-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
/
Copy pathLight.js
95 lines (69 loc) · 1.94 KB
/
Light.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { Object3D } from '../core/Object3D.js';
import { Color } from '../math/Color.js';
/**
* Abstract base class for lights - all other light types inherit the
* properties and methods described here.
*
* @abstract
* @augments Object3D
*/
class Light extends Object3D {
/**
* Constructs a new light.
*
* @param {(number|Color|string)} [color=0xffffff] - The light's color.
* @param {number} [intensity=1] - The light's strength/intensity.
*/
constructor( color, intensity = 1 ) {
super();
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isLight = true;
this.type = 'Light';
/**
* The light's color.
*
* @type {Color}
*/
this.color = new Color( color );
/**
* The light's intensity.
*
* @type {number}
* @default 1
*/
this.intensity = intensity;
}
/**
* Frees the GPU-related resources allocated by this instance. Call this
* method whenever this instance is no longer used in your app.
*/
dispose() {
// Empty here in base class; some subclasses override.
}
copy( source, recursive ) {
super.copy( source, recursive );
this.color.copy( source.color );
this.intensity = source.intensity;
return this;
}
toJSON( meta ) {
const data = super.toJSON( meta );
data.object.color = this.color.getHex();
data.object.intensity = this.intensity;
if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
if ( this.distance !== undefined ) data.object.distance = this.distance;
if ( this.angle !== undefined ) data.object.angle = this.angle;
if ( this.decay !== undefined ) data.object.decay = this.decay;
if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
if ( this.target !== undefined ) data.object.target = this.target.uuid;
return data;
}
}
export { Light };