@pirireis/webglobeplugins 0.15.2-3.alpha → 0.15.2-alpha

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 (45) hide show
  1. package/Math/arc-generate-points copy.js +366 -0
  2. package/Math/arc.js +2 -1
  3. package/Math/circle-cdf-points.js +170 -1
  4. package/Math/circle.js +25 -0
  5. package/Math/globe-util/horizon-plane.js +112 -0
  6. package/Math/methods.js +2 -2
  7. package/Math/vec3.js +2 -6
  8. package/altitude-locator/draw-subset-obj.js +16 -0
  9. package/altitude-locator/plugin.js +1 -1
  10. package/bearing-line/plugin.js +2 -3
  11. package/package.json +1 -1
  12. package/point-tracks/plugin.js +22 -82
  13. package/programs/line-on-globe/lines-color-instanced-flat.js +1 -0
  14. package/programs/line-on-globe/linestrip/linestrip.js +28 -2
  15. package/programs/line-on-globe/paddings/paddings.js +1 -0
  16. package/programs/point-on-globe/element-globe-surface-glow.js +1 -0
  17. package/programs/rings/partial-ring/piece-of-pie copy.js +286 -0
  18. package/programs/totems/camerauniformblock.js +0 -7
  19. package/programs/totems/canvas-webglobe-info.js +9 -9
  20. package/range-tools-on-terrain/bearing-line/adapters.js +5 -8
  21. package/range-tools-on-terrain/bearing-line/plugin.js +20 -95
  22. package/range-tools-on-terrain/circle-line-chain/adapters.js +8 -15
  23. package/range-tools-on-terrain/circle-line-chain/chain-list-map.js +15 -32
  24. package/range-tools-on-terrain/circle-line-chain/plugin.js +15 -75
  25. package/range-tools-on-terrain/range-ring/adapters.js +6 -74
  26. package/range-tools-on-terrain/range-ring/plugin.js +7 -222
  27. package/range-tools-on-terrain/range-ring/types.js +1 -9
  28. package/semiplugins/lightweight/line-plugin.js +47 -65
  29. package/semiplugins/lightweight/piece-of-pie-plugin.js +18 -44
  30. package/semiplugins/shape-on-terrain/arc-plugin.js +100 -197
  31. package/semiplugins/shape-on-terrain/circle-plugin.js +90 -209
  32. package/semiplugins/shape-on-terrain/derived/padding-plugin.js +101 -0
  33. package/semiplugins/shape-on-terrain/one-degree-padding.js +85 -0
  34. package/util/account/single-attribute-buffer-management/buffer-manager.js +0 -10
  35. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +8 -145
  36. package/util/account/single-attribute-buffer-management/object-store.js +0 -7
  37. package/util/build-strategy/static-dynamic.js +1 -11
  38. package/util/check/typecheck.js +0 -12
  39. package/util/geometry/index.js +1 -2
  40. package/programs/totems/globe-changes.js +0 -59
  41. package/semiplugins/interface.js +0 -1
  42. package/semiplugins/shape-on-terrain/padding-1-degree.js +0 -538
  43. package/util/account/single-attribute-buffer-management/buffer-orchestrator1.js +0 -159
  44. package/util/frame-counter-trigger.js +0 -84
  45. package/write-text/context-text4.js +0 -140
@@ -1,6 +1,5 @@
1
1
  import { LineOnGlobeCache } from "../../programs/line-on-globe/naive-accurate-flexible";
2
- import { BufferOrchestrator } from "../../util/account/single-attribute-buffer-management/buffer-orchestrator";
3
- import { BufferManager } from "../../util/account/single-attribute-buffer-management/buffer-manager";
2
+ import { BufferMapOrchestrator } from "../../util/account/create-buffermap-orchastration";
4
3
  import { sphereCoord } from "../../util/geometry/index";
5
4
  import { constraintFloat } from "../../util/check/typecheck";
6
5
  export class LinePlugin {
@@ -11,36 +10,33 @@ export class LinePlugin {
11
10
  vao = null;
12
11
  _options;
13
12
  _uboHandler = null;
14
- bufferOrchestrator;
15
- bufferManagersMap = new Map();
13
+ _bufferOrchestrator = null;
16
14
  _freed = false;
17
- constructor(id, { flatViewOn = true, globeViewOn = true, variativeColorsOn = false, defaultColor = [1, 1, 1, 1], dashedLineOpacityVariativeOn = false, dashedLineRatioVariativeOn = false, bufferType = "DYNAMIC_DRAW", opacity = 1.0, initialCapacity = 10 } = {}) {
15
+ constructor(id, { flatViewOn = true, globeViewOn = true, variativeColorsOn = false, defaultColor = [1, 1, 1, 1], dashedLineOpacityVariativeOn = false, dashedLineRatioVariativeOn = false, bufferType = "DYNAMIC_DRAW", opacity = 1.0 } = {}) {
18
16
  this.id = id;
19
17
  this._options = {
20
- flatViewOn: flatViewOn ?? true,
21
- globeViewOn: globeViewOn ?? true,
22
- variativeColorsOn: variativeColorsOn ?? false,
23
- defaultColor: defaultColor ?? [1, 1, 1, 1],
24
- dashedLineOpacityVariativeOn: dashedLineOpacityVariativeOn ?? false,
25
- dashedLineRatioVariativeOn: dashedLineRatioVariativeOn ?? false,
26
- bufferType: bufferType ?? "DYNAMIC_DRAW",
27
- opacity: opacity ?? 1.0,
28
- initialCapacity: initialCapacity ?? 10
18
+ flatViewOn,
19
+ globeViewOn,
20
+ variativeColorsOn,
21
+ defaultColor,
22
+ dashedLineOpacityVariativeOn,
23
+ dashedLineRatioVariativeOn,
24
+ bufferType,
25
+ opacity
29
26
  };
30
- this.bufferOrchestrator = new BufferOrchestrator({ capacity: initialCapacity ?? 10 });
31
27
  }
32
28
  init(globe, gl) {
33
29
  this.globe = globe;
34
30
  this.gl = gl;
35
31
  this.program = LineOnGlobeCache.get(globe);
36
32
  this._uboHandler = this.program.createUBO();
37
- this.setDefaultColor(this._options.defaultColor);
38
- this._fillManagerMap();
33
+ this._bufferOrchestrator = new BufferMapOrchestrator(gl, this._createBufferDetailsMap(), 10 // initial capacity
34
+ );
39
35
  this.vao = this.program.createVAO(...this._createSelectBufferNames().map((key) => {
40
36
  if (key === null) {
41
37
  return null;
42
38
  }
43
- const bufferManagerComp = this.bufferManagersMap.get(key);
39
+ const bufferManagerComp = this._bufferOrchestrator?.bufferManagersMap.get(key);
44
40
  if (bufferManagerComp === undefined) {
45
41
  throw new Error(`Buffer key ${key} does not exist in bufferManagersMap`);
46
42
  }
@@ -53,43 +49,26 @@ export class LinePlugin {
53
49
  }));
54
50
  }
55
51
  // PLUGIN INTERFACE METHODS
56
- increaseSpace(amount) {
57
- if (this._freed) {
58
- console.warn("Plugin is freed, cannot increase space");
59
- return;
60
- }
61
- if (this.globe === null) {
62
- console.warn("Globe is not initialized.");
63
- return;
64
- }
65
- if (typeof amount !== "number" || amount <= 0) {
66
- console.warn("Invalid amount, must be a positive number");
67
- return;
68
- }
69
- this.bufferOrchestrator.ensureSpace(amount, this.bufferManagersMap);
70
- }
71
52
  insertBulk(items) {
72
- const { bufferOrchestrator, bufferManagersMap, globe } = this;
73
- if (!bufferOrchestrator || !globe) {
53
+ const { _bufferOrchestrator, globe } = this;
54
+ if (!_bufferOrchestrator || !globe) {
74
55
  throw new Error("Buffer orchestrator or globe is not initialized.");
75
56
  }
76
- bufferOrchestrator.insertBulk(items, bufferManagersMap);
57
+ _bufferOrchestrator.insertBulk(items);
77
58
  this.globe?.DrawRender();
78
59
  }
79
60
  deleteBulk(keys) {
80
- const { bufferOrchestrator, bufferManagersMap, globe } = this;
81
- if (!bufferOrchestrator || !globe) {
61
+ const { _bufferOrchestrator, globe } = this;
62
+ if (!_bufferOrchestrator || !globe) {
82
63
  throw new Error("Buffer orchestrator or globe is not initialized.");
83
64
  }
84
- bufferOrchestrator.deleteBulk(keys, bufferManagersMap);
65
+ _bufferOrchestrator.deleteBulk(keys);
85
66
  this.globe?.DrawRender();
86
67
  }
87
- setPluginOpacity(opacity, drawRender = false) {
68
+ setPluginOpacity(opacity) {
88
69
  constraintFloat(opacity, 0, 1);
89
70
  this._options.opacity = opacity;
90
- if (drawRender) {
91
- this.globe?.DrawRender();
92
- }
71
+ this.globe?.DrawRender();
93
72
  }
94
73
  setPluginDashedLineRatio(ratio) {
95
74
  constraintFloat(ratio, 0, 1);
@@ -102,19 +81,14 @@ export class LinePlugin {
102
81
  this._options.defaultColor[3] = opacity; // Update the default color's alpha channel
103
82
  this.globe?.DrawRender();
104
83
  }
105
- setDefaultColor(color, drawRender = false) {
84
+ setDefaultColor(color) {
106
85
  if (!this.globe || !this.gl) {
107
86
  console.warn("Globe or WebGL context is not initialized.");
108
87
  return;
109
88
  }
110
89
  this._options.defaultColor = color;
111
90
  this._uboHandler?.updateSingle("u_color", new Float32Array(color));
112
- if (drawRender) {
113
- this.globe.DrawRender();
114
- }
115
- }
116
- updateCoordinates(items) {
117
- throw new Error("Method not implemented.");
91
+ this.globe?.DrawRender();
118
92
  }
119
93
  // GLOBE INTERACTION METHODS
120
94
  draw3D() {
@@ -125,10 +99,11 @@ export class LinePlugin {
125
99
  if (!this.globe || !this.gl || !this.program || !this.vao) {
126
100
  throw new Error("Globe, GL context or program is not initialized.");
127
101
  }
128
- const { bufferOrchestrator, _options, _uboHandler, vao } = this;
129
- if (!bufferOrchestrator || !bufferOrchestrator || !_uboHandler) {
102
+ const { _bufferOrchestrator, _options, _uboHandler, vao } = this;
103
+ if (!_bufferOrchestrator || !_bufferOrchestrator || !_uboHandler) {
130
104
  throw new Error("Buffer orchestrator is not initialized.");
131
105
  }
106
+ const { bufferOrchestrator } = _bufferOrchestrator;
132
107
  const { flatViewOn, globeViewOn, opacity } = _options;
133
108
  const drawOptions = {
134
109
  drawRange: {
@@ -152,60 +127,67 @@ export class LinePlugin {
152
127
  if (this._freed)
153
128
  return;
154
129
  // TODO: FILL
155
- this.bufferManagersMap.forEach((manager) => {
156
- manager.bufferManager.free();
157
- });
130
+ this._bufferOrchestrator?.free();
158
131
  this._uboHandler?.free();
159
132
  LineOnGlobeCache.release(this.globe);
160
133
  this._freed = true;
161
134
  }
162
135
  // IMPLICIT INTERFACE METHODS
163
- _fillManagerMap() {
136
+ _createBufferDetailsMap() {
164
137
  const globe = this.globe;
165
138
  const { flatViewOn, globeViewOn, variativeColorsOn, dashedLineOpacityVariativeOn, dashedLineRatioVariativeOn, bufferType = "DYNAMIC_DRAW" } = this._options;
166
- const m = this.bufferManagersMap;
167
- const initialCapacity = this._options.initialCapacity;
139
+ const m = new Map();
168
140
  if (flatViewOn) {
169
141
  m.set("start_position", {
170
- bufferManager: new BufferManager(globe.gl, 2, { bufferType, initialCapacity: this._options.initialCapacity }),
142
+ itemSize: 2,
143
+ bufferType: bufferType, // TODO: Ask User?
144
+ buffer: null,
171
145
  adaptor: (item) => {
172
146
  const result = new Float32Array(globe.api_GetMercator2DPoint(item.start[0], item.start[1]));
173
147
  return result;
174
148
  }
175
149
  });
176
150
  m.set("end_position", {
177
- bufferManager: new BufferManager(globe.gl, 2, { bufferType, initialCapacity: this._options.initialCapacity }),
151
+ itemSize: 2,
152
+ bufferType: bufferType,
153
+ buffer: null,
178
154
  adaptor: (item) => new Float32Array(globe.api_GetMercator2DPoint(item.end[0], item.end[1]))
179
155
  });
180
156
  }
181
157
  if (globeViewOn) {
182
158
  m.set("start_position_3d", {
183
- bufferManager: new BufferManager(globe.gl, 3, { bufferType, initialCapacity: this._options.initialCapacity }),
159
+ itemSize: 3,
160
+ bufferType: bufferType,
184
161
  adaptor: (item) => sphereCoord(item.start[0], item.start[1], globe, item.start_altitude || 0)
185
162
  });
186
163
  m.set("end_position_3d", {
187
- bufferManager: new BufferManager(globe.gl, 3, { bufferType, initialCapacity: this._options.initialCapacity }),
164
+ itemSize: 3,
165
+ bufferType: bufferType,
188
166
  adaptor: (item) => sphereCoord(item.end[0], item.end[1], globe, item.end_altitude || 0)
189
167
  });
190
168
  }
191
169
  if (variativeColorsOn) {
192
170
  m.set("color", {
193
- bufferManager: new BufferManager(globe.gl, 4, { bufferType, initialCapacity: this._options.initialCapacity }),
171
+ itemSize: 4,
172
+ bufferType: bufferType,
194
173
  adaptor: (item) => new Float32Array(item.color !== undefined ? item.color : [-1, -1, -1, -1])
195
174
  });
196
175
  }
197
176
  if (dashedLineOpacityVariativeOn) {
198
177
  m.set("dashed_line_opacity", {
199
- bufferManager: new BufferManager(globe.gl, 1, { bufferType, initialCapacity: this._options.initialCapacity }),
178
+ itemSize: 1,
179
+ bufferType: bufferType,
200
180
  adaptor: (item) => new Float32Array(item.dashed_line_opacity !== undefined ? [item.dashed_line_opacity] : [-1])
201
181
  });
202
182
  }
203
183
  if (dashedLineRatioVariativeOn) {
204
184
  m.set("dashed_line_ratio", {
205
- bufferManager: new BufferManager(globe.gl, 1, { bufferType, initialCapacity: this._options.initialCapacity }),
185
+ itemSize: 1,
186
+ bufferType: bufferType,
206
187
  adaptor: (item) => new Float32Array(item.dashed_line_ratio !== undefined ? [item.dashed_line_ratio] : [-1])
207
188
  });
208
189
  }
190
+ return m;
209
191
  }
210
192
  _createSelectBufferNames() {
211
193
  const { flatViewOn, globeViewOn, variativeColorsOn, dashedLineOpacityVariativeOn, dashedLineRatioVariativeOn } = this._options;
@@ -19,19 +19,13 @@ export class PieceOfPiePlugin {
19
19
  _pluginOptions = {
20
20
  bufferType: "STATIC_DRAW",
21
21
  initialCapacity: INITIAL_CAPACITY,
22
- opacity: 1.0, // Default opacity is 1.0
23
- defaultHeightFromGroundIn3D: 0, // Default altitude is ground level
24
- defaultColor: [1, 1, 1, 1], // Default color is white with full opacity
25
- variativeColorsOn: false, // Default is to not use variative colors
22
+ defaultAltitude: 0, // Default altitude is ground level
26
23
  };
27
- constructor(id, options = null) {
24
+ constructor(id, options = {}) {
28
25
  this.id = id;
29
- if (options) {
30
- this._pluginOptions = {
31
- ...this._pluginOptions,
32
- ...options
33
- };
34
- }
26
+ options.bufferType && (this._pluginOptions.bufferType = options.bufferType);
27
+ options.initialCapacity && (this._pluginOptions.initialCapacity = options.initialCapacity);
28
+ options.defaultAltitude && (this._pluginOptions.defaultAltitude = options.defaultAltitude);
35
29
  }
36
30
  insertBulk(items) {
37
31
  this.bufferOrchestrator.insertBulk(items, this.bufferManagersMap);
@@ -41,12 +35,10 @@ export class PieceOfPiePlugin {
41
35
  this.bufferOrchestrator.deleteBulk(keys, this.bufferManagersMap);
42
36
  this.globe?.DrawRender();
43
37
  }
44
- setPluginOpacity(opacity, drawRender = true) {
38
+ setPluginOpacity(opacity) {
45
39
  opacityCheck(opacity);
46
40
  this._uboHandler?.updateSingle("u_opacity", new Float32Array([opacity]));
47
- if (drawRender) {
48
- this.globe?.DrawRender();
49
- }
41
+ this.globe?.DrawRender();
50
42
  }
51
43
  setDrawMode(drawMode) {
52
44
  if (drawMode !== "TRIANGLE_FAN" && drawMode !== "LINE_STRIP" && drawMode !== "BOTH") {
@@ -55,17 +47,6 @@ export class PieceOfPiePlugin {
55
47
  this.drawMode = drawMode;
56
48
  this.globe?.DrawRender();
57
49
  }
58
- setDefaultColor(color) {
59
- if (this._isFreed) {
60
- console.warn("PieceOfPiePlugin is freed, cannot set default color.");
61
- return;
62
- }
63
- if (!Array.isArray(color) || color.length !== 4) {
64
- throw new Error("Color must be an array of 4 numbers [R, G, B, A].");
65
- }
66
- this._uboHandler?.updateSingle("u_color", new Float32Array(color));
67
- this.globe?.DrawRender();
68
- }
69
50
  _createBufferManagersMap() {
70
51
  const { gl, globe, _pluginOptions } = this;
71
52
  const { bufferType, initialCapacity } = _pluginOptions;
@@ -79,7 +60,7 @@ export class PieceOfPiePlugin {
79
60
  }],
80
61
  ["centerCoords3d", {
81
62
  bufferManager: new BufferManager(gl, 3, { bufferType, initialCapacity }),
82
- adaptor: (item) => sphereCoord(item.center[0], item.center[1], globe, (item.altitude ?? this._pluginOptions.defaultHeightFromGroundIn3D) / 1000)
63
+ adaptor: (item) => sphereCoord(item.center[0], item.center[1], globe, (item.altitude ?? this._pluginOptions.defaultAltitude) / 1000)
83
64
  }],
84
65
  ["startAngle2d", {
85
66
  bufferManager: new BufferManager(gl, 1, { bufferType, initialCapacity }),
@@ -121,22 +102,21 @@ export class PieceOfPiePlugin {
121
102
  bufferManager: new BufferManager(gl, 1, { bufferType, initialCapacity }),
122
103
  adaptor: (item) => new Float32Array([item.fillingMode ?? 0])
123
104
  }],
105
+ ["rgba", {
106
+ bufferManager: new BufferManager(gl, 4, { bufferType, initialCapacity }),
107
+ adaptor: (item) => {
108
+ if (!item.color || item.color.length === 0) {
109
+ return new Float32Array([1, 1, 1, 1]); // Default color if none provided
110
+ }
111
+ return new Float32Array(item.color);
112
+ }
113
+ }
114
+ ],
124
115
  ["radius", {
125
116
  bufferManager: new BufferManager(gl, 1, { bufferType, initialCapacity }),
126
117
  adaptor: (item) => new Float32Array([item.radius])
127
118
  }],
128
119
  ]);
129
- if (this._pluginOptions.variativeColorsOn) {
130
- bufferManagersMap.set("rgba", {
131
- bufferManager: new BufferManager(gl, 4, { bufferType, initialCapacity }),
132
- adaptor: (item) => {
133
- if (!item.color || item.color.length === 0) {
134
- return new Float32Array([1, 1, 1, 1]); // Default color if none provided
135
- }
136
- return new Float32Array(item.color);
137
- }
138
- });
139
- }
140
120
  this.bufferManagersMap = bufferManagersMap;
141
121
  }
142
122
  init(globe, gl) {
@@ -155,9 +135,6 @@ export class PieceOfPiePlugin {
155
135
  'rgba',
156
136
  'radius',
157
137
  'fillingMode'].map((name) => {
158
- if (!this.bufferManagersMap?.has(name)) {
159
- return null; // this make vao with default attribute value with no buffer bound to it
160
- }
161
138
  const buffer = this.bufferManagersMap?.get(name)?.bufferManager.buffer;
162
139
  return {
163
140
  buffer: buffer,
@@ -165,9 +142,6 @@ export class PieceOfPiePlugin {
165
142
  offset: 0,
166
143
  };
167
144
  }));
168
- this._uboHandler = this.program.createUBO();
169
- this._uboHandler.updateSingle("u_color", new Float32Array(this._pluginOptions.defaultColor));
170
- this._uboHandler.updateSingle("u_opacity", new Float32Array([this._pluginOptions.opacity ?? 1.0])); // Default opacity is 1.0
171
145
  }
172
146
  draw3D() {
173
147
  if (!this.gl || !this.program || !this.vao || !this.globe) {