@openglobus/og 0.13.7 → 0.13.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/css/og.css +388 -129
- package/dist/@openglobus/og.css +1 -1
- package/dist/@openglobus/og.esm.js +2 -2
- package/dist/@openglobus/og.esm.js.map +1 -1
- package/dist/@openglobus/og.umd.js +2 -2
- package/dist/@openglobus/og.umd.js.map +1 -1
- package/package.json +20 -19
- package/src/og/Globe.js +15 -16
- package/src/og/Object3d.js +417 -0
- package/src/og/arial.js +1705 -1703
- package/src/og/camera/Camera.js +640 -640
- package/src/og/control/EarthCoordinates.js +1 -1
- package/src/og/control/GeoImageDragControl.js +102 -75
- package/src/og/control/LayerAnimation.js +383 -0
- package/src/og/control/LayerSwitcher.js +506 -159
- package/src/og/control/Lighting.js +27 -27
- package/src/og/control/MouseNavigation.js +460 -460
- package/src/og/control/RulerSwitcher.js +69 -0
- package/src/og/control/Sun.js +170 -170
- package/src/og/control/UIhelpers.js +146 -0
- package/src/og/control/ZoomControl.js +0 -2
- package/src/og/control/index.js +5 -1
- package/src/og/control/ruler/Ruler.js +43 -0
- package/src/og/control/ruler/RulerScene.js +374 -0
- package/src/og/control/visibleExtent/Segment.js +3 -5
- package/src/og/ellipsoid/Ellipsoid.js +19 -0
- package/src/og/ellipsoid/wgs84.js +1 -1
- package/src/og/entity/Entity.js +1 -1
- package/src/og/entity/GeoObject.js +1 -1
- package/src/og/entity/LabelHandler.js +6 -2
- package/src/og/entity/LabelWorker.js +38 -53
- package/src/og/layer/BaseGeoImage.js +347 -312
- package/src/og/layer/CanvasTiles.js +312 -290
- package/src/og/layer/GeoImage.js +222 -214
- package/src/og/layer/GeoVideo.js +291 -291
- package/src/og/layer/Layer.js +94 -70
- package/src/og/layer/Material.js +109 -109
- package/src/og/layer/Vector.js +81 -14
- package/src/og/layer/XYZ.js +23 -11
- package/src/og/light/LightSource.js +364 -363
- package/src/og/math/Vec3.js +1 -1
- package/src/og/math.js +6 -6
- package/src/og/quadTree/Node.js +8 -6
- package/src/og/renderer/Renderer.js +2 -3
- package/src/og/res/images.js +0 -2
- package/src/og/scene/Planet.js +106 -44
- package/src/og/segment/Segment.js +34 -64
- package/src/og/segment/Slice.js +1 -1
- package/src/og/shaders/drawnode.js +1 -1
- package/src/og/shaders/label.js +30 -42
- package/src/og/terrain/GlobusTerrain.js +31 -20
- package/src/og/terrain/MapboxTerrain.js +1 -1
- package/src/og/utils/BaseWorker.js +46 -0
- package/src/og/utils/FontAtlas.js +1 -2
- package/src/og/utils/GeoImageCreator.js +164 -161
- package/src/og/utils/Loader.js +187 -153
- package/src/og/utils/NormalMapCreator.js +403 -412
- package/src/og/utils/PlainSegmentWorker.js +29 -55
- package/src/og/utils/TerrainWorker.js +572 -589
- package/src/og/utils/VectorTileCreator.js +1 -1
- package/src/og/utils/functionComposition.js +13 -0
- package/src/og/webgl/Handler.js +42 -41
- package/src/og/webgl/ProgramController.js +143 -143
- package/types/Object3d.d.ts +22 -0
- package/types/arial.d.ts +1 -0
- package/types/camera/PlanetCamera.d.ts +4 -0
- package/types/control/GeoImageDragControl.d.ts +2 -0
- package/types/control/LayerAnimation.d.ts +73 -0
- package/types/control/LayerSwitcher.d.ts +55 -11
- package/types/control/MouseNavigation.d.ts +1 -0
- package/types/control/MouseWheelZoomControl.d.ts +1 -0
- package/types/control/Sun.d.ts +2 -1
- package/types/control/TouchNavigation.d.ts +1 -0
- package/types/control/UIhelpers.d.ts +13 -0
- package/types/control/index.d.ts +3 -1
- package/types/control/ruler/Ruler.d.ts +13 -0
- package/types/control/ruler/RulerScene.d.ts +48 -0
- package/types/ellipsoid/Ellipsoid.d.ts +8 -0
- package/types/entity/LabelHandler.d.ts +2 -0
- package/types/entity/LabelWorker.d.ts +5 -7
- package/types/layer/BaseGeoImage.d.ts +9 -1
- package/types/layer/CanvasTiles.d.ts +5 -1
- package/types/layer/GeoImage.d.ts +1 -0
- package/types/layer/GeoTexture2d.d.ts +1 -0
- package/types/layer/Layer.d.ts +28 -32
- package/types/layer/Vector.d.ts +9 -0
- package/types/layer/WMS.d.ts +1 -0
- package/types/layer/XYZ.d.ts +8 -5
- package/types/math.d.ts +2 -2
- package/types/quadTree/EntityCollectionNode.d.ts +7 -0
- package/types/quadTree/Node.d.ts +1 -2
- package/types/renderer/Renderer.d.ts +1 -1
- package/types/renderer/RendererEvents.d.ts +16 -0
- package/types/res/images.d.ts +0 -1
- package/types/scene/Planet.d.ts +21 -6
- package/types/segment/SegmentLonLat.d.ts +2 -0
- package/types/terrain/BilTerrain.d.ts +6 -0
- package/types/terrain/GlobusTerrain.d.ts +7 -0
- package/types/terrain/MapboxTerrain.d.ts +8 -0
- package/types/utils/BaseWorker.d.ts +14 -0
- package/types/utils/Loader.d.ts +4 -1
- package/types/utils/PlainSegmentWorker.d.ts +4 -6
- package/types/utils/TerrainWorker.d.ts +4 -6
- package/types/utils/functionComposition.d.ts +5 -0
- package/types/webgl/Handler.d.ts +4 -1
|
@@ -1,363 +1,364 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module og/light/LightSource
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
import { Vec3 } from "../math/Vec3.js";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Represents basic light source.
|
|
11
|
-
* @class
|
|
12
|
-
* @param {string} [name] - Light source name.
|
|
13
|
-
* @param {Object} [params] - Light parameters:
|
|
14
|
-
* @param {Vec3} [params.position] - Light source position if it is a point light, otherwise it is a light direction vector.
|
|
15
|
-
* @param {Vec3} [params.ambient] - Ambient RGB color.
|
|
16
|
-
* @param {Vec3} [params.diffuse] - Diffuse RGB color.
|
|
17
|
-
* @param {Vec3} [params.specular] - Specular RGB color.
|
|
18
|
-
* @param {number} [params.shininess] - Specular shininess.
|
|
19
|
-
*/
|
|
20
|
-
class LightSource {
|
|
21
|
-
static get _staticCounter() {
|
|
22
|
-
if (!this._counter && this._counter !== 0) {
|
|
23
|
-
this._counter = 0;
|
|
24
|
-
}
|
|
25
|
-
return this._counter;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static set _staticCounter(n) {
|
|
29
|
-
this._counter = n;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
constructor(name, params) {
|
|
33
|
-
params = params || {};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Light name.
|
|
37
|
-
* @protected
|
|
38
|
-
* @type {string}
|
|
39
|
-
*/
|
|
40
|
-
this._name = name || "light_" + LightSource._staticCounter++;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Render node where light is shines.
|
|
44
|
-
* @protected
|
|
45
|
-
* @type {RenderNode}
|
|
46
|
-
*/
|
|
47
|
-
this._renderNode = null;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Light position.
|
|
51
|
-
* @protected
|
|
52
|
-
* @type {Vec3}
|
|
53
|
-
*/
|
|
54
|
-
this._position = params.position || new Vec3();
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* True if the light is directional.
|
|
58
|
-
* @public
|
|
59
|
-
* @type {boolean}
|
|
60
|
-
*/
|
|
61
|
-
this.directional = params.derectional != undefined ? params.derectional : true;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Ambient color.
|
|
65
|
-
* @protected
|
|
66
|
-
* @type {Vec3}
|
|
67
|
-
*/
|
|
68
|
-
this._ambient = params.ambient || new Vec3();
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Diffuse color.
|
|
72
|
-
* @protected
|
|
73
|
-
* @type {Vec3}
|
|
74
|
-
*/
|
|
75
|
-
this._diffuse = params.diffuse || new Vec3(0.8, 0.8, 0.8);
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Specular color.
|
|
79
|
-
* @protected
|
|
80
|
-
* @type {Vec3}
|
|
81
|
-
*/
|
|
82
|
-
this._specular = params.specular || new Vec3(0.18, 0.18, 0.18);
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Shininess.
|
|
86
|
-
* @protected
|
|
87
|
-
* @type {number}
|
|
88
|
-
*/
|
|
89
|
-
this._shininess = params.shininess != undefined ? params.shininess : 3.3;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Light activity.
|
|
93
|
-
* @protected
|
|
94
|
-
* @type {boolean}
|
|
95
|
-
*/
|
|
96
|
-
this._active = true;
|
|
97
|
-
|
|
98
|
-
this._tempAmbient = this._ambient.clone();
|
|
99
|
-
this._tempDiffuse = this._diffuse.clone();
|
|
100
|
-
this._tempSpecular = this._specular.clone();
|
|
101
|
-
this._tempShininess = this._shininess;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Creates clone of the current light object.
|
|
106
|
-
* @todo: TODO
|
|
107
|
-
* @public
|
|
108
|
-
* @returns {LightSource}
|
|
109
|
-
*/
|
|
110
|
-
clone() {
|
|
111
|
-
// TODO
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Set light activity. If activity is false the light doesn't shine.
|
|
116
|
-
* @public
|
|
117
|
-
* @param {boolean} active - Light activity.
|
|
118
|
-
*/
|
|
119
|
-
setActive(active) {
|
|
120
|
-
if (active && !this._active) {
|
|
121
|
-
var rn = this._renderNode;
|
|
122
|
-
if (rn) {
|
|
123
|
-
var index = rn._lightsNames.indexOf(this._name);
|
|
124
|
-
this._shininess = rn._lightsParamsf[index] = this._tempShininess;
|
|
125
|
-
if (index != -1) {
|
|
126
|
-
index *= 9;
|
|
127
|
-
this._ambient.x = rn._lightsParamsv[index] = this._tempAmbient.x;
|
|
128
|
-
this._ambient.y = rn._lightsParamsv[index + 1] = this._tempAmbient.y;
|
|
129
|
-
this._ambient.z = rn._lightsParamsv[index + 2] = this._tempAmbient.z;
|
|
130
|
-
this._diffuse.x = rn._lightsParamsv[index + 3] = this._tempDiffuse.x;
|
|
131
|
-
this._diffuse.y = rn._lightsParamsv[index + 4] = this._tempDiffuse.y;
|
|
132
|
-
this._diffuse.z = rn._lightsParamsv[index + 5] = this._tempDiffuse.z;
|
|
133
|
-
this._specular.x = rn._lightsParamsv[index + 6] = this._tempSpecular.x;
|
|
134
|
-
this._specular.y = rn._lightsParamsv[index + 7] = this._tempSpecular.y;
|
|
135
|
-
this._specular.z = rn._lightsParamsv[index + 8] = this._tempSpecular.z;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
this._active = true;
|
|
139
|
-
} else if (!active && this._active) {
|
|
140
|
-
this._tempAmbient = this._ambient.clone();
|
|
141
|
-
this._tempDiffuse = this._diffuse.clone();
|
|
142
|
-
this._tempSpecular = this._specular.clone();
|
|
143
|
-
this._tempShininess = this._shininess;
|
|
144
|
-
this.setBlack();
|
|
145
|
-
this._active = false;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Gets light activity.
|
|
151
|
-
* @public
|
|
152
|
-
* @returns {boolean}
|
|
153
|
-
*/
|
|
154
|
-
isActive() {
|
|
155
|
-
return this._active;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Set light source position, or if it is a directional type sets light direction vector.
|
|
160
|
-
* @public
|
|
161
|
-
* @param {Vec3} position - Light position or direction vector.
|
|
162
|
-
* @returns {LightSource}
|
|
163
|
-
*/
|
|
164
|
-
setPosition3v(position) {
|
|
165
|
-
this._position.x = position.x;
|
|
166
|
-
this._position.y = position.y;
|
|
167
|
-
this._position.z = position.z;
|
|
168
|
-
return this;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Set light source position, or if it is a directional type sets light direction vector.
|
|
173
|
-
* @public
|
|
174
|
-
* @param {Vec3} position - Light position or direction vector.
|
|
175
|
-
* @returns {LightSource}
|
|
176
|
-
*/
|
|
177
|
-
setPosition(x, y, z) {
|
|
178
|
-
this._position.x = x;
|
|
179
|
-
this._position.y = y;
|
|
180
|
-
this._position.z = z;
|
|
181
|
-
return this;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Returns light source position, or if it is a directional type sets light direction vector.
|
|
186
|
-
* @public
|
|
187
|
-
* @returns {Vec3} - Light source position/direction.
|
|
188
|
-
*/
|
|
189
|
-
getPosition() {
|
|
190
|
-
return this._position.clone();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Set ambient color.
|
|
195
|
-
* @public
|
|
196
|
-
* @param {Vec3} rgb - Ambient color.
|
|
197
|
-
* @returns {LightSource}
|
|
198
|
-
*/
|
|
199
|
-
setAmbient3v(rgb) {
|
|
200
|
-
return this.setAmbient(rgb.x, rgb.y, rgb.z);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Set diffuse color.
|
|
205
|
-
* @public
|
|
206
|
-
* @param {Vec3} rgb - Diffuse color.
|
|
207
|
-
* @returns {LightSource}
|
|
208
|
-
*/
|
|
209
|
-
setDiffuse3v(rgb) {
|
|
210
|
-
return this.setDiffuse(rgb.x, rgb.y, rgb.z);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Set specular color.
|
|
215
|
-
* @public
|
|
216
|
-
* @param {Vec3} rgb - Specular color.
|
|
217
|
-
* @returns {LightSource}
|
|
218
|
-
*/
|
|
219
|
-
setSpecular3v(rgb) {
|
|
220
|
-
return this.setSpecular(rgb.x, rgb.y, rgb.z);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Set ambient color.
|
|
225
|
-
* @public
|
|
226
|
-
* @param {Vec3} rgb - Ambient color.
|
|
227
|
-
* @returns {LightSource}
|
|
228
|
-
*/
|
|
229
|
-
setAmbient(r, g, b) {
|
|
230
|
-
this._ambient.set(r, g, b);
|
|
231
|
-
var rn = this._renderNode;
|
|
232
|
-
if (rn) {
|
|
233
|
-
var index = 9 * rn._lightsNames.indexOf(this._name);
|
|
234
|
-
if (index != -1) {
|
|
235
|
-
rn._lightsParamsv[index] = r;
|
|
236
|
-
rn._lightsParamsv[index + 1] = g;
|
|
237
|
-
rn._lightsParamsv[index + 2] = b;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return this;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Set diffuse color.
|
|
245
|
-
* @public
|
|
246
|
-
* @returns {LightSource}
|
|
247
|
-
*/
|
|
248
|
-
setDiffuse(r, g, b) {
|
|
249
|
-
this._diffuse.set(r, g, b);
|
|
250
|
-
var rn = this._renderNode;
|
|
251
|
-
if (rn) {
|
|
252
|
-
var index = 9 * rn._lightsNames.indexOf(this._name);
|
|
253
|
-
if (index != -1) {
|
|
254
|
-
rn._lightsParamsv[index + 3] = r;
|
|
255
|
-
rn._lightsParamsv[index + 4] = g;
|
|
256
|
-
rn._lightsParamsv[index + 5] = b;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return this;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Set specular color.
|
|
264
|
-
* @public
|
|
265
|
-
* @returns {LightSource}
|
|
266
|
-
*/
|
|
267
|
-
setSpecular(r, g, b) {
|
|
268
|
-
this._specular.set(r, g, b);
|
|
269
|
-
var rn = this._renderNode;
|
|
270
|
-
if (rn) {
|
|
271
|
-
var index = 9 * rn._lightsNames.indexOf(this._name);
|
|
272
|
-
if (index != -1) {
|
|
273
|
-
rn._lightsParamsv[index + 6] = r;
|
|
274
|
-
rn._lightsParamsv[index + 7] = g;
|
|
275
|
-
rn._lightsParamsv[index + 8] = b;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return this;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Set material shininess.
|
|
283
|
-
* @public
|
|
284
|
-
* @returns {LightSource}
|
|
285
|
-
*/
|
|
286
|
-
setShininess(shininess) {
|
|
287
|
-
this._shininess = shininess;
|
|
288
|
-
var rn = this._renderNode;
|
|
289
|
-
if (rn) {
|
|
290
|
-
var index = rn._lightsNames.indexOf(this._name);
|
|
291
|
-
if (index != -1) {
|
|
292
|
-
rn._lightsParamsf[index] = shininess;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return this;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Sets light to black.
|
|
300
|
-
* @public
|
|
301
|
-
* @returns {LightSource}
|
|
302
|
-
*/
|
|
303
|
-
setBlack() {
|
|
304
|
-
this._ambient.clear();
|
|
305
|
-
this._diffuse.clear();
|
|
306
|
-
this._specular.clear();
|
|
307
|
-
this._shininess = 0;
|
|
308
|
-
var rn = this._renderNode;
|
|
309
|
-
if (rn) {
|
|
310
|
-
var index = 9 * rn._lightsNames.indexOf(this._name);
|
|
311
|
-
if (index != -1) {
|
|
312
|
-
rn._lightsParamsv[index] =
|
|
313
|
-
rn._lightsParamsv[index + 1] =
|
|
314
|
-
rn._lightsParamsv[index + 2] =
|
|
315
|
-
rn._lightsParamsv[index + 3] =
|
|
316
|
-
rn._lightsParamsv[index + 4] =
|
|
317
|
-
rn._lightsParamsv[index + 5] =
|
|
318
|
-
rn._lightsParamsv[index + 6] =
|
|
319
|
-
rn._lightsParamsv[index + 7] =
|
|
320
|
-
rn._lightsParamsv[index + 8] =
|
|
321
|
-
0;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return this;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Adds current light to the render node scene.
|
|
329
|
-
* @public
|
|
330
|
-
* @param {RenderNode} renderNode - Render node scene.
|
|
331
|
-
* @returns {LightSource}
|
|
332
|
-
*/
|
|
333
|
-
addTo(renderNode) {
|
|
334
|
-
this._renderNode = renderNode;
|
|
335
|
-
renderNode._lights.push(this);
|
|
336
|
-
renderNode._lightsNames.push(this._name);
|
|
337
|
-
renderNode._lightsParamsf.push(this._shininess);
|
|
338
|
-
renderNode._lightsParamsv.push.apply(renderNode._lightsParamsv, this._ambient.toVec());
|
|
339
|
-
renderNode._lightsParamsv.push.apply(renderNode._lightsParamsv, this._diffuse.toVec());
|
|
340
|
-
renderNode._lightsParamsv.push.apply(renderNode._lightsParamsv, this._specular.toVec());
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
*
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
rn.
|
|
355
|
-
rn.
|
|
356
|
-
rn.
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module og/light/LightSource
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
import { Vec3 } from "../math/Vec3.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Represents basic light source.
|
|
11
|
+
* @class
|
|
12
|
+
* @param {string} [name] - Light source name.
|
|
13
|
+
* @param {Object} [params] - Light parameters:
|
|
14
|
+
* @param {Vec3} [params.position] - Light source position if it is a point light, otherwise it is a light direction vector.
|
|
15
|
+
* @param {Vec3} [params.ambient] - Ambient RGB color.
|
|
16
|
+
* @param {Vec3} [params.diffuse] - Diffuse RGB color.
|
|
17
|
+
* @param {Vec3} [params.specular] - Specular RGB color.
|
|
18
|
+
* @param {number} [params.shininess] - Specular shininess.
|
|
19
|
+
*/
|
|
20
|
+
class LightSource {
|
|
21
|
+
static get _staticCounter() {
|
|
22
|
+
if (!this._counter && this._counter !== 0) {
|
|
23
|
+
this._counter = 0;
|
|
24
|
+
}
|
|
25
|
+
return this._counter;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static set _staticCounter(n) {
|
|
29
|
+
this._counter = n;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
constructor(name, params) {
|
|
33
|
+
params = params || {};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Light name.
|
|
37
|
+
* @protected
|
|
38
|
+
* @type {string}
|
|
39
|
+
*/
|
|
40
|
+
this._name = name || "light_" + LightSource._staticCounter++;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Render node where light is shines.
|
|
44
|
+
* @protected
|
|
45
|
+
* @type {RenderNode}
|
|
46
|
+
*/
|
|
47
|
+
this._renderNode = null;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Light position.
|
|
51
|
+
* @protected
|
|
52
|
+
* @type {Vec3}
|
|
53
|
+
*/
|
|
54
|
+
this._position = params.position || new Vec3();
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* True if the light is directional.
|
|
58
|
+
* @public
|
|
59
|
+
* @type {boolean}
|
|
60
|
+
*/
|
|
61
|
+
this.directional = params.derectional != undefined ? params.derectional : true;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Ambient color.
|
|
65
|
+
* @protected
|
|
66
|
+
* @type {Vec3}
|
|
67
|
+
*/
|
|
68
|
+
this._ambient = params.ambient || new Vec3();
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Diffuse color.
|
|
72
|
+
* @protected
|
|
73
|
+
* @type {Vec3}
|
|
74
|
+
*/
|
|
75
|
+
this._diffuse = params.diffuse || new Vec3(0.8, 0.8, 0.8);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Specular color.
|
|
79
|
+
* @protected
|
|
80
|
+
* @type {Vec3}
|
|
81
|
+
*/
|
|
82
|
+
this._specular = params.specular || new Vec3(0.18, 0.18, 0.18);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Shininess.
|
|
86
|
+
* @protected
|
|
87
|
+
* @type {number}
|
|
88
|
+
*/
|
|
89
|
+
this._shininess = params.shininess != undefined ? params.shininess : 3.3;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Light activity.
|
|
93
|
+
* @protected
|
|
94
|
+
* @type {boolean}
|
|
95
|
+
*/
|
|
96
|
+
this._active = true;
|
|
97
|
+
|
|
98
|
+
this._tempAmbient = this._ambient.clone();
|
|
99
|
+
this._tempDiffuse = this._diffuse.clone();
|
|
100
|
+
this._tempSpecular = this._specular.clone();
|
|
101
|
+
this._tempShininess = this._shininess;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Creates clone of the current light object.
|
|
106
|
+
* @todo: TODO
|
|
107
|
+
* @public
|
|
108
|
+
* @returns {LightSource}
|
|
109
|
+
*/
|
|
110
|
+
clone() {
|
|
111
|
+
// TODO
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Set light activity. If activity is false the light doesn't shine.
|
|
116
|
+
* @public
|
|
117
|
+
* @param {boolean} active - Light activity.
|
|
118
|
+
*/
|
|
119
|
+
setActive(active) {
|
|
120
|
+
if (active && !this._active) {
|
|
121
|
+
var rn = this._renderNode;
|
|
122
|
+
if (rn) {
|
|
123
|
+
var index = rn._lightsNames.indexOf(this._name);
|
|
124
|
+
this._shininess = rn._lightsParamsf[index] = this._tempShininess;
|
|
125
|
+
if (index != -1) {
|
|
126
|
+
index *= 9;
|
|
127
|
+
this._ambient.x = rn._lightsParamsv[index] = this._tempAmbient.x;
|
|
128
|
+
this._ambient.y = rn._lightsParamsv[index + 1] = this._tempAmbient.y;
|
|
129
|
+
this._ambient.z = rn._lightsParamsv[index + 2] = this._tempAmbient.z;
|
|
130
|
+
this._diffuse.x = rn._lightsParamsv[index + 3] = this._tempDiffuse.x;
|
|
131
|
+
this._diffuse.y = rn._lightsParamsv[index + 4] = this._tempDiffuse.y;
|
|
132
|
+
this._diffuse.z = rn._lightsParamsv[index + 5] = this._tempDiffuse.z;
|
|
133
|
+
this._specular.x = rn._lightsParamsv[index + 6] = this._tempSpecular.x;
|
|
134
|
+
this._specular.y = rn._lightsParamsv[index + 7] = this._tempSpecular.y;
|
|
135
|
+
this._specular.z = rn._lightsParamsv[index + 8] = this._tempSpecular.z;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
this._active = true;
|
|
139
|
+
} else if (!active && this._active) {
|
|
140
|
+
this._tempAmbient = this._ambient.clone();
|
|
141
|
+
this._tempDiffuse = this._diffuse.clone();
|
|
142
|
+
this._tempSpecular = this._specular.clone();
|
|
143
|
+
this._tempShininess = this._shininess;
|
|
144
|
+
this.setBlack();
|
|
145
|
+
this._active = false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Gets light activity.
|
|
151
|
+
* @public
|
|
152
|
+
* @returns {boolean}
|
|
153
|
+
*/
|
|
154
|
+
isActive() {
|
|
155
|
+
return this._active;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Set light source position, or if it is a directional type sets light direction vector.
|
|
160
|
+
* @public
|
|
161
|
+
* @param {Vec3} position - Light position or direction vector.
|
|
162
|
+
* @returns {LightSource}
|
|
163
|
+
*/
|
|
164
|
+
setPosition3v(position) {
|
|
165
|
+
this._position.x = position.x;
|
|
166
|
+
this._position.y = position.y;
|
|
167
|
+
this._position.z = position.z;
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Set light source position, or if it is a directional type sets light direction vector.
|
|
173
|
+
* @public
|
|
174
|
+
* @param {Vec3} position - Light position or direction vector.
|
|
175
|
+
* @returns {LightSource}
|
|
176
|
+
*/
|
|
177
|
+
setPosition(x, y, z) {
|
|
178
|
+
this._position.x = x;
|
|
179
|
+
this._position.y = y;
|
|
180
|
+
this._position.z = z;
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Returns light source position, or if it is a directional type sets light direction vector.
|
|
186
|
+
* @public
|
|
187
|
+
* @returns {Vec3} - Light source position/direction.
|
|
188
|
+
*/
|
|
189
|
+
getPosition() {
|
|
190
|
+
return this._position.clone();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Set ambient color.
|
|
195
|
+
* @public
|
|
196
|
+
* @param {Vec3} rgb - Ambient color.
|
|
197
|
+
* @returns {LightSource}
|
|
198
|
+
*/
|
|
199
|
+
setAmbient3v(rgb) {
|
|
200
|
+
return this.setAmbient(rgb.x, rgb.y, rgb.z);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Set diffuse color.
|
|
205
|
+
* @public
|
|
206
|
+
* @param {Vec3} rgb - Diffuse color.
|
|
207
|
+
* @returns {LightSource}
|
|
208
|
+
*/
|
|
209
|
+
setDiffuse3v(rgb) {
|
|
210
|
+
return this.setDiffuse(rgb.x, rgb.y, rgb.z);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Set specular color.
|
|
215
|
+
* @public
|
|
216
|
+
* @param {Vec3} rgb - Specular color.
|
|
217
|
+
* @returns {LightSource}
|
|
218
|
+
*/
|
|
219
|
+
setSpecular3v(rgb) {
|
|
220
|
+
return this.setSpecular(rgb.x, rgb.y, rgb.z);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Set ambient color.
|
|
225
|
+
* @public
|
|
226
|
+
* @param {Vec3} rgb - Ambient color.
|
|
227
|
+
* @returns {LightSource}
|
|
228
|
+
*/
|
|
229
|
+
setAmbient(r, g, b) {
|
|
230
|
+
this._ambient.set(r, g, b);
|
|
231
|
+
var rn = this._renderNode;
|
|
232
|
+
if (rn) {
|
|
233
|
+
var index = 9 * rn._lightsNames.indexOf(this._name);
|
|
234
|
+
if (index != -1) {
|
|
235
|
+
rn._lightsParamsv[index] = r;
|
|
236
|
+
rn._lightsParamsv[index + 1] = g;
|
|
237
|
+
rn._lightsParamsv[index + 2] = b;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Set diffuse color.
|
|
245
|
+
* @public
|
|
246
|
+
* @returns {LightSource}
|
|
247
|
+
*/
|
|
248
|
+
setDiffuse(r, g, b) {
|
|
249
|
+
this._diffuse.set(r, g, b);
|
|
250
|
+
var rn = this._renderNode;
|
|
251
|
+
if (rn) {
|
|
252
|
+
var index = 9 * rn._lightsNames.indexOf(this._name);
|
|
253
|
+
if (index != -1) {
|
|
254
|
+
rn._lightsParamsv[index + 3] = r;
|
|
255
|
+
rn._lightsParamsv[index + 4] = g;
|
|
256
|
+
rn._lightsParamsv[index + 5] = b;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Set specular color.
|
|
264
|
+
* @public
|
|
265
|
+
* @returns {LightSource}
|
|
266
|
+
*/
|
|
267
|
+
setSpecular(r, g, b) {
|
|
268
|
+
this._specular.set(r, g, b);
|
|
269
|
+
var rn = this._renderNode;
|
|
270
|
+
if (rn) {
|
|
271
|
+
var index = 9 * rn._lightsNames.indexOf(this._name);
|
|
272
|
+
if (index != -1) {
|
|
273
|
+
rn._lightsParamsv[index + 6] = r;
|
|
274
|
+
rn._lightsParamsv[index + 7] = g;
|
|
275
|
+
rn._lightsParamsv[index + 8] = b;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Set material shininess.
|
|
283
|
+
* @public
|
|
284
|
+
* @returns {LightSource}
|
|
285
|
+
*/
|
|
286
|
+
setShininess(shininess) {
|
|
287
|
+
this._shininess = shininess;
|
|
288
|
+
var rn = this._renderNode;
|
|
289
|
+
if (rn) {
|
|
290
|
+
var index = rn._lightsNames.indexOf(this._name);
|
|
291
|
+
if (index != -1) {
|
|
292
|
+
rn._lightsParamsf[index] = shininess;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return this;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Sets light to black.
|
|
300
|
+
* @public
|
|
301
|
+
* @returns {LightSource}
|
|
302
|
+
*/
|
|
303
|
+
setBlack() {
|
|
304
|
+
this._ambient.clear();
|
|
305
|
+
this._diffuse.clear();
|
|
306
|
+
this._specular.clear();
|
|
307
|
+
this._shininess = 0;
|
|
308
|
+
var rn = this._renderNode;
|
|
309
|
+
if (rn) {
|
|
310
|
+
var index = 9 * rn._lightsNames.indexOf(this._name);
|
|
311
|
+
if (index != -1) {
|
|
312
|
+
rn._lightsParamsv[index] =
|
|
313
|
+
rn._lightsParamsv[index + 1] =
|
|
314
|
+
rn._lightsParamsv[index + 2] =
|
|
315
|
+
rn._lightsParamsv[index + 3] =
|
|
316
|
+
rn._lightsParamsv[index + 4] =
|
|
317
|
+
rn._lightsParamsv[index + 5] =
|
|
318
|
+
rn._lightsParamsv[index + 6] =
|
|
319
|
+
rn._lightsParamsv[index + 7] =
|
|
320
|
+
rn._lightsParamsv[index + 8] =
|
|
321
|
+
0;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return this;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Adds current light to the render node scene.
|
|
329
|
+
* @public
|
|
330
|
+
* @param {RenderNode} renderNode - Render node scene.
|
|
331
|
+
* @returns {LightSource}
|
|
332
|
+
*/
|
|
333
|
+
addTo(renderNode) {
|
|
334
|
+
this._renderNode = renderNode;
|
|
335
|
+
renderNode._lights.push(this);
|
|
336
|
+
renderNode._lightsNames.push(this._name);
|
|
337
|
+
renderNode._lightsParamsf.push(this._shininess);
|
|
338
|
+
renderNode._lightsParamsv.push.apply(renderNode._lightsParamsv, this._ambient.toVec());
|
|
339
|
+
renderNode._lightsParamsv.push.apply(renderNode._lightsParamsv, this._diffuse.toVec());
|
|
340
|
+
renderNode._lightsParamsv.push.apply(renderNode._lightsParamsv, this._specular.toVec());
|
|
341
|
+
renderNode.transformLights();
|
|
342
|
+
return this;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Removes from render node scene.
|
|
347
|
+
* @public
|
|
348
|
+
*/
|
|
349
|
+
remove() {
|
|
350
|
+
var rn = this.renderNode;
|
|
351
|
+
if (rn) {
|
|
352
|
+
var li = rn.getLightById(this._name);
|
|
353
|
+
if (li != -1) {
|
|
354
|
+
rn._lights.splice(li, 1);
|
|
355
|
+
rn._lightsNames.splice(li, 1);
|
|
356
|
+
rn._lightsParamsf.splice(li, 1);
|
|
357
|
+
rn._lightsParamsv.splice(li, 9);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
this._renderNode = null;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export { LightSource };
|