@pirireis/webglobeplugins 0.8.9 → 0.8.11

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.
@@ -7,7 +7,7 @@ import { mapGetOrThrow } from "../util/check/get";
7
7
  import { populateFloat32Array } from "../util/jshelpers/data-filler";
8
8
  import { ContextTextWriter3 } from '../write-text/context-text3'
9
9
  import { constraintFloat, isBoolean } from '../util/check/typecheck';
10
-
10
+ import { normalize } from '../util/geometry';
11
11
  import { createBufferAndReadInfo } from '../util/gl-util/buffer/integrate-buffer';
12
12
 
13
13
  export const RINGPARTIAL_DRAW_MODE = Object.freeze({
@@ -322,6 +322,9 @@ export default class BearingLinePlugin {
322
322
  this.circle3DProgram = Circle3DCache.get(globe);
323
323
  const circleFlatEdgeCount = this.circleFlatEdgeCount
324
324
  {
325
+ const sphereCoord = (long, lat) => {
326
+ return normalize(globe.api_GetCartesian3DPoint(long, lat, 0, 0), 6378.137);
327
+ }
325
328
  // createBuffers
326
329
  const bufferType = "DYNAMIC_DRAW";
327
330
  const initialCapacity = this.bufferOrchestrator.capacity;
@@ -337,7 +340,7 @@ export default class BearingLinePlugin {
337
340
  }],
338
341
  ["centerCoords3d", {
339
342
  'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
340
- 'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.long, item.lat, 0, 0)),
343
+ 'adaptor': (item) => sphereCoord(item.long, item.lat, 0, 0),
341
344
  }],
342
345
  ["targetCoords2d", {
343
346
  'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
@@ -345,7 +348,8 @@ export default class BearingLinePlugin {
345
348
  }],
346
349
  ["targetCoords3d", {
347
350
  'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
348
- 'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.endLong, item.endLat, 0, 0))
351
+ 'adaptor': (item) => new Float32Array(
352
+ globe.api_GetCartesian3DPoint(item.endLong, item.endLat, 0, 0))
349
353
  }],
350
354
  ["bearingTargetCoords2d", {
351
355
  'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
@@ -9,7 +9,7 @@ import { populateFloat32Array } from "../util/jshelpers/data-filler";
9
9
  import { ContextTextWriter3 } from '../write-text/context-text3';
10
10
  import { isBoolean, constraintFloat, opacityCheck } from '../util/check/typecheck';
11
11
  import { createBufferAndReadInfo } from '../util/gl-util/buffer/integrate-buffer';
12
-
12
+ import { sphereCoord } from '../util/geometry/index';
13
13
  /**
14
14
  * Insert info to chain list map (nodes and properties)
15
15
  *
@@ -264,6 +264,7 @@ export class CircleLineChainPlugin {
264
264
 
265
265
  const _circleFlatEdgeCount = this._circleFlatEdgeCount;
266
266
  {
267
+
267
268
  // createBuffers
268
269
  const bufferType = "DYNAMIC_DRAW";
269
270
  const initialCapacity = this.bufferOrchestrator.capacity;
@@ -275,7 +276,7 @@ export class CircleLineChainPlugin {
275
276
  }],
276
277
  ["centerCoords3d", {
277
278
  'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
278
- 'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.long, item.lat, 0, 0)),
279
+ 'adaptor': (item) => sphereCoord(item.long, item.lat, globe),
279
280
  }],
280
281
  ["targetCoords2d", {
281
282
  'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
@@ -283,7 +284,7 @@ export class CircleLineChainPlugin {
283
284
  }],
284
285
  ["targetCoords3d", {
285
286
  'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
286
- 'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.targetLong, item.targetLat, 0, 0)),
287
+ 'adaptor': (item) => sphereCoord(item.targetLong, item.targetLat, globe),
287
288
  }],
288
289
  ["rgba", {
289
290
  'bufferManager': new BufferManager(gl, 4, { bufferType, initialCapacity }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.8.9",
3
+ "version": "0.8.11",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -67,7 +67,7 @@ class PointHeatmapFlow {
67
67
 
68
68
  /**
69
69
  * @param {Float32Array} data
70
- * @format [x, y, z, height] x,y,z is normalized 3d cartesian coordinates. Height in kilometers. Set 6371.137 for ground level.
70
+ * @format [x, y, z, height] x,y,z is normalized 3d cartesian coordinates. Height in kilometers. Set 6378.137 for ground level.
71
71
  */
72
72
  setData(data) {
73
73
  const { gl, buffer } = this;
@@ -128,7 +128,6 @@ class Logic {
128
128
  attributeLoader(gl, dashRatioObj, 3, 1, { divisor });
129
129
  attributeLoader(gl, dashOpacityObj, 4, 1, { divisor });
130
130
 
131
-
132
131
  gl.bindVertexArray(null);
133
132
  gl.bindVertexArray(null);
134
133
  return vao;
@@ -1,7 +1,8 @@
1
1
  import { createProgram } from "../../util/webglobjectbuilders";
2
2
  import { CameraUniformBlockString, CameraUniformBlockTotemCache } from "../totems/camerauniformblock";
3
3
  import { noRegisterGlobeProgramCache } from "../programcache";
4
- import { vaoAttributeLoader } from "../../util/account/util";
4
+ // import { vaoAttributeLoader } from "../../util/account/util";
5
+ import { attributeLoader } from "../../util/gl-util/buffer/integrate-buffer";
5
6
  import { Z_ALPHA_MODE } from "./util";
6
7
  import {
7
8
  cartesian3DToGLPosition,
@@ -127,24 +128,16 @@ class Logic {
127
128
  const vao = gl.createVertexArray();
128
129
  const divisor = 1;
129
130
  gl.bindVertexArray(vao);
130
- { // make this a function end import from account module.
131
- const { buffer, stride = 0, offset = 0 } = center3dObj;
132
- vaoAttributeLoader(gl, buffer, 0, 3, stride, offset, divisor);
133
- }
134
- {
135
- const { buffer, stride = 0, offset = 0 } = bigRadiusObj;
136
- vaoAttributeLoader(gl, buffer, 1, 1, stride, offset, divisor);
137
- }
138
- {
139
- const { buffer, stride = 0, offset = 0 } = smallRadiusObj;
140
- vaoAttributeLoader(gl, buffer, 2, 1, stride, offset, divisor);
141
- }
142
- {
143
- const { buffer, stride = 0, offset = 0 } = colorObj;
144
- vaoAttributeLoader(gl, buffer, 3, 4, stride, offset, divisor);
145
- }
146
131
 
147
- gl.bindVertexArray(null);
132
+
133
+ attributeLoader(gl, center3dObj, 0, 3, { divisor });
134
+
135
+ attributeLoader(gl, bigRadiusObj, 1, 1, { divisor });
136
+
137
+ attributeLoader(gl, smallRadiusObj, 2, 1, { divisor });
138
+
139
+ attributeLoader(gl, colorObj, 3, 4, { divisor });
140
+
148
141
  gl.bindVertexArray(null);
149
142
  return vao;
150
143
  }
@@ -193,8 +193,8 @@ class Logic {
193
193
 
194
194
 
195
195
  createVAO(
196
- startPotisionBufferObj, startPotision3DBufferObj,
197
- endPositionBufferObj, endPosition3DBufferObj,
196
+ startPotision2DBufferObj, startPotision3DBufferObj,
197
+ endPosition2DBufferObj, endPosition3DBufferObj,
198
198
  dashRatioBufferObj,
199
199
  dashOpacityBufferObj,
200
200
  colorBufferObj) {
@@ -205,9 +205,9 @@ class Logic {
205
205
 
206
206
  const divisor = 1;
207
207
 
208
- attributeLoader(gl, startPotisionBufferObj, 0, 2, { divisor });
208
+ attributeLoader(gl, startPotision2DBufferObj, 0, 2, { divisor });
209
209
  attributeLoader(gl, startPotision3DBufferObj, 1, 3, { divisor });
210
- attributeLoader(gl, endPositionBufferObj, 2, 2, { divisor });
210
+ attributeLoader(gl, endPosition2DBufferObj, 2, 2, { divisor });
211
211
  attributeLoader(gl, endPosition3DBufferObj, 3, 3, { divisor });
212
212
  attributeLoader(gl, dashRatioBufferObj, 4, 1, { divisor, escapeValues: [escapeValue] });
213
213
  attributeLoader(gl, dashOpacityBufferObj, 5, 1, { divisor, escapeValues: [escapeValue] });
@@ -57,11 +57,14 @@ import RangeRingAngleText from "./rangeringangletext";
57
57
  import { Z_ALPHA_MODE } from "../programs/line-on-globe/util";
58
58
  import { ENUM_HIDE } from "./enum";
59
59
  import { opacityCheck, constraintFloat } from "../util/check/typecheck";
60
+ import { normalize } from "../util/geometry"
60
61
  const CIRCLE_FLAT_EDGE_COUNT = 362; // 360 + 2 for closing the circle and a cutting point
61
62
 
62
63
 
63
-
64
-
64
+ const coordOnSphere = (long, lat, globe) => {
65
+ const coord = globe.api_GetCartesian3DPoint(long, lat, 0, 0);
66
+ return normalize(coord, 6378.137);
67
+ }
65
68
 
66
69
  class RangeRings {
67
70
  constructor(id,
@@ -108,7 +111,7 @@ class RangeRings {
108
111
  const datas = this.__reconstructCentralRings(centerID);
109
112
  bufferOrchestrator.updateBulk(datas, bufferManagersCompMap, ["centerCoords3d", "centerCoords2dflat", "targetCoords3d", "centerCoords2dflatForPadding"]);
110
113
  const paddingDatas = this.__reconstructCentralRingsBigPaddings(centerID);
111
- paddingBufferOrchestrator.updateBulk(paddingDatas, bufferManagersCompMapPadding, ["circlePoint", "paddingPoint", "circlePoint3d", "paddingPoint3d"]);
114
+ paddingBufferOrchestrator.updateBulk(paddingDatas, bufferManagersCompMapPadding, ["circlePoint2d", "paddingPoint2d", "circlePoint3d", "paddingPoint3d"]);
112
115
  }
113
116
  this.paddingTextPlugin?.updateCentersXY(items);
114
117
 
@@ -144,7 +147,7 @@ class RangeRings {
144
147
  for (const item of items) {
145
148
  _ringAccount.insertCenter(item);
146
149
  const datas = this.__reconstructCentralRings(item.centerID);
147
- bufferOrchestrator.insertBulk(datas, bufferManagersCompMap,);
150
+ bufferOrchestrator.insertBulk(datas, bufferManagersCompMap);
148
151
  const paddingDatas = this.__reconstructCentralRingsBigPaddings(item.centerID);
149
152
  paddingBufferOrchestrator.insertBulk(paddingDatas, bufferManagersCompMapPadding);
150
153
  }
@@ -309,7 +312,7 @@ class RangeRings {
309
312
  this._circleProgram3D = CircleCache3D.get(globe);
310
313
  this._padding2dProgram = LinesColorInstancedFlatCache.get(globe);
311
314
  this._padding3dProgram = CirclePadding3DCache.get(globe);
312
- this._bigPadding3dFlatProgram = LineOnGlobeCache.get(globe);
315
+ this._lineOnGlobe_bigPadding = LineOnGlobeCache.get(globe);
313
316
 
314
317
  }
315
318
 
@@ -406,13 +409,13 @@ class RangeRings {
406
409
  this.paddingBufferOrchestrator = new BufferOrchestrator({ capacity: initialCapacity });
407
410
  this.bufferManagersCompMapPadding = new Map(
408
411
  [
409
- ["circlePoint", {
412
+ ["circlePoint2d", {
410
413
  'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
411
- 'adaptor': (item) => item.circlePoint,
414
+ 'adaptor': (item) => item.circlePoint2d,
412
415
  }],
413
- ["paddingPoint", {
416
+ ["paddingPoint2d", {
414
417
  'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
415
- 'adaptor': (item) => item.paddingPoint,
418
+ 'adaptor': (item) => item.paddingPoint2d,
416
419
  }],
417
420
  ["circlePoint3d", {
418
421
  'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
@@ -427,19 +430,19 @@ class RangeRings {
427
430
  'adaptor': (item) => new Float32Array(item.rgba)
428
431
  }],
429
432
 
430
- ["dashOpacity", {
431
- 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
432
- 'adaptor': (item) => new Float32Array([1]),
433
- }],
434
- ["dashRatio", {
435
- 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
436
- 'adaptor': (item) => new Float32Array([1]),
437
- }],
433
+ // ["dashOpacity", {
434
+ // 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
435
+ // 'adaptor': (item) => new Float32Array([1]),
436
+ // }],
437
+ // ["dashRatio", {
438
+ // 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
439
+ // 'adaptor': (item) => new Float32Array([1]),
440
+ // }],
438
441
  ]
439
442
  );
440
443
 
441
- this._bigPadding3dFlatVAO = this._bigPadding3dFlatProgram.createVAO(//"dashRatio", "dashOpacity"
442
- ...["circlePoint", "circlePoint3d", "paddingPoint", "paddingPoint3d", null, null, "rgba",].map(key =>
444
+ this._bigPadding3dFlatVAO = this._lineOnGlobe_bigPadding.createVAO(//"dashRatio", "dashOpacity"
445
+ ...["circlePoint2d", "circlePoint3d", "paddingPoint2d", "paddingPoint3d", null, null, "rgba",].map(key =>
443
446
  (key === null) ? null : obj(this.bufferManagersCompMapPadding.get(key)))
444
447
  );
445
448
 
@@ -451,6 +454,7 @@ class RangeRings {
451
454
 
452
455
  }
453
456
 
457
+ // IMPLICIT METHODS
454
458
 
455
459
  __reconstructCentralRingsBigPaddings(centerID) {
456
460
  const { globe } = this;
@@ -466,10 +470,10 @@ class RangeRings {
466
470
  const paddingPoint = globe.Math.FindPointByPolar(long, lat, radius - padding, azimuthAngle); // long lat
467
471
  result.push({
468
472
  key: ringBigPaddingKeyMethod(centerID, ringID, azimuthAngle),
469
- circlePoint: new Float32Array(globe.api_GetMercator2DPoint(circlePoint.long, circlePoint.lat)),
470
- paddingPoint: new Float32Array(globe.api_GetMercator2DPoint(paddingPoint.long, paddingPoint.lat)),
471
- circlePoint3d: new Float32Array(globe.api_GetCartesian3DPoint(circlePoint.long, circlePoint.lat, 0, 0)),
472
- paddingPoint3d: new Float32Array(globe.api_GetCartesian3DPoint(paddingPoint.long, paddingPoint.lat, 0, 0)),
473
+ circlePoint2d: new Float32Array(globe.api_GetMercator2DPoint(circlePoint.long, circlePoint.lat)),
474
+ paddingPoint2d: new Float32Array(globe.api_GetMercator2DPoint(paddingPoint.long, paddingPoint.lat)),
475
+ circlePoint3d: coordOnSphere(circlePoint.long, circlePoint.lat, globe),
476
+ paddingPoint3d: coordOnSphere(paddingPoint.long, paddingPoint.lat, globe),
473
477
  rgba: color,
474
478
  hide,
475
479
  textHide
@@ -481,7 +485,6 @@ class RangeRings {
481
485
  return result;
482
486
  }
483
487
 
484
- // IMPLICIT METHODS
485
488
 
486
489
  __reconstructCentralRings(centerID) {
487
490
  const { globe } = this;
@@ -489,7 +492,7 @@ class RangeRings {
489
492
  if (centerItem === undefined) throw new Error("Center not found");
490
493
 
491
494
  const { long, lat, rgba, rings, hide = 0, textHide = 0 } = centerItem;
492
- const centerCoords3d = globe.api_GetCartesian3DPoint(long, lat, 0, 0);
495
+ const centerCoords3d = coordOnSphere(long, lat, globe);
493
496
 
494
497
  const result = [];
495
498
 
@@ -498,7 +501,7 @@ class RangeRings {
498
501
  const centerCoords2dflat = centerCoords2dflatDataCreatorWithRadius(globe, long, lat, radius, { edgeCount: CIRCLE_FLAT_EDGE_COUNT });
499
502
  const radiusPadding = hide === ENUM_HIDE.HIDE_1_DEGREE_PADDINGS ? radius : radius - padding / 3;
500
503
  const targetPoint = globe.Math.FindPointByPolar(long, lat, radius, 0); // long lat
501
- const targetCoords3d = new Float32Array(globe.api_GetCartesian3DPoint(targetPoint.long, targetPoint.lat, 0, 0));
504
+ const targetCoords3d = coordOnSphere(targetPoint.long, targetPoint.lat, globe);
502
505
  const centerCoords2dflatForPadding = centerCoords2dflatDataCreatorWithRadius(globe, long, lat, radiusPadding, { edgeCount: CIRCLE_FLAT_EDGE_COUNT });
503
506
  result.push({
504
507
  key,
@@ -573,7 +576,7 @@ class RangeRings {
573
576
  draw3D() {
574
577
  const {
575
578
  globe, gl,
576
- _circleProgram2D, _circleProgram3D, _padding2dProgram, _padding3dProgram, _bigPadding3dFlatProgram,
579
+ _circleProgram2D, _circleProgram3D, _padding2dProgram, _padding3dProgram, _lineOnGlobe_bigPadding,
577
580
  _circle2DVao, _circle3DVao, _oneDegree2DPaddingVao, _padding3dOneDegreeVao, _bigPadding3dFlatVAO,
578
581
  bufferOrchestrator, paddingBufferOrchestrator,
579
582
  _opacity, _oneDegreePadding, _zAlphaOnDegreePadding } = this;
@@ -588,8 +591,8 @@ class RangeRings {
588
591
  // _padding2dProgram.draw(bigPaddingVAO, paddingBufferOrchestrator.length, _opacity);
589
592
  if (_oneDegreePadding) _padding2dProgram.draw(_oneDegree2DPaddingVao, bufferOrchestrator.length * CIRCLE_FLAT_EDGE_COUNT, _opacity, _zAlphaOnDegreePadding);
590
593
  }
591
- const drawOptions = { drawRange: { first: 0, count: bufferOrchestrator.length } };
592
- _bigPadding3dFlatProgram.draw(_bigPadding3dFlatVAO, drawOptions, _opacity);
594
+ const drawOptions = { drawRange: { first: 0, count: paddingBufferOrchestrator.length } };
595
+ _lineOnGlobe_bigPadding.draw(_bigPadding3dFlatVAO, drawOptions, _opacity);
593
596
  this._textWritersMap.forEach((textWriter) => textWriter.draw());
594
597
  gl.enable(gl.DEPTH_TEST);
595
598
  }
@@ -615,7 +618,7 @@ class RangeRings {
615
618
  this._circleProgram3D = null;
616
619
  this._padding2dProgram = null;
617
620
  this._padding3dProgram = null;
618
- this._bigPadding3dFlatProgram = null;
621
+ this._lineOnGlobe_bigPadding = null;
619
622
  this.paddingTextPlugin?.free();
620
623
  this._isFreed = true;
621
624
  }
@@ -26,4 +26,25 @@ export function latLongBboxtoPixelXYBbox(minX, minY, maxX, maxY) {
26
26
  }
27
27
 
28
28
 
29
- // export { GeoDataFromTexture } from './geodatafromtexture';
29
+ /**
30
+ *
31
+ * @param {Float32List} array
32
+ * @returns {Float32Array}
33
+ */
34
+ export function normalize(array, newLength = 1) {
35
+ let total = 0;
36
+ for (let i = 0; i < array.length; i++) {
37
+ total += array[i] * array[i];
38
+ }
39
+ const len = newLength / Math.sqrt(total);
40
+ const result = new Float32Array(array.length);
41
+ for (let i = 0; i < array.length; i++) {
42
+ result[i] = array[i] * len;
43
+ }
44
+ return result;
45
+ }
46
+
47
+
48
+ export function sphereCoord(long, lat, globe) {
49
+ return normalize(globe.api_GetCartesian3DPoint(long, lat, 0, 0), 6378.137);
50
+ }