@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.
Files changed (106) 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 +417 -0
  11. package/src/og/arial.js +1705 -1703
  12. package/src/og/camera/Camera.js +640 -640
  13. package/src/og/control/EarthCoordinates.js +1 -1
  14. package/src/og/control/GeoImageDragControl.js +102 -75
  15. package/src/og/control/LayerAnimation.js +383 -0
  16. package/src/og/control/LayerSwitcher.js +506 -159
  17. package/src/og/control/Lighting.js +27 -27
  18. package/src/og/control/MouseNavigation.js +460 -460
  19. package/src/og/control/RulerSwitcher.js +69 -0
  20. package/src/og/control/Sun.js +170 -170
  21. package/src/og/control/UIhelpers.js +146 -0
  22. package/src/og/control/ZoomControl.js +0 -2
  23. package/src/og/control/index.js +5 -1
  24. package/src/og/control/ruler/Ruler.js +43 -0
  25. package/src/og/control/ruler/RulerScene.js +374 -0
  26. package/src/og/control/visibleExtent/Segment.js +3 -5
  27. package/src/og/ellipsoid/Ellipsoid.js +19 -0
  28. package/src/og/ellipsoid/wgs84.js +1 -1
  29. package/src/og/entity/Entity.js +1 -1
  30. package/src/og/entity/GeoObject.js +1 -1
  31. package/src/og/entity/LabelHandler.js +6 -2
  32. package/src/og/entity/LabelWorker.js +38 -53
  33. package/src/og/layer/BaseGeoImage.js +347 -312
  34. package/src/og/layer/CanvasTiles.js +312 -290
  35. package/src/og/layer/GeoImage.js +222 -214
  36. package/src/og/layer/GeoVideo.js +291 -291
  37. package/src/og/layer/Layer.js +94 -70
  38. package/src/og/layer/Material.js +109 -109
  39. package/src/og/layer/Vector.js +81 -14
  40. package/src/og/layer/XYZ.js +23 -11
  41. package/src/og/light/LightSource.js +364 -363
  42. package/src/og/math/Vec3.js +1 -1
  43. package/src/og/math.js +6 -6
  44. package/src/og/quadTree/Node.js +8 -6
  45. package/src/og/renderer/Renderer.js +2 -3
  46. package/src/og/res/images.js +0 -2
  47. package/src/og/scene/Planet.js +106 -44
  48. package/src/og/segment/Segment.js +34 -64
  49. package/src/og/segment/Slice.js +1 -1
  50. package/src/og/shaders/drawnode.js +1 -1
  51. package/src/og/shaders/label.js +30 -42
  52. package/src/og/terrain/GlobusTerrain.js +31 -20
  53. package/src/og/terrain/MapboxTerrain.js +1 -1
  54. package/src/og/utils/BaseWorker.js +46 -0
  55. package/src/og/utils/FontAtlas.js +1 -2
  56. package/src/og/utils/GeoImageCreator.js +164 -161
  57. package/src/og/utils/Loader.js +187 -153
  58. package/src/og/utils/NormalMapCreator.js +403 -412
  59. package/src/og/utils/PlainSegmentWorker.js +29 -55
  60. package/src/og/utils/TerrainWorker.js +572 -589
  61. package/src/og/utils/VectorTileCreator.js +1 -1
  62. package/src/og/utils/functionComposition.js +13 -0
  63. package/src/og/webgl/Handler.js +42 -41
  64. package/src/og/webgl/ProgramController.js +143 -143
  65. package/types/Object3d.d.ts +22 -0
  66. package/types/arial.d.ts +1 -0
  67. package/types/camera/PlanetCamera.d.ts +4 -0
  68. package/types/control/GeoImageDragControl.d.ts +2 -0
  69. package/types/control/LayerAnimation.d.ts +73 -0
  70. package/types/control/LayerSwitcher.d.ts +55 -11
  71. package/types/control/MouseNavigation.d.ts +1 -0
  72. package/types/control/MouseWheelZoomControl.d.ts +1 -0
  73. package/types/control/Sun.d.ts +2 -1
  74. package/types/control/TouchNavigation.d.ts +1 -0
  75. package/types/control/UIhelpers.d.ts +13 -0
  76. package/types/control/index.d.ts +3 -1
  77. package/types/control/ruler/Ruler.d.ts +13 -0
  78. package/types/control/ruler/RulerScene.d.ts +48 -0
  79. package/types/ellipsoid/Ellipsoid.d.ts +8 -0
  80. package/types/entity/LabelHandler.d.ts +2 -0
  81. package/types/entity/LabelWorker.d.ts +5 -7
  82. package/types/layer/BaseGeoImage.d.ts +9 -1
  83. package/types/layer/CanvasTiles.d.ts +5 -1
  84. package/types/layer/GeoImage.d.ts +1 -0
  85. package/types/layer/GeoTexture2d.d.ts +1 -0
  86. package/types/layer/Layer.d.ts +28 -32
  87. package/types/layer/Vector.d.ts +9 -0
  88. package/types/layer/WMS.d.ts +1 -0
  89. package/types/layer/XYZ.d.ts +8 -5
  90. package/types/math.d.ts +2 -2
  91. package/types/quadTree/EntityCollectionNode.d.ts +7 -0
  92. package/types/quadTree/Node.d.ts +1 -2
  93. package/types/renderer/Renderer.d.ts +1 -1
  94. package/types/renderer/RendererEvents.d.ts +16 -0
  95. package/types/res/images.d.ts +0 -1
  96. package/types/scene/Planet.d.ts +21 -6
  97. package/types/segment/SegmentLonLat.d.ts +2 -0
  98. package/types/terrain/BilTerrain.d.ts +6 -0
  99. package/types/terrain/GlobusTerrain.d.ts +7 -0
  100. package/types/terrain/MapboxTerrain.d.ts +8 -0
  101. package/types/utils/BaseWorker.d.ts +14 -0
  102. package/types/utils/Loader.d.ts +4 -1
  103. package/types/utils/PlainSegmentWorker.d.ts +4 -6
  104. package/types/utils/TerrainWorker.d.ts +4 -6
  105. package/types/utils/functionComposition.d.ts +5 -0
  106. package/types/webgl/Handler.d.ts +4 -1
@@ -0,0 +1,374 @@
1
+ 'use strict';
2
+
3
+ import * as math from '../../math.js';
4
+ import { RenderNode } from '../../scene/RenderNode.js';
5
+ import { Events } from '../../Events.js';
6
+ import { LonLat } from '../../LonLat.js';
7
+ import { Vec3 } from '../../math/Vec3.js';
8
+ import { Vec2 } from '../../math/Vec2.js';
9
+ import { Vector } from '../../layer/Vector.js';
10
+ import { Entity } from '../../entity/Entity.js';
11
+ import { Ellipsoid } from '../../ellipsoid/Ellipsoid.js';
12
+ import { Object3d } from '../../Object3d.js';
13
+
14
+ const OUTLINE_COUNT = 120;
15
+
16
+ const MAX_SCALE = 0.005;
17
+ const MIN_SCALE = 0.001;
18
+ const MAX_SCALE_HEIGHT = 3000.0;
19
+ const MIN_SCALE_HEIGHT = 19000000.0;
20
+
21
+ function distanceFormat(v) {
22
+ if (v > 1000) {
23
+ return `${(v / 1000).toFixed(1)} km`;
24
+ } else if (v > 9) {
25
+ return `${Math.round(v)} m`;
26
+ } else {
27
+ return `${v.toFixed(1)} m`;
28
+ }
29
+ }
30
+
31
+ class RulerScene extends RenderNode {
32
+ constructor(options = {}) {
33
+ super(options.name);
34
+
35
+ this.events = new Events(EVENT_NAMES);
36
+
37
+ this._ignoreTerrain = options.ignoreTerrain != undefined ? options.ignoreTerrain : true;
38
+
39
+ this._planet = options.planet || null;
40
+
41
+ this._startLonLat = null;
42
+ this._preventClick = false;
43
+ this._stopDrawing = false;
44
+
45
+ this._pickedCorner = null;
46
+ this._startPos = null;
47
+ this._startClick = new Vec2();
48
+
49
+ this._heading = 0;
50
+
51
+ this._propsLabel = new Entity({
52
+ 'name': 'propsLabel',
53
+ 'label': {
54
+ text: "",
55
+ size: 11,
56
+ color: "rgba(455,455,455,1.0)",
57
+ outlineColor: "rgba(0,0,0,0.34)",
58
+ outline: 0.23,
59
+ align: "center",
60
+ offset: [0, 18]
61
+ }
62
+ });
63
+
64
+ this._propsLabel.label.setVisibility(false);
65
+
66
+ this._trackEntity = new Entity({
67
+ polyline: {
68
+ path3v: [],
69
+ thickness: 3.8,
70
+ color: "rgb(455,455,455)",
71
+ isClosed: false
72
+ }
73
+ });
74
+
75
+ this._trackEntity.polyline.altitude = 0.01;
76
+
77
+ let obj3d = Object3d.createCylinder(1.1, 0, 2.7, 20, 1, true, false, 0, 0, 0)
78
+
79
+ this._cornerEntity = [
80
+ new Entity({
81
+ geoObject: {
82
+ scale: 1,
83
+ instanced: true,
84
+ tag: "ruler",
85
+ color: "rgb(0,305,0)",
86
+ vertices: obj3d.vertices,
87
+ indices: obj3d.indexes,
88
+ normals: obj3d.normals
89
+ },
90
+ properties: {
91
+ name: "start"
92
+ }
93
+ }),
94
+ new Entity({
95
+ geoObject: {
96
+ scale: 1,
97
+ instanced: true,
98
+ tag: "ruler",
99
+ color: "rgb(455,0,0)",
100
+ vertices: obj3d.vertices,
101
+ indices: obj3d.indexes,
102
+ normals: obj3d.normals
103
+ },
104
+ properties: {
105
+ name: "end"
106
+ }
107
+
108
+ })
109
+ ];
110
+
111
+ this._trackLayer = new Vector("track", {
112
+ entities: [this._trackEntity, this._propsLabel],
113
+ pickingEnabled: false,
114
+ polygonOffsetUnits: -1.0,
115
+ relativeToGround: true,
116
+ displayInLayerSwitcher: false
117
+ });
118
+
119
+ this._cornersLayer = new Vector("corners", {
120
+ entities: [this._cornerEntity[0], this._cornerEntity[1]],
121
+ pickingEnabled: true,
122
+ displayInLayerSwitcher: false
123
+ });
124
+ }
125
+
126
+ set ignoreTerrain(v) {
127
+ this._ignoreTerrain = v;
128
+ if (v) {
129
+ //...redraw line
130
+ }
131
+ }
132
+
133
+ bindPlanet(planet) {
134
+ this._planet = planet;
135
+ }
136
+
137
+ init() {
138
+ this._activate();
139
+ }
140
+
141
+ onremove() {
142
+ this._deactivate();
143
+ }
144
+
145
+ _activate() {
146
+
147
+ this._propsLabel.label.setVisibility(false);
148
+ this._onLclick_ = this._onLclick.bind(this);
149
+ this.renderer.events.on("lclick", this._onLclick_, this);
150
+ this._onMouseMove_ = this._onMouseMove.bind(this);
151
+ this.renderer.events.on("mousemove", this._onMouseMove_, this);
152
+ this._onLdblclick_ = this._onLdblclick.bind(this);
153
+ this.renderer.events.on("ldblclick", this._onLdblclick_, this);
154
+
155
+ this._onCornerEnter_ = this._onCornerEnter.bind(this);
156
+ this._cornersLayer.events.on("mouseenter", this._onCornerEnter_, this);
157
+
158
+ this._onCornerLeave_ = this._onCornerLeave.bind(this);
159
+ this._cornersLayer.events.on("mouseleave", this._onCornerLeave_, this);
160
+
161
+ this._onCornerLdown_ = this._onCornerLdown.bind(this);
162
+ this._cornersLayer.events.on("ldown", this._onCornerLdown_, this);
163
+
164
+ this._onCornerLup_ = this._onCornerLup.bind(this);
165
+ this._cornersLayer.events.on("lup", this._onCornerLup, this);
166
+
167
+ this._planet.addLayer(this._trackLayer);
168
+ this._planet.addLayer(this._cornersLayer);
169
+
170
+ }
171
+
172
+ _deactivate() {
173
+ this._startLonLat = null;
174
+ this._preventClick = false;
175
+ this._stopDrawing = false;
176
+ this._pickedCorner = null;
177
+ this._trackLayer.remove();
178
+ this._cornersLayer.remove();
179
+ this.renderer.events.off("lclick", this._onLclick_);
180
+ this.renderer.events.off("mousemove", this._onMouseMove_);
181
+ this._cornersLayer.events.off("mouseenter", this._onCornerEnter_);
182
+ this._cornersLayer.events.off("mouseleave", this._onCornerLeave_);
183
+ this._cornersLayer.events.off("ldown", this._onCornerLdown_);
184
+ this._cornersLayer.events.off("lup", this._onCornerLup_);
185
+
186
+ this.clear();
187
+
188
+ this._onLclick_ = null;
189
+ this._onMouseMove_ = null;
190
+ this._onCornerLeave_ = null;
191
+ this._onCornerEnter_ = null;
192
+ this._onCornerLdown_ = null;
193
+ this._onCornerLup_ = null;
194
+ }
195
+
196
+ _onCornerLdown(e) {
197
+ if (!this._startLonLat) {
198
+ this.renderer.controls.mouseNavigation.deactivate();
199
+ this._startClick.set(e.x, e.y);
200
+ let coords = e.pickingObject.getCartesian();
201
+ this._startPos = this._planet.getPixelFromCartesian(coords);
202
+ this._pickedCorner = e.pickingObject;
203
+ if (e.pickingObject.properties.name == "start") {
204
+ this._anchorLonLat = this._cornerEntity[1].getLonLat().clone();
205
+ } else {
206
+ this._anchorLonLat = this._cornerEntity[0].getLonLat().clone();
207
+ }
208
+ }
209
+ }
210
+
211
+ _onCornerLup(e) {
212
+ if (this._pickedCorner) {
213
+ this.renderer.controls.mouseNavigation.activate();
214
+ this._pickedCorner = null;
215
+ this._anchorLonLat = null;
216
+ }
217
+ }
218
+
219
+ _onCornerEnter(e) {
220
+ e.renderer.handler.canvas.style.cursor = "pointer";
221
+ }
222
+
223
+ _onCornerLeave(e) {
224
+ e.renderer.handler.canvas.style.cursor = "default";
225
+ }
226
+
227
+ _onLdblclick() {
228
+ this._preventClick = true;
229
+ }
230
+
231
+ _onLclick(e) {
232
+ let startLonLat = this._planet.getLonLatFromPixelTerrain(e);
233
+ this._timeout = setTimeout(() => {
234
+ if (!this._preventClick) {
235
+ if (!this._startLonLat) {
236
+ this._stopDrawing = false;
237
+ this._propsLabel.label.setVisibility(false);
238
+ this._trackEntity.polyline.setPath3v([]);
239
+ this._cornerEntity[0].geoObject.setVisibility(true);
240
+ this._cornerEntity[1].geoObject.setVisibility(true);
241
+ this._startLonLat = startLonLat;
242
+ } else {
243
+ this._startLonLat = null;
244
+ }
245
+ }
246
+ this._preventClick = false;
247
+ this._stopDrawing = false;
248
+ clearTimeout(this._timeout);
249
+ }, 200);
250
+
251
+ if (this._startLonLat) {
252
+ this._stopDrawing = true;
253
+ }
254
+ }
255
+
256
+ _drawLine(startLonLat, endLonLat, startPos) {
257
+
258
+ if (!startPos) {
259
+ startPos = this._planet.ellipsoid.lonLatToCartesian(startLonLat);
260
+ }
261
+
262
+ let endPos = this._planet.ellipsoid.lonLatToCartesian(endLonLat);
263
+
264
+ let length = this._planet.ellipsoid.getGreatCircleDistance(startLonLat, endLonLat);
265
+ this._heading = Ellipsoid.getRhumbBearing(startLonLat, endLonLat);
266
+
267
+ let path = [];
268
+ let dir = endPos.sub(startPos);
269
+ let dist = dir.length();
270
+ dir.normalize();
271
+
272
+ for (let i = 0; i < OUTLINE_COUNT; i++) {
273
+ let f = dir.scaleTo(i * dist / OUTLINE_COUNT).addA(startPos);
274
+ path.push(f);
275
+ }
276
+ path.push(endPos);
277
+
278
+ this._trackEntity.polyline.setPath3v([path]);
279
+
280
+ if (this._ignoreTerrain) {
281
+ this._propsLabel.setCartesian3v(path[Math.floor(path.length / 2)]);
282
+ this._propsLabel.label.setText(`${distanceFormat(length)}, ${Math.round(this._heading)} deg`);
283
+ }
284
+ }
285
+
286
+ _onMouseMove(e) {
287
+ if (this._startLonLat && !this._stopDrawing) {
288
+ this._propsLabel.label.setVisibility(true);
289
+ let endLonLat = this._planet.getLonLatFromPixelTerrain(e);
290
+ if (!endLonLat) return;
291
+ this._drawLine(this._startLonLat, endLonLat);
292
+ } else if (this._pickedCorner) {
293
+ let newLonLat = this._planet.getLonLatFromPixelTerrain(e);
294
+ if (newLonLat) {
295
+ if (this._pickedCorner.properties.name === "start") {
296
+ this._drawLine(newLonLat, this._anchorLonLat);
297
+ } else {
298
+ this._drawLine(this._anchorLonLat, newLonLat);
299
+ }
300
+ }
301
+ }
302
+ }
303
+
304
+ clear() {
305
+ // удаляем трек
306
+ this._trackEntity.polyline.clear();
307
+ this._cornerEntity[0].geoObject.setVisibility(false);
308
+ this._cornerEntity[1].geoObject.setVisibility(false);
309
+ }
310
+
311
+ getScale(cart) {
312
+ let r = this.renderer;
313
+ let t = 1.0 - (r.activeCamera._lonLat.height - MAX_SCALE_HEIGHT) / (MIN_SCALE_HEIGHT - MAX_SCALE_HEIGHT);
314
+ let _distanceToCamera = cart.distance(r.activeCamera.eye);
315
+ return math.lerp(t < 0 ? 0 : t, MAX_SCALE, MIN_SCALE) * _distanceToCamera;
316
+ }
317
+
318
+ frame() {
319
+ let t = this._trackEntity.polyline.getPath3v()[0];
320
+ if (t) {
321
+ this._cornerEntity[0].setCartesian3v(t[0].clone());
322
+ this._cornerEntity[1].setCartesian3v(t[t.length - 1].clone());
323
+
324
+ this._cornerEntity[0].geoObject.setScale(this.getScale(this._cornerEntity[0].getCartesian()));
325
+ this._cornerEntity[1].geoObject.setScale(this.getScale(this._cornerEntity[1].getCartesian()));
326
+
327
+ if (!this._ignoreTerrain) {
328
+ let res = 0;
329
+ for (let i = 0, len = t.length - 1; i < len; i++) {
330
+ res += t[i + 1].distance(t[i]);
331
+ }
332
+
333
+ this._propsLabel.setCartesian3v(t[Math.floor(t.length / 2)]);
334
+ this._propsLabel.label.setText(`${distanceFormat(res)}, ${Math.round(this._heading)} deg`);
335
+ }
336
+ }
337
+ }
338
+
339
+ get ellipsoid() {
340
+ return this._planet ? this._planet.ellipsoid : null;
341
+ }
342
+ }
343
+
344
+ const EVENT_NAMES = [
345
+ "add",
346
+ "remove",
347
+ "mousemove",
348
+ "mouseenter",
349
+ "mouseleave",
350
+ "lclick",
351
+ "rclick",
352
+ "mclick",
353
+ "ldblclick",
354
+ "rdblclick",
355
+ "mdblclick",
356
+ "lup",
357
+ "rup",
358
+ "mup",
359
+ "ldown",
360
+ "rdown",
361
+ "mdown",
362
+ "lhold",
363
+ "rhold",
364
+ "mhold",
365
+ "mousewheel",
366
+ "touchmove",
367
+ "touchstart",
368
+ "touchend",
369
+ "doubletouch",
370
+ "touchleave",
371
+ "touchenter"
372
+ ];
373
+
374
+ export { RulerScene };
@@ -257,10 +257,7 @@ class Segment {
257
257
  * @returns {boolean} -
258
258
  */
259
259
  acceptForRendering(camera) {
260
- return (
261
- camera.projectedSize(this.bsphere.center, this._plainRadius) <
262
- 256 / this.planet._lodRatio
263
- );
260
+ return camera.projectedSize(this.bsphere.center, this._plainRadius) < (256 / this.planet._lodRatio);
264
261
  }
265
262
 
266
263
  /**
@@ -403,8 +400,9 @@ class Segment {
403
400
  * @param {Float32Array} elevations - Elevation data.
404
401
  */
405
402
  elevationsExists(elevations) {
403
+ const segment = this;
406
404
  if (this.plainReady && this.terrainIsLoading) {
407
- this.planet._terrainWorker.make(this, elevations);
405
+ this.planet._terrainWorker.make(segment, elevations);
408
406
 
409
407
  this.plainVerticesHigh = null;
410
408
  this.plainVerticesLow = null;
@@ -57,6 +57,25 @@ class Ellipsoid {
57
57
  return -Math.acos(d);
58
58
  }
59
59
 
60
+ /**
61
+ * Returns the distance travelling from ‘this’ point to destination point along a rhumb line.
62
+ *
63
+ * @param {LonLat} start coordinates.
64
+ * @param {LonLat} end coordinates
65
+ * @returns {number} Distance in m between this point and destination point (same units as radius).
66
+ */
67
+ rhumbDistanceTo(startLonLat, endLonLat) {
68
+ const f1 = startLonLat.lat * math.RADIANS;
69
+ const f2 = endLonLat.lat * math.RADIANS;
70
+ const df = f2 - f1;
71
+ let d = Math.abs(endLonLat.lon - startLonLat.lon) * math.RADIANS;
72
+ if (Math.abs(d) > Math.PI) d = d > 0 ? -(2 * Math.PI - d) : (2 * Math.PI + d);
73
+ const dd = Math.log(Math.tan(f2 / 2 + Math.PI / 4) / Math.tan(f1 / 2 + Math.PI / 4));
74
+ const q = Math.abs(dd) > 10e-12 ? df / dd : Math.cos(f1);
75
+ const t = Math.sqrt(df * df + q * q * d * d); // angular distance in radians
76
+ return t * this._a;
77
+ }
78
+
60
79
  /**
61
80
  * Returns the midpoint between two points on the great circle.
62
81
  * @param {LonLat} lonLat1 - Longitude/latitude of first point.
@@ -10,4 +10,4 @@ import { Ellipsoid } from "./Ellipsoid.js";
10
10
  * WGS84 ellipsoid object.
11
11
  * @type {Ellipsoid}
12
12
  */
13
- export const wgs84 = new Ellipsoid(6378137.0, 6356752.3142);
13
+ export const wgs84 = new Ellipsoid(6378137.0, 6356752.3142); // Equitorial Radius (m), Polar Radius (m)
@@ -65,7 +65,7 @@ class Entity {
65
65
  * @public
66
66
  * @type {string}
67
67
  */
68
- this.properties.name = this.properties.name || options.name || "";
68
+ this.properties.name = this.properties.name != undefined ? this.properties.name : "";
69
69
 
70
70
  /**
71
71
  * Children entities.
@@ -20,7 +20,7 @@ class GeoObject {
20
20
  constructor(options) {
21
21
  options = options || {};
22
22
 
23
- this.scale = options.scale || 0.02;
23
+ this.scale = options.scale || 1.0;
24
24
  this.scaleByDistance = new Float32Array(options.scaleByDistance || [MAX32, MAX32, MAX32]);
25
25
 
26
26
  /**
@@ -85,7 +85,8 @@ class LabelHandler extends BillboardHandler {
85
85
  }
86
86
 
87
87
  _addLabelToArrays(label) {
88
- this._renderer.labelWorker.make(this, label);
88
+ this._renderer.labelWorker.make(label);
89
+ console.time(`label${label.id}`)
89
90
  }
90
91
 
91
92
  assignFontAtlas(label) {
@@ -121,6 +122,8 @@ class LabelHandler extends BillboardHandler {
121
122
  label.update();
122
123
 
123
124
  this.refresh();
125
+ console.timeEnd(`label${label.id}`)
126
+ console.log(label)
124
127
  }
125
128
  }
126
129
 
@@ -205,6 +208,7 @@ class LabelHandler extends BillboardHandler {
205
208
  ec = this._entityCollection;
206
209
 
207
210
  gl.disable(gl.CULL_FACE);
211
+ //gl.disable(gl.DEPTH_TEST);
208
212
 
209
213
  gl.uniform1iv(shu.fontTextureArr, r.fontAtlas.samplerArr);
210
214
  gl.uniform4fv(shu.sdfParamsArr, r.fontAtlas.sdfParamsArr);
@@ -385,7 +389,7 @@ class LabelHandler extends BillboardHandler {
385
389
  if (isRTL) {
386
390
  _rtl_ = RTL;
387
391
  }
388
-
392
+
389
393
  let offset = 0.0;
390
394
  let kern = fa.kernings;
391
395
 
@@ -2,76 +2,61 @@
2
2
 
3
3
  // import { QueueArray } from '../QueueArray.js';
4
4
 
5
+ import { BaseWorker } from "../utils/BaseWorker.js";
6
+
5
7
  export const LOCK_UPDATE = -2;
6
8
  export const LOCK_FREE = -1;
7
9
 
8
- class LabelWorker {
10
+ class LabelWorker extends BaseWorker {
9
11
  constructor(numWorkers = 4) {
10
- this._id = 0;
11
- this._source = {};
12
-
13
- this._freeWorkerQueue = []; //new QueueArray(numWorkers);
14
- var labelProgramm = new Blob([_programm], { type: "application/javascript" });
15
-
16
- var that = this;
17
-
18
- for (let i = 0; i < numWorkers; i++) {
19
- var w = new Worker(URL.createObjectURL(labelProgramm));
20
- w.onmessage = function (e) {
21
-
22
- let s = that._source[e.data.id];
23
-
24
- if (s.label._lockId === LOCK_UPDATE) {
25
- that.make(s.handler, s.label);
26
- } else {
27
- s.handler.workerCallback(e.data, s.label);
28
- }
12
+ super(numWorkers, _programm);
13
+ this._source = new Map();
14
+ }
29
15
 
30
- that._source[e.data.id] = null;
31
- delete that._source[e.data.id];
32
- that._freeWorkerQueue.unshift(this);
16
+ _onMessage(e) {
33
17
 
34
- that.check();
35
- };
18
+ let label = this._source.get(e.data.id);
36
19
 
37
- this._freeWorkerQueue.push(w);
20
+ if (label._lockId === LOCK_UPDATE) {
21
+ requestAnimationFrame(() => {
22
+ this.make(label);
23
+ });
24
+ } else {
25
+ label._handler.workerCallback(e.data, label);
38
26
  }
39
27
 
40
- this._pendingQueue = []; //new QueueArray(512);
41
- }
28
+ this._source.delete(e.data.id);
29
+ super._onMessage(e)
42
30
 
43
- check() {
44
- if (this._pendingQueue.length) {
45
- var p = this._pendingQueue.pop();
46
- this.make(p.handler, p.label);
47
- }
31
+ this.check();
48
32
  }
49
33
 
50
- make(handler, label) {
51
34
 
35
+ make() {
36
+ const label = arguments[0],
37
+ handler = label._handler;
52
38
  if (handler._entityCollection) {
53
- let source = { handler: handler, label: label };
54
39
 
55
- if (this._freeWorkerQueue.length) {
56
- var w = this._freeWorkerQueue.pop();
40
+ if (this._workerQueue.length) {
41
+ var w = this._workerQueue.pop();
57
42
 
58
- this._source[this._id] = source;
43
+ this._source.set(this._id, label);
59
44
 
60
45
  let labelData = new Float32Array([
61
- /*0*/this._id++,
62
- /*1*/handler._maxLetters,
63
- /*2*/label.getVisibility() ? 1 : 0,
64
- /*3, 4, 5*/label._positionHigh.x, label._positionHigh.y, label._positionHigh.z,
65
- /*6, 7, 8*/label._positionLow.x, label._positionLow.y, label._positionLow.z,
66
- /*9*/label._size,
67
- /*10, 11, 12*/label._offset.x, label._offset.y, label._offset.z,
68
- /*13, 14, 15, 16*/label._color.x, label._color.y, label._color.z, label._color.w,
69
- /*17*/label._rotation,
70
- /*18, 19, 20*/label._alignedAxis.x, label._alignedAxis.y, label._alignedAxis.z,
71
- /*21*/label._fontIndex,
72
- /*22*/label._outline,
73
- /*23, 24, 25, 26*/label._outlineColor.x, label._outlineColor.y, label._outlineColor.z, label._outlineColor.w,
74
- /*27, 28, 29*/label._entity._pickingColor.x, label._entity._pickingColor.y, label._entity._pickingColor.z
46
+ /*0*/this._id++,
47
+ /*1*/handler._maxLetters,
48
+ /*2*/label.getVisibility() ? 1 : 0,
49
+ /*3, 4, 5*/label._positionHigh.x, label._positionHigh.y, label._positionHigh.z,
50
+ /*6, 7, 8*/label._positionLow.x, label._positionLow.y, label._positionLow.z,
51
+ /*9*/label._size,
52
+ /*10, 11, 12*/label._offset.x, label._offset.y, label._offset.z,
53
+ /*13, 14, 15, 16*/label._color.x, label._color.y, label._color.z, label._color.w,
54
+ /*17*/label._rotation,
55
+ /*18, 19, 20*/label._alignedAxis.x, label._alignedAxis.y, label._alignedAxis.z,
56
+ /*21*/label._fontIndex,
57
+ /*22*/label._outline,
58
+ /*23, 24, 25, 26*/label._outlineColor.x, label._outlineColor.y, label._outlineColor.z, label._outlineColor.w,
59
+ /*27, 28, 29*/label._entity._pickingColor.x, label._entity._pickingColor.y, label._entity._pickingColor.z
75
60
  ]);
76
61
 
77
62
  label._lockId = this._id;
@@ -82,7 +67,7 @@ class LabelWorker {
82
67
  labelData.buffer,
83
68
  ]);
84
69
  } else {
85
- this._pendingQueue.push(source);
70
+ this._pendingQueue.push(label);
86
71
  }
87
72
  }
88
73
  }