@pirireis/webglobeplugins 0.8.2 → 0.8.4

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.
@@ -0,0 +1,14 @@
1
+ const findFirstIndexInRange = (container, value) => {
2
+ let start = 0;
3
+ let end = container.length - 1;
4
+ let mid = 0;
5
+ while (start <= end) {
6
+ mid = Math.floor((start + end) / 2);
7
+ if (container[mid] <= value && value <= container[mid + 1]) return mid;
8
+ if (container[mid] < value) start = mid + 1;
9
+ else end = mid - 1;
10
+ }
11
+ return null;
12
+ }
13
+
14
+ export { findFirstIndexInRange };
@@ -0,0 +1,26 @@
1
+ # Programs
2
+
3
+ 1) points with depth (3d/2d), draw to framebuffer and use this until projection or data changes, has picking
4
+ 2) glow hearth-beat effect points on the target point
5
+ 3) glow plane effect on surface projection of target point
6
+ 4) a line from the target point to the surface
7
+ 5) info box on the target point
8
+
9
+ all except 1 are optional
10
+
11
+ # Inputs
12
+
13
+ 1) Target point ( long, lat, depth in meter)
14
+ 2) info box content
15
+
16
+ # Derived Cases
17
+
18
+ ## Time dimension
19
+
20
+ Either:
21
+ 1) load all points at once ordered by time. Draw range of points
22
+ 2) Select points on time window and load them. Draw them
23
+
24
+ Approach 1 is simple yet it needs time series as input.
25
+ Approach 2 flexible, memory efficient. Client side is complex.
26
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -33,6 +33,7 @@ class PointTracksPlugin {
33
33
  this._opacity = opacity;
34
34
  this.program = null
35
35
  this._lastWH = { w: 0, h: 0 };
36
+ this._focusParams = { on: false, length: 0, elementBuffer: null };
36
37
  this.pointSizes = {
37
38
  pointSize,
38
39
  selectionPointFilling,
@@ -47,6 +48,7 @@ class PointTracksPlugin {
47
48
  this.gl = gl;
48
49
  this._pickerDisplayer = new PickerDisplayer(globe);
49
50
  this._pointProgram = pointOnGlobeProgramCache.get(globe);
51
+ this._focusParams.elementBuffer = gl.createBuffer();
50
52
  this._initBufferManagers();
51
53
  }
52
54
 
@@ -161,13 +163,20 @@ class PointTracksPlugin {
161
163
  throw new Error("Too many points, Point count cannot exceed 2147483647");
162
164
  }
163
165
  const { _bufferManagersMap, _bufferOrchestrator } = this;
164
- console.log("point tracks plugin insert bulk", flattenedPoints);
165
166
  _bufferOrchestrator.insertBulk(flattenedPoints, _bufferManagersMap);
166
167
  this.globe?.DrawRender();
167
168
 
168
169
  }
169
170
 
170
171
 
172
+ flush() {
173
+ const capacity = 100
174
+ this._bufferOrchestrator?.flush({ capacity });
175
+ this._bufferManagersMap.forEach(({ bufferManager }) => bufferManager.resetWithCapacity(capacity));
176
+ this._tracksToPointsMap.clear();
177
+ this.globe?.DrawRender();
178
+ }
179
+
171
180
  /**
172
181
  * @param {string} trackID
173
182
  */
@@ -184,6 +193,17 @@ class PointTracksPlugin {
184
193
  this.globe?.DrawRender();
185
194
  }
186
195
 
196
+ focusTracks(trackIDs = null) {
197
+ if (!this.globe) return;
198
+ if (!trackIDs) {
199
+ this._focusParams.on = false;
200
+ this.globe?.DrawRender();
201
+ return;
202
+ }
203
+
204
+ this._focusParams.on = this._fillElementBuffer(trackIDs);
205
+ this.globe.DrawRender();
206
+ }
187
207
 
188
208
  /**
189
209
  * @param {string} trackID
@@ -206,6 +226,7 @@ class PointTracksPlugin {
206
226
  this._isFreed = true;
207
227
  this._pickerDisplayer.free();
208
228
  pointOnGlobeProgramCache.release(this.globe);
229
+ this.gl.deleteBuffer(this._focusParams.elementBuffer);
209
230
  this._bufferManagersMap.forEach(
210
231
  ({ bufferManager, adaptor }) => bufferManager.free()
211
232
  );
@@ -218,17 +239,28 @@ class PointTracksPlugin {
218
239
 
219
240
  _pickerDisplayer.bindFBO();
220
241
  _pickerDisplayer.clearTextures();
221
- _pointProgram.draw(_vao, _bufferOrchestrator.length,
222
- {
223
- hoveredID: this._selectedID,
224
- opacity: this._opacity,
225
- pointSize: this.pointSizes.pointSize,
226
- hoveredPointSize: this.pointSizes.hoveredPointSize
227
-
228
- });
229
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
230
242
 
243
+ if (this._focusParams.on) {
244
+ _pointProgram.draw(_vao, this._focusParams.length,
245
+ {
246
+ hoveredID: this._selectedID,
247
+ opacity: this._opacity,
248
+ pointSize: this.pointSizes.pointSize,
249
+ hoveredPointSize: this.pointSizes.hoveredPointSize,
250
+ elementBuffer: this._focusParams.elementBuffer
251
+ });
252
+ } else {
253
+ _pointProgram.draw(_vao, _bufferOrchestrator.length,
254
+ {
255
+ hoveredID: this._selectedID,
256
+ opacity: this._opacity,
257
+ pointSize: this.pointSizes.pointSize,
258
+ hoveredPointSize: this.pointSizes.hoveredPointSize
259
+ });
260
+ }
261
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
231
262
  _pickerDisplayer.drawColorTexture();
263
+
232
264
  this._selfSelect();
233
265
  }
234
266
 
@@ -237,7 +269,6 @@ class PointTracksPlugin {
237
269
  const w = this.globe.api_ScrW();
238
270
  const h = this.globe.api_ScrH();
239
271
  if (w === this._lastWH.w && h === this._lastWH.h) return;
240
- console.log("point tracks plugin resize", w, h);
241
272
 
242
273
  this._lastWH.w = w;
243
274
  this._lastWH.h = h;
@@ -280,6 +311,35 @@ class PointTracksPlugin {
280
311
  });
281
312
 
282
313
  }
314
+
315
+
316
+ _fillElementBuffer(trackIDs) {
317
+
318
+ let length = 0;
319
+ const indexes = [];
320
+
321
+ for (const trackID of trackIDs) {
322
+ const pointSet = this._tracksToPointsMap.get(trackID);
323
+ if (!pointSet) continue;
324
+ const points = Array.from(pointSet);
325
+ for (const pointID of points) {
326
+ const key = keyMethod(trackID, pointID);
327
+ const index = this._bufferOrchestrator.offsetMap.get(key);
328
+ indexes.push(index);
329
+ length++;
330
+ }
331
+ }
332
+ this._focusParams.length = length;
333
+ if (length === 0) {
334
+ return false;
335
+ }
336
+ const { gl } = this;
337
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._focusParams.elementBuffer);
338
+ gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint32Array(indexes), gl.STATIC_DRAW);
339
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
340
+ return true;
341
+ }
342
+
283
343
  }
284
344
 
285
345
 
File without changes
@@ -135,7 +135,7 @@ class PointOnGlobeProgram {
135
135
  }
136
136
 
137
137
 
138
- draw(vao, length, { opacity = 1.0, hoveredID = -1, pointSize = 2.0, hoveredPointSize = 4.0 } = {}) {
138
+ draw(vao, length, { opacity = 1.0, hoveredID = -1, pointSize = 2.0, hoveredPointSize = 4.0, elementBuffer = null } = {}) {
139
139
  if (length === 0 || opacity === 0) return;
140
140
  const { gl, program, uniforms } = this;
141
141
  gl.useProgram(program);
@@ -157,12 +157,19 @@ class PointOnGlobeProgram {
157
157
  }
158
158
  gl.bindVertexArray(vao);
159
159
  this.cameraBlockTotem.bind(this.cameraBlockBingingPoint);
160
- gl.drawArrays(gl.POINTS, 0, length);
160
+ if (elementBuffer) {
161
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementBuffer);
162
+ gl.drawElements(gl.POINTS, length, gl.UNSIGNED_INT, 0);
163
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
164
+ } else {
165
+ gl.drawArrays(gl.POINTS, 0, length);
166
+ }
161
167
  this.cameraBlockTotem.unbind(this.cameraBlockBingingPoint);
162
168
  gl.bindVertexArray(null);
163
169
  }
164
170
 
165
171
 
172
+
166
173
  free() {
167
174
  if (this._isFreed) return;
168
175
  const { gl, globe } = this;
@@ -111,7 +111,6 @@ export class BufferOrchestrator {
111
111
  }
112
112
 
113
113
 
114
-
115
114
  getOffset(key) {
116
115
  return this.offsetMap.get(key);
117
116
  }
@@ -166,8 +165,9 @@ export class BufferOrchestrator {
166
165
  * Flushes metadata and sets length to 0 without actualize change on buffers
167
166
  * This method created for cases in which data is loaded on each frame
168
167
  */
169
- flush() {
168
+ flush({ capacity = 10 } = {}) {
170
169
  this._length = 0;
170
+ this._capacity = capacity;
171
171
  this.tombstoneOffSet = []
172
172
  this.offsetMap.clear();
173
173
  }
package/wind/plugin.js CHANGED
@@ -327,6 +327,32 @@ const defaultRampColors = [
327
327
  ];
328
328
 
329
329
 
330
+ const windyLegendData = {
331
+ "thresholds": [0, 3, 3, 5, 5, 7, 10, 10, 13, 15, 15, 17, 20, 20, 25, 25, 30],
332
+ // 0 5 10 20 30 40 60
333
+ // "thresholds": [0, 5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 40, 60],
334
+ "values": [
335
+ "#6271B8",
336
+ "#6271B8",
337
+ "#6271B8",
338
+ "#6271B8",
339
+ "#3D6EA3",
340
+ "#4A94AA",
341
+ "#4A9294",
342
+ "#4D8E7C",
343
+ "#4CA44C",
344
+ "#67A436",
345
+ "#A28740",
346
+ "#A26D5C",
347
+ "#8D3F5C",
348
+ "#974B91",
349
+ "#5F64A0",
350
+ "#5B88A1",
351
+ "#5B88A1"
352
+ ]
353
+ };
354
+
355
+
330
356
  export default class WindPlugin {
331
357
 
332
358
  /**
@@ -355,7 +381,7 @@ export default class WindPlugin {
355
381
  maxSpeed = 1000.0,
356
382
  height = 0.0,
357
383
  numParticles = 40000,
358
- legendData = null
384
+ legendData = windyLegendData
359
385
  } = {}) {
360
386
 
361
387
  this.id = id;