@pirireis/webglobeplugins 0.15.16-alpha → 0.15.18-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 (24) hide show
  1. package/Math/methods.js +2 -2
  2. package/package.json +1 -1
  3. package/point-tracks/plugin.js +18 -13
  4. package/programs/line-on-globe/linestrip/linestrip.js +0 -1
  5. package/programs/totems/globe-changes.js +52 -0
  6. package/range-tools-on-terrain/bearing-line/adapters.js +8 -5
  7. package/range-tools-on-terrain/bearing-line/plugin.js +6 -4
  8. package/range-tools-on-terrain/circle-line-chain/adapters.js +2 -0
  9. package/range-tools-on-terrain/circle-line-chain/plugin.js +24 -4
  10. package/range-tools-on-terrain/range-ring/adapters.js +59 -7
  11. package/range-tools-on-terrain/range-ring/plugin.js +23 -3
  12. package/semiplugins/lightweight/line-plugin.js +8 -4
  13. package/semiplugins/lightweight/piece-of-pie-plugin.js +4 -2
  14. package/semiplugins/shape-on-terrain/arc-plugin.js +34 -10
  15. package/semiplugins/shape-on-terrain/circle-plugin.js +46 -21
  16. package/semiplugins/shape-on-terrain/padding-1-degree.js +357 -190
  17. package/util/account/single-attribute-buffer-management/buffer-manager.js +12 -0
  18. package/util/account/single-attribute-buffer-management/buffer-orchestrator copy.js +161 -0
  19. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +91 -5
  20. package/util/account/single-attribute-buffer-management/chunked-buffer-manager.js +75 -0
  21. package/util/account/single-attribute-buffer-management/chunked-buffer-orchestrator.js +195 -0
  22. package/util/account/single-attribute-buffer-management/object-store.js +7 -0
  23. package/util/check/typecheck.js +12 -0
  24. package/util/geometry/index.js +2 -1
@@ -1,190 +1,357 @@
1
- "use strict";
2
- // // One Degree Padding
3
- // /**
4
- // * 2d coordinates are loaded ones
5
- // * 3d coordinates are calculated on the fly.
6
- // *
7
- // * 2d paddings are fixed size
8
- // * 3d paddings gets shortened as lod increases
9
- // *
10
- // * color buffer is shared and does not change on unless insert or delete
11
- // * changing color can be done by re inserting
12
- // *
13
- // *
14
- // *
15
- // */
16
- // import { Globe, LongLat, Meter, Color, BUFFER_TYPE, UBOHandler } from '../../types';
17
- // import { BufferManagersMap } from '../../util/account/single-attribute-buffer-management/types';
18
- // import { BufferManager } from '../../util/account/single-attribute-buffer-management/buffer-manager';
19
- // import { BufferOrchestrator } from '../../util/account/single-attribute-buffer-management/buffer-orchestrator';
20
- // import { LineStripProgramCache, LineProgram } from '../../programs/line-on-globe/linestrip/linestrip';
21
- // import { ProgramInterface } from '../../types';
22
- // import { SemiPluginInterface } from '../interface';
23
- // export type Padding1DegreeInput = {
24
- // key: string;
25
- // center: LongLat;
26
- // outerRadius: Meter;
27
- // heightFromGroundIn3D?: Meter; // optional, if not provided, defaultHeightFromGroundIn3D will be used
28
- // color: Color;
29
- // };
30
- // export type Padding1DegreeOptions = {
31
- // bufferType: BUFFER_TYPE;
32
- // variativeColorsOn: boolean;
33
- // defaultColor: Color;
34
- // defaultHeightFromGroundIn3D: Meter;
35
- // }
36
- // const initialCapacity = 2; // initial capacity for the buffer managers
37
- // // const _float32Array = new Float32Array(360 * 3 * 2).fill(NaN);
38
- // export class Paddings1Degree implements ProgramInterface, SemiPluginInterface {
39
- // id: string;
40
- // private globe: Globe | null = null;
41
- // private bufferOrchestrator: BufferOrchestrator;
42
- // private bufferManagersMap: BufferManagersMap;
43
- // private lineProgram: LineProgram | null = null;
44
- // private _LODCoeffecientForPaddingScale: number = 1;
45
- // private _PaddingSizeRatio = 0.1; // 0.1 means 10% of the padding size is used for 3d padding
46
- // private _innerPaddingRatio = 0.9; //
47
- // private _float32Array: Float32Array | null = null; // this is used to forward the data to the buffer manager
48
- // private _uboHandler: UBOHandler | null = null; // this is used to forward the data to the shader program
49
- // private _bufferNames: string[] = ["position2d", "position3d"];
50
- // private _options: Padding1DegreeOptions = {
51
- // bufferType: "STATIC_DRAW",
52
- // variativeColorsOn: false,
53
- // defaultColor: [1, 1, 1, 1], // white color
54
- // defaultHeightFromGroundIn3D: 0.1, // 10 cm from ground
55
- // };
56
- // constructor(id: string, options: Padding1DegreeOptions | null = null) {
57
- // this.id = id;
58
- // this.bufferManagersMap = new Map();
59
- // this.lineProgram = null;
60
- // this._options = options ? { ...this._options, ...options } : this._options;
61
- // this.bufferOrchestrator = new BufferOrchestrator()
62
- // if (this._options.variativeColorsOn) {
63
- // this._bufferNames.push("color");
64
- // }
65
- // }
66
- // insertBulk(data: Padding1DegreeInput[]): void {
67
- // if (this.globe === null) {
68
- // throw new Error("Globe is not initialized");
69
- // }
70
- // // create floa32array
71
- // this._float32Array = new Float32Array(360 * 4 * 4); // largest float32Array
72
- // this.bufferOrchestrator.insertBulk(data, this.bufferManagersMap, this._bufferNames);
73
- // this.globe?.DrawRender();
74
- // }
75
- // init(globe: Globe): void {
76
- // this.globe = globe;
77
- // this.lineProgram = LineStripProgramCache.get(globe);
78
- // const bufferManagersMap = new Map(
79
- // [
80
- // ["position2d", {
81
- // bufferManager: new BufferManager(globe.gl as WebGL2RenderingContext,
82
- // 360 * 2 * 3, // plus 1 to cut
83
- // { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
84
- // adaptor: (PaddingInput: Padding1DegreeInput) => {
85
- // if (this._float32Array === null) {
86
- // throw new Error("Float32Array is not initialized");
87
- // } else {
88
- // this._float32Array.fill(NaN); // reset the float32Array
89
- // }
90
- // for (let i = 0; i < 360; i++) {
91
- // let { long, lat } = globe.Math.FindPointByPolar(
92
- // PaddingInput.center[0], // center long
93
- // PaddingInput.center[1], // center lat
94
- // PaddingInput.outerRadius, // outer radius
95
- // i, // angle
96
- // );
97
- // let coords = globe.api_GetMercator2DPoint(long, lat);
98
- // // fill the second coordinate with 0
99
- // this._float32Array[i * 3] = coords[0];
100
- // this._float32Array[i * 3 + 1] = coords[1];
101
- // ({ long, lat } = globe.Math.FindPointByPolar(
102
- // PaddingInput.center[0], // center long
103
- // PaddingInput.center[1], // center lat
104
- // PaddingInput.outerRadius * this._innerPaddingRatio, // inner radius
105
- // i, // angle
106
- // ));
107
- // let innerCoords = globe.api_GetMercator2DPoint(long, lat);
108
- // // fill the second coordinate with 0
109
- // this._float32Array[i * 3 + 2] = innerCoords[0];
110
- // this._float32Array[i * 3 + 3] = innerCoords[1];
111
- // }
112
- // return this._float32Array.subarray(0, 360 * 2 * 3);
113
- // }
114
- // }
115
- // ],
116
- // [
117
- // "position3d", {
118
- // bufferManager: new BufferManager(globe.gl as WebGL2RenderingContext,
119
- // 360 * 3 * 3, // plus 1 to cut
120
- // { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
121
- // adaptor: (PaddingInput: Padding1DegreeInput) => {
122
- // if (this._float32Array === null) {
123
- // throw new Error("Float32Array is not initialized");
124
- // } else {
125
- // this._float32Array.fill(NaN); // reset the float32Array
126
- // }
127
- // const _float32Array = this._float32Array;
128
- // for (let i = 0; i < 360; i++) {
129
- // const height = PaddingInput.heightFromGroundIn3D ? PaddingInput.heightFromGroundIn3D : this._options.defaultHeightFromGroundIn3D;
130
- // let { long, lat, } = globe.Math.FindPointByPolar(
131
- // PaddingInput.center[0], // center long
132
- // PaddingInput.center[1], // center lat
133
- // PaddingInput.outerRadius, // outer radius
134
- // i, // angle
135
- // );
136
- // let coords = globe.api_GetCartesian3DPoint(long, lat, height, 0);
137
- // // fill the second coordinate with 0
138
- // _float32Array[i * 4] = coords[0];
139
- // _float32Array[i * 4 + 1] = coords[1];
140
- // ({ long, lat } = globe.Math.FindPointByPolar(
141
- // PaddingInput.center[0], // center long
142
- // PaddingInput.center[1], // center lat
143
- // PaddingInput.outerRadius * this._innerPaddingRatio, // inner radius
144
- // i, // angle
145
- // ));
146
- // let innerCoords = globe.api_GetCartesian3DPoint(long, lat, height, 0);
147
- // // fill the second coordinate with 0
148
- // _float32Array[i * 4 + 2] = innerCoords[0];
149
- // _float32Array[i * 4 + 3] = innerCoords[1];
150
- // }
151
- // return _float32Array.subarray(0, 360 * 3 * 3);
152
- // }
153
- // }
154
- // ],
155
- // ]
156
- // );
157
- // if (this._options.variativeColorsOn) {
158
- // bufferManagersMap.set(
159
- // "color", {
160
- // bufferManager: new BufferManager(globe.gl as WebGL2RenderingContext,
161
- // 360 * 4 * 3, // 4 for RGBA
162
- // { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
163
- // adaptor: (PaddingInput: Padding1DegreeInput) => {
164
- // const color = PaddingInput.color || this._options.defaultColor;
165
- // const colorArray = new Float32Array(360 * 4 * 3);
166
- // this._float32Array = colorArray; // store for forwarding
167
- // for (let i = 0; i < 360; i++) {
168
- // this._float32Array[i * 4] = color[0];
169
- // this._float32Array[i * 4 + 1] = color[1];
170
- // this._float32Array[i * 4 + 2] = color[2];
171
- // this._float32Array[i * 4 + 3] = color[3];
172
- // this._float32Array[i * 4 + 4] = color[0];
173
- // this._float32Array[i * 4 + 5] = color[1];
174
- // this._float32Array[i * 4 + 6] = color[2];
175
- // this._float32Array[i * 4 + 7] = color[3];
176
- // }
177
- // return this._float32Array.subarray(0, 360 * 4 * 3);
178
- // }
179
- // }
180
- // );
181
- // }
182
- // this.bufferOrchestrator.resetWithCapacity(bufferManagersMap, initialCapacity);
183
- // this._uboHandler = this.lineProgram.createUBO("STATIC_DRAW");
184
- // this._uboHandler.updateSingle("u_color", new Float32Array(this._options.defaultColor));
185
- // }
186
- // // This method is called when the plugin is destroyed
187
- // __updateLODCoefficientForPaddingScale(): void {
188
- // // TODO: call this ones when lod changes or each frame // maybe only on 3d geometry
189
- // }
190
- // }
1
+ // One Degree Padding
2
+ /**
3
+ * 2d coordinates are loaded ones
4
+ * 3d coordinates are calculated on the fly.
5
+ *
6
+ * 2d paddings are fixed size
7
+ * 3d paddings gets shortened as lod increases
8
+ *
9
+ * color buffer is shared and does not change on unless insert or delete
10
+ * changing color can be done by re inserting
11
+ *
12
+ *
13
+ *
14
+ */
15
+ import { BufferManager } from '../../util/account/single-attribute-buffer-management/buffer-manager';
16
+ import { BufferOrchestrator } from '../../util/account/single-attribute-buffer-management/buffer-orchestrator';
17
+ import { LineStripProgramCache } from '../../programs/line-on-globe/linestrip/linestrip';
18
+ import { opacityCheck, colorCheck } from '../../util/check/typecheck';
19
+ const initialCapacity = 2; // initial capacity for the buffer managers
20
+ // const _float32Array = new Float32Array(360 * 3 * 2).fill(NaN);
21
+ export class Padding1DegreePlugin {
22
+ id;
23
+ globe = null;
24
+ bufferOrchestrator;
25
+ bufferManagersMap;
26
+ lineProgram = null;
27
+ _opacityLODCoef = 1;
28
+ _pluginOpacity = 1; // this is used to set the opacity of the plugin
29
+ _innerPaddingRatio = 0.9; //
30
+ _float32Array = null; // this is used to forward the data to the buffer manager
31
+ _uboHandler = null; // this is used to forward the data to the shader program
32
+ _bufferNames = ["position2d", "position3d"];
33
+ _vao = null; // this is used to store the VAO for the plugin
34
+ _freed = false; // this is used to check if the plugin is freed or not
35
+ _lastCAM_LOD = { camInfo: -1, lod: -1 }; // this is used to store the last zoom and lod values
36
+ _dataMap = new Map();
37
+ _options = {
38
+ bufferType: "STATIC_DRAW",
39
+ variativeColorsOn: false,
40
+ defaultColor: [1, 1, 1, 1], // white color
41
+ defaultHeightFromGroundIn3D: 0.1, // 10 cm from ground
42
+ adativePaddingSize: true, // if true, the padding size will be adaptive to the LOD
43
+ adaptiveOpacity: true, // if true, the opacity will be adaptive to the LOD
44
+ isMSL: false // if true, no elevation of terrain
45
+ };
46
+ constructor(id, options = null) {
47
+ this.id = id;
48
+ this.bufferManagersMap = new Map();
49
+ this.lineProgram = null;
50
+ this._options = options ? { ...this._options, ...options } : this._options;
51
+ this.bufferOrchestrator = new BufferOrchestrator();
52
+ if (this._options.variativeColorsOn) {
53
+ this._bufferNames.push("color");
54
+ }
55
+ }
56
+ insertBulk(inputs) {
57
+ if (this.globe === null) {
58
+ console.warn("Globe is not initialized, cannot insert input");
59
+ return;
60
+ }
61
+ if (this._freed) {
62
+ console.warn("Plugin is freed, cannot insert input");
63
+ return;
64
+ }
65
+ const wrapper = [null];
66
+ this._float32Array = new Float32Array(360 * 4 * 4); // largest float32Array
67
+ for (let i = 0; i < inputs.length; i++) {
68
+ const coords = preAdapter(this.globe, inputs[i], this._innerPaddingRatio, null);
69
+ const paddingInput = { ...inputs[i], ...coords };
70
+ this._dataMap.set(paddingInput.key, paddingInput);
71
+ wrapper[0] = paddingInput;
72
+ this.bufferOrchestrator.insertBulk(wrapper, this.bufferManagersMap, this._bufferNames);
73
+ }
74
+ this._float32Array = null;
75
+ this.globe?.DrawRender();
76
+ }
77
+ deleteBulk(keys) {
78
+ if (this.globe === null) {
79
+ console.warn("Globe is not initialized, cannot delete data");
80
+ return;
81
+ }
82
+ if (this._freed) {
83
+ console.warn("Plugin is freed, cannot delete data");
84
+ return;
85
+ }
86
+ this.bufferOrchestrator.deleteBulk(keys, this.bufferManagersMap);
87
+ this.globe?.DrawRender();
88
+ }
89
+ setPluginOpacity(opacity) {
90
+ if (this._freed) {
91
+ console.warn("Plugin is freed, cannot set opacity");
92
+ return;
93
+ }
94
+ if (this.globe === null) {
95
+ console.warn("Globe is not initialized, cannot set opacity");
96
+ return;
97
+ }
98
+ opacityCheck(opacity);
99
+ this._opacityLODCoef = opacity;
100
+ this._uboHandler?.updateSingle("u_opacity", new Float32Array([opacity]));
101
+ this.globe.DrawRender();
102
+ }
103
+ setDefaultColor(color) {
104
+ if (this._freed) {
105
+ console.warn("Plugin is freed, cannot set default color");
106
+ return;
107
+ }
108
+ if (this.globe === null) {
109
+ console.warn("Globe is not initialized, cannot set default color");
110
+ return;
111
+ }
112
+ colorCheck(color);
113
+ this._options.defaultColor = color;
114
+ this._uboHandler?.updateSingle("u_color", new Float32Array(color));
115
+ this.globe.DrawRender();
116
+ }
117
+ setElevationMode(mode) {
118
+ switch (mode) {
119
+ case "msl":
120
+ this._options.isMSL = true;
121
+ break;
122
+ case "agl":
123
+ this._options.isMSL = false;
124
+ break;
125
+ default:
126
+ throw new Error(`Unknown elevation mode: ${mode}`);
127
+ }
128
+ this._buildPaddings("elevation");
129
+ this.globe?.DrawRender();
130
+ }
131
+ init(globe) {
132
+ this.globe = globe;
133
+ this.lineProgram = LineStripProgramCache.get(globe);
134
+ const bufferManagersMap = new Map([
135
+ ["position2d", {
136
+ bufferManager: new BufferManager(globe.gl, 360 * 2 * 3, // plus 1 to cut
137
+ { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
138
+ adaptor: (paddingInput) => {
139
+ if (this._float32Array === null) {
140
+ throw new Error("Float32Array is not initialized");
141
+ }
142
+ else {
143
+ this._float32Array.fill(NaN); // reset the float32Array
144
+ }
145
+ for (let i = 0; i < 360; i++) {
146
+ const startCoords = paddingInput.startCoords[i];
147
+ const endCoords = paddingInput.endCoords[i];
148
+ if (startCoords === null || endCoords === null) {
149
+ continue;
150
+ }
151
+ let coords = globe.api_GetMercator2DPoint(startCoords[0], startCoords[1]);
152
+ // fill the second coordinate with 0
153
+ this._float32Array[i * 6] = coords[0];
154
+ this._float32Array[i * 6 + 1] = coords[1];
155
+ let innerCoords = globe.api_GetMercator2DPoint(endCoords[0], endCoords[1]);
156
+ // fill the second coordinate with 0
157
+ this._float32Array[i * 6 + 2] = innerCoords[0];
158
+ this._float32Array[i * 6 + 3] = innerCoords[1];
159
+ }
160
+ return this._float32Array.subarray(0, 360 * 2 * 3);
161
+ }
162
+ }
163
+ ],
164
+ [
165
+ "position3d", {
166
+ bufferManager: new BufferManager(globe.gl, 360 * 3 * 3, // plus 1 to cut
167
+ { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
168
+ adaptor: (paddingInput) => {
169
+ if (this._float32Array === null) {
170
+ throw new Error("Float32Array is not initialized");
171
+ }
172
+ else {
173
+ this._float32Array.fill(NaN); // reset the float32Array
174
+ }
175
+ const _float32Array = this._float32Array;
176
+ for (let i = 0; i < 360; i++) {
177
+ const startCoords = paddingInput.startCoords[i];
178
+ const endCoords = paddingInput.endCoords[i];
179
+ if (startCoords === null || endCoords === null) {
180
+ continue;
181
+ }
182
+ const height = paddingInput.heightFromGroundIn3D ?? this._options.defaultHeightFromGroundIn3D;
183
+ let coords = globe.api_GetCartesian3DPoint(startCoords[0], startCoords[1], height, this._options.isMSL);
184
+ // fill the second coordinate with 0
185
+ _float32Array[i * 9] = coords[0];
186
+ _float32Array[i * 9 + 1] = coords[1];
187
+ _float32Array[i * 9 + 2] = coords[2];
188
+ let innerCoords = globe.api_GetCartesian3DPoint(endCoords[0], endCoords[1], height, this._options.isMSL);
189
+ // fill the second coordinate with 0
190
+ _float32Array[i * 9 + 3] = innerCoords[0];
191
+ _float32Array[i * 9 + 4] = innerCoords[1];
192
+ _float32Array[i * 9 + 5] = innerCoords[2];
193
+ }
194
+ return _float32Array.subarray(0, 360 * 3 * 3);
195
+ }
196
+ }
197
+ ],
198
+ ]);
199
+ if (this._options.variativeColorsOn) {
200
+ bufferManagersMap.set("color", {
201
+ bufferManager: new BufferManager(globe.gl, 360 * 4 * 3, // 4 for RGBA
202
+ { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
203
+ adaptor: (paddingInput) => {
204
+ if (this._float32Array === null) {
205
+ throw new Error("Float32Array is not initialized");
206
+ }
207
+ else {
208
+ this._float32Array.fill(NaN); // reset the float32Array
209
+ }
210
+ if (!paddingInput.colorsRatios) {
211
+ const color = this._options.defaultColor;
212
+ const colorArray = new Float32Array(360 * 4 * 3);
213
+ this._float32Array = colorArray; // store for forwarding
214
+ for (let i = 0; i < 360; i++) {
215
+ this._float32Array[i * 12] = color[0];
216
+ this._float32Array[i * 12 + 1] = color[1];
217
+ this._float32Array[i * 12 + 2] = color[2];
218
+ this._float32Array[i * 12 + 3] = color[3] * this._opacityLODCoef;
219
+ this._float32Array[i * 12 + 4] = color[0];
220
+ this._float32Array[i * 12 + 5] = color[1];
221
+ this._float32Array[i * 12 + 6] = color[2];
222
+ this._float32Array[i * 12 + 7] = 0; //color[3] * this._opacityLODCoef;
223
+ }
224
+ return this._float32Array.subarray(0, 360 * 4 * 3);
225
+ }
226
+ else {
227
+ const colorsRatios = paddingInput.colorsRatios;
228
+ let i = 0;
229
+ for (const colorRatio of colorsRatios) {
230
+ const color = colorRatio.color;
231
+ const ratio = colorRatio.ratio;
232
+ for (let j = 0; j < ratio; j++) {
233
+ this._float32Array[i * 12] = color[0];
234
+ this._float32Array[i * 12 + 1] = color[1];
235
+ this._float32Array[i * 12 + 2] = color[2];
236
+ this._float32Array[i * 12 + 3] = color[3] * this._opacityLODCoef;
237
+ this._float32Array[i * 12 + 4] = color[0];
238
+ this._float32Array[i * 12 + 5] = color[1];
239
+ this._float32Array[i * 12 + 6] = color[2];
240
+ this._float32Array[i * 12 + 7] = 0; // color[3] * this._opacityLODCoef;
241
+ i++;
242
+ }
243
+ }
244
+ return this._float32Array.subarray(0, 360 * 4 * 3);
245
+ }
246
+ }
247
+ });
248
+ }
249
+ const vaoInput = ["position3d", "position2d", "color"].map((name) => {
250
+ const bufferManager = bufferManagersMap.get(name);
251
+ if (!bufferManager) {
252
+ return null;
253
+ }
254
+ return {
255
+ buffer: bufferManager.bufferManager.buffer,
256
+ stride: 0,
257
+ offset: 0
258
+ };
259
+ });
260
+ this._vao = this.lineProgram.createVAO(vaoInput[0], vaoInput[1], vaoInput[2]);
261
+ this.bufferManagersMap = bufferManagersMap;
262
+ this.bufferOrchestrator.resetWithCapacity(bufferManagersMap, initialCapacity);
263
+ this._uboHandler = this.lineProgram.createUBO("STATIC_DRAW");
264
+ this._uboHandler.updateSingle("u_color", new Float32Array(this._options.defaultColor));
265
+ }
266
+ draw3D() {
267
+ if (this._freed) {
268
+ console.warn("Plugin is freed, cannot draw");
269
+ return;
270
+ }
271
+ if (this.globe === null || this.lineProgram === null || this._vao === null) {
272
+ console.warn("Globe or LineProgram or VAO is not initialized, cannot draw");
273
+ return;
274
+ }
275
+ const gl = this.globe.gl;
276
+ const drawOptions = {
277
+ drawRange: {
278
+ first: 0,
279
+ count: this.bufferOrchestrator.length * (360 * 3), // plus 1 is for cutting linestrips
280
+ },
281
+ };
282
+ gl.disable(gl.DEPTH_TEST);
283
+ this.lineProgram.draw(this._vao, drawOptions, this._pluginOpacity, this._uboHandler);
284
+ gl.enable(gl.DEPTH_TEST);
285
+ }
286
+ free() {
287
+ if (this._freed) {
288
+ console.warn("Plugin is already freed");
289
+ return;
290
+ }
291
+ if (!this.globe || !this.lineProgram) {
292
+ console.warn("Globe or LineProgram is not initialized, cannot free the plugin");
293
+ return;
294
+ }
295
+ this._freed = true;
296
+ LineStripProgramCache.release(this.lineProgram);
297
+ this.lineProgram = null;
298
+ this._uboHandler?.free();
299
+ this._uboHandler = null;
300
+ this.globe.gl.deleteVertexArray(this._vao);
301
+ this.globe = null;
302
+ this._vao = null;
303
+ this.bufferManagersMap.forEach((bufferManager) => {
304
+ bufferManager.bufferManager.free();
305
+ });
306
+ this._float32Array = null;
307
+ }
308
+ __updateLODRelatedParameters() {
309
+ const lod = this.globe?.api_GetCurrentLODWithDecimal();
310
+ this._innerPaddingRatio = 1 - Math.pow(0.7, lod);
311
+ }
312
+ _buildPaddings(level) {
313
+ }
314
+ __onCamOrLodChange() {
315
+ //TODO: implement -> on lod change the _innerPaddingRatio and all positions should be recalculated.
316
+ // calculation
317
+ // if cam change, recalculate 3d positions
318
+ }
319
+ }
320
+ function preAdapter(globe, paddingInput, paddingRatio, startCoords) {
321
+ const endCoords = new Array(360);
322
+ if (startCoords === null) {
323
+ startCoords = new Array(360);
324
+ for (let i = 0; i < 360; i++) {
325
+ const { long, lat } = globe.Math.FindPointByPolar(paddingInput.center[0], // center long
326
+ paddingInput.center[1], // center lat
327
+ paddingInput.outerRadius, // outer radius
328
+ i);
329
+ const { long: endLong, lat: endLat } = globe.Math.FindPointByPolar(paddingInput.center[0], // center long
330
+ paddingInput.center[1], // center lat
331
+ paddingInput.outerRadius * paddingRatio, // inner radius
332
+ i);
333
+ const longDifference = Math.abs(long - endLong);
334
+ const latDifference = Math.abs(lat - endLat);
335
+ if (longDifference > 45) {
336
+ startCoords[i] = null;
337
+ endCoords[i] = null;
338
+ continue;
339
+ }
340
+ // Assign the calculated coordinates
341
+ startCoords[i] = [long, lat];
342
+ endCoords[i] = [endLong, endLat];
343
+ }
344
+ }
345
+ else {
346
+ // Handle case when startCoords is provided
347
+ for (let i = 0; i < 360; i++) {
348
+ if (startCoords[i] === null) {
349
+ endCoords[i] = null;
350
+ continue;
351
+ }
352
+ const { long: endLong, lat: endLat } = globe.Math.FindPointByPolar(paddingInput.center[0], paddingInput.center[1], paddingInput.outerRadius * paddingRatio, i);
353
+ endCoords[i] = [endLong, endLat];
354
+ }
355
+ }
356
+ return { startCoords, endCoords };
357
+ }
@@ -60,6 +60,18 @@ export class BufferManager {
60
60
  }
61
61
  gl.bindBuffer(gl.ARRAY_BUFFER, null);
62
62
  }
63
+ insertConsecutiveBulk(items, offset, adapter, Constructor = Float32Array) {
64
+ const { gl, buffer, itemSize } = this;
65
+ const cpuBuffer = new Constructor(itemSize * items.length);
66
+ console.log('cpuBuffer', cpuBuffer);
67
+ console.log(typeof cpuBuffer);
68
+ for (let i = 0; i < items.length; i++) {
69
+ cpuBuffer.set(adapter(items[i]), i * itemSize);
70
+ }
71
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
72
+ gl.bufferSubData(gl.ARRAY_BUFFER, offset * itemSize * 4, cpuBuffer);
73
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
74
+ }
63
75
  // TODO: this is broken
64
76
  defrag(offsetValues, occupiedCapacity, newCapacity) {
65
77
  const { gl, buffer, bufferType, itemSize } = this;