@pirireis/webglobeplugins 0.17.1 → 1.0.3

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 (67) hide show
  1. package/Math/haversine.js +22 -0
  2. package/Math/methods.js +15 -2
  3. package/Math/tessellation/methods.js +4 -1
  4. package/Math/tessellation/nearest-value-padding.js +112 -0
  5. package/Math/tessellation/spherical-triangle-area.js +99 -0
  6. package/Math/tessellation/tile-merger.js +346 -215
  7. package/Math/tessellation/triangle-tessellation.js +381 -9
  8. package/Math/vec3.js +4 -0
  9. package/Math/xyz-tile.js +18 -0
  10. package/altitude-locator/plugin.js +1 -2
  11. package/investigation-tools/draw/tiles/adapters.js +2 -2
  12. package/investigation-tools/draw/tiles/tiles.js +2 -2
  13. package/package.json +1 -1
  14. package/programs/helpers/fadeaway.js +6 -1
  15. package/programs/point-on-globe/square-pixel-point.js +1 -0
  16. package/programs/polygon-on-globe/texture-dem-triangles.js +94 -116
  17. package/programs/totems/camera-totem-attactment-interface.js +1 -0
  18. package/programs/totems/camerauniformblock.js +33 -22
  19. package/programs/totems/dem-textures-manager.js +265 -0
  20. package/programs/vectorfields/logics/drawrectangleparticles.js +51 -18
  21. package/programs/vectorfields/logics/{ubo-new.js → particle-ubo.js} +5 -14
  22. package/programs/vectorfields/logics/pixelbased.js +42 -36
  23. package/programs/vectorfields/pingpongbuffermanager.js +34 -8
  24. package/semiplugins/shape-on-terrain/terrain-polygon/adapters.js +55 -0
  25. package/semiplugins/shape-on-terrain/terrain-polygon/data/cache.js +102 -0
  26. package/semiplugins/shape-on-terrain/terrain-polygon/data/index-polygon-map.js +45 -0
  27. package/semiplugins/shape-on-terrain/terrain-polygon/data/manager.js +4 -0
  28. package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.js +177 -0
  29. package/semiplugins/shape-on-terrain/terrain-polygon/data/polygon-to-triangles.js +100 -0
  30. package/semiplugins/shape-on-terrain/terrain-polygon/data/random.js +121 -0
  31. package/semiplugins/shape-on-terrain/terrain-polygon/data/types.js +1 -0
  32. package/semiplugins/shape-on-terrain/terrain-polygon/data/worker-contact.js +63 -0
  33. package/semiplugins/shape-on-terrain/terrain-polygon/data/worker.js +125 -0
  34. package/semiplugins/shape-on-terrain/terrain-polygon/terrain-polygon.js +219 -0
  35. package/semiplugins/shape-on-terrain/terrain-polygon/types.js +8 -0
  36. package/semiplugins/shell/bbox-renderer/logic.js +18 -58
  37. package/semiplugins/shell/bbox-renderer/object.js +19 -9
  38. package/tracks/point-heat-map/point-to-heat-map-flow.js +1 -1
  39. package/tracks/point-tracks/plugin.js +13 -6
  40. package/tracks/timetracks/program-line-strip.js +1 -1
  41. package/util/account/single-attribute-buffer-management/buffer-manager.js +5 -3
  42. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +2 -2
  43. package/util/gl-util/uniform-block/manager.js +20 -10
  44. package/util/helper-methods.js +8 -0
  45. package/util/picking/fence.js +4 -2
  46. package/util/picking/picker-displayer.js +51 -9
  47. package/util/programs/draw-texture-on-canvas.js +18 -15
  48. package/util/shaderfunctions/geometrytransformations.js +67 -1
  49. package/vectorfield/waveparticles/plugin.js +241 -116
  50. package/vectorfield/wind/adapters/image-to-fields.js +61 -0
  51. package/vectorfield/wind/adapters/types.js +1 -0
  52. package/vectorfield/wind/imagetovectorfieldandmagnitude.js +6 -9
  53. package/vectorfield/wind/plugin-persistant copy.js +364 -0
  54. package/vectorfield/wind/plugin-persistant.js +375 -0
  55. package/vectorfield/wind/plugin.js +1 -1
  56. package/Math/tessellation/earcut/adapters.js +0 -37
  57. package/Math/tessellation/hybrid-triangle-tessellation-meta.js +0 -123
  58. package/Math/tessellation/shred-input.js +0 -18
  59. package/Math/tessellation/tiler.js +0 -50
  60. package/Math/tessellation/triangle-tessellation-meta.js +0 -523
  61. package/programs/polygon-on-globe/texture-dem-triangle-test-plugin-triangle.js +0 -328
  62. package/programs/vectorfields/logics/drawrectangleparticles1.js +0 -112
  63. package/semiplugins/shape-on-terrain/terrain-cover/texture-dem-cover.js +0 -1
  64. package/util/gl-util/uniform-block/types.js +0 -1
  65. package/util/webglobe/index.js +0 -2
  66. /package/Math/tessellation/{zoom-catch.js → constants.js} +0 -0
  67. /package/util/{webglobe/gldefaultstates.js → globe-default-gl-states.js} +0 -0
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Calculate great-circle distance (arc length) between two lat/lon points
3
+ * @param lat1 Latitude of point 1 (Radian)
4
+ * @param lon1 Longitude of point 1 (Radian)
5
+ * @param lat2 Latitude of point 2 (Radian)
6
+ * @param lon2 Longitude of point 2 (Radian)
7
+ * @returns Distance in unit sphere radius
8
+ */
9
+ export function haversine(lat1, lon1, lat2, lon2) {
10
+ // Convert to radians in-place (minimal allocations)
11
+ const φ1 = lat1;
12
+ const φ2 = lat2;
13
+ const Δφ = lat2 - lat1;
14
+ const Δλ = lon2 - lon1;
15
+ // Haversine: a = sin²(Δφ/2) + cos(φ1)cos(φ2)sin²(Δλ/2)
16
+ const a = Math.sin(Δφ * 0.5) ** 2 +
17
+ Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ * 0.5) ** 2;
18
+ // c = 2 * atan2(√a, √(1−a))
19
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
20
+ return c; // arc length
21
+ }
22
+ ;
package/Math/methods.js CHANGED
@@ -18,10 +18,23 @@ export const radianToMercator = (xy) => {
18
18
  };
19
19
  export function radianToMercatorXY(xy) {
20
20
  return [
21
- xy[0] * Math.pow(2, 8),
22
- Math.log(Math.tan(Math.PI / 4 + xy[1] / 2)) * Math.pow(2, 8)
21
+ xy[0],
22
+ Math.log(Math.tan(Math.PI / 4 + xy[1] / 2)),
23
23
  ];
24
24
  }
25
+ export function globeBBoxToXYBBOX(t) {
26
+ // this code scales Y to linear integration
27
+ return {
28
+ ll: radianToMercatorXY([t.ll.x * RADIAN, t.ll.y * RADIAN]), // west longitude, north latitude
29
+ ur: radianToMercatorXY([t.ur.x * RADIAN, t.ur.y * RADIAN]) // east longitude, south latitude
30
+ };
31
+ }
32
+ export function tileXY2Radian(x, y, zoom) {
33
+ const n = Math.pow(2, zoom);
34
+ const long = x / n * 2 * Math.PI - Math.PI;
35
+ const lat = Math.atan(Math.sinh(Math.PI - (y / n * 2 * Math.PI)));
36
+ return [long, lat];
37
+ }
25
38
  export const radianToCartesian3d = (xy) => {
26
39
  const x = Math.cos(xy[1]) * Math.cos(xy[0]);
27
40
  const y = Math.cos(xy[1]) * Math.sin(xy[0]);
@@ -1,4 +1,4 @@
1
- import { TILE_COUNTS } from "./zoom-catch";
1
+ import { TILE_COUNTS } from "./constants";
2
2
  /**
3
3
  * If the slope is not close the zero not very important but
4
4
  * If a line goes along a parallel its latitude can tilt a lot
@@ -9,6 +9,9 @@ import { TILE_COUNTS } from "./zoom-catch";
9
9
  *
10
10
  *
11
11
  */
12
+ export function calculateMergedMeshDimLength(tileCount, sourceLength) {
13
+ return sourceLength * tileCount - (tileCount - 1);
14
+ }
12
15
  export function latToTileY(lat, zoom) {
13
16
  return (1 - Math.log(Math.tan(lat) + 1 / Math.cos(lat)) / Math.PI) / 2 * TILE_COUNTS[zoom];
14
17
  }
@@ -0,0 +1,112 @@
1
+ import { calculateMergedMeshDimLength } from "./methods";
2
+ //TODO: file name to be changed to nearest-value-padding.ts
3
+ const around = [
4
+ [1, 0],
5
+ [0, 1],
6
+ [-1, 0],
7
+ [0, -1],
8
+ ];
9
+ export class NearestValuePadding {
10
+ mergedTileCount;
11
+ tileDimenstionLength;
12
+ mergedMeshDimLength;
13
+ // Changed to string to prevent collisions with absolute coordinates
14
+ tileGrid = new Set();
15
+ constructor(tileDimenstionLength, mergedTileCount) {
16
+ this.tileDimenstionLength = tileDimenstionLength;
17
+ this.mergedTileCount = mergedTileCount;
18
+ this.mergedMeshDimLength = calculateMergedMeshDimLength(mergedTileCount, tileDimenstionLength);
19
+ }
20
+ _keyMaker(x, y) {
21
+ return `${x}_${y}`;
22
+ }
23
+ insert(x, y) {
24
+ const { tileGrid } = this;
25
+ tileGrid.add(this._keyMaker(x, y));
26
+ }
27
+ fillTileFromBorders(mesh, relX, // Changed to relative coordinates
28
+ relY) {
29
+ const { tileDimenstionLength, mergedMeshDimLength } = this;
30
+ // Tiles share edges, so stride is dimension - 1
31
+ const stride = tileDimenstionLength - 1;
32
+ const startX = relX * stride;
33
+ const startY = relY * stride;
34
+ const endX = startX + tileDimenstionLength;
35
+ const endY = startY + tileDimenstionLength;
36
+ const queue = [];
37
+ const getIndex = (gx, gy) => gy * mergedMeshDimLength + gx;
38
+ // 1. Collect valid border pixels as seeds
39
+ // Top and Bottom borders
40
+ for (let lx = 0; lx < tileDimenstionLength; lx++) {
41
+ const gx = startX + lx;
42
+ // Top
43
+ const topIdx = getIndex(gx, startY);
44
+ if (topIdx < mesh.length && !isNaN(mesh[topIdx]))
45
+ queue.push(topIdx);
46
+ // Bottom
47
+ const bottomIdx = getIndex(gx, startY + tileDimenstionLength - 1);
48
+ if (bottomIdx < mesh.length && !isNaN(mesh[bottomIdx]))
49
+ queue.push(bottomIdx);
50
+ }
51
+ // Left and Right borders (excluding corners)
52
+ for (let ly = 1; ly < tileDimenstionLength - 1; ly++) {
53
+ const gy = startY + ly;
54
+ // Left
55
+ const leftIdx = getIndex(startX, gy);
56
+ if (leftIdx < mesh.length && !isNaN(mesh[leftIdx]))
57
+ queue.push(leftIdx);
58
+ // Right
59
+ const rightIdx = getIndex(startX + tileDimenstionLength - 1, gy);
60
+ if (rightIdx < mesh.length && !isNaN(mesh[rightIdx]))
61
+ queue.push(rightIdx);
62
+ }
63
+ // 2. BFS Flood Fill
64
+ let head = 0;
65
+ while (head < queue.length) {
66
+ const idx = queue[head++];
67
+ const val = mesh[idx];
68
+ const cx = idx % mergedMeshDimLength;
69
+ const cy = Math.floor(idx / mergedMeshDimLength);
70
+ const neighbors = [
71
+ { nx: cx + 1, ny: cy },
72
+ { nx: cx - 1, ny: cy },
73
+ { nx: cx, ny: cy + 1 },
74
+ { nx: cx, ny: cy - 1 },
75
+ ];
76
+ for (const { nx, ny } of neighbors) {
77
+ // Check if neighbor is within the current tile bounds
78
+ if (nx >= startX && nx < endX && ny >= startY && ny < endY) {
79
+ const nIdx = getIndex(nx, ny);
80
+ if (nIdx < mesh.length && isNaN(mesh[nIdx])) {
81
+ mesh[nIdx] = val;
82
+ queue.push(nIdx);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ clamp(mesh, minX, minY, maxX, maxY) {
89
+ // traverse all tiles, if tileSet doesnt have the tile, calculate border verteces indexes.
90
+ // for top index check the index on left-top, top, tight-top to fill closest value
91
+ const { tileGrid, mergedTileCount } = this;
92
+ // Use passed absolute bounds directly
93
+ for (let x = minX; x <= maxX; x++) {
94
+ for (let y = minY; y <= maxY; y++) {
95
+ const key = this._keyMaker(x, y);
96
+ if (tileGrid.has(key)) {
97
+ continue;
98
+ }
99
+ // Calculate relative coordinates for mesh access
100
+ const relX = x - minX;
101
+ const relY = y - minY;
102
+ // Ensure we stay within the allocated merged mesh
103
+ if (relX >= 0 && relX < mergedTileCount && relY >= 0 && relY < mergedTileCount) {
104
+ this.fillTileFromBorders(mesh, relX, relY);
105
+ }
106
+ }
107
+ }
108
+ }
109
+ clear() {
110
+ this.tileGrid.clear();
111
+ }
112
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Calculates the 3D surface area of a spherical triangle defined by three unit vectors
3
+ * on the surface of a sphere of radius R, using Girard's Theorem.
4
+ *
5
+ * @param p1 The first unit vector [x, y, z].
6
+ * @param p2 The second unit vector [x, y, z].
7
+ * @param p3 The third unit vector [x, y, z].
8
+ * @param R The radius of the sphere (e.g., 6378.137 for Earth's radius).
9
+ * @returns The surface area of the spherical triangle.
10
+ */
11
+ export function sphericalTriangleArea(p1, p2, p3, R) {
12
+ // --- 1. Utility Functions ---
13
+ /** Calculates the dot product of two vectors. */
14
+ const dot = (v1, v2) => v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
15
+ /** Calculates the cross product of two vectors. */
16
+ const cross = (v1, v2) => [
17
+ v1[1] * v2[2] - v1[2] * v2[1],
18
+ v1[2] * v2[0] - v1[0] * v2[2],
19
+ v1[0] * v2[1] - v1[1] * v2[0],
20
+ ];
21
+ /** Calculates the squared magnitude (length squared) of a vector. */
22
+ const magSq = (v) => v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
23
+ // --- 2. Calculate Plane Normals ---
24
+ // The interior angles are the angles between the planes that contain the edges.
25
+ // The normal N_AB is perpendicular to the plane containing the segment P1-P2 and the origin.
26
+ const n_p1p2 = cross(p1, p2);
27
+ const n_p2p3 = cross(p2, p3);
28
+ const n_p3p1 = cross(p3, p1);
29
+ // Magnitudes (squared) of the normals. Since P1, P2, P3 are unit vectors,
30
+ // the magnitude of the cross product (sin(angle)) is not 1, so we must normalize later.
31
+ const n12_sq = magSq(n_p1p2);
32
+ const n23_sq = magSq(n_p2p3);
33
+ const n31_sq = magSq(n_p3p1);
34
+ // Handle degenerate cases (e.g., points are collinear or on a great circle)
35
+ if (n12_sq < 1e-9 || n23_sq < 1e-9 || n31_sq < 1e-9) {
36
+ return 0;
37
+ }
38
+ // --- 3. Calculate Interior Angles (Alpha, Beta, Gamma) ---
39
+ // The angle between two planes is the angle between their normal vectors (N_a, N_b).
40
+ // Angle = arccos( (N_a . N_b) / (||N_a|| * ||N_b||) )
41
+ // Angle at P1 (Alpha): angle between normal N_p3p1 and N_p1p2
42
+ const cos_alpha = dot(n_p3p1, n_p1p2) / Math.sqrt(n31_sq * n12_sq);
43
+ const alpha = Math.acos(Math.min(1.0, Math.max(-1.0, cos_alpha))); // Clamp for floating point errors
44
+ // Angle at P2 (Beta): angle between normal N_p1p2 and N_p2p3
45
+ const cos_beta = dot(n_p1p2, n_p2p3) / Math.sqrt(n12_sq * n23_sq);
46
+ const beta = Math.acos(Math.min(1.0, Math.max(-1.0, cos_beta)));
47
+ // Angle at P3 (Gamma): angle between normal N_p2p3 and N_p3p1
48
+ const cos_gamma = dot(n_p2p3, n_p3p1) / Math.sqrt(n23_sq * n31_sq);
49
+ const gamma = Math.acos(Math.min(1.0, Math.max(-1.0, cos_gamma)));
50
+ // --- 4. Apply Girard's Theorem ---
51
+ // Spherical Excess (E): The amount by which the sum of the interior angles exceeds PI.
52
+ const spherical_excess = alpha + beta + gamma - Math.PI;
53
+ // The surface area A is given by R^2 * E.
54
+ // Use Math.abs() to ensure a positive area, regardless of vertex winding order.
55
+ const area = R * R * Math.abs(spherical_excess);
56
+ return area;
57
+ }
58
+ // Define Earth's radius (R_3D) for context, though it's not strictly necessary if R is passed in.
59
+ const R_EARTH = 6378.137; // km
60
+ /**
61
+ * Calculates the Culling Area Threshold (A_CULL) for a given zoom level.
62
+ * Triangles with area LESS than this threshold are considered too small to display.
63
+ *
64
+ * @param zoomLevel The current integer zoom level (Z).
65
+ * @param R The radius of the sphere (e.g., 6378.137 for Earth).
66
+ * @param C1_Factor A tuning constant determining the base visibility level (Default: 1.0).
67
+ * Lower values mean smaller triangles are culled at early zoom levels.
68
+ * @returns The area threshold in R units squared (e.g., km^2).
69
+ */
70
+ export function generateCullAreaThreshold(zoomLevel, R, C1_Factor = 1.0) {
71
+ // A_BASE_CULL should represent a "small" area on the sphere (e.g., 1 square degree equivalent).
72
+ // We scale it by R^2 to get the area in the correct units (e.g., km^2).
73
+ // The R^2 * 4 * Math.PI factor is the total surface area of the sphere.
74
+ // The denominator provides a large base number so the initial area is small.
75
+ // A simplified base area using 1/1,000,000th of the total spherical area for Z=0
76
+ const A_BASE_CULL = (4 * Math.PI * R * R) / 1000000;
77
+ // A_CULL scales exponentially with -2 * Z (since area is proportional to the square of linear size)
78
+ const threshold = C1_Factor * A_BASE_CULL * Math.pow(2, -2 * zoomLevel);
79
+ return threshold;
80
+ }
81
+ /**
82
+ * Calculates the Tessellation Area Threshold (A_TESS) for a given zoom level.
83
+ * Triangles with area GREATER than this threshold require subdivision (tessellation).
84
+ *
85
+ * @param zoomLevel The current integer zoom level (Z).
86
+ * @param R The radius of the sphere (e.g., 6378.137 for Earth).
87
+ * @param C2_Factor A tuning constant determining the relative size for tessellation.
88
+ * Higher values mean tessellation happens less aggressively (Default: 100.0).
89
+ * @returns The area threshold in R units squared (e.g., km^2).
90
+ */
91
+ export function generateTessellationAreaThreshold(zoomLevel, R, C2_Factor = 100.0) {
92
+ // This threshold should be significantly larger than the CULL threshold.
93
+ // We can directly derive it by applying a large constant factor (C2_Factor)
94
+ // to the cull threshold, maintaining the same exponential scaling.
95
+ // Use the Cull function as a base:
96
+ const A_CULL_BASE = generateCullAreaThreshold(zoomLevel, R, 1.0);
97
+ const threshold = C2_Factor * A_CULL_BASE;
98
+ return threshold;
99
+ }