@pirireis/webglobeplugins 0.6.18 → 0.6.20

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.
@@ -1,10 +1,14 @@
1
1
  import { pieceOfPieProgramCache } from '../programs/rings/partial-ring/piece-of-pie';
2
2
  import { LineOnGlobeCache } from '../programs/line-on-globe/naive-accurate';
3
- import { CircleCache } from '../programs/line-on-globe/circle-accurate';
3
+ import { CircleCache as Circle3DCache } from '../programs/line-on-globe/circle-accurate-3d';
4
+ import { CircleCache, EDGE_COUNT as flatCircleEdgeCount } from '../programs/line-on-globe/circle-accurate-flat';
4
5
  import { BufferOrchestrator, BufferManager } from '../util/account';
5
6
  import { AngledLineProgramCache } from '../programs/line-on-globe/angled-line'; // TODO calculate the bearing target for 2d and 3d and use lineOnGlobeProgram
6
7
  import { mapGetOrThrow } from "../util/check/get";
8
+ import { populateFloat32Array } from "../util/jshelpers/data-filler";
7
9
  import { ContextTextWriter } from '../write-text/context-text'
10
+
11
+
8
12
  export const RINGPARTIAL_DRAW_MODE = Object.freeze({
9
13
  LINE_STRIP: "LINE_STRIP",
10
14
  TRIANGLE_FAN: "TRIANGLE_FAN",
@@ -30,6 +34,8 @@ const constraintFloat = (x, lowerBound, upperBound) => {
30
34
  *
31
35
  */
32
36
 
37
+
38
+
33
39
  export default class Plugin {
34
40
  /**
35
41
  *
@@ -113,6 +119,7 @@ export default class Plugin {
113
119
  this.ringProgram = pieceOfPieProgramCache.get(globe);
114
120
  this.angledLineProgram = AngledLineProgramCache.get(globe);
115
121
  this.circleProgram = CircleCache.get(globe);
122
+ this.circle3DProgram = Circle3DCache.get(globe);
116
123
  // this.angleTextContext = new ContextTextWriter(globe);
117
124
  // this.distanceTextContext = new ContextTextWriter(globe);
118
125
  {
@@ -126,6 +133,10 @@ export default class Plugin {
126
133
  'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
127
134
  'adaptor': (item) => new Float32Array(globe.api_GetMercator2DPoint(item.long, item.lat)),
128
135
  }],
136
+ ["centerCoords2dflat", {
137
+ 'bufferManager': new BufferManager(gl, flatCircleEdgeCount * 2, { bufferType, initialCapacity }),
138
+ 'adaptor': (item) => item.centerCoords2dflat,
139
+ }],
129
140
  ["centerCoords3d", {
130
141
  'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
131
142
  'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.long, item.lat, 0, 0)),
@@ -200,19 +211,35 @@ export default class Plugin {
200
211
  }],
201
212
  ["dashOpacity", {
202
213
  'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
203
- 'adaptor': (item) => new Float32Array([item.dashOpacity])
214
+ 'adaptor': (item) => new Float32Array([item.dashOpacity]),
204
215
  }],
216
+
217
+ // normal circle
205
218
  ["circleDashAngle", {
206
- 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
207
- 'adaptor': (item) => new Float32Array([item.circleDashAngle / 360])
208
- }]
219
+ 'bufferManager': new BufferManager(gl, flatCircleEdgeCount, { bufferType, initialCapacity }),
220
+ 'adaptor': (item) => new Float32Array(item.rgba),
221
+ }],
222
+ // CIRCLE Mercator
223
+ ["rgbaMercator", {
224
+ 'bufferManager': new BufferManager(gl, 4 * flatCircleEdgeCount, { bufferType, initialCapacity }),
225
+ 'adaptor': (item) => populateFloat32Array.fillWithListData(flatCircleEdgeCount, item.rgba),
226
+ }],
227
+ ["circleDashAngleMercator", {
228
+ 'bufferManager': new BufferManager(gl, flatCircleEdgeCount, { bufferType, initialCapacity }),
229
+ 'adaptor': (item) => populateFloat32Array.fillFloat32Array(flatCircleEdgeCount, item.circleDashAngle / 360),
230
+ }],
231
+ ["dashOpacityMercator", {
232
+ 'bufferManager': new BufferManager(gl, flatCircleEdgeCount, { bufferType, initialCapacity }),
233
+ 'adaptor': (item) => populateFloat32Array.fillFloat32Array(flatCircleEdgeCount, item.dashOpacity),
234
+ }],
235
+
209
236
  ]
210
237
  );
211
238
  }
212
239
 
213
240
 
214
- const obj = function (bufferManagerComp) {
215
- return { 'buffer': bufferManagerComp.bufferManager.buffer, 'stride': 0, 'offset': 0 }
241
+ const obj = function (bufferManagerComp, divisor = 1) {
242
+ return { 'buffer': bufferManagerComp.bufferManager.buffer, 'stride': 0, 'offset': 0, divisor }
216
243
 
217
244
  };
218
245
 
@@ -233,7 +260,12 @@ export default class Plugin {
233
260
  }
234
261
  // centerObj, startAngleObj, radiusObj, colorObj, dashRatioObj, dashOpacityObj
235
262
  this.circleVao = this.circleProgram.createVAO(
236
- ...["centerCoords2d", "centerCoords3d", "bigRadius", "rgba", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
263
+ ...["centerCoords2dflat", "rgbaMercator", "circleDashAngleMercator", "dashOpacityMercator"].map(key => obj(this.bufferManagersCompMap.get(key)))
264
+ );
265
+ this.circle3DVao = this.circle3DProgram.createVAO(
266
+ ...["centerCoords3d", "bigRadius", "rgba", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key)))
267
+ );
268
+
237
269
  }
238
270
 
239
271
 
@@ -241,7 +273,7 @@ export default class Plugin {
241
273
  draw3D() {
242
274
  const { gl } = this;
243
275
  gl.disable(gl.DEPTH_TEST);
244
-
276
+ const is3D = this.globe.api_GetCurrentGeometry() === 0;
245
277
  this.lineProgram.draw(this.lineVao, this.bufferOrchestrator.length, this._opacity);
246
278
  if (this.drawAngleRing) {
247
279
  this.ringProgram.draw(this.bufferOrchestrator.length, this.ringVao, 360, this._opacity * 0.8, RINGPARTIAL_DRAW_MODE.TRIANGLE_FAN);
@@ -251,7 +283,11 @@ export default class Plugin {
251
283
  this.lineProgram.draw(this.bearingLineVAO, this.bufferOrchestrator.length, this._opacity * 0.8);
252
284
  }
253
285
  if (this.drawVRM) {
254
- this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
286
+ if (is3D) {
287
+ this.circle3DProgram.draw(this.circle3DVao, this.bufferOrchestrator.length, this._opacity);
288
+ } else {
289
+ this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
290
+ }
255
291
  }
256
292
  if (this.drawText) {
257
293
  this._textContextInjectionMap.forEach((e) => { e.writer.draw(); });
@@ -323,7 +359,7 @@ export default class Plugin {
323
359
  }
324
360
 
325
361
  bufferOrchestrator.updateBulk(data, bufferManagersCompMap, ["centerCoords2d", "centerCoords3d", "targetCoords2d", "targetCoords3d", "startAngle", "tailAngle",
326
- "startAngle2d", "tailAngle2d", "startAngle3d", "tailAngle3d", "bearingTargetCoords2d", "bearingTargetCoords3d",
362
+ "startAngle2d", "tailAngle2d", "startAngle3d", "tailAngle3d", "bearingTargetCoords2d", "bearingTargetCoords3d", "centerCoords2dflat",
327
363
  "bearingAngle", "bigRadius", "radius"]);
328
364
  globe.DrawRender();
329
365
  }
@@ -338,12 +374,13 @@ export default class Plugin {
338
374
  */
339
375
  updatePartial(items, propertyIDs = [], textWriterInjectionSubSetIDs = []) { // textWriterInjectionSubSetIDs = []
340
376
  if (propertyIDs.length === 0) console.warn("updatePartial is called with no target propertyIDs");
377
+ const fixedPropertyIDs = this.__fixPartialProperties(propertyIDs)
341
378
  const { _textContextInjectionMap, bufferOrchestrator, bufferManagersCompMap } = this;
342
379
  const writers = textWriterGetOrThrow(this._textContextInjectionMap, textWriterInjectionSubSetIDs);
343
380
  for (let item of items) { this._insertTexts(item, writers) }
344
- bufferOrchestrator.updateBulk(items, bufferManagersCompMap, propertyIDs);
381
+ bufferOrchestrator.updateBulk(items, bufferManagersCompMap, fixedPropertyIDs);
345
382
  // patch to update text opacity
346
- for (const property of propertyIDs) {
383
+ for (const property of fixedPropertyIDs) {
347
384
  if (property === "rgba") {
348
385
  _textContextInjectionMap.forEach((v) => {
349
386
  const { writer } = v;
@@ -375,31 +412,46 @@ export default class Plugin {
375
412
  };
376
413
  }
377
414
 
415
+
378
416
  __updateCoordsAdaptor(item) {
417
+ const { globe } = this;
379
418
  const lat = radian(item.lat)
380
419
  const long = radian(item.long)
381
420
  const endLat = radian(item.endLat)
382
421
  const endLong = radian(item.endLong)
383
- const bigRadius = item.bigRadius !== undefined ? item.bigRadius : this.globe.Math.GetDist3D(item.long, item.lat, item.endLong, item.endLat);
422
+ const bigRadius = item.bigRadius !== undefined ? item.bigRadius : globe.Math.GetDist3D(item.long, item.lat, item.endLong, item.endLat);
384
423
  const radius = item.radius !== undefined ? item.radius : bigRadius * 0.2;
385
-
386
-
387
- const { long: bearingLong, lat: bearingLat } = this.globe.Math.FindPointByPolar(item.long, item.lat, bigRadius, item.bearingAngle)
388
-
424
+ const { long: bearingLong, lat: bearingLat } = globe.Math.FindPointByPolar(item.long, item.lat, bigRadius, item.bearingAngle)
389
425
  const startAngle2d = calculateStartAngle(long, lat, endLong, endLat);
390
426
  const bearingAngle2d = calculateStartAngle(long, lat, radian(bearingLong), radian(bearingLat))
391
427
  let tailAngle2d = bearingAngle2d - startAngle2d;
392
428
  if (tailAngle2d > 0) {
393
429
  tailAngle2d -= Math.PI * 2;
394
430
  }
395
-
396
431
  const bearingAngle = radian(item.bearingAngle - 90);
397
- const startAngle3d = radian(this.globe.Math.GetAzimuthAngle(item.long, item.lat, item.endLong, item.endLat)) - radian(90);
432
+ const startAngleOfCircle = globe.Math.GetAzimuthAngle(item.long, item.lat, item.endLong, item.endLat) //startAngle2d * 180 / Math.PI;
433
+ const startAngle3d = radian(startAngleOfCircle) - radian(90);
398
434
  let tailAngle3d = bearingAngle - startAngle3d;
399
435
  if (tailAngle3d > 0) {
400
436
  tailAngle3d -= Math.PI * 2;
401
437
  }
402
438
 
439
+ const centerCoords2dflat = new Float32Array(flatCircleEdgeCount * 2);
440
+ const radius2d = globe.Math.GetDist2D(item.long, item.lat, item.endLong, item.endLat);
441
+ const pointsLongLat = globe.Math.GetEllipseGeo(
442
+ item.long,
443
+ item.lat,
444
+ radius2d,
445
+ radius2d,
446
+ startAngleOfCircle,
447
+ 360 / (flatCircleEdgeCount - 2), // 1 for return to start point, 1 for cutting circles
448
+ );
449
+
450
+ for (let i = 1; i < flatCircleEdgeCount; i++) {
451
+ const { long: lg, lat: lt } = pointsLongLat[i - 1];
452
+ centerCoords2dflat.set(globe.api_GetMercator2DPoint(lg, lt), i * 2);
453
+ }
454
+
403
455
  return {
404
456
  key: item.key,
405
457
  lat: item.lat,
@@ -414,11 +466,25 @@ export default class Plugin {
414
466
  startAngle3d,
415
467
  tailAngle3d,
416
468
  bearingLong,
417
- bearingLat
469
+ bearingLat,
470
+ centerCoords2dflat
418
471
  };
419
472
  }
420
473
 
421
474
 
475
+ __fixPartialProperties(propertyIDs) {
476
+ const s = new Set(["rgba", "dashOpacity", "circleDashAngle"]);
477
+ const result = []
478
+ for (const item of propertyIDs) {
479
+ result.push(item);
480
+ console.log(item + " is processing")
481
+ if (s.has(item)) {
482
+ console.log(item + "Mercator is added")
483
+ result.push(item + "Mercator");
484
+ }
485
+ }
486
+ return result;
487
+ }
422
488
 
423
489
  //TODO free
424
490
  free() {
@@ -426,10 +492,18 @@ export default class Plugin {
426
492
  this.bufferManagersCompMap.forEach(({ bufferManager, adaptor }) => {
427
493
  bufferManager.free();
428
494
  });
429
- LineOnGlobeCache.release(this.globe);
430
- pieceOfPieProgramCache.release(this.globe);
431
- CircleCache.release(this.globe);
432
- AngledLineProgramCache.release(this.globe);
495
+
496
+ const { gl, globe } = this;
497
+ gl.deleteVertexArray(this.lineVao);
498
+ gl.deleteVertexArray(this.ringVao);
499
+ gl.deleteVertexArray(this.bearingLineVAO);
500
+ gl.deleteVertexArray(this.circleVao);
501
+ gl.deleteVertexArray(this.circle3DVao);
502
+ LineOnGlobeCache.release(globe);
503
+ pieceOfPieProgramCache.release(globe);
504
+ CircleCache.release(globe);
505
+ AngledLineProgramCache.release(globe);
506
+ Circle3DCache.release(globe)
433
507
  this.isFreed = true;
434
508
  }
435
509
 
@@ -1,10 +1,12 @@
1
1
  import { LineOnGlobeCache } from '../programs/line-on-globe/naive-accurate';
2
- import { CircleCache } from '../programs/line-on-globe/circle-accurate';
2
+ import { CircleCache, EDGE_COUNT as EDGE_COUNT_2D_CIRCLE, centerCoords2dflatDataCreator } from '../programs/line-on-globe/circle-accurate-flat';
3
+ import { CircleCache as Circle3DCache } from '../programs/line-on-globe/circle-accurate-3d';
3
4
  import { LineToTheOriginCache } from "../programs/line-on-globe/to-the-origin"
4
5
  import { BufferOrchestrator, BufferManager } from "../util/account";
5
6
  import { ChainListMap } from "./chain-list-map";
6
7
  import { mapGetOrThrow } from "../util/check/get";
7
8
  import { keyMethod } from "./util";
9
+ import { populateFloat32Array } from "../util/jshelpers/data-filler";
8
10
  import { ContextTextWriter3 } from '../write-text/context-text3';
9
11
  // TODO: Add update buffer and update text mehods on add, delete, update methods
10
12
 
@@ -76,7 +78,9 @@ export class CircleLineChainPlugin {
76
78
  _initOrchestrations() {
77
79
  const { gl, globe } = this;
78
80
  this.lineProgram = LineOnGlobeCache.get(globe);
79
- this.circleProgram = CircleCache.get(globe);
81
+ this.circleProgram2d = CircleCache.get(globe);
82
+ this.circle3DProgram = Circle3DCache.get(globe);
83
+
80
84
  this.lineToTheOriginProgram = LineToTheOriginCache.get(globe);
81
85
  {
82
86
  // createBuffers
@@ -133,7 +137,30 @@ export class CircleLineChainPlugin {
133
137
  if (item.circleProperties?.rgba) return new Float32Array(item.circleProperties.rgba);
134
138
  return new Float32Array(item.chainProperties.rgba);
135
139
  }
136
- }]
140
+ }],
141
+ // Mercator buffers
142
+ ["circleDashAngleMercator", {
143
+ 'bufferManager': new BufferManager(gl, 1 * EDGE_COUNT_2D_CIRCLE, { bufferType, initialCapacity }),
144
+ 'adaptor': (item) => {
145
+ if (item.circleProperties?.circleDashAngle) return new Float32Array([item.circleProperties.circleDashAngle / 360]);
146
+ return new populateFloat32Array.fillFloat32Array(EDGE_COUNT_2D_CIRCLE, item.chainProperties.circleDashAngle / 360);
147
+ }
148
+ }],
149
+ ["rgbaCircleMercator", { // 62
150
+ "bufferManager": new BufferManager(gl, 4 * EDGE_COUNT_2D_CIRCLE, { bufferType, initialCapacity }),
151
+ "adaptor": (item) => {
152
+ if (item.circleProperties?.rgba) return populateFloat32Array.fillWithListData(EDGE_COUNT_2D_CIRCLE, item.circleProperties.rgba);
153
+ return populateFloat32Array.fillWithListData(EDGE_COUNT_2D_CIRCLE, item.chainProperties.rgba);
154
+ }
155
+ }],
156
+ ["dashOpacityMercator", {
157
+ 'bufferManager': new BufferManager(gl, 1 * EDGE_COUNT_2D_CIRCLE, { bufferType, initialCapacity }),
158
+ 'adaptor': (item) => populateFloat32Array.fillFloat32Array(EDGE_COUNT_2D_CIRCLE, item.chainProperties.dashOpacity)
159
+ }],
160
+ ["centerCoords2dMercator", {
161
+ 'bufferManager': new BufferManager(gl, 2 * EDGE_COUNT_2D_CIRCLE, { bufferType, initialCapacity }),
162
+ 'adaptor': (item) => item.centerCoords2dflat,
163
+ }],
137
164
  ]
138
165
  );
139
166
  // (startPotisionBufferObj, endPositionBufferObj, dashRatioBufferObj, colorBufferObj)
@@ -142,10 +169,14 @@ export class CircleLineChainPlugin {
142
169
  };
143
170
  this.lineVao = this.lineProgram.createVAO(
144
171
  ...['centerCoords2d', 'centerCoords3d', 'targetCoords2d', 'targetCoords3d', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
145
- this.circleVao = this.circleProgram.createVAO(
146
- ...["centerCoords2d", "centerCoords3d", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
172
+ this.circleVao2d = this.circleProgram2d.createVAO(
173
+ ...["centerCoords2dMercator", "rgbaCircleMercator", "circleDashAngleMercator", "dashOpacityMercator"].map(key => obj(this.bufferManagersCompMap.get(key))));
147
174
  this.toOriginVao = this.lineToTheOriginProgram.createVAO(
148
175
  ...["targetCoords3d", "rgba"].map(key => obj(this.bufferManagersCompMap.get(key))));
176
+ this.circle3DVao = this.circle3DProgram.createVAO(
177
+ ...["centerCoords3d", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key)))
178
+ );
179
+
149
180
  }
150
181
 
151
182
  }
@@ -338,13 +369,16 @@ export class CircleLineChainPlugin {
338
369
  const { globe } = this;
339
370
  // this.lineVao = this.lineProgram.createVAO(
340
371
  // ...['centerCoords', 'targetCoords', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
341
- // this.circleVao = this.circleProgram.createVAO(
372
+ // this.circleVao2d = this.circleProgram2d.createVAO(
342
373
  // ...["centerCoords", "bigRadius", "rgba", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
343
374
  // }
344
375
 
345
376
  const radiusM = radiusMethod(globe);
346
377
  const callback = (v, i, array, chainProperties) => {
347
378
  if (i == array.length - 1) return null;
379
+
380
+ const centerCoords2dflat = centerCoords2dflatDataCreator(globe, v.long, v.lat, array[i + 1].long, array[i + 1].lat);
381
+
348
382
  return {
349
383
  chainProperties: chainProperties,
350
384
  bigRadius: radiusM(v, i, array),
@@ -354,7 +388,9 @@ export class CircleLineChainPlugin {
354
388
  lat: v.lat,
355
389
  lineProperties: v.lineProperties,
356
390
  circleProperties: v.circleProperties,
391
+ centerCoords2dflat,
357
392
  key: v.__identity__
393
+
358
394
  }
359
395
  }
360
396
  const bulkData = [];
@@ -381,8 +417,15 @@ export class CircleLineChainPlugin {
381
417
  })
382
418
  LineOnGlobeCache.release(this.globe);
383
419
  CircleCache.release(this.globe);
420
+ Circle3DCache.release(this.globe);
421
+ LineToTheOriginCache.release(this.globe);
422
+ this._textContextWriterInjectionMap.forEach((writer) => writer.free());
423
+ const { gl } = this;
424
+ gl.deleteVertexArray(this.lineVao);
425
+ gl.deleteVertexArray(this.circleVao2d);
426
+ gl.deleteVertexArray(this.toOriginVao);
384
427
  this.lineProgram = null;
385
- this.circleProgram = null;
428
+ this.circleProgram2d = null;
386
429
  this.isFreed = true;
387
430
  }
388
431
 
@@ -390,9 +433,16 @@ export class CircleLineChainPlugin {
390
433
  const { gl, globe } = this;
391
434
  gl.disable(gl.DEPTH_TEST);
392
435
  this.lineProgram.draw(this.lineVao, this.bufferOrchestrator.length, this._opacity);
393
- if (this._drawCircleOn) this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
394
436
  this._textContextWriterInjectionMap.forEach((writer) => writer.draw());
395
437
  this.lineToTheOriginProgram.draw(this.toOriginVao, this.bufferOrchestrator.length, this._opacity);
438
+ const is3D = globe.api_GetCurrentGeometry() === 0;
439
+ if (this._drawCircleOn) {
440
+ if (is3D) {
441
+ this.circle3DProgram.draw(this.circle3DVao, this.bufferOrchestrator.length, this._opacity);
442
+ } else {
443
+ this.circleProgram2d.draw(this.circleVao2d, this.bufferOrchestrator.length, this._opacity);
444
+ }
445
+ }
396
446
  gl.enable(gl.DEPTH_TEST);
397
447
  }
398
448
  }