@openglobus/og 0.12.4 → 0.13.0

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 (93) hide show
  1. package/README.md +0 -2
  2. package/dist/@openglobus/og.esm.js +2 -2
  3. package/dist/@openglobus/og.esm.js.map +1 -1
  4. package/dist/@openglobus/og.umd.js +2 -2
  5. package/dist/@openglobus/og.umd.js.map +1 -1
  6. package/package.json +7 -7
  7. package/src/og/Extent.js +3 -3
  8. package/src/og/Globe.js +277 -275
  9. package/src/og/ImageCanvas.js +3 -3
  10. package/src/og/LonLat.js +9 -9
  11. package/src/og/QueueArray.js +2 -2
  12. package/src/og/Rectangle.js +5 -5
  13. package/src/og/bv/Box.js +1 -1
  14. package/src/og/bv/Sphere.js +2 -2
  15. package/src/og/camera/Camera.js +1 -1
  16. package/src/og/camera/PlanetCamera.js +649 -646
  17. package/src/og/control/LayerSwitcher.js +1 -1
  18. package/src/og/control/MouseNavigation.js +22 -13
  19. package/src/og/control/MouseWheelZoomControl.js +2 -2
  20. package/src/og/control/ScaleControl.js +1 -1
  21. package/src/og/control/TouchNavigation.js +319 -319
  22. package/src/og/control/ZoomControl.js +132 -132
  23. package/src/og/control/visibleExtent/Segment.js +12 -12
  24. package/src/og/ellipsoid/Ellipsoid.js +577 -567
  25. package/src/og/entity/BillboardHandler.js +878 -1051
  26. package/src/og/entity/Entity.js +1 -1
  27. package/src/og/entity/EntityCollection.js +847 -857
  28. package/src/og/entity/GeoObjectHandler.js +2 -2
  29. package/src/og/entity/LabelHandler.js +888 -1040
  30. package/src/og/entity/LabelWorker.js +0 -6
  31. package/src/og/entity/PointCloud.js +495 -495
  32. package/src/og/entity/Polyline.js +2218 -2222
  33. package/src/og/entity/RayHandler.js +1 -1
  34. package/src/og/layer/CanvasTiles.js +6 -3
  35. package/src/og/layer/GeoImage.js +1 -1
  36. package/src/og/layer/KML.js +5 -5
  37. package/src/og/layer/Layer.js +800 -752
  38. package/src/og/layer/Vector.js +997 -1010
  39. package/src/og/layer/XYZ.js +359 -357
  40. package/src/og/math/Line2.js +4 -4
  41. package/src/og/math/Quat.js +2 -2
  42. package/src/og/math/Ray.js +2 -2
  43. package/src/og/math/Vec2.js +524 -524
  44. package/src/og/math/Vec3.js +900 -900
  45. package/src/og/math/Vec4.js +261 -261
  46. package/src/og/math.js +397 -398
  47. package/src/og/quadTree/EntityCollectionNode.js +389 -387
  48. package/src/og/renderer/Renderer.js +14 -20
  49. package/src/og/renderer/RendererEvents.js +1034 -1045
  50. package/src/og/scene/Planet.js +12 -9
  51. package/src/og/scene/RenderNode.js +347 -354
  52. package/src/og/segment/Segment.js +3 -1
  53. package/src/og/segment/SegmentLonLat.js +1 -4
  54. package/src/og/shaders/billboard.js +220 -204
  55. package/src/og/shaders/drawnode.js +603 -603
  56. package/src/og/shaders/label.js +596 -456
  57. package/src/og/shaders/polyline.js +365 -361
  58. package/src/og/terrain/MapboxTerrain.js +1 -1
  59. package/src/og/utils/FontAtlas.js +209 -200
  60. package/src/og/utils/GeoImageCreator.js +4 -5
  61. package/src/og/utils/TextureAtlas.js +4 -4
  62. package/src/og/utils/VectorTileCreator.js +414 -414
  63. package/src/og/utils/shared.js +1 -1
  64. package/src/og/webgl/Handler.js +28 -60
  65. package/src/og/webgl/Multisample.js +260 -260
  66. package/src/og/webgl/Program.js +411 -396
  67. package/types/bv/Box.d.ts +1 -1
  68. package/types/bv/Sphere.d.ts +1 -1
  69. package/types/camera/PlanetCamera.d.ts +3 -3
  70. package/types/control/LayerSwitcher.d.ts +1 -1
  71. package/types/ellipsoid/Ellipsoid.d.ts +9 -2
  72. package/types/entity/BillboardHandler.d.ts +0 -4
  73. package/types/entity/EntityCollection.d.ts +0 -8
  74. package/types/entity/LabelHandler.d.ts +0 -2
  75. package/types/entity/Polyline.d.ts +1 -1
  76. package/types/layer/KML.d.ts +11 -11
  77. package/types/layer/Layer.d.ts +4 -0
  78. package/types/layer/Vector.d.ts +1 -8
  79. package/types/math/Line2.d.ts +4 -4
  80. package/types/math/Ray.d.ts +2 -2
  81. package/types/math/Vec2.d.ts +1 -1
  82. package/types/math/Vec3.d.ts +1 -1
  83. package/types/math/Vec4.d.ts +2 -2
  84. package/types/math.d.ts +1 -1
  85. package/types/renderer/Renderer.d.ts +1 -1
  86. package/types/renderer/RendererEvents.d.ts +1 -1
  87. package/types/shaders/label.d.ts +1 -1
  88. package/types/utils/FontAtlas.d.ts +3 -2
  89. package/types/utils/TextureAtlas.d.ts +3 -3
  90. package/types/utils/VectorTileCreator.d.ts +4 -4
  91. package/types/utils/shared.d.ts +1 -1
  92. package/types/webgl/Handler.d.ts +6 -31
  93. package/types/webgl/Program.d.ts +2 -0
@@ -1,495 +1,495 @@
1
- /**
2
- * @module og/entity/PointCloud
3
- */
4
-
5
- "use strict";
6
-
7
- import { Vec3 } from "../math/Vec3.js";
8
- import { Vec4 } from "../math/Vec4.js";
9
-
10
- const COORDINATES_BUFFER = 0;
11
- const COLOR_BUFFER = 1;
12
- const PICKING_COLOR_BUFFER = 2;
13
-
14
- /**
15
- * PointCloud object.
16
- * @class
17
- * @param {*} [options] - Point cloud options:
18
- * @param {Array.<Array.<number>>} [options.points] - Points cartesian coordinates array,
19
- * where first three is cartesian coordinates, next fourth is a RGBA color, and last is an point properties.
20
- * @param {number} [options.pointSize] - Point screen size in pixels.
21
- * @param {number} [options.pickingDistance] - Point border picking size in screen pixels.
22
- * @param {boolean} [options.visibility] - Point cloud visibility.
23
- * @example <caption>Creates point cloud with two ten pixel size points</caption>
24
- * new og.Entity({
25
- * pointCloud: {
26
- * pointSize: 10,
27
- * points: [
28
- * [0, 0, 0, 255, 255, 255, 255, { 'name': 'White point' }],
29
- * [100, 100, 0, 255, 0, 0, 255, { 'name': 'Red point' }]
30
- * ]
31
- * }
32
- * });
33
- */
34
- class PointCloud {
35
- constructor(options) {
36
- options = options || {};
37
-
38
- /**
39
- * Object unic identifier.
40
- * @public
41
- * @readonly
42
- * @type {number}
43
- */
44
- this.id = PointCloud._staticCounter++;
45
-
46
- /**
47
- * Cloud visibility.
48
- * @public
49
- * @type {boolean}
50
- */
51
- this.visibility = options.visibility != undefined ? options.visibility : true;
52
-
53
- /**
54
- * Point screen size in pixels.
55
- * @public
56
- * @type {number}
57
- */
58
- this.pointSize = options.pointSize || 3;
59
-
60
- /**
61
- * Point picking border size in pixels.
62
- * @public
63
- * @type {number}
64
- */
65
- this.pickingDistance = options.pickingDistance || 0;
66
-
67
- /**
68
- * Parent collection render node.
69
- * @private
70
- * @type {RenderNode}
71
- */
72
- this._renderNode = null;
73
-
74
- /**
75
- * Entity instance that holds this point cloud.
76
- * @private
77
- * @type {Entity}
78
- */
79
- this._entity = null;
80
-
81
- /**
82
- * Points properties.
83
- * @private
84
- * @type {Array.<*>}
85
- */
86
- this._points = [];
87
-
88
- /**
89
- * Coordinates array.
90
- * @private
91
- * @type {Array.<number>}
92
- */
93
- this._coordinatesData = [];
94
-
95
- /**
96
- * Color array.
97
- * @private
98
- * @type {Array.<number>}
99
- */
100
- this._colorData = [];
101
-
102
- /**
103
- * Picking color array.
104
- * @private
105
- * @type {Array.<number>}
106
- */
107
- this._pickingColorData = [];
108
-
109
- this._coordinatesBuffer = null;
110
- this._colorBuffer = null;
111
- this._pickingColorBuffer = null;
112
-
113
- /**
114
- * Handler that stores and renders this object.
115
- * @private
116
- * @type {PointCloudHandler}
117
- */
118
- this._handler = null;
119
- this._handlerIndex = -1;
120
-
121
- this._buffersUpdateCallbacks = [];
122
- this._buffersUpdateCallbacks[COORDINATES_BUFFER] = this._createCoordinatesBuffer;
123
- this._buffersUpdateCallbacks[COLOR_BUFFER] = this._createColorBuffer;
124
- this._buffersUpdateCallbacks[PICKING_COLOR_BUFFER] = this._createPickingColorBuffer;
125
-
126
- this._changedBuffers = new Array(this._buffersUpdateCallbacks.length);
127
-
128
- this.setPoints(options.points);
129
- }
130
-
131
- static get _staticCounter() {
132
- if (!this._counter && this._counter !== 0) {
133
- this._counter = 0;
134
- }
135
- return this._counter;
136
- }
137
-
138
- static set _staticCounter(n) {
139
- this._counter = n;
140
- }
141
-
142
- /**
143
- * Clears point cloud data
144
- * @public
145
- */
146
- clear() {
147
- this._points.length = 0;
148
- this._points = [];
149
-
150
- this._coordinatesData.length = 0;
151
- this._coordinatesData = [];
152
-
153
- this._colorData.length = 0;
154
- this._colorData = [];
155
-
156
- this._pickingColorData.length = 0;
157
- this._pickingColorData = [];
158
-
159
- this._deleteBuffers();
160
- }
161
-
162
- /**
163
- * Set point cloud opacity.
164
- * @public
165
- * @param {number} opacity - Cloud opacity.
166
- */
167
- setOpacity(opacity) {
168
- this.opacity = opacity;
169
- }
170
-
171
- /**
172
- * Sets cloud visibility.
173
- * @public
174
- * @param {number} visibility - Visibility flag.
175
- */
176
- setVisibility(visibility) {
177
- this.visibility = visibility;
178
- }
179
-
180
- /**
181
- * @return {boolean} Point cloud visibily.
182
- */
183
- getVisibility() {
184
- return this.visibility;
185
- }
186
-
187
- /**
188
- * Assign rendering scene node.
189
- * @public
190
- * @param {RenderNode} renderNode - Assigned render node.
191
- */
192
- setRenderNode(renderNode) {
193
- this._renderNode = renderNode;
194
- this._setPickingColors();
195
- }
196
-
197
- /**
198
- * Removes from entity.
199
- * @public
200
- */
201
- remove() {
202
- this._entity = null;
203
- this._handler && this._handler.remove(this);
204
- }
205
-
206
- /**
207
- * Adds points to render.
208
- * @public
209
- * @param {Array.<Array<number>>} points - Point cloud array.
210
- * @example
211
- * var points = [[0, 0, 0, 255, 255, 255, 255, { 'name': 'White point' }], [100, 100, 0, 255, 0, 0, 255, { 'name': 'Red point' }]];
212
- */
213
- setPoints(points) {
214
- this.clear();
215
- for (var i = 0; i < points.length; i++) {
216
- var pi = points[i];
217
- var pos = new Vec3(pi[0], pi[1], pi[2]),
218
- col = new Vec4(pi[3], pi[4], pi[5], pi[6] == undefined ? 255.0 : pi[6]);
219
- this._coordinatesData.push(pos.x, pos.y, pos.z);
220
- this._colorData.push(col.x / 255.0, col.y / 255.0, col.z / 255.0, col.w / 255.0);
221
- var p = {
222
- _pickingColor: new Vec3(),
223
- _entityCollection: this._entity && this._entity._entityCollection,
224
- index: i,
225
- position: pos,
226
- color: col,
227
- pointCloud: this,
228
- properties: pi[7] || {}
229
- };
230
- this._points.push(p);
231
-
232
- if (this._renderNode) {
233
- this._renderNode.renderer.assignPickingColor(p);
234
- this._pickingColorData.push(
235
- p._pickingColor.x / 255.0,
236
- p._pickingColor.y / 255.0,
237
- p._pickingColor.z / 255.0,
238
- 1.0
239
- );
240
- }
241
- }
242
-
243
- this._changedBuffers[COORDINATES_BUFFER] = true;
244
- this._changedBuffers[COLOR_BUFFER] = true;
245
- this._changedBuffers[PICKING_COLOR_BUFFER] = true;
246
- }
247
-
248
- setPointPosition(index, x, y, z) {
249
- // TODO: ...
250
-
251
- this._changedBuffers[COORDINATES_BUFFER] = true;
252
- }
253
-
254
- setPointColor(index, r, g, b, a) {
255
- // TODO: ...
256
-
257
- this._changedBuffers[COLOR_BUFFER] = true;
258
- }
259
-
260
- addPoints(points) {
261
- // TODO: ...
262
-
263
- this._changedBuffers[COORDINATES_BUFFER] = true;
264
- this._changedBuffers[COLOR_BUFFER] = true;
265
- this._changedBuffers[PICKING_COLOR_BUFFER] = true;
266
- }
267
-
268
- addPoint(index, point) {
269
- // TODO: ...
270
-
271
- this._changedBuffers[COORDINATES_BUFFER] = true;
272
- this._changedBuffers[COLOR_BUFFER] = true;
273
- this._changedBuffers[PICKING_COLOR_BUFFER] = true;
274
- }
275
-
276
- /**
277
- * Returns specific point by index.
278
- * @public
279
- * @param {number} index - Point index.
280
- * @return {*} Specific point
281
- */
282
- getPoint(index) {
283
- return this._points[index];
284
- }
285
-
286
- removePoint(index) {
287
- // TODO: ...
288
-
289
- this._changedBuffers[COORDINATES_BUFFER] = true;
290
- this._changedBuffers[COLOR_BUFFER] = true;
291
- this._changedBuffers[PICKING_COLOR_BUFFER] = true;
292
- }
293
-
294
- insertPoint(index, point) {
295
- // TODO: ...
296
-
297
- this._changedBuffers[COORDINATES_BUFFER] = true;
298
- this._changedBuffers[COLOR_BUFFER] = true;
299
- this._changedBuffers[PICKING_COLOR_BUFFER] = true;
300
- }
301
-
302
- /**
303
- * Each point iterator.
304
- * @public
305
- * @param {callback} callback -
306
- */
307
- each(callback) {
308
- var i = this._points.length;
309
- while (i--) {
310
- callback && callback(this._points[i]);
311
- }
312
- }
313
-
314
- draw() {
315
- if (this.visibility && this._coordinatesData.length) {
316
- this._update();
317
-
318
- var rn = this._renderNode;
319
- var r = rn.renderer;
320
- var sh = r.handler.programs.pointCloud;
321
- var p = sh._program;
322
- var gl = r.handler.gl,
323
- sha = p.attributes,
324
- shu = p.uniforms;
325
-
326
- gl.polygonOffset(
327
- this._handler._entityCollection.polygonOffsetFactor,
328
- this._handler._entityCollection.polygonOffsetUnits
329
- );
330
-
331
- sh.activate();
332
-
333
- gl.uniformMatrix4fv(
334
- shu.projectionViewMatrix,
335
- false,
336
- r.activeCamera._projectionViewMatrix._m
337
- );
338
-
339
- gl.uniform1f(shu.opacity, this._handler._entityCollection._fadingOpacity);
340
-
341
- gl.uniform1f(shu.pointSize, this.pointSize);
342
-
343
- gl.bindBuffer(gl.ARRAY_BUFFER, this._coordinatesBuffer);
344
- gl.vertexAttribPointer(
345
- sha.coordinates,
346
- this._coordinatesBuffer.itemSize,
347
- gl.FLOAT,
348
- false,
349
- 0,
350
- 0
351
- );
352
-
353
- gl.bindBuffer(gl.ARRAY_BUFFER, this._colorBuffer);
354
- gl.vertexAttribPointer(sha.colors, this._colorBuffer.itemSize, gl.FLOAT, false, 0, 0);
355
-
356
- gl.drawArrays(gl.POINTS, 0, this._coordinatesBuffer.numItems);
357
- }
358
- }
359
-
360
- drawPicking() {
361
- if (this.visibility && this._coordinatesData.length) {
362
- var rn = this._renderNode;
363
- var r = rn.renderer;
364
- var sh = r.handler.programs.pointCloud;
365
- var p = sh._program;
366
- var gl = r.handler.gl,
367
- sha = p.attributes,
368
- shu = p.uniforms;
369
-
370
- sh.activate();
371
-
372
- gl.polygonOffset(
373
- this._handler._entityCollection.polygonOffsetFactor,
374
- this._handler._entityCollection.polygonOffsetUnits
375
- );
376
-
377
- gl.uniformMatrix4fv(
378
- shu.projectionViewMatrix,
379
- false,
380
- r.activeCamera._projectionViewMatrix._m
381
- );
382
-
383
- gl.uniform1f(shu.opacity, this._handler._entityCollection._fadingOpacity);
384
-
385
- gl.uniform1f(shu.pointSize, this.pointSize + this.pickingDistance);
386
-
387
- gl.bindBuffer(gl.ARRAY_BUFFER, this._coordinatesBuffer);
388
- gl.vertexAttribPointer(
389
- sha.coordinates,
390
- this._coordinatesBuffer.itemSize,
391
- gl.FLOAT,
392
- false,
393
- 0,
394
- 0
395
- );
396
-
397
- gl.bindBuffer(gl.ARRAY_BUFFER, this._pickingColorBuffer);
398
- gl.vertexAttribPointer(
399
- sha.colors,
400
- this._pickingColorBuffer.itemSize,
401
- gl.FLOAT,
402
- false,
403
- 0,
404
- 0
405
- );
406
-
407
- gl.drawArrays(gl.POINTS, 0, this._coordinatesBuffer.numItems);
408
- }
409
- }
410
-
411
- /**
412
- * Update gl buffers.
413
- * @private
414
- */
415
- _update() {
416
- if (this._renderNode) {
417
- var i = this._changedBuffers.length;
418
- while (i--) {
419
- if (this._changedBuffers[i]) {
420
- this._buffersUpdateCallbacks[i].call(this);
421
- this._changedBuffers[i] = false;
422
- }
423
- }
424
- }
425
- }
426
-
427
- /**
428
- * Delete buffers
429
- * @private
430
- */
431
- _deleteBuffers() {
432
- if (this._renderNode) {
433
- var r = this._renderNode.renderer,
434
- gl = r.handler.gl;
435
-
436
- gl.deleteBuffer(this._coordinatesBuffer);
437
- gl.deleteBuffer(this._colorBuffer);
438
- gl.deleteBuffer(this._pickingColorBuffer);
439
- }
440
-
441
- this._coordinatesBuffer = null;
442
- this._colorBuffer = null;
443
- this._pickingColorBuffer = null;
444
- }
445
-
446
- _createCoordinatesBuffer() {
447
- var h = this._renderNode.renderer.handler;
448
- h.gl.deleteBuffer(this._coordinatesBuffer);
449
- this._coordinatesBuffer = h.createArrayBuffer(
450
- new Float32Array(this._coordinatesData),
451
- 3,
452
- this._coordinatesData.length / 3
453
- );
454
- }
455
-
456
- _createColorBuffer() {
457
- var h = this._renderNode.renderer.handler;
458
- h.gl.deleteBuffer(this._colorBuffer);
459
- this._colorBuffer = h.createArrayBuffer(
460
- new Float32Array(this._colorData),
461
- 4,
462
- this._colorData.length / 4
463
- );
464
- }
465
-
466
- _createPickingColorBuffer() {
467
- var h = this._renderNode.renderer.handler;
468
- h.gl.deleteBuffer(this._pickingColorBuffer);
469
- this._pickingColorBuffer = h.createArrayBuffer(
470
- new Float32Array(this._pickingColorData),
471
- 4,
472
- this._pickingColorData.length / 4
473
- );
474
- }
475
-
476
- _setPickingColors() {
477
- if (this._renderNode) {
478
- for (var i = 0; i < this._points.length; i++) {
479
- var p = this._points[i];
480
- p._entity = this._entity;
481
- p._entityCollection = this._entity._entityCollection;
482
- this._renderNode.renderer.assignPickingColor(p);
483
- this._pickingColorData.push(
484
- p._pickingColor.x / 255.0,
485
- p._pickingColor.y / 255.0,
486
- p._pickingColor.z / 255.0,
487
- 1.0
488
- );
489
- }
490
- this._changedBuffers[PICKING_COLOR_BUFFER] = true;
491
- }
492
- }
493
- }
494
-
495
- export { PointCloud };
1
+ /**
2
+ * @module og/entity/PointCloud
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import { Vec3 } from "../math/Vec3.js";
8
+ import { Vec4 } from "../math/Vec4.js";
9
+
10
+ const COORDINATES_BUFFER = 0;
11
+ const COLOR_BUFFER = 1;
12
+ const PICKING_COLOR_BUFFER = 2;
13
+
14
+ /**
15
+ * PointCloud object.
16
+ * @class
17
+ * @param {*} [options] - Point cloud options:
18
+ * @param {Array.<Array.<number>>} [options.points] - Points cartesian coordinates array,
19
+ * where first three is cartesian coordinates, next fourth is a RGBA color, and last is an point properties.
20
+ * @param {number} [options.pointSize] - Point screen size in pixels.
21
+ * @param {number} [options.pickingDistance] - Point border picking size in screen pixels.
22
+ * @param {boolean} [options.visibility] - Point cloud visibility.
23
+ * @example <caption>Creates point cloud with two ten pixel size points</caption>
24
+ * new og.Entity({
25
+ * pointCloud: {
26
+ * pointSize: 10,
27
+ * points: [
28
+ * [0, 0, 0, 255, 255, 255, 255, { 'name': 'White point' }],
29
+ * [100, 100, 0, 255, 0, 0, 255, { 'name': 'Red point' }]
30
+ * ]
31
+ * }
32
+ * });
33
+ */
34
+ class PointCloud {
35
+ constructor(options) {
36
+ options = options || {};
37
+
38
+ /**
39
+ * Object unic identifier.
40
+ * @public
41
+ * @readonly
42
+ * @type {number}
43
+ */
44
+ this.id = PointCloud._staticCounter++;
45
+
46
+ /**
47
+ * Cloud visibility.
48
+ * @public
49
+ * @type {boolean}
50
+ */
51
+ this.visibility = options.visibility != undefined ? options.visibility : true;
52
+
53
+ /**
54
+ * Point screen size in pixels.
55
+ * @public
56
+ * @type {number}
57
+ */
58
+ this.pointSize = options.pointSize || 3;
59
+
60
+ /**
61
+ * Point picking border size in pixels.
62
+ * @public
63
+ * @type {number}
64
+ */
65
+ this.pickingDistance = options.pickingDistance || 0;
66
+
67
+ /**
68
+ * Parent collection render node.
69
+ * @private
70
+ * @type {RenderNode}
71
+ */
72
+ this._renderNode = null;
73
+
74
+ /**
75
+ * Entity instance that holds this point cloud.
76
+ * @private
77
+ * @type {Entity}
78
+ */
79
+ this._entity = null;
80
+
81
+ /**
82
+ * Points properties.
83
+ * @private
84
+ * @type {Array.<*>}
85
+ */
86
+ this._points = [];
87
+
88
+ /**
89
+ * Coordinates array.
90
+ * @private
91
+ * @type {Array.<number>}
92
+ */
93
+ this._coordinatesData = [];
94
+
95
+ /**
96
+ * Color array.
97
+ * @private
98
+ * @type {Array.<number>}
99
+ */
100
+ this._colorData = [];
101
+
102
+ /**
103
+ * Picking color array.
104
+ * @private
105
+ * @type {Array.<number>}
106
+ */
107
+ this._pickingColorData = [];
108
+
109
+ this._coordinatesBuffer = null;
110
+ this._colorBuffer = null;
111
+ this._pickingColorBuffer = null;
112
+
113
+ /**
114
+ * Handler that stores and renders this object.
115
+ * @private
116
+ * @type {PointCloudHandler}
117
+ */
118
+ this._handler = null;
119
+ this._handlerIndex = -1;
120
+
121
+ this._buffersUpdateCallbacks = [];
122
+ this._buffersUpdateCallbacks[COORDINATES_BUFFER] = this._createCoordinatesBuffer;
123
+ this._buffersUpdateCallbacks[COLOR_BUFFER] = this._createColorBuffer;
124
+ this._buffersUpdateCallbacks[PICKING_COLOR_BUFFER] = this._createPickingColorBuffer;
125
+
126
+ this._changedBuffers = new Array(this._buffersUpdateCallbacks.length);
127
+
128
+ this.setPoints(options.points);
129
+ }
130
+
131
+ static get _staticCounter() {
132
+ if (!this._counter && this._counter !== 0) {
133
+ this._counter = 0;
134
+ }
135
+ return this._counter;
136
+ }
137
+
138
+ static set _staticCounter(n) {
139
+ this._counter = n;
140
+ }
141
+
142
+ /**
143
+ * Clears point cloud data
144
+ * @public
145
+ */
146
+ clear() {
147
+ this._points.length = 0;
148
+ this._points = [];
149
+
150
+ this._coordinatesData.length = 0;
151
+ this._coordinatesData = [];
152
+
153
+ this._colorData.length = 0;
154
+ this._colorData = [];
155
+
156
+ this._pickingColorData.length = 0;
157
+ this._pickingColorData = [];
158
+
159
+ this._deleteBuffers();
160
+ }
161
+
162
+ /**
163
+ * Set point cloud opacity.
164
+ * @public
165
+ * @param {number} opacity - Cloud opacity.
166
+ */
167
+ setOpacity(opacity) {
168
+ this.opacity = opacity;
169
+ }
170
+
171
+ /**
172
+ * Sets cloud visibility.
173
+ * @public
174
+ * @param {number} visibility - Visibility flag.
175
+ */
176
+ setVisibility(visibility) {
177
+ this.visibility = visibility;
178
+ }
179
+
180
+ /**
181
+ * @return {boolean} Point cloud visibily.
182
+ */
183
+ getVisibility() {
184
+ return this.visibility;
185
+ }
186
+
187
+ /**
188
+ * Assign rendering scene node.
189
+ * @public
190
+ * @param {RenderNode} renderNode - Assigned render node.
191
+ */
192
+ setRenderNode(renderNode) {
193
+ this._renderNode = renderNode;
194
+ this._setPickingColors();
195
+ }
196
+
197
+ /**
198
+ * Removes from entity.
199
+ * @public
200
+ */
201
+ remove() {
202
+ this._entity = null;
203
+ this._handler && this._handler.remove(this);
204
+ }
205
+
206
+ /**
207
+ * Adds points to render.
208
+ * @public
209
+ * @param {Array.<Array<number>>} points - Point cloud array.
210
+ * @example
211
+ * var points = [[0, 0, 0, 255, 255, 255, 255, { 'name': 'White point' }], [100, 100, 0, 255, 0, 0, 255, { 'name': 'Red point' }]];
212
+ */
213
+ setPoints(points) {
214
+ this.clear();
215
+ for (var i = 0; i < points.length; i++) {
216
+ var pi = points[i];
217
+ var pos = new Vec3(pi[0], pi[1], pi[2]),
218
+ col = new Vec4(pi[3], pi[4], pi[5], pi[6] == undefined ? 255.0 : pi[6]);
219
+ this._coordinatesData.push(pos.x, pos.y, pos.z);
220
+ this._colorData.push(col.x / 255.0, col.y / 255.0, col.z / 255.0, col.w / 255.0);
221
+ var p = {
222
+ _pickingColor: new Vec3(),
223
+ _entityCollection: this._entity && this._entity._entityCollection,
224
+ index: i,
225
+ position: pos,
226
+ color: col,
227
+ pointCloud: this,
228
+ properties: pi[7] || {}
229
+ };
230
+ this._points.push(p);
231
+
232
+ if (this._renderNode) {
233
+ this._renderNode.renderer.assignPickingColor(p);
234
+ this._pickingColorData.push(
235
+ p._pickingColor.x / 255.0,
236
+ p._pickingColor.y / 255.0,
237
+ p._pickingColor.z / 255.0,
238
+ 1.0
239
+ );
240
+ }
241
+ }
242
+
243
+ this._changedBuffers[COORDINATES_BUFFER] = true;
244
+ this._changedBuffers[COLOR_BUFFER] = true;
245
+ this._changedBuffers[PICKING_COLOR_BUFFER] = true;
246
+ }
247
+
248
+ setPointPosition(index, x, y, z) {
249
+ // TODO: ...
250
+
251
+ this._changedBuffers[COORDINATES_BUFFER] = true;
252
+ }
253
+
254
+ setPointColor(index, r, g, b, a) {
255
+ // TODO: ...
256
+
257
+ this._changedBuffers[COLOR_BUFFER] = true;
258
+ }
259
+
260
+ addPoints(points) {
261
+ // TODO: ...
262
+
263
+ this._changedBuffers[COORDINATES_BUFFER] = true;
264
+ this._changedBuffers[COLOR_BUFFER] = true;
265
+ this._changedBuffers[PICKING_COLOR_BUFFER] = true;
266
+ }
267
+
268
+ addPoint(index, point) {
269
+ // TODO: ...
270
+
271
+ this._changedBuffers[COORDINATES_BUFFER] = true;
272
+ this._changedBuffers[COLOR_BUFFER] = true;
273
+ this._changedBuffers[PICKING_COLOR_BUFFER] = true;
274
+ }
275
+
276
+ /**
277
+ * Returns specific point by index.
278
+ * @public
279
+ * @param {number} index - Point index.
280
+ * @return {*} Specific point
281
+ */
282
+ getPoint(index) {
283
+ return this._points[index];
284
+ }
285
+
286
+ removePoint(index) {
287
+ // TODO: ...
288
+
289
+ this._changedBuffers[COORDINATES_BUFFER] = true;
290
+ this._changedBuffers[COLOR_BUFFER] = true;
291
+ this._changedBuffers[PICKING_COLOR_BUFFER] = true;
292
+ }
293
+
294
+ insertPoint(index, point) {
295
+ // TODO: ...
296
+
297
+ this._changedBuffers[COORDINATES_BUFFER] = true;
298
+ this._changedBuffers[COLOR_BUFFER] = true;
299
+ this._changedBuffers[PICKING_COLOR_BUFFER] = true;
300
+ }
301
+
302
+ /**
303
+ * Each point iterator.
304
+ * @public
305
+ * @param {callback} callback -
306
+ */
307
+ each(callback) {
308
+ var i = this._points.length;
309
+ while (i--) {
310
+ callback && callback(this._points[i]);
311
+ }
312
+ }
313
+
314
+ draw() {
315
+ if (this.visibility && this._coordinatesData.length) {
316
+ this._update();
317
+
318
+ var rn = this._renderNode;
319
+ var r = rn.renderer;
320
+ var sh = r.handler.programs.pointCloud;
321
+ var p = sh._program;
322
+ var gl = r.handler.gl,
323
+ sha = p.attributes,
324
+ shu = p.uniforms;
325
+
326
+ // gl.polygonOffset(
327
+ // this._handler._entityCollection.polygonOffsetFactor,
328
+ // this._handler._entityCollection.polygonOffsetUnits
329
+ // );
330
+
331
+ sh.activate();
332
+
333
+ gl.uniformMatrix4fv(
334
+ shu.projectionViewMatrix,
335
+ false,
336
+ r.activeCamera._projectionViewMatrix._m
337
+ );
338
+
339
+ gl.uniform1f(shu.opacity, this._handler._entityCollection._fadingOpacity);
340
+
341
+ gl.uniform1f(shu.pointSize, this.pointSize);
342
+
343
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._coordinatesBuffer);
344
+ gl.vertexAttribPointer(
345
+ sha.coordinates,
346
+ this._coordinatesBuffer.itemSize,
347
+ gl.FLOAT,
348
+ false,
349
+ 0,
350
+ 0
351
+ );
352
+
353
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._colorBuffer);
354
+ gl.vertexAttribPointer(sha.colors, this._colorBuffer.itemSize, gl.FLOAT, false, 0, 0);
355
+
356
+ gl.drawArrays(gl.POINTS, 0, this._coordinatesBuffer.numItems);
357
+ }
358
+ }
359
+
360
+ drawPicking() {
361
+ if (this.visibility && this._coordinatesData.length) {
362
+ var rn = this._renderNode;
363
+ var r = rn.renderer;
364
+ var sh = r.handler.programs.pointCloud;
365
+ var p = sh._program;
366
+ var gl = r.handler.gl,
367
+ sha = p.attributes,
368
+ shu = p.uniforms;
369
+
370
+ sh.activate();
371
+
372
+ // gl.polygonOffset(
373
+ // this._handler._entityCollection.polygonOffsetFactor,
374
+ // this._handler._entityCollection.polygonOffsetUnits
375
+ // );
376
+
377
+ gl.uniformMatrix4fv(
378
+ shu.projectionViewMatrix,
379
+ false,
380
+ r.activeCamera._projectionViewMatrix._m
381
+ );
382
+
383
+ gl.uniform1f(shu.opacity, this._handler._entityCollection._fadingOpacity);
384
+
385
+ gl.uniform1f(shu.pointSize, this.pointSize + this.pickingDistance);
386
+
387
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._coordinatesBuffer);
388
+ gl.vertexAttribPointer(
389
+ sha.coordinates,
390
+ this._coordinatesBuffer.itemSize,
391
+ gl.FLOAT,
392
+ false,
393
+ 0,
394
+ 0
395
+ );
396
+
397
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._pickingColorBuffer);
398
+ gl.vertexAttribPointer(
399
+ sha.colors,
400
+ this._pickingColorBuffer.itemSize,
401
+ gl.FLOAT,
402
+ false,
403
+ 0,
404
+ 0
405
+ );
406
+
407
+ gl.drawArrays(gl.POINTS, 0, this._coordinatesBuffer.numItems);
408
+ }
409
+ }
410
+
411
+ /**
412
+ * Update gl buffers.
413
+ * @private
414
+ */
415
+ _update() {
416
+ if (this._renderNode) {
417
+ var i = this._changedBuffers.length;
418
+ while (i--) {
419
+ if (this._changedBuffers[i]) {
420
+ this._buffersUpdateCallbacks[i].call(this);
421
+ this._changedBuffers[i] = false;
422
+ }
423
+ }
424
+ }
425
+ }
426
+
427
+ /**
428
+ * Delete buffers
429
+ * @private
430
+ */
431
+ _deleteBuffers() {
432
+ if (this._renderNode) {
433
+ var r = this._renderNode.renderer,
434
+ gl = r.handler.gl;
435
+
436
+ gl.deleteBuffer(this._coordinatesBuffer);
437
+ gl.deleteBuffer(this._colorBuffer);
438
+ gl.deleteBuffer(this._pickingColorBuffer);
439
+ }
440
+
441
+ this._coordinatesBuffer = null;
442
+ this._colorBuffer = null;
443
+ this._pickingColorBuffer = null;
444
+ }
445
+
446
+ _createCoordinatesBuffer() {
447
+ var h = this._renderNode.renderer.handler;
448
+ h.gl.deleteBuffer(this._coordinatesBuffer);
449
+ this._coordinatesBuffer = h.createArrayBuffer(
450
+ new Float32Array(this._coordinatesData),
451
+ 3,
452
+ this._coordinatesData.length / 3
453
+ );
454
+ }
455
+
456
+ _createColorBuffer() {
457
+ var h = this._renderNode.renderer.handler;
458
+ h.gl.deleteBuffer(this._colorBuffer);
459
+ this._colorBuffer = h.createArrayBuffer(
460
+ new Float32Array(this._colorData),
461
+ 4,
462
+ this._colorData.length / 4
463
+ );
464
+ }
465
+
466
+ _createPickingColorBuffer() {
467
+ var h = this._renderNode.renderer.handler;
468
+ h.gl.deleteBuffer(this._pickingColorBuffer);
469
+ this._pickingColorBuffer = h.createArrayBuffer(
470
+ new Float32Array(this._pickingColorData),
471
+ 4,
472
+ this._pickingColorData.length / 4
473
+ );
474
+ }
475
+
476
+ _setPickingColors() {
477
+ if (this._renderNode) {
478
+ for (var i = 0; i < this._points.length; i++) {
479
+ var p = this._points[i];
480
+ p._entity = this._entity;
481
+ p._entityCollection = this._entity._entityCollection;
482
+ this._renderNode.renderer.assignPickingColor(p);
483
+ this._pickingColorData.push(
484
+ p._pickingColor.x / 255.0,
485
+ p._pickingColor.y / 255.0,
486
+ p._pickingColor.z / 255.0,
487
+ 1.0
488
+ );
489
+ }
490
+ this._changedBuffers[PICKING_COLOR_BUFFER] = true;
491
+ }
492
+ }
493
+ }
494
+
495
+ export { PointCloud };