@pirireis/webglobeplugins 0.8.7 → 0.8.9

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.
@@ -442,7 +442,7 @@ export default class BearingLinePlugin {
442
442
  ...["centerCoords2dflat", "rgbaMercator", "circleDashAngleMercator", "dashOpacityMercator"
443
443
  ].map(key => vaoOBJ(key)));
444
444
  this.circle3DVao = this.circle3DProgram.createVAO(
445
- ...["centerCoords3d", "bigRadius", "rgba", "circleDashAngle", "dashOpacity", "startAngle2d"
445
+ ...["centerCoords3d", "targetCoords3d", "rgba", "circleDashAngle", "dashOpacity"
446
446
  ].map(key => vaoOBJ(key)));
447
447
  }
448
448
 
@@ -292,10 +292,10 @@ export class CircleLineChainPlugin {
292
292
  return new Float32Array(item.chainProperties.rgba);
293
293
  }
294
294
  }],
295
- ["bigRadius", {
296
- 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
297
- 'adaptor': (item) => new Float32Array([item.bigRadius])
298
- }],
295
+ // ["bigRadius", {
296
+ // 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
297
+ // 'adaptor': (item) => new Float32Array([item.bigRadius])
298
+ // }],
299
299
  ["dashRatio", {
300
300
  'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
301
301
  'adaptor': (item) => new Float32Array([item.chainProperties.dashRatio])
@@ -354,7 +354,7 @@ export class CircleLineChainPlugin {
354
354
  ].map(key => obj(key)));
355
355
 
356
356
  this.circle3DVao = this.circle3DProgram.createVAO(
357
- ...["centerCoords3d", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"
357
+ ...["centerCoords3d", "targetCoords3d", "rgbaCircle", "circleDashAngle", "dashOpacity"
358
358
  ].map(key => obj(key))
359
359
  );
360
360
 
@@ -376,7 +376,7 @@ export class CircleLineChainPlugin {
376
376
  _reconstructChains(chainKeys) {
377
377
  const { globe } = this;
378
378
 
379
- const radiusM = radiusMethod(globe);
379
+ // const radiusM = radiusMethod(globe);
380
380
  const callback = (v, i, array, chainProperties) => {
381
381
  if (i === array.length - 1) return null;
382
382
 
@@ -384,7 +384,7 @@ export class CircleLineChainPlugin {
384
384
 
385
385
  return {
386
386
  chainProperties: chainProperties,
387
- bigRadius: radiusM(v, i, array),
387
+ // bigRadius: radiusM(v, i, array),
388
388
  targetLong: array[i + 1].long,
389
389
  targetLat: array[i + 1].lat,
390
390
  long: v.long,
@@ -458,7 +458,7 @@ export class CircleLineChainPlugin {
458
458
 
459
459
 
460
460
 
461
- const radiusMethod = (globe) => (v, i, array) => {
462
- return globe.Math.GetDist3D(v.long, v.lat, array[i + 1].long, array[i + 1].lat)
463
- }
461
+ // const radiusMethod = (globe) => (v, i, array) => {
462
+ // return globe.Math.GetDist3D(v.long, v.lat, array[i + 1].long, array[i + 1].lat)
463
+ // }
464
464
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.8.7",
3
+ "version": "0.8.9",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -4,11 +4,11 @@ import { noRegisterGlobeProgramCache } from "../programcache";
4
4
  // import { vaoAttributeLoader } from "../../util/account/util";
5
5
  import { attributeLoader } from "../../util/gl-util/buffer/integrate-buffer";
6
6
  import {
7
- longLatRadToMercator, longLatRadToCartesian3D, cartesian3DToGLPosition, mercatorXYToGLPosition, realDistanceOnSphereR1,
7
+ cartesian3DToGLPosition,
8
8
  circleLimpFromLongLatRadCenterCartesian3D_accurate,
9
- circleLimpFromLongLatRadCenterMercatorCompass_accurate,
10
- circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate,
11
- POLE
9
+ circleOnSphere,
10
+ POLE,
11
+ PI
12
12
  } from "../../util/shaderfunctions/geometrytransformations";
13
13
 
14
14
 
@@ -21,27 +21,22 @@ import {
21
21
  * center_position is too small or doenst loaded as expected.
22
22
  */
23
23
  const EDGE_COUNT_ON_SPHERE = 360;
24
-
24
+ //${circleLimpFromLongLatRadCenterCartesian3D_accurate}
25
25
  const vertexShaderSource = `#version 300 es
26
26
  precision highp float;
27
+ ${PI}
27
28
  ${CameraUniformBlockString}
28
- ${longLatRadToMercator}
29
- ${longLatRadToCartesian3D}
30
29
  ${cartesian3DToGLPosition}
31
- ${mercatorXYToGLPosition}
32
- ${realDistanceOnSphereR1}
33
- ${circleLimpFromLongLatRadCenterCartesian3D_accurate}
34
- ${circleLimpFromLongLatRadCenterMercatorCompass_accurate}
35
- ${circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate}
30
+ ${circleOnSphere}
36
31
 
37
32
  uniform float edge_count;
38
33
 
39
34
  in vec3 center_position3d;
40
- in float radius;
35
+ in vec3 target_position3d;
36
+ // in float radius;
41
37
  in vec4 color;
42
38
  in float dash_ratio;
43
39
  in float dash_opacity;
44
- in float initial_angle;
45
40
 
46
41
  out float interpolation;
47
42
  out vec4 v_color;
@@ -51,7 +46,7 @@ void main() {
51
46
  interpolation = float( gl_VertexID ) / ${EDGE_COUNT_ON_SPHERE}.0;
52
47
  if ( is3D ) {
53
48
  float angle = PI * 2.0 * interpolation;
54
- vec3 position = circleLimpFromLongLatRadCenterCartesian3D_accurate(center_position3d, radius, angle + initial_angle);
49
+ vec3 position = circleOnSphere(center_position3d, target_position3d, angle);
55
50
  gl_Position = cartesian3DToGLPosition(position);
56
51
  } else {
57
52
  return;
@@ -107,11 +102,10 @@ class Logic {
107
102
 
108
103
  { // assign attribute locations
109
104
  gl.bindAttribLocation(program, 0, "center_position3d");
110
- gl.bindAttribLocation(program, 1, "radius");
105
+ gl.bindAttribLocation(program, 1, "target_position3d");
111
106
  gl.bindAttribLocation(program, 2, "color");
112
107
  gl.bindAttribLocation(program, 3, "dash_ratio");
113
108
  gl.bindAttribLocation(program, 4, "dash_opacity");
114
- gl.bindAttribLocation(program, 5, "initial_angle");
115
109
  }
116
110
 
117
111
  this.cameraBindingPoint = 0;
@@ -120,7 +114,7 @@ class Logic {
120
114
  gl.uniformBlockBinding(program, cameraBlockLocation, this.cameraBindingPoint);
121
115
  }
122
116
 
123
- createVAO(center3dObj, radiusObj, colorObj, dashRatioObj, dashOpacityObj, initialAngleObj) {
117
+ createVAO(center3dObj, target3dObj, colorObj, dashRatioObj, dashOpacityObj) {
124
118
  const { gl } = this;
125
119
  const vao = gl.createVertexArray();
126
120
  const divisor = 1;
@@ -128,11 +122,11 @@ class Logic {
128
122
  gl.bindVertexArray(vao);
129
123
 
130
124
  attributeLoader(gl, center3dObj, 0, 3, { divisor });
131
- attributeLoader(gl, radiusObj, 1, 1, { divisor });
125
+ attributeLoader(gl, target3dObj, 1, 3, { divisor });
126
+ // attributeLoader(gl, radiusObj, 1, 1, { divisor });
132
127
  attributeLoader(gl, colorObj, 2, 4, { divisor });
133
128
  attributeLoader(gl, dashRatioObj, 3, 1, { divisor });
134
129
  attributeLoader(gl, dashOpacityObj, 4, 1, { divisor });
135
- attributeLoader(gl, initialAngleObj, 5, 1, { divisor, escapeValues: [0] });
136
130
 
137
131
 
138
132
  gl.bindVertexArray(null);
@@ -106,7 +106,7 @@ class RangeRings {
106
106
  } = this;
107
107
  for (const { centerID } of items) {
108
108
  const datas = this.__reconstructCentralRings(centerID);
109
- bufferOrchestrator.updateBulk(datas, bufferManagersCompMap, ["centerCoords3d", "centerCoords2dflat", "centerCoords2dflatForPadding"]);
109
+ bufferOrchestrator.updateBulk(datas, bufferManagersCompMap, ["centerCoords3d", "centerCoords2dflat", "targetCoords3d", "centerCoords2dflatForPadding"]);
110
110
  const paddingDatas = this.__reconstructCentralRingsBigPaddings(centerID);
111
111
  paddingBufferOrchestrator.updateBulk(paddingDatas, bufferManagersCompMapPadding, ["circlePoint", "paddingPoint", "circlePoint3d", "paddingPoint3d"]);
112
112
  }
@@ -329,6 +329,11 @@ class RangeRings {
329
329
  'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
330
330
  'adaptor': (item) => new Float32Array(item.centerCoords3d),
331
331
  }],
332
+ ["targetCoords3d", {
333
+ 'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
334
+ 'adaptor': (item) => new Float32Array(item.targetCoords3d),
335
+ }],
336
+
332
337
  ["rgba", {
333
338
  'bufferManager': new BufferManager(gl, 4, { bufferType, initialCapacity }),
334
339
  'adaptor': (item) => new Float32Array(item.hide === ENUM_HIDE.HIDE ? [0, 0, 0, 0] : item.rgba)
@@ -385,8 +390,9 @@ class RangeRings {
385
390
  this._circle2DVao = this._circleProgram2D.createVAO(
386
391
  ...["centerCoords2dflat", "rgbaMercator", "circleDashAngleMercator", "dashOpacityMercator"].map(key => obj(this.bufferManagersCompMap.get(key)))
387
392
  );
393
+
388
394
  this._circle3DVao = this._circleProgram3D.createVAO(
389
- ...["centerCoords3d", "radius3d", "rgba", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key)))
395
+ ...["centerCoords3d", "targetCoords3d", "rgba", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key)))
390
396
  );
391
397
 
392
398
  this._oneDegree2DPaddingVao = this._padding2dProgram.createVAO(
@@ -441,6 +447,8 @@ class RangeRings {
441
447
  ...["centerCoords3d", "radius3d", "radius3dsmall", "rgba"].map(key => obj(this.bufferManagersCompMap.get(key)))
442
448
  );
443
449
 
450
+
451
+
444
452
  }
445
453
 
446
454
 
@@ -489,10 +497,13 @@ class RangeRings {
489
497
  const key = __identity__;
490
498
  const centerCoords2dflat = centerCoords2dflatDataCreatorWithRadius(globe, long, lat, radius, { edgeCount: CIRCLE_FLAT_EDGE_COUNT });
491
499
  const radiusPadding = hide === ENUM_HIDE.HIDE_1_DEGREE_PADDINGS ? radius : radius - padding / 3;
500
+ 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));
492
502
  const centerCoords2dflatForPadding = centerCoords2dflatDataCreatorWithRadius(globe, long, lat, radiusPadding, { edgeCount: CIRCLE_FLAT_EDGE_COUNT });
493
503
  result.push({
494
504
  key,
495
505
  centerCoords3d,
506
+ targetCoords3d,
496
507
  centerCoords2dflat,
497
508
  radius,
498
509
  padding,
@@ -245,10 +245,10 @@ vec3 pointsOnSphereBetween(vec3 a, vec3 b, float ratio) {
245
245
  b = normalize(b);
246
246
 
247
247
  // Compute the dot product and clamp it to avoid numerical issues
248
- float dotProduct = clamp(dot(a, b), -1.0, 1.0);
248
+ // float dotProduct = clamp(dot(a, b), -1.0, 1.0);
249
249
 
250
250
  // Compute the angle between the points
251
- float theta = acos(dotProduct);
251
+ float theta = acos(dot(a, b));
252
252
 
253
253
  // Handle the edge case where the points are nearly identical
254
254
  if (theta < 0.0001) {
@@ -284,7 +284,66 @@ vec3 circleLimpFromLongLatRadCenterCartesian3D_accurate( vec3 geoW, float radius
284
284
  tangent1 = cos(angle) * tangent1 - sin(angle) * cross(normal, tangent1);
285
285
  float radius_in_angle = radius/R;
286
286
  float projected_radius = sin(radius_in_angle) * R / 1000.0;
287
- return (geoW * cos(radius_in_angle))+ tangent1 * projected_radius;
287
+ return (geoW * cos(radius_in_angle)) + tangent1 * projected_radius;
288
+ }`;
289
+
290
+
291
+ const circleOnSphere = `
292
+ vec3 rotateVectorAroundAxis(vec3 v, vec3 axis, float angle) {
293
+ float c = cos(angle);
294
+ float s = sin(angle);
295
+ float t = 1.0 - c;
296
+ vec3 normalizedAxis = normalize(axis); // Ensure axis is unit length
297
+
298
+ return vec3(
299
+ (t * normalizedAxis.x * normalizedAxis.x + c) * v.x +
300
+ (t * normalizedAxis.x * normalizedAxis.y - s * normalizedAxis.z) * v.y +
301
+ (t * normalizedAxis.x * normalizedAxis.z + s * normalizedAxis.y) * v.z,
302
+
303
+ (t * normalizedAxis.x * normalizedAxis.y + s * normalizedAxis.z) * v.x +
304
+ (t * normalizedAxis.y * normalizedAxis.y + c) * v.y +
305
+ (t * normalizedAxis.y * normalizedAxis.z - s * normalizedAxis.x) * v.z,
306
+
307
+ (t * normalizedAxis.x * normalizedAxis.z - s * normalizedAxis.y) * v.x +
308
+ (t * normalizedAxis.y * normalizedAxis.z + s * normalizedAxis.x) * v.y +
309
+ (t * normalizedAxis.z * normalizedAxis.z + c) * v.z
310
+ );
311
+
312
+ // Alternative, more compact way using cross and dot products:
313
+ // vec3 crossProd = cross(normalizedAxis, v);
314
+ // float dotProd = dot(normalizedAxis, v);
315
+ // return v * c + crossProd * s + normalizedAxis * dotProd * t;
316
+ }
317
+
318
+ /**
319
+ * @brief Calculates a point on a circle drawn on the surface of a sphere.
320
+ * The sphere is assumed to be centered at the origin (0,0,0).
321
+ * The circle's center on the sphere surface is M, and H is a starting point on the circle.
322
+ * The function returns the point obtained by rotating H around the axis defined by M by angle A.
323
+ *
324
+ * @param M The center point of the circle on the sphere's surface. The vector from the origin to M defines the rotation axis.
325
+ * @param H A starting point on the circle (also on the sphere's surface).
326
+ * @param A The angle of rotation in radians. Use radians(degrees) if your input is in degrees.
327
+ * @return A vec3 representing the calculated point on the sphere's surface.
328
+ */
329
+ vec3 circleOnSphere(vec3 M, vec3 H, float A) {
330
+ // The rotation axis is the vector from the origin to the circle's center point M on the sphere.
331
+ // This axis vector needs to be normalized for the rotation formula.
332
+ vec3 rotationAxis = normalize(M);
333
+
334
+ // Rotate the starting point H around the rotation axis by angle A.
335
+ vec3 rotatedPoint = rotateVectorAroundAxis(H, rotationAxis, A);
336
+
337
+ // Optional but recommended: Re-normalize the result to ensure it stays exactly on the sphere's surface,
338
+ // counteracting potential floating-point inaccuracies, especially if the original sphere radius was 1.
339
+ // If the sphere has a different radius R, you might want to normalize and multiply by R:
340
+ // float radius = length(M); // Assuming M is exactly on the surface
341
+ // return normalize(rotatedPoint) * radius;
342
+ // If it's a unit sphere:
343
+ // return normalize(rotatedPoint);
344
+
345
+ // For simplicity, returning the direct result of rotation. Assume M and H were perfectly on the sphere.
346
+ return rotatedPoint;
288
347
  }`;
289
348
 
290
349
  const circleLimpFromLongLatRadCenterMercatorCompass_accurate = `
@@ -324,6 +383,6 @@ export {
324
383
  slerp,
325
384
  circleLimpFromLongLatRadCenterCartesian3D_accurate,
326
385
  circleLimpFromLongLatRadCenterMercatorCompass_accurate,
327
- circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate
328
-
386
+ circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate,
387
+ circleOnSphere,
329
388
  }