@loaders.gl/raster 5.0.0-beta.2 → 5.0.0-beta.5
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/README.md +1 -1
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/geotiff/advanced.cjs +4 -4
- package/dist/geotiff/geotiff-loader-types.js +1 -1
- package/dist/geotiff/geotiff-raster-loader-types.js +1 -1
- package/dist/geotiff/geotiff-source-loader.js +1 -1
- package/dist/geotiff/loaders.js +1 -1
- package/dist/geotiff/ometiff-source-loader.js +1 -1
- package/dist/index.cjs +4 -4
- package/dist/lerc/lerc-loader-types.js +1 -1
- package/dist/quantized-mesh-worker.js +985 -368
- package/dist/terrain/index.cjs +26 -525
- package/dist/terrain/index.cjs.map +4 -4
- package/dist/terrain/lib/parse-terrain.d.ts +2 -0
- package/dist/terrain/lib/parse-terrain.d.ts.map +1 -1
- package/dist/terrain/lib/parse-terrain.js +23 -38
- package/dist/terrain/lib/parse-terrain.js.map +1 -1
- package/dist/terrain/lib/utils/version.js +1 -1
- package/dist/terrain/quantized-mesh-loader.js +1 -1
- package/dist/terrain/quantized-mesh-loader.js.map +1 -1
- package/dist/terrain/terrain-loader.js +1 -1
- package/dist/terrain/terrain-loader.js.map +1 -1
- package/dist/terrain-worker.js +16699 -15463
- package/package.json +6 -7
- package/src/terrain/lib/parse-terrain.ts +36 -40
- package/src/terrain/quantized-mesh-loader.ts +1 -1
- package/src/terrain/terrain-loader.ts +1 -1
- package/dist/terrain/libs/README.md +0 -10
- package/dist/terrain/libs/martini-LICENSE +0 -15
- package/dist/terrain/libs/martini.d.mts +0 -19
- package/dist/terrain/libs/martini.mjs +0 -164
- package/src/terrain/libs/README.md +0 -10
- package/src/terrain/libs/martini-LICENSE +0 -15
- package/src/terrain/libs/martini.d.mts +0 -19
- package/src/terrain/libs/martini.mjs +0 -164
package/dist/terrain/index.cjs
CHANGED
|
@@ -64,7 +64,7 @@ var QuantizedMeshFormat = {
|
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
// dist/terrain/lib/utils/version.js
|
|
67
|
-
var VERSION = true ? "5.0.0-beta.
|
|
67
|
+
var VERSION = true ? "5.0.0-beta.5" : "latest";
|
|
68
68
|
|
|
69
69
|
// dist/terrain/terrain-loader-types.js
|
|
70
70
|
var TerrainLoader = {
|
|
@@ -93,513 +93,14 @@ var TerrainLoader = {
|
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
// dist/terrain/terrain-loader.js
|
|
96
|
-
var
|
|
96
|
+
var import_arrow_worker_transport = require("@loaders.gl/core/arrow-worker-transport");
|
|
97
97
|
var import_loader_utils2 = require("@loaders.gl/core/loader-utils");
|
|
98
98
|
var import_schema_utils2 = require("@loaders.gl/core/schema-utils");
|
|
99
99
|
var import_images = require("@loaders.gl/images");
|
|
100
100
|
|
|
101
101
|
// dist/terrain/lib/parse-terrain.js
|
|
102
102
|
var import_schema_utils = require("@loaders.gl/core/schema-utils");
|
|
103
|
-
|
|
104
|
-
// dist/terrain/libs/martini.mjs
|
|
105
|
-
var Martini = class {
|
|
106
|
-
constructor(gridSize = 257) {
|
|
107
|
-
this.gridSize = gridSize;
|
|
108
|
-
const tileSize = gridSize - 1;
|
|
109
|
-
if (tileSize & tileSize - 1) throw new Error(
|
|
110
|
-
`Expected grid size to be 2^n+1, got ${gridSize}.`
|
|
111
|
-
);
|
|
112
|
-
this.numTriangles = tileSize * tileSize * 2 - 2;
|
|
113
|
-
this.numParentTriangles = this.numTriangles - tileSize * tileSize;
|
|
114
|
-
this.indices = new Uint32Array(this.gridSize * this.gridSize);
|
|
115
|
-
this.coords = new Uint16Array(this.numTriangles * 4);
|
|
116
|
-
for (let i = 0; i < this.numTriangles; i++) {
|
|
117
|
-
let id = i + 2;
|
|
118
|
-
let ax = 0, ay = 0, bx = 0, by = 0, cx = 0, cy = 0;
|
|
119
|
-
if (id & 1) {
|
|
120
|
-
bx = by = cx = tileSize;
|
|
121
|
-
} else {
|
|
122
|
-
ax = ay = cy = tileSize;
|
|
123
|
-
}
|
|
124
|
-
while ((id >>= 1) > 1) {
|
|
125
|
-
const mx = ax + bx >> 1;
|
|
126
|
-
const my = ay + by >> 1;
|
|
127
|
-
if (id & 1) {
|
|
128
|
-
bx = ax;
|
|
129
|
-
by = ay;
|
|
130
|
-
ax = cx;
|
|
131
|
-
ay = cy;
|
|
132
|
-
} else {
|
|
133
|
-
ax = bx;
|
|
134
|
-
ay = by;
|
|
135
|
-
bx = cx;
|
|
136
|
-
by = cy;
|
|
137
|
-
}
|
|
138
|
-
cx = mx;
|
|
139
|
-
cy = my;
|
|
140
|
-
}
|
|
141
|
-
const k = i * 4;
|
|
142
|
-
this.coords[k + 0] = ax;
|
|
143
|
-
this.coords[k + 1] = ay;
|
|
144
|
-
this.coords[k + 2] = bx;
|
|
145
|
-
this.coords[k + 3] = by;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
createTile(terrain) {
|
|
149
|
-
return new Tile(terrain, this);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
var Tile = class {
|
|
153
|
-
constructor(terrain, martini) {
|
|
154
|
-
const size = martini.gridSize;
|
|
155
|
-
if (terrain.length !== size * size) throw new Error(
|
|
156
|
-
`Expected terrain data of length ${size * size} (${size} x ${size}), got ${terrain.length}.`
|
|
157
|
-
);
|
|
158
|
-
this.terrain = terrain;
|
|
159
|
-
this.martini = martini;
|
|
160
|
-
this.errors = new Float32Array(terrain.length);
|
|
161
|
-
this.update();
|
|
162
|
-
}
|
|
163
|
-
update() {
|
|
164
|
-
const { numTriangles, numParentTriangles, coords, gridSize: size } = this.martini;
|
|
165
|
-
const { terrain, errors } = this;
|
|
166
|
-
for (let i = numTriangles - 1; i >= 0; i--) {
|
|
167
|
-
const k = i * 4;
|
|
168
|
-
const ax = coords[k + 0];
|
|
169
|
-
const ay = coords[k + 1];
|
|
170
|
-
const bx = coords[k + 2];
|
|
171
|
-
const by = coords[k + 3];
|
|
172
|
-
const mx = ax + bx >> 1;
|
|
173
|
-
const my = ay + by >> 1;
|
|
174
|
-
const cx = mx + my - ay;
|
|
175
|
-
const cy = my + ax - mx;
|
|
176
|
-
const interpolatedHeight = (terrain[ay * size + ax] + terrain[by * size + bx]) / 2;
|
|
177
|
-
const middleIndex = my * size + mx;
|
|
178
|
-
const middleError = Math.abs(interpolatedHeight - terrain[middleIndex]);
|
|
179
|
-
errors[middleIndex] = Math.max(errors[middleIndex], middleError);
|
|
180
|
-
if (i < numParentTriangles) {
|
|
181
|
-
const leftChildIndex = (ay + cy >> 1) * size + (ax + cx >> 1);
|
|
182
|
-
const rightChildIndex = (by + cy >> 1) * size + (bx + cx >> 1);
|
|
183
|
-
errors[middleIndex] = Math.max(errors[middleIndex], errors[leftChildIndex], errors[rightChildIndex]);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
getMesh(maxError = 0) {
|
|
188
|
-
const { gridSize: size, indices } = this.martini;
|
|
189
|
-
const { errors } = this;
|
|
190
|
-
let numVertices = 0;
|
|
191
|
-
let numTriangles = 0;
|
|
192
|
-
const max = size - 1;
|
|
193
|
-
indices.fill(0);
|
|
194
|
-
function countElements(ax, ay, bx, by, cx, cy) {
|
|
195
|
-
const mx = ax + bx >> 1;
|
|
196
|
-
const my = ay + by >> 1;
|
|
197
|
-
if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {
|
|
198
|
-
countElements(cx, cy, ax, ay, mx, my);
|
|
199
|
-
countElements(bx, by, cx, cy, mx, my);
|
|
200
|
-
} else {
|
|
201
|
-
indices[ay * size + ax] = indices[ay * size + ax] || ++numVertices;
|
|
202
|
-
indices[by * size + bx] = indices[by * size + bx] || ++numVertices;
|
|
203
|
-
indices[cy * size + cx] = indices[cy * size + cx] || ++numVertices;
|
|
204
|
-
numTriangles++;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
countElements(0, 0, max, max, max, 0);
|
|
208
|
-
countElements(max, max, 0, 0, 0, max);
|
|
209
|
-
const vertices = new Uint16Array(numVertices * 2);
|
|
210
|
-
const triangles = new Uint32Array(numTriangles * 3);
|
|
211
|
-
let triIndex = 0;
|
|
212
|
-
function processTriangle(ax, ay, bx, by, cx, cy) {
|
|
213
|
-
const mx = ax + bx >> 1;
|
|
214
|
-
const my = ay + by >> 1;
|
|
215
|
-
if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {
|
|
216
|
-
processTriangle(cx, cy, ax, ay, mx, my);
|
|
217
|
-
processTriangle(bx, by, cx, cy, mx, my);
|
|
218
|
-
} else {
|
|
219
|
-
const a = indices[ay * size + ax] - 1;
|
|
220
|
-
const b = indices[by * size + bx] - 1;
|
|
221
|
-
const c = indices[cy * size + cx] - 1;
|
|
222
|
-
vertices[2 * a] = ax;
|
|
223
|
-
vertices[2 * a + 1] = ay;
|
|
224
|
-
vertices[2 * b] = bx;
|
|
225
|
-
vertices[2 * b + 1] = by;
|
|
226
|
-
vertices[2 * c] = cx;
|
|
227
|
-
vertices[2 * c + 1] = cy;
|
|
228
|
-
triangles[triIndex++] = a;
|
|
229
|
-
triangles[triIndex++] = b;
|
|
230
|
-
triangles[triIndex++] = c;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
processTriangle(0, 0, max, max, max, 0);
|
|
234
|
-
processTriangle(max, max, 0, 0, 0, max);
|
|
235
|
-
return { vertices, triangles };
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
// dist/terrain/lib/delatin/index.js
|
|
240
|
-
var Delatin = class {
|
|
241
|
-
constructor(data, width, height = width) {
|
|
242
|
-
this.data = data;
|
|
243
|
-
this.width = width;
|
|
244
|
-
this.height = height;
|
|
245
|
-
this.coords = [];
|
|
246
|
-
this.triangles = [];
|
|
247
|
-
this._halfedges = [];
|
|
248
|
-
this._candidates = [];
|
|
249
|
-
this._queueIndices = [];
|
|
250
|
-
this._queue = [];
|
|
251
|
-
this._errors = [];
|
|
252
|
-
this._rms = [];
|
|
253
|
-
this._pending = [];
|
|
254
|
-
this._pendingLen = 0;
|
|
255
|
-
this._rmsSum = 0;
|
|
256
|
-
const x1 = width - 1;
|
|
257
|
-
const y1 = height - 1;
|
|
258
|
-
const p0 = this._addPoint(0, 0);
|
|
259
|
-
const p1 = this._addPoint(x1, 0);
|
|
260
|
-
const p2 = this._addPoint(0, y1);
|
|
261
|
-
const p3 = this._addPoint(x1, y1);
|
|
262
|
-
const t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);
|
|
263
|
-
this._addTriangle(p0, p3, p1, t0, -1, -1);
|
|
264
|
-
this._flush();
|
|
265
|
-
}
|
|
266
|
-
// refine the mesh until its maximum error gets below the given one
|
|
267
|
-
run(maxError = 1) {
|
|
268
|
-
while (this.getMaxError() > maxError) {
|
|
269
|
-
this.refine();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
// refine the mesh with a single point
|
|
273
|
-
refine() {
|
|
274
|
-
this._step();
|
|
275
|
-
this._flush();
|
|
276
|
-
}
|
|
277
|
-
// max error of the current mesh
|
|
278
|
-
getMaxError() {
|
|
279
|
-
return this._errors[0];
|
|
280
|
-
}
|
|
281
|
-
// root-mean-square deviation of the current mesh
|
|
282
|
-
getRMSD() {
|
|
283
|
-
return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;
|
|
284
|
-
}
|
|
285
|
-
// height value at a given position
|
|
286
|
-
heightAt(x, y) {
|
|
287
|
-
return this.data[this.width * y + x];
|
|
288
|
-
}
|
|
289
|
-
// rasterize and queue all triangles that got added or updated in _step
|
|
290
|
-
_flush() {
|
|
291
|
-
const coords = this.coords;
|
|
292
|
-
for (let i = 0; i < this._pendingLen; i++) {
|
|
293
|
-
const t = this._pending[i];
|
|
294
|
-
const a = 2 * this.triangles[t * 3 + 0];
|
|
295
|
-
const b = 2 * this.triangles[t * 3 + 1];
|
|
296
|
-
const c = 2 * this.triangles[t * 3 + 2];
|
|
297
|
-
this._findCandidate(coords[a], coords[a + 1], coords[b], coords[b + 1], coords[c], coords[c + 1], t);
|
|
298
|
-
}
|
|
299
|
-
this._pendingLen = 0;
|
|
300
|
-
}
|
|
301
|
-
// rasterize a triangle, find its max error, and queue it for processing
|
|
302
|
-
_findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {
|
|
303
|
-
const minX = Math.min(p0x, p1x, p2x);
|
|
304
|
-
const minY = Math.min(p0y, p1y, p2y);
|
|
305
|
-
const maxX = Math.max(p0x, p1x, p2x);
|
|
306
|
-
const maxY = Math.max(p0y, p1y, p2y);
|
|
307
|
-
let w00 = orient(p1x, p1y, p2x, p2y, minX, minY);
|
|
308
|
-
let w01 = orient(p2x, p2y, p0x, p0y, minX, minY);
|
|
309
|
-
let w02 = orient(p0x, p0y, p1x, p1y, minX, minY);
|
|
310
|
-
const a01 = p1y - p0y;
|
|
311
|
-
const b01 = p0x - p1x;
|
|
312
|
-
const a12 = p2y - p1y;
|
|
313
|
-
const b12 = p1x - p2x;
|
|
314
|
-
const a20 = p0y - p2y;
|
|
315
|
-
const b20 = p2x - p0x;
|
|
316
|
-
const a = orient(p0x, p0y, p1x, p1y, p2x, p2y);
|
|
317
|
-
const z0 = this.heightAt(p0x, p0y) / a;
|
|
318
|
-
const z1 = this.heightAt(p1x, p1y) / a;
|
|
319
|
-
const z2 = this.heightAt(p2x, p2y) / a;
|
|
320
|
-
let maxError = 0;
|
|
321
|
-
let mx = 0;
|
|
322
|
-
let my = 0;
|
|
323
|
-
let rms = 0;
|
|
324
|
-
for (let y = minY; y <= maxY; y++) {
|
|
325
|
-
let dx = 0;
|
|
326
|
-
if (w00 < 0 && a12 !== 0) {
|
|
327
|
-
dx = Math.max(dx, Math.floor(-w00 / a12));
|
|
328
|
-
}
|
|
329
|
-
if (w01 < 0 && a20 !== 0) {
|
|
330
|
-
dx = Math.max(dx, Math.floor(-w01 / a20));
|
|
331
|
-
}
|
|
332
|
-
if (w02 < 0 && a01 !== 0) {
|
|
333
|
-
dx = Math.max(dx, Math.floor(-w02 / a01));
|
|
334
|
-
}
|
|
335
|
-
let w0 = w00 + a12 * dx;
|
|
336
|
-
let w1 = w01 + a20 * dx;
|
|
337
|
-
let w2 = w02 + a01 * dx;
|
|
338
|
-
let wasInside = false;
|
|
339
|
-
for (let x = minX + dx; x <= maxX; x++) {
|
|
340
|
-
if (w0 >= 0 && w1 >= 0 && w2 >= 0) {
|
|
341
|
-
wasInside = true;
|
|
342
|
-
const z = z0 * w0 + z1 * w1 + z2 * w2;
|
|
343
|
-
const dz = Math.abs(z - this.heightAt(x, y));
|
|
344
|
-
rms += dz * dz;
|
|
345
|
-
if (dz > maxError) {
|
|
346
|
-
maxError = dz;
|
|
347
|
-
mx = x;
|
|
348
|
-
my = y;
|
|
349
|
-
}
|
|
350
|
-
} else if (wasInside) {
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
w0 += a12;
|
|
354
|
-
w1 += a20;
|
|
355
|
-
w2 += a01;
|
|
356
|
-
}
|
|
357
|
-
w00 += b12;
|
|
358
|
-
w01 += b20;
|
|
359
|
-
w02 += b01;
|
|
360
|
-
}
|
|
361
|
-
if (mx === p0x && my === p0y || mx === p1x && my === p1y || mx === p2x && my === p2y) {
|
|
362
|
-
maxError = 0;
|
|
363
|
-
}
|
|
364
|
-
this._candidates[2 * t] = mx;
|
|
365
|
-
this._candidates[2 * t + 1] = my;
|
|
366
|
-
this._rms[t] = rms;
|
|
367
|
-
this._queuePush(t, maxError, rms);
|
|
368
|
-
}
|
|
369
|
-
// process the next triangle in the queue, splitting it with a new point
|
|
370
|
-
_step() {
|
|
371
|
-
const t = this._queuePop();
|
|
372
|
-
const e0 = t * 3 + 0;
|
|
373
|
-
const e1 = t * 3 + 1;
|
|
374
|
-
const e2 = t * 3 + 2;
|
|
375
|
-
const p0 = this.triangles[e0];
|
|
376
|
-
const p1 = this.triangles[e1];
|
|
377
|
-
const p2 = this.triangles[e2];
|
|
378
|
-
const ax = this.coords[2 * p0];
|
|
379
|
-
const ay = this.coords[2 * p0 + 1];
|
|
380
|
-
const bx = this.coords[2 * p1];
|
|
381
|
-
const by = this.coords[2 * p1 + 1];
|
|
382
|
-
const cx = this.coords[2 * p2];
|
|
383
|
-
const cy = this.coords[2 * p2 + 1];
|
|
384
|
-
const px = this._candidates[2 * t];
|
|
385
|
-
const py = this._candidates[2 * t + 1];
|
|
386
|
-
const pn = this._addPoint(px, py);
|
|
387
|
-
if (orient(ax, ay, bx, by, px, py) === 0) {
|
|
388
|
-
this._handleCollinear(pn, e0);
|
|
389
|
-
} else if (orient(bx, by, cx, cy, px, py) === 0) {
|
|
390
|
-
this._handleCollinear(pn, e1);
|
|
391
|
-
} else if (orient(cx, cy, ax, ay, px, py) === 0) {
|
|
392
|
-
this._handleCollinear(pn, e2);
|
|
393
|
-
} else {
|
|
394
|
-
const h0 = this._halfedges[e0];
|
|
395
|
-
const h1 = this._halfedges[e1];
|
|
396
|
-
const h2 = this._halfedges[e2];
|
|
397
|
-
const t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);
|
|
398
|
-
const t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);
|
|
399
|
-
const t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);
|
|
400
|
-
this._legalize(t0);
|
|
401
|
-
this._legalize(t1);
|
|
402
|
-
this._legalize(t2);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
// add coordinates for a new vertex
|
|
406
|
-
_addPoint(x, y) {
|
|
407
|
-
const i = this.coords.length >> 1;
|
|
408
|
-
this.coords.push(x, y);
|
|
409
|
-
return i;
|
|
410
|
-
}
|
|
411
|
-
// add or update a triangle in the mesh
|
|
412
|
-
_addTriangle(a, b, c, ab, bc, ca, e = this.triangles.length) {
|
|
413
|
-
const t = e / 3;
|
|
414
|
-
this.triangles[e + 0] = a;
|
|
415
|
-
this.triangles[e + 1] = b;
|
|
416
|
-
this.triangles[e + 2] = c;
|
|
417
|
-
this._halfedges[e + 0] = ab;
|
|
418
|
-
this._halfedges[e + 1] = bc;
|
|
419
|
-
this._halfedges[e + 2] = ca;
|
|
420
|
-
if (ab >= 0) {
|
|
421
|
-
this._halfedges[ab] = e + 0;
|
|
422
|
-
}
|
|
423
|
-
if (bc >= 0) {
|
|
424
|
-
this._halfedges[bc] = e + 1;
|
|
425
|
-
}
|
|
426
|
-
if (ca >= 0) {
|
|
427
|
-
this._halfedges[ca] = e + 2;
|
|
428
|
-
}
|
|
429
|
-
this._candidates[2 * t + 0] = 0;
|
|
430
|
-
this._candidates[2 * t + 1] = 0;
|
|
431
|
-
this._queueIndices[t] = -1;
|
|
432
|
-
this._rms[t] = 0;
|
|
433
|
-
this._pending[this._pendingLen++] = t;
|
|
434
|
-
return e;
|
|
435
|
-
}
|
|
436
|
-
_legalize(a) {
|
|
437
|
-
const b = this._halfedges[a];
|
|
438
|
-
if (b < 0) {
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
const a0 = a - a % 3;
|
|
442
|
-
const b0 = b - b % 3;
|
|
443
|
-
const al = a0 + (a + 1) % 3;
|
|
444
|
-
const ar = a0 + (a + 2) % 3;
|
|
445
|
-
const bl = b0 + (b + 2) % 3;
|
|
446
|
-
const br = b0 + (b + 1) % 3;
|
|
447
|
-
const p0 = this.triangles[ar];
|
|
448
|
-
const pr = this.triangles[a];
|
|
449
|
-
const pl = this.triangles[al];
|
|
450
|
-
const p1 = this.triangles[bl];
|
|
451
|
-
const coords = this.coords;
|
|
452
|
-
if (!inCircle(coords[2 * p0], coords[2 * p0 + 1], coords[2 * pr], coords[2 * pr + 1], coords[2 * pl], coords[2 * pl + 1], coords[2 * p1], coords[2 * p1 + 1])) {
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
const hal = this._halfedges[al];
|
|
456
|
-
const har = this._halfedges[ar];
|
|
457
|
-
const hbl = this._halfedges[bl];
|
|
458
|
-
const hbr = this._halfedges[br];
|
|
459
|
-
this._queueRemove(a0 / 3);
|
|
460
|
-
this._queueRemove(b0 / 3);
|
|
461
|
-
const t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);
|
|
462
|
-
const t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);
|
|
463
|
-
this._legalize(t0 + 1);
|
|
464
|
-
this._legalize(t1 + 2);
|
|
465
|
-
}
|
|
466
|
-
// handle a case where new vertex is on the edge of a triangle
|
|
467
|
-
_handleCollinear(pn, a) {
|
|
468
|
-
const a0 = a - a % 3;
|
|
469
|
-
const al = a0 + (a + 1) % 3;
|
|
470
|
-
const ar = a0 + (a + 2) % 3;
|
|
471
|
-
const p0 = this.triangles[ar];
|
|
472
|
-
const pr = this.triangles[a];
|
|
473
|
-
const pl = this.triangles[al];
|
|
474
|
-
const hal = this._halfedges[al];
|
|
475
|
-
const har = this._halfedges[ar];
|
|
476
|
-
const b = this._halfedges[a];
|
|
477
|
-
if (b < 0) {
|
|
478
|
-
const t02 = this._addTriangle(pn, p0, pr, -1, har, -1, a0);
|
|
479
|
-
const t12 = this._addTriangle(p0, pn, pl, t02, -1, hal);
|
|
480
|
-
this._legalize(t02 + 1);
|
|
481
|
-
this._legalize(t12 + 2);
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
const b0 = b - b % 3;
|
|
485
|
-
const bl = b0 + (b + 2) % 3;
|
|
486
|
-
const br = b0 + (b + 1) % 3;
|
|
487
|
-
const p1 = this.triangles[bl];
|
|
488
|
-
const hbl = this._halfedges[bl];
|
|
489
|
-
const hbr = this._halfedges[br];
|
|
490
|
-
this._queueRemove(b0 / 3);
|
|
491
|
-
const t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);
|
|
492
|
-
const t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);
|
|
493
|
-
const t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);
|
|
494
|
-
const t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);
|
|
495
|
-
this._legalize(t0);
|
|
496
|
-
this._legalize(t1);
|
|
497
|
-
this._legalize(t2);
|
|
498
|
-
this._legalize(t3);
|
|
499
|
-
}
|
|
500
|
-
// priority queue methods
|
|
501
|
-
_queuePush(t, error, rms) {
|
|
502
|
-
const i = this._queue.length;
|
|
503
|
-
this._queueIndices[t] = i;
|
|
504
|
-
this._queue.push(t);
|
|
505
|
-
this._errors.push(error);
|
|
506
|
-
this._rmsSum += rms;
|
|
507
|
-
this._queueUp(i);
|
|
508
|
-
}
|
|
509
|
-
_queuePop() {
|
|
510
|
-
const n = this._queue.length - 1;
|
|
511
|
-
this._queueSwap(0, n);
|
|
512
|
-
this._queueDown(0, n);
|
|
513
|
-
return this._queuePopBack();
|
|
514
|
-
}
|
|
515
|
-
_queuePopBack() {
|
|
516
|
-
const t = this._queue.pop();
|
|
517
|
-
this._errors.pop();
|
|
518
|
-
this._rmsSum -= this._rms[t];
|
|
519
|
-
this._queueIndices[t] = -1;
|
|
520
|
-
return t;
|
|
521
|
-
}
|
|
522
|
-
_queueRemove(t) {
|
|
523
|
-
const i = this._queueIndices[t];
|
|
524
|
-
if (i < 0) {
|
|
525
|
-
const it = this._pending.indexOf(t);
|
|
526
|
-
if (it !== -1) {
|
|
527
|
-
this._pending[it] = this._pending[--this._pendingLen];
|
|
528
|
-
} else {
|
|
529
|
-
throw new Error("Broken triangulation (something went wrong).");
|
|
530
|
-
}
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
const n = this._queue.length - 1;
|
|
534
|
-
if (n !== i) {
|
|
535
|
-
this._queueSwap(i, n);
|
|
536
|
-
if (!this._queueDown(i, n)) {
|
|
537
|
-
this._queueUp(i);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
this._queuePopBack();
|
|
541
|
-
}
|
|
542
|
-
_queueLess(i, j) {
|
|
543
|
-
return this._errors[i] > this._errors[j];
|
|
544
|
-
}
|
|
545
|
-
_queueSwap(i, j) {
|
|
546
|
-
const pi = this._queue[i];
|
|
547
|
-
const pj = this._queue[j];
|
|
548
|
-
this._queue[i] = pj;
|
|
549
|
-
this._queue[j] = pi;
|
|
550
|
-
this._queueIndices[pi] = j;
|
|
551
|
-
this._queueIndices[pj] = i;
|
|
552
|
-
const e = this._errors[i];
|
|
553
|
-
this._errors[i] = this._errors[j];
|
|
554
|
-
this._errors[j] = e;
|
|
555
|
-
}
|
|
556
|
-
_queueUp(j0) {
|
|
557
|
-
let j = j0;
|
|
558
|
-
while (true) {
|
|
559
|
-
const i = j - 1 >> 1;
|
|
560
|
-
if (i === j || !this._queueLess(j, i)) {
|
|
561
|
-
break;
|
|
562
|
-
}
|
|
563
|
-
this._queueSwap(i, j);
|
|
564
|
-
j = i;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
_queueDown(i0, n) {
|
|
568
|
-
let i = i0;
|
|
569
|
-
while (true) {
|
|
570
|
-
const j1 = 2 * i + 1;
|
|
571
|
-
if (j1 >= n || j1 < 0) {
|
|
572
|
-
break;
|
|
573
|
-
}
|
|
574
|
-
const j2 = j1 + 1;
|
|
575
|
-
let j = j1;
|
|
576
|
-
if (j2 < n && this._queueLess(j2, j1)) {
|
|
577
|
-
j = j2;
|
|
578
|
-
}
|
|
579
|
-
if (!this._queueLess(j, i)) {
|
|
580
|
-
break;
|
|
581
|
-
}
|
|
582
|
-
this._queueSwap(i, j);
|
|
583
|
-
i = j;
|
|
584
|
-
}
|
|
585
|
-
return i > i0;
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
function orient(ax, ay, bx, by, cx, cy) {
|
|
589
|
-
return (bx - cx) * (ay - cy) - (by - cy) * (ax - cx);
|
|
590
|
-
}
|
|
591
|
-
function inCircle(ax, ay, bx, by, cx, cy, px, py) {
|
|
592
|
-
const dx = ax - px;
|
|
593
|
-
const dy = ay - py;
|
|
594
|
-
const ex = bx - px;
|
|
595
|
-
const ey = by - py;
|
|
596
|
-
const fx = cx - px;
|
|
597
|
-
const fy = cy - py;
|
|
598
|
-
const ap = dx * dx + dy * dy;
|
|
599
|
-
const bp = ex * ex + ey * ey;
|
|
600
|
-
const cp = fx * fx + fy * fy;
|
|
601
|
-
return dx * (ey * cp - bp * fy) - dy * (ex * cp - bp * fx) + ap * (ex * fy - ey * fx) < 0;
|
|
602
|
-
}
|
|
103
|
+
var import_terrain = require("@math.gl/geospatial/terrain");
|
|
603
104
|
|
|
604
105
|
// dist/terrain/lib/helpers/skirt.js
|
|
605
106
|
var import_loader_utils = require("@loaders.gl/core/loader-utils");
|
|
@@ -701,27 +202,27 @@ function decodeTerrainHeightmapInto(image, elevationDecoder, heights, rowStride)
|
|
|
701
202
|
|
|
702
203
|
// dist/terrain/lib/parse-terrain.js
|
|
703
204
|
function makeTerrainMeshFromImage(terrainImage, terrainOptions) {
|
|
704
|
-
const {
|
|
205
|
+
const { bounds, elevationDecoder } = terrainOptions;
|
|
705
206
|
const { data, width, height } = terrainImage;
|
|
706
207
|
let terrain;
|
|
707
208
|
let mesh;
|
|
708
209
|
switch (terrainOptions.tesselator) {
|
|
709
210
|
case "martini":
|
|
710
211
|
terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
|
|
711
|
-
mesh =
|
|
212
|
+
mesh = getTerrainTileMesh(terrainOptions, width, height, terrain, "martini");
|
|
712
213
|
break;
|
|
713
214
|
case "delatin":
|
|
714
215
|
terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
|
|
715
|
-
mesh =
|
|
216
|
+
mesh = getTerrainTileMesh(terrainOptions, width, height, terrain, "delatin");
|
|
716
217
|
break;
|
|
717
218
|
// auto
|
|
718
219
|
default:
|
|
719
220
|
if (width === height && !(height & width - 1)) {
|
|
720
221
|
terrain = getTerrain(data, width, height, elevationDecoder, "martini");
|
|
721
|
-
mesh =
|
|
222
|
+
mesh = getTerrainTileMesh(terrainOptions, width, height, terrain, "martini");
|
|
722
223
|
} else {
|
|
723
224
|
terrain = getTerrain(data, width, height, elevationDecoder, "delatin");
|
|
724
|
-
mesh =
|
|
225
|
+
mesh = getTerrainTileMesh(terrainOptions, width, height, terrain, "delatin");
|
|
725
226
|
}
|
|
726
227
|
break;
|
|
727
228
|
}
|
|
@@ -757,19 +258,19 @@ function makeTerrainMeshFromImage(terrainImage, terrainOptions) {
|
|
|
757
258
|
attributes
|
|
758
259
|
};
|
|
759
260
|
}
|
|
760
|
-
function
|
|
761
|
-
const
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
const
|
|
772
|
-
return { vertices, triangles };
|
|
261
|
+
function getTerrainTileMesh(terrainOptions, width, height, terrain, tesselator) {
|
|
262
|
+
const field = new import_terrain.HeightField({
|
|
263
|
+
width: width + 1,
|
|
264
|
+
height: height + 1,
|
|
265
|
+
heights: terrain,
|
|
266
|
+
rowStep: [0, -1]
|
|
267
|
+
});
|
|
268
|
+
const options = {
|
|
269
|
+
maxError: terrainOptions.meshMaxError,
|
|
270
|
+
maxSampleTests: terrainOptions.meshMaxSampleTests ?? Math.max(1e7, 32 * terrain.length)
|
|
271
|
+
};
|
|
272
|
+
const mesh = tesselator === "martini" ? (0, import_terrain.createMartiniTerrainMesh)(field, options) : (0, import_terrain.createDelatinTerrainMesh)(field, options);
|
|
273
|
+
return { vertices: mesh.gridCoordinates, triangles: mesh.indices };
|
|
773
274
|
}
|
|
774
275
|
function getTerrain(imageData, width, height, elevationDecoder, tesselator) {
|
|
775
276
|
const terrain = new Float32Array((width + 1) * (height + 1));
|
|
@@ -813,8 +314,8 @@ function getMeshAttributes(vertices, terrain, width, height, bounds) {
|
|
|
813
314
|
var { preload: _TerrainLoaderPreload, ...TerrainLoaderMetadataWithoutPreload } = TerrainLoader;
|
|
814
315
|
var TerrainLoaderWithParser = {
|
|
815
316
|
...TerrainLoaderMetadataWithoutPreload,
|
|
816
|
-
serializeWorkerResult:
|
|
817
|
-
deserializeWorkerResult:
|
|
317
|
+
serializeWorkerResult: import_arrow_worker_transport.serializeArrowWorkerResult,
|
|
318
|
+
deserializeWorkerResult: import_arrow_worker_transport.deserializeArrowWorkerResult,
|
|
818
319
|
/** Image decoder requested by terrain workers through the nested parse bridge. */
|
|
819
320
|
subloaders: { ImageLoader: import_images.ImageLoader },
|
|
820
321
|
parse: parseTerrain
|
|
@@ -866,7 +367,7 @@ var QuantizedMeshLoader = {
|
|
|
866
367
|
};
|
|
867
368
|
|
|
868
369
|
// dist/terrain/quantized-mesh-loader.js
|
|
869
|
-
var
|
|
370
|
+
var import_arrow_worker_transport2 = require("@loaders.gl/core/arrow-worker-transport");
|
|
870
371
|
var import_schema_utils4 = require("@loaders.gl/core/schema-utils");
|
|
871
372
|
|
|
872
373
|
// dist/terrain/lib/parse-quantized-mesh.js
|
|
@@ -1148,8 +649,8 @@ function getMeshAttributes2(vertexData, header, bounds) {
|
|
|
1148
649
|
var { preload: _QuantizedMeshLoaderPreload, ...QuantizedMeshLoaderMetadataWithoutPreload } = QuantizedMeshLoader;
|
|
1149
650
|
var QuantizedMeshLoaderWithParser = {
|
|
1150
651
|
...QuantizedMeshLoaderMetadataWithoutPreload,
|
|
1151
|
-
serializeWorkerResult:
|
|
1152
|
-
deserializeWorkerResult:
|
|
652
|
+
serializeWorkerResult: import_arrow_worker_transport2.serializeArrowWorkerResult,
|
|
653
|
+
deserializeWorkerResult: import_arrow_worker_transport2.deserializeArrowWorkerResult,
|
|
1153
654
|
parseSync: parseQuantizedMeshInRequestedShape,
|
|
1154
655
|
parse: async (arrayBuffer, options) => parseQuantizedMeshInRequestedShape(arrayBuffer, options)
|
|
1155
656
|
};
|