@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.
- package/Math/haversine.js +22 -0
- package/Math/methods.js +15 -2
- package/Math/tessellation/methods.js +4 -1
- package/Math/tessellation/nearest-value-padding.js +112 -0
- package/Math/tessellation/spherical-triangle-area.js +99 -0
- package/Math/tessellation/tile-merger.js +346 -215
- package/Math/tessellation/triangle-tessellation.js +381 -9
- package/Math/vec3.js +4 -0
- package/Math/xyz-tile.js +18 -0
- package/altitude-locator/plugin.js +1 -2
- package/investigation-tools/draw/tiles/adapters.js +2 -2
- package/investigation-tools/draw/tiles/tiles.js +2 -2
- package/package.json +1 -1
- package/programs/helpers/fadeaway.js +6 -1
- package/programs/point-on-globe/square-pixel-point.js +1 -0
- package/programs/polygon-on-globe/texture-dem-triangles.js +94 -116
- package/programs/totems/camera-totem-attactment-interface.js +1 -0
- package/programs/totems/camerauniformblock.js +33 -22
- package/programs/totems/dem-textures-manager.js +265 -0
- package/programs/vectorfields/logics/drawrectangleparticles.js +51 -18
- package/programs/vectorfields/logics/{ubo-new.js → particle-ubo.js} +5 -14
- package/programs/vectorfields/logics/pixelbased.js +42 -36
- package/programs/vectorfields/pingpongbuffermanager.js +34 -8
- package/semiplugins/shape-on-terrain/terrain-polygon/adapters.js +55 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/cache.js +102 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/index-polygon-map.js +45 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/manager.js +4 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.js +177 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/polygon-to-triangles.js +100 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/random.js +121 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/types.js +1 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/worker-contact.js +63 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/worker.js +125 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/terrain-polygon.js +219 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/types.js +8 -0
- package/semiplugins/shell/bbox-renderer/logic.js +18 -58
- package/semiplugins/shell/bbox-renderer/object.js +19 -9
- package/tracks/point-heat-map/point-to-heat-map-flow.js +1 -1
- package/tracks/point-tracks/plugin.js +13 -6
- package/tracks/timetracks/program-line-strip.js +1 -1
- package/util/account/single-attribute-buffer-management/buffer-manager.js +5 -3
- package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +2 -2
- package/util/gl-util/uniform-block/manager.js +20 -10
- package/util/helper-methods.js +8 -0
- package/util/picking/fence.js +4 -2
- package/util/picking/picker-displayer.js +51 -9
- package/util/programs/draw-texture-on-canvas.js +18 -15
- package/util/shaderfunctions/geometrytransformations.js +67 -1
- package/vectorfield/waveparticles/plugin.js +241 -116
- package/vectorfield/wind/adapters/image-to-fields.js +61 -0
- package/vectorfield/wind/adapters/types.js +1 -0
- package/vectorfield/wind/imagetovectorfieldandmagnitude.js +6 -9
- package/vectorfield/wind/plugin-persistant copy.js +364 -0
- package/vectorfield/wind/plugin-persistant.js +375 -0
- package/vectorfield/wind/plugin.js +1 -1
- package/Math/tessellation/earcut/adapters.js +0 -37
- package/Math/tessellation/hybrid-triangle-tessellation-meta.js +0 -123
- package/Math/tessellation/shred-input.js +0 -18
- package/Math/tessellation/tiler.js +0 -50
- package/Math/tessellation/triangle-tessellation-meta.js +0 -523
- package/programs/polygon-on-globe/texture-dem-triangle-test-plugin-triangle.js +0 -328
- package/programs/vectorfields/logics/drawrectangleparticles1.js +0 -112
- package/semiplugins/shape-on-terrain/terrain-cover/texture-dem-cover.js +0 -1
- package/util/gl-util/uniform-block/types.js +0 -1
- package/util/webglobe/index.js +0 -2
- /package/Math/tessellation/{zoom-catch.js → constants.js} +0 -0
- /package/util/{webglobe/gldefaultstates.js → globe-default-gl-states.js} +0 -0
|
@@ -1,14 +1,386 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @author Toprak Ozturk
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @description Finds inner and edge cut points of givin triangle for given zoom level
|
|
6
|
+
*
|
|
7
|
+
* @param {number} zoomLevel - The current zoom level
|
|
8
|
+
* @param {LongLat} p1 - First point of triangle
|
|
9
|
+
* @param {LongLat} p2 - Second point of triangle
|
|
10
|
+
* @param {LongLat} p3 - Third point of triangle
|
|
11
|
+
*
|
|
12
|
+
*
|
|
13
|
+
* @returns {positions: LongLat[], indices: number[]} - positions are the inner and edge cut points of triangle, indices are the index array for triangle faces
|
|
14
|
+
*/
|
|
15
|
+
import { create as createArc, calculateZLimitPoint } from "../arc";
|
|
16
|
+
import { createUnitVectorFromLongLat, equals, vec3ToLongLatRadians, clone } from "../vec3";
|
|
17
|
+
import { TILE_COUNTS } from "./constants";
|
|
18
|
+
import { pointsOnArc } from "../juction/arc-plane";
|
|
19
|
+
import { latToTileY, tileYtoLat } from "./methods";
|
|
20
|
+
import Delaunator from "delaunator";
|
|
21
|
+
import { radianToMercatorXY } from "../methods";
|
|
22
|
+
const KEY_PRECISION = 9;
|
|
23
|
+
// TODO:get rid of embedded lists. always flat list
|
|
24
|
+
const TILE_DEM_VERTEX_COUNT = 5; // 5x5 grid for DEM
|
|
25
|
+
const TILE_DEM_STEPCOUNT = TILE_DEM_VERTEX_COUNT - 1; // 4 inner divisions in each dimension
|
|
26
|
+
const _plane = /*@__PURE__*/ { normal: [0, 0, 0], distance: 0 };
|
|
27
|
+
const _resultPoints = /*@__PURE__*/ [[0, 0, 0], [0, 0, 0]];
|
|
28
|
+
function createBBox(p1, p2, limitVec) {
|
|
29
|
+
if (limitVec) {
|
|
30
|
+
const limitLongLat = vec3ToLongLatRadians(limitVec);
|
|
31
|
+
return {
|
|
32
|
+
min: [Math.min(p1[0], p2[0], limitLongLat[0]), Math.min(p1[1], p2[1], limitLongLat[1])],
|
|
33
|
+
max: [Math.max(p1[0], p2[0], limitLongLat[0]), Math.max(p1[1], p2[1], limitLongLat[1])],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
min: [Math.min(p1[0], p2[0]), Math.min(p1[1], p2[1])],
|
|
38
|
+
max: [Math.max(p1[0], p2[0]), Math.max(p1[1], p2[1])],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function radianCheck(point) {
|
|
42
|
+
return point[0] >= -Math.PI && point[0] <= Math.PI && point[1] >= -Math.PI
|
|
43
|
+
&& point[1] <= Math.PI / 2 && point[1] >= -Math.PI / 2;
|
|
44
|
+
}
|
|
45
|
+
export function createTriangleTessellationMeta(p1, p2, p3) {
|
|
46
|
+
if (!radianCheck(p1) || !radianCheck(p2) || !radianCheck(p3)) {
|
|
47
|
+
throw new Error('Points must be in radian range: ' +
|
|
48
|
+
'p1:' + p1[0] + ',' + p1[1] +
|
|
49
|
+
' p2:' + p2[0] + ',' + p2[1] +
|
|
50
|
+
' p3:' + p3[0] + ',' + p3[1]);
|
|
51
|
+
}
|
|
52
|
+
const p1v3 = createUnitVectorFromLongLat(p1);
|
|
53
|
+
const p2v3 = createUnitVectorFromLongLat(p2);
|
|
54
|
+
const p3v3 = createUnitVectorFromLongLat(p3);
|
|
55
|
+
const arc1 = createArc(p1v3, p2v3);
|
|
56
|
+
const arc2 = createArc(p2v3, p3v3);
|
|
57
|
+
const arc3 = createArc(p3v3, p1v3);
|
|
58
|
+
const limitVec = [0, 0, 0];
|
|
59
|
+
if (calculateZLimitPoint(arc1, limitVec)) {
|
|
60
|
+
arc1.exceededLimit = [limitVec[0], limitVec[1], limitVec[2]];
|
|
61
|
+
}
|
|
62
|
+
arc1.bbox = createBBox(p1, p2, arc1.exceededLimit);
|
|
63
|
+
arc1.p0LongLat = p1;
|
|
64
|
+
arc1.p1LongLat = p2;
|
|
65
|
+
if (calculateZLimitPoint(arc2, limitVec)) {
|
|
66
|
+
arc2.exceededLimit = [limitVec[0], limitVec[1], limitVec[2]];
|
|
67
|
+
}
|
|
68
|
+
arc2.bbox = createBBox(p2, p3, arc2.exceededLimit);
|
|
69
|
+
arc2.p0LongLat = p2;
|
|
70
|
+
arc2.p1LongLat = p3;
|
|
71
|
+
if (calculateZLimitPoint(arc3, limitVec)) {
|
|
72
|
+
arc3.exceededLimit = [limitVec[0], limitVec[1], limitVec[2]];
|
|
73
|
+
}
|
|
74
|
+
arc3.bbox = createBBox(p3, p1, arc3.exceededLimit);
|
|
75
|
+
arc3.p0LongLat = p3;
|
|
76
|
+
arc3.p1LongLat = p1;
|
|
77
|
+
const bbox = {
|
|
78
|
+
min: [
|
|
79
|
+
Math.min(arc1.bbox.min[0], arc2.bbox.min[0], arc3.bbox.min[0]),
|
|
80
|
+
Math.min(arc1.bbox.min[1], arc2.bbox.min[1], arc3.bbox.min[1])
|
|
81
|
+
],
|
|
82
|
+
max: [
|
|
83
|
+
Math.max(arc1.bbox.max[0], arc2.bbox.max[0], arc3.bbox.max[0]),
|
|
84
|
+
Math.max(arc1.bbox.max[1], arc2.bbox.max[1], arc3.bbox.max[1])
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
const meta = {
|
|
88
|
+
arcs: [arc1, arc2, arc3],
|
|
89
|
+
bbox,
|
|
90
|
+
showThreshold: calculateShowThreshold(arc1, arc2, arc3)
|
|
91
|
+
};
|
|
92
|
+
meta.shortCut = partialTessellation(meta, [{
|
|
93
|
+
bbox: meta.bbox,
|
|
94
|
+
zoom: 0
|
|
95
|
+
}], TILE_DEM_STEPCOUNT);
|
|
96
|
+
return meta;
|
|
97
|
+
}
|
|
98
|
+
function calculateShowThreshold(arc1, arc2, arc3) {
|
|
99
|
+
const largestCoverAngle = Math.max(arc1.coverAngle, arc2.coverAngle, arc3.coverAngle);
|
|
100
|
+
return Math.PI / largestCoverAngle;
|
|
101
|
+
}
|
|
102
|
+
export function zoomLevelShowThreshold(zoomLevel, tileRatio) {
|
|
103
|
+
const tileCount = TILE_COUNTS[zoomLevel];
|
|
104
|
+
return tileCount / tileRatio / 2;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
3
107
|
*
|
|
108
|
+
* @param triangleMeta
|
|
109
|
+
* @param zoom
|
|
110
|
+
* @param angle
|
|
111
|
+
* @param dimension false for longitude (meridian) true for latitude (parallel)
|
|
4
112
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
113
|
+
function getPoints(triangleMeta, angle, dimension) {
|
|
114
|
+
// find which arcs are cut by plane
|
|
115
|
+
const radians = angle;
|
|
116
|
+
if (dimension) {
|
|
117
|
+
_plane.normal[0] = 0;
|
|
118
|
+
_plane.normal[1] = 0;
|
|
119
|
+
_plane.normal[2] = 1;
|
|
120
|
+
_plane.distance = Math.sin(radians);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
_plane.normal[0] = Math.sin(radians);
|
|
124
|
+
_plane.normal[1] = -Math.cos(radians);
|
|
125
|
+
_plane.normal[2] = 0;
|
|
126
|
+
_plane.distance = 0;
|
|
127
|
+
}
|
|
128
|
+
let result = [];
|
|
129
|
+
// Add debugging
|
|
130
|
+
let resultsFromDistinctArcs = 0;
|
|
131
|
+
for (let i = 0; i < 3; i++) {
|
|
132
|
+
const arc = triangleMeta.arcs[i];
|
|
133
|
+
const coordIndex = dimension ? 1 : 0;
|
|
134
|
+
const minCoord = arc.bbox.min[coordIndex];
|
|
135
|
+
const maxCoord = arc.bbox.max[coordIndex];
|
|
136
|
+
if (minCoord > angle || maxCoord < angle) {
|
|
137
|
+
continue; // arc is out of range
|
|
138
|
+
}
|
|
139
|
+
const count = pointsOnArc(arc, _plane, _resultPoints);
|
|
140
|
+
if (count === 1) {
|
|
141
|
+
result.push({ vec: clone(_resultPoints[0]), longLat: vec3ToLongLatRadians(_resultPoints[0]), arcIndex: i });
|
|
142
|
+
}
|
|
143
|
+
else if (count === 2) {
|
|
144
|
+
// throw new Error('Unexpected 2 cut points on arc, should be max 1'); // TODO DELETE this line later
|
|
145
|
+
result.push({ vec: [..._resultPoints[0]], longLat: vec3ToLongLatRadians(_resultPoints[0]), arcIndex: i });
|
|
146
|
+
result.push({ vec: clone(_resultPoints[1]), longLat: vec3ToLongLatRadians(_resultPoints[1]), arcIndex: i }); // TODO: this is a fix for a bug, need to investigate later
|
|
147
|
+
}
|
|
148
|
+
resultsFromDistinctArcs += 1;
|
|
149
|
+
}
|
|
150
|
+
if (resultsFromDistinctArcs === 3) {
|
|
151
|
+
result = filterDuplicate(result);
|
|
152
|
+
}
|
|
153
|
+
if (result.length !== 2 && result.length !== 4) {
|
|
154
|
+
// throw new Error(`Unexpected cut count for tile cut, got: ${result.length}, angle: ${angle * 180 / Math.PI}, dimension: ${dimension ? 'latitude' : 'longitude'} \n`);
|
|
155
|
+
console.error(`Unexpected cut count for tile cut, got: ${result.length}, angle: ${angle * 180 / Math.PI}, dimension: ${dimension ? 'latitude' : 'longitude'} \n`);
|
|
156
|
+
return [];
|
|
157
|
+
}
|
|
158
|
+
if (dimension) {
|
|
159
|
+
result.sort((a, b) => {
|
|
160
|
+
return a.longLat[0] - b.longLat[0]; // sort by x for latitude cuts
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
function getEdgePoints(triangleMeta, edgePointIndexSets) {
|
|
166
|
+
const points = [
|
|
167
|
+
triangleMeta.arcs[0].p0,
|
|
168
|
+
triangleMeta.arcs[1].p0,
|
|
169
|
+
triangleMeta.arcs[2].p0,
|
|
170
|
+
];
|
|
171
|
+
edgePointIndexSets[0].add(0);
|
|
172
|
+
edgePointIndexSets[0].add(1);
|
|
173
|
+
edgePointIndexSets[1].add(1);
|
|
174
|
+
edgePointIndexSets[1].add(2);
|
|
175
|
+
edgePointIndexSets[2].add(2);
|
|
176
|
+
edgePointIndexSets[2].add(0);
|
|
177
|
+
let exceededLimitPointIndex = 3;
|
|
178
|
+
for (let i = 0; i < 3; i++) {
|
|
179
|
+
if (triangleMeta.arcs[i].exceededLimit) {
|
|
180
|
+
points.push(triangleMeta.arcs[i].exceededLimit);
|
|
181
|
+
edgePointIndexSets[i].add(exceededLimitPointIndex);
|
|
182
|
+
exceededLimitPointIndex++;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return points;
|
|
186
|
+
}
|
|
187
|
+
// TODO: EDGES NEED ! LEVEL MORE ZOOM LEVEL OF RESOLUTION as THEY CAN BE NEIGHBOURS OF HIGHER ZOOM LEVEL TILES....
|
|
188
|
+
// simple strategy: get max zoom level of neighbour, add edge cuts based on that zoom level, do not fill inner points.
|
|
189
|
+
// partialTessellation cure this problem automatically
|
|
190
|
+
function filterDuplicate(points) {
|
|
191
|
+
if (points.length < 2) {
|
|
192
|
+
return points;
|
|
193
|
+
}
|
|
194
|
+
const result = [points[0]];
|
|
195
|
+
for (let i = 1; i < points.length; i++) {
|
|
196
|
+
let isDuplicate = false;
|
|
197
|
+
for (let j = 0; j < result.length; j++) {
|
|
198
|
+
if (equals(points[i].vec, result[j].vec)) {
|
|
199
|
+
isDuplicate = true;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (!isDuplicate) {
|
|
204
|
+
result.push(points[i]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
function filterEdgePointTriangles(indeces, edgePointIndices) {
|
|
210
|
+
const result = [];
|
|
211
|
+
for (let i = 0; i < indeces.length; i += 3) {
|
|
212
|
+
const i0 = indeces[i];
|
|
213
|
+
const i1 = indeces[i + 1];
|
|
214
|
+
const i2 = indeces[i + 2];
|
|
215
|
+
if ((edgePointIndices[0].has(i0) && edgePointIndices[0].has(i1) && edgePointIndices[0].has(i2)) ||
|
|
216
|
+
(edgePointIndices[1].has(i0) && edgePointIndices[1].has(i1) && edgePointIndices[1].has(i2)) ||
|
|
217
|
+
(edgePointIndices[2].has(i0) && edgePointIndices[2].has(i1) && edgePointIndices[2].has(i2))) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
result.push(i0, i1, i2);
|
|
221
|
+
}
|
|
222
|
+
return new Uint32Array(result);
|
|
223
|
+
}
|
|
224
|
+
export function partialTessellation(triangleMeta, limits, innerCuts) {
|
|
225
|
+
// TODO: pointMap can be local variable and cleaned after function call to avoid reinitialization overhead
|
|
226
|
+
const pointMap = new Map(); // Key: "lon|lat", Value: index
|
|
227
|
+
const allVec3s = [];
|
|
228
|
+
const allLongLats = [];
|
|
229
|
+
let pointCounter = 0;
|
|
230
|
+
const stepCount = innerCuts - 1; //
|
|
231
|
+
const edgePointIndexSets = [new Set(), new Set(), new Set()];
|
|
232
|
+
// addTriangleVerticesToEdgeSets(edgePointIndexSets);
|
|
233
|
+
/**
|
|
234
|
+
* Precision for coordinate keys in the map. 1e-12 radians is
|
|
235
|
+
* extremely small (sub-millimeter on Earth's surface) and avoids
|
|
236
|
+
* floating point inaccuracies causing duplicate points.
|
|
237
|
+
*/
|
|
238
|
+
/**
|
|
239
|
+
* Adds a point to the vertex arrays if it doesn't already exist.
|
|
240
|
+
* Returns the index of the point (new or existing).
|
|
241
|
+
*/
|
|
242
|
+
const addPoint = (longLat, vec3, edgeIndex) => {
|
|
243
|
+
const key = `${Math.round(longLat[0] * 1e9)}|${Math.round(longLat[1] * 1e9)}`;
|
|
244
|
+
let index = pointMap.get(key);
|
|
245
|
+
if (index !== undefined) {
|
|
246
|
+
if (edgeIndex !== undefined) {
|
|
247
|
+
edgePointIndexSets[edgeIndex].add(index);
|
|
248
|
+
}
|
|
249
|
+
return index; // Point already exists
|
|
250
|
+
}
|
|
251
|
+
// Point is new, add it
|
|
252
|
+
const v3 = vec3 || createUnitVectorFromLongLat(longLat);
|
|
253
|
+
allVec3s.push(v3[0], v3[1], v3[2]);
|
|
254
|
+
allLongLats.push(longLat[0], longLat[1]);
|
|
255
|
+
index = pointCounter++;
|
|
256
|
+
pointMap.set(key, index);
|
|
257
|
+
if (edgeIndex !== undefined) {
|
|
258
|
+
edgePointIndexSets[edgeIndex].add(index);
|
|
259
|
+
}
|
|
260
|
+
return index;
|
|
261
|
+
};
|
|
262
|
+
// 1. Add triangle's "shell" (for Delaunay) and "edge" (vertices/limits) points
|
|
263
|
+
// These points constrain the triangulation.
|
|
264
|
+
const edgePoints = getEdgePoints(triangleMeta, edgePointIndexSets);
|
|
265
|
+
// Assuming shellPoints and edgePoints have the same length and correspond
|
|
266
|
+
for (let i = 0; i < edgePoints.length; i++) {
|
|
267
|
+
addPoint(vec3ToLongLatRadians(edgePoints[i]), edgePoints[i], undefined);
|
|
268
|
+
}
|
|
269
|
+
// 2. Iterate through each tile limit
|
|
270
|
+
for (let i = 0; i < limits.length; i++) {
|
|
271
|
+
const tileBBox = limits[i].bbox;
|
|
272
|
+
const zoom = limits[i].zoom;
|
|
273
|
+
// 2a. Calculate the intersection BBOX (the area we'll work on)
|
|
274
|
+
const workBBox = {
|
|
275
|
+
min: [
|
|
276
|
+
Math.max(triangleMeta.bbox.min[0], tileBBox.min[0]),
|
|
277
|
+
Math.max(triangleMeta.bbox.min[1], tileBBox.min[1])
|
|
278
|
+
],
|
|
279
|
+
max: [
|
|
280
|
+
Math.min(triangleMeta.bbox.max[0], tileBBox.max[0]),
|
|
281
|
+
Math.min(triangleMeta.bbox.max[1], tileBBox.max[1])
|
|
282
|
+
],
|
|
283
|
+
};
|
|
284
|
+
// If the intersection is invalid (no overlap), skip this tile
|
|
285
|
+
if (workBBox.min[0] >= workBBox.max[0] || workBBox.min[1] >= workBBox.max[1]) {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
// 2b. Calculate grid steps for this tile's zoom
|
|
289
|
+
const tileCount = TILE_COUNTS[zoom];
|
|
290
|
+
const lonStep = (2 * Math.PI) / tileCount / stepCount;
|
|
291
|
+
const latStep = 1.0 / stepCount; // This is in tileY units
|
|
292
|
+
// 2c. Generate Latitude (Parallel) Points
|
|
293
|
+
const startTileY = latToTileY(workBBox.max[1], zoom); // max lat -> min tileY
|
|
294
|
+
const endTileY = latToTileY(workBBox.min[1], zoom); // min lat -> max tileY
|
|
295
|
+
// let currentY = Math.ceil(startTileY / latStep) * latStep;
|
|
296
|
+
let currentY = startTileY - Math.abs(startTileY % latStep);
|
|
297
|
+
// if (currentY < startTileY - 1e-9) currentY += latStep; // Ensure we start inside or on edge
|
|
298
|
+
if (currentY === startTileY)
|
|
299
|
+
currentY -= latStep; // since start point is already added
|
|
300
|
+
while (currentY <= endTileY + 1e-9) {
|
|
301
|
+
const lat = tileYtoLat(currentY, zoom);
|
|
302
|
+
// Skip if rounding put us slightly outside the work box
|
|
303
|
+
if (lat < workBBox.min[1] - 1e-9 || lat > workBBox.max[1] + 1e-9) {
|
|
304
|
+
currentY += latStep;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
// Find where this latitude line intersects the triangle
|
|
308
|
+
const intersections = getPoints(triangleMeta, lat, true);
|
|
309
|
+
if (intersections.length === 0) {
|
|
310
|
+
currentY += latStep;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
for (let i = 0; i < intersections.length; i += 2) {
|
|
314
|
+
const p0 = intersections[i]; // {vec, longLat, arcIndex}
|
|
315
|
+
const p1 = intersections[i + 1];
|
|
316
|
+
// Find the segment of this latitude line that is *inside* both
|
|
317
|
+
// the triangle (p0-p1) AND the tile BBOX (workBBox)
|
|
318
|
+
const triMinLon = Math.min(p0.longLat[0], p1.longLat[0]);
|
|
319
|
+
const triMaxLon = Math.max(p0.longLat[0], p1.longLat[0]);
|
|
320
|
+
const segMinLon = Math.max(workBBox.min[0], triMinLon);
|
|
321
|
+
const segMaxLon = Math.min(workBBox.max[0], triMaxLon);
|
|
322
|
+
// If this clipped segment is valid, generate points
|
|
323
|
+
if (segMinLon < segMaxLon - 1e-9) {
|
|
324
|
+
// Add the exact start and end points of the clipped segment
|
|
325
|
+
addPoint(p0.longLat, p0.vec, p0.arcIndex);
|
|
326
|
+
addPoint(p1.longLat, p1.vec, p1.arcIndex);
|
|
327
|
+
// Add fill points *between* them
|
|
328
|
+
let currentLon = Math.ceil(segMinLon / lonStep) * lonStep;
|
|
329
|
+
if (currentLon < segMinLon - 1e-9)
|
|
330
|
+
currentLon += lonStep;
|
|
331
|
+
while (currentLon < segMaxLon - 1e-9) {
|
|
332
|
+
addPoint([currentLon, lat], undefined, undefined);
|
|
333
|
+
currentLon += lonStep;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
currentY += latStep;
|
|
338
|
+
}
|
|
339
|
+
// 2d. Generate Longitude (Meridian) Points
|
|
340
|
+
const startLon = workBBox.min[0];
|
|
341
|
+
const endLon = workBBox.max[0];
|
|
342
|
+
let currentLon = Math.ceil(startLon / lonStep) * lonStep;
|
|
343
|
+
if (currentLon < startLon - 1e-9)
|
|
344
|
+
currentLon += lonStep;
|
|
345
|
+
while (currentLon <= endLon + 1e-9) {
|
|
346
|
+
// Find where this longitude line intersects the triangle
|
|
347
|
+
const intersections = getPoints(triangleMeta, currentLon, false);
|
|
348
|
+
if (intersections.length === 0) {
|
|
349
|
+
currentLon += lonStep;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
for (const p of intersections) {
|
|
353
|
+
const pLongLat = p.longLat;
|
|
354
|
+
// Check if this point is inside the *workBBox*
|
|
355
|
+
if (pLongLat[1] >= workBBox.min[1] - 1e-9 &&
|
|
356
|
+
pLongLat[1] <= workBBox.max[1] + 1e-9) {
|
|
357
|
+
addPoint(pLongLat, p.vec, p.arcIndex);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
currentLon += lonStep;
|
|
361
|
+
}
|
|
362
|
+
} // End loop over limits
|
|
363
|
+
// 3. Triangulate
|
|
364
|
+
// We must have at least 3 points to make a triangle
|
|
365
|
+
if (pointCounter < 3) {
|
|
366
|
+
return {
|
|
367
|
+
vec3s: new Float32Array(),
|
|
368
|
+
longLats: new Float32Array(),
|
|
369
|
+
indices: new Uint32Array(),
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
const delaunator = new Delaunator(allLongLats);
|
|
373
|
+
let indices = delaunator.triangles;
|
|
374
|
+
indices = filterEdgePointTriangles(indices, edgePointIndexSets);
|
|
375
|
+
// Convert to Mercator
|
|
376
|
+
for (let i = 0; i < allLongLats.length / 2; i++) {
|
|
377
|
+
const xy = radianToMercatorXY([allLongLats[i * 2], allLongLats[i * 2 + 1]]);
|
|
378
|
+
allLongLats[i * 2] = xy[0];
|
|
379
|
+
allLongLats[i * 2 + 1] = xy[1];
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
vec3s: new Float32Array(allVec3s),
|
|
383
|
+
longLats: new Float32Array(allLongLats),
|
|
384
|
+
indices: indices,
|
|
385
|
+
};
|
|
14
386
|
}
|
package/Math/vec3.js
CHANGED
|
@@ -148,4 +148,8 @@ function vec3ToLongLatRadians(v) {
|
|
|
148
148
|
Math.asin(v[2])
|
|
149
149
|
];
|
|
150
150
|
}
|
|
151
|
+
export function vec3ToLongLatRadiansOut(out, v) {
|
|
152
|
+
out[0] = Math.atan2(v[1], v[0]);
|
|
153
|
+
out[1] = Math.asin(v[2]);
|
|
154
|
+
}
|
|
151
155
|
export { create, set, clone, copy, add, subtract, negate, dot, cross, multiplyScalar, divideScalar, lengthSquared, length, normalize, distanceSquared, distance, equals, fromUnitVectorToLongLat, fromLongLatToUnitVector, applyQuaternion, randomUnit, str, createUnitVectorFromLongLat, vec3ToLongLatDegrees, vec3ToLongLatRadians };
|
package/Math/xyz-tile.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RADIAN } from "./methods";
|
|
2
|
+
export function xyzToBBOX(x, y, z) {
|
|
3
|
+
const n = Math.pow(2, z);
|
|
4
|
+
const lonMin = x / n * 360 - 180;
|
|
5
|
+
const lonMax = (x + 1) / n * 360 - 180;
|
|
6
|
+
const latMinRad = Math.atan(Math.sinh(Math.PI * (1 - 2 * (y + 1) / n)));
|
|
7
|
+
const latMaxRad = Math.atan(Math.sinh(Math.PI * (1 - 2 * y / n)));
|
|
8
|
+
return {
|
|
9
|
+
ll: {
|
|
10
|
+
x: lonMin,
|
|
11
|
+
y: latMinRad / RADIAN
|
|
12
|
+
},
|
|
13
|
+
ur: {
|
|
14
|
+
x: lonMax,
|
|
15
|
+
y: latMaxRad / RADIAN
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -4,8 +4,7 @@ import { ElementPointGlowProgramCache } from '../programs/point-on-globe/element
|
|
|
4
4
|
import { ElementGlobeSufaceGlowCache } from '../programs/point-on-globe/element-globe-surface-glow.js';
|
|
5
5
|
import { LineOnGlobeCache } from '../programs/line-on-globe/naive-accurate-flexible';
|
|
6
6
|
import { BufferOrchestrator, BufferManager } from "../util/account";
|
|
7
|
-
|
|
8
|
-
import { PickerDisplayer } from '../util/picking/picker-displayer.js';
|
|
7
|
+
import { PickerDisplayer } from '../util/picking/picker-displayer';
|
|
9
8
|
import { wgs84ToCartesian3d, wgs84ToMercator } from '../Math/methods';
|
|
10
9
|
import { constraintFloat, opacityCheck } from '../util/check/typecheck';
|
|
11
10
|
import { createBufferAndReadInfo } from '../util/gl-util/buffer/attribute-loader';
|
|
@@ -21,7 +21,7 @@ export function tileToArcInputs(tiles, color) {
|
|
|
21
21
|
// msl?: boolean | null;
|
|
22
22
|
// }
|
|
23
23
|
for (const tile of tiles) {
|
|
24
|
-
const tileKey = `tile_${tile.
|
|
24
|
+
const tileKey = `tile_${tile.x}_${tile.y}`;
|
|
25
25
|
const bbox = tile.bbox;
|
|
26
26
|
// left side
|
|
27
27
|
result.push(boilerArcInput([bbox.ll.x, bbox.ll.y], [bbox.ll.x, bbox.ur.y], color, `${tileKey}_left`));
|
|
@@ -50,7 +50,7 @@ export function mergedTileToArcInputs(mergedTile, color) {
|
|
|
50
50
|
export function tilesToContextWriter4Inputs(tiles) {
|
|
51
51
|
const result = [];
|
|
52
52
|
for (const tile of tiles) {
|
|
53
|
-
const tileKey = `L_${tile.level}_R${tile.
|
|
53
|
+
const tileKey = `L_${tile.level}_R${tile.x}_C${tile.y}`;
|
|
54
54
|
const centerLong = (tile.bbox.ll.x + tile.bbox.ur.x) / 2;
|
|
55
55
|
const centerLat = (tile.bbox.ll.y + tile.bbox.ur.y) / 2;
|
|
56
56
|
result.push({
|
|
@@ -59,7 +59,7 @@ export class TilesRendererPlugin {
|
|
|
59
59
|
// this.globe.api_GetDrawedTilesInfo(),
|
|
60
60
|
// this.globe
|
|
61
61
|
// );
|
|
62
|
-
const drawnTiles = this.globe.
|
|
62
|
+
const drawnTiles = this.globe.api_GetVisibleTilesInfo();
|
|
63
63
|
let maxLevel = 0;
|
|
64
64
|
let minLevel = Number.MAX_VALUE;
|
|
65
65
|
const tileMap = new Map();
|
|
@@ -98,7 +98,7 @@ export class TilesRendererPlugin {
|
|
|
98
98
|
this.arcPlugin.insertBulk(arcInputs);
|
|
99
99
|
}
|
|
100
100
|
// drawMergedBBoxes:
|
|
101
|
-
const mergedTiles = mergeMeshes(drawnTiles, 12, 5, 4);
|
|
101
|
+
const mergedTiles = mergeMeshes(drawnTiles, 12, 5, 4, this.globe);
|
|
102
102
|
const color = [255, 255, 0, 255]; // Yellow
|
|
103
103
|
const arcMergedInputs = mergedTiles.map(mergedTile => mergedTileToArcInputs(mergedTile, color)).flat();
|
|
104
104
|
this.arcPlugin.insertBulk(arcMergedInputs);
|
package/package.json
CHANGED
|
@@ -25,7 +25,12 @@ void main() {
|
|
|
25
25
|
outColor = vec4(color.rgb, color.a * opacity);
|
|
26
26
|
}
|
|
27
27
|
`;
|
|
28
|
-
class FadeAwayProgram {
|
|
28
|
+
export class FadeAwayProgram {
|
|
29
|
+
gl;
|
|
30
|
+
program;
|
|
31
|
+
vao;
|
|
32
|
+
uniforms;
|
|
33
|
+
_buffer;
|
|
29
34
|
constructor(gl) {
|
|
30
35
|
this.gl = gl;
|
|
31
36
|
this.program = createProgram(gl, vertexShaderSource, fragmentShaderSource);
|
|
@@ -116,6 +116,7 @@ class PointOnGlobeProgram {
|
|
|
116
116
|
gl.bindBuffer(gl.ARRAY_BUFFER, rgbaBuffer);
|
|
117
117
|
gl.enableVertexAttribArray(2);
|
|
118
118
|
gl.vertexAttribPointer(2, 4, gl.FLOAT, false, 0, 0);
|
|
119
|
+
// gl.vertexAttribPointer(2, 4, gl.UNSIGNED_INT, true, 0, 0);
|
|
119
120
|
}
|
|
120
121
|
gl.bindVertexArray(null);
|
|
121
122
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|