@openglobus/og 0.13.8 → 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.
Files changed (85) hide show
  1. package/README.md +1 -1
  2. package/css/og.css +388 -129
  3. package/dist/@openglobus/og.css +1 -1
  4. package/dist/@openglobus/og.esm.js +2 -2
  5. package/dist/@openglobus/og.esm.js.map +1 -1
  6. package/dist/@openglobus/og.umd.js +2 -2
  7. package/dist/@openglobus/og.umd.js.map +1 -1
  8. package/package.json +20 -19
  9. package/src/og/Globe.js +15 -16
  10. package/src/og/Object3d.js +33 -0
  11. package/src/og/control/GeoImageDragControl.js +102 -75
  12. package/src/og/control/LayerAnimation.js +306 -38
  13. package/src/og/control/LayerSwitcher.js +506 -159
  14. package/src/og/control/Lighting.js +27 -27
  15. package/src/og/control/RulerSwitcher.js +69 -0
  16. package/src/og/control/UIhelpers.js +146 -0
  17. package/src/og/control/index.js +3 -1
  18. package/src/og/control/ruler/RulerScene.js +6 -2
  19. package/src/og/control/visibleExtent/Segment.js +2 -1
  20. package/src/og/ellipsoid/wgs84.js +1 -1
  21. package/src/og/entity/LabelHandler.js +5 -2
  22. package/src/og/entity/LabelWorker.js +38 -53
  23. package/src/og/layer/BaseGeoImage.js +347 -312
  24. package/src/og/layer/CanvasTiles.js +312 -290
  25. package/src/og/layer/GeoImage.js +222 -214
  26. package/src/og/layer/GeoVideo.js +291 -291
  27. package/src/og/layer/Layer.js +71 -30
  28. package/src/og/layer/Material.js +109 -109
  29. package/src/og/layer/Vector.js +1 -0
  30. package/src/og/layer/XYZ.js +20 -12
  31. package/src/og/light/LightSource.js +364 -363
  32. package/src/og/math.js +2 -2
  33. package/src/og/quadTree/Node.js +7 -5
  34. package/src/og/renderer/Renderer.js +1 -1
  35. package/src/og/scene/Planet.js +103 -42
  36. package/src/og/segment/Segment.js +34 -56
  37. package/src/og/segment/Slice.js +1 -1
  38. package/src/og/shaders/drawnode.js +1 -1
  39. package/src/og/terrain/GlobusTerrain.js +31 -20
  40. package/src/og/terrain/MapboxTerrain.js +1 -1
  41. package/src/og/utils/BaseWorker.js +46 -0
  42. package/src/og/utils/GeoImageCreator.js +164 -161
  43. package/src/og/utils/Loader.js +60 -33
  44. package/src/og/utils/NormalMapCreator.js +403 -412
  45. package/src/og/utils/PlainSegmentWorker.js +29 -55
  46. package/src/og/utils/TerrainWorker.js +572 -589
  47. package/src/og/utils/functionComposition.js +13 -0
  48. package/src/og/webgl/Handler.js +42 -41
  49. package/types/Object3d.d.ts +1 -0
  50. package/types/camera/PlanetCamera.d.ts +4 -0
  51. package/types/control/GeoImageDragControl.d.ts +2 -0
  52. package/types/control/LayerAnimation.d.ts +73 -0
  53. package/types/control/LayerSwitcher.d.ts +55 -11
  54. package/types/control/MouseNavigation.d.ts +1 -0
  55. package/types/control/MouseWheelZoomControl.d.ts +1 -0
  56. package/types/control/Sun.d.ts +1 -0
  57. package/types/control/TouchNavigation.d.ts +1 -0
  58. package/types/control/UIhelpers.d.ts +13 -0
  59. package/types/control/index.d.ts +2 -1
  60. package/types/entity/LabelHandler.d.ts +2 -0
  61. package/types/entity/LabelWorker.d.ts +5 -7
  62. package/types/layer/BaseGeoImage.d.ts +9 -1
  63. package/types/layer/CanvasTiles.d.ts +5 -1
  64. package/types/layer/GeoImage.d.ts +1 -0
  65. package/types/layer/GeoTexture2d.d.ts +1 -0
  66. package/types/layer/Layer.d.ts +5 -1
  67. package/types/layer/Vector.d.ts +7 -0
  68. package/types/layer/WMS.d.ts +1 -0
  69. package/types/layer/XYZ.d.ts +8 -6
  70. package/types/math.d.ts +1 -1
  71. package/types/quadTree/EntityCollectionNode.d.ts +7 -0
  72. package/types/quadTree/Node.d.ts +1 -2
  73. package/types/renderer/Renderer.d.ts +1 -1
  74. package/types/renderer/RendererEvents.d.ts +16 -0
  75. package/types/scene/Planet.d.ts +19 -4
  76. package/types/segment/SegmentLonLat.d.ts +2 -0
  77. package/types/terrain/BilTerrain.d.ts +6 -0
  78. package/types/terrain/GlobusTerrain.d.ts +7 -0
  79. package/types/terrain/MapboxTerrain.d.ts +8 -0
  80. package/types/utils/BaseWorker.d.ts +14 -0
  81. package/types/utils/Loader.d.ts +3 -1
  82. package/types/utils/PlainSegmentWorker.d.ts +4 -6
  83. package/types/utils/TerrainWorker.d.ts +4 -6
  84. package/types/utils/functionComposition.d.ts +5 -0
  85. 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
- return this;
342
- }
343
-
344
- /**
345
- * Removes from render node scene.
346
- * @public
347
- */
348
- remove() {
349
- var rn = this.renderNode;
350
- if (rn) {
351
- var li = rn.getLightById(this._name);
352
- if (li != -1) {
353
- rn._lights.splice(li, 1);
354
- rn._lightsNames.splice(li, 1);
355
- rn._lightsParamsf.splice(li, 1);
356
- rn._lightsParamsv.splice(li, 9);
357
- }
358
- }
359
- this._renderNode = null;
360
- }
361
- }
362
-
363
- export { LightSource };
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 };