@loaders.gl/terrain 4.0.0-beta.2 → 4.0.0-beta.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 (69) hide show
  1. package/dist/dist.dev.js +1214 -0
  2. package/dist/index.cjs +1020 -0
  3. package/dist/{esm/index.js → index.js} +4 -4
  4. package/dist/index.js.map +1 -0
  5. package/dist/lib/decode-quantized-mesh.js.map +1 -0
  6. package/dist/lib/delatin/index.js.map +1 -0
  7. package/dist/lib/helpers/skirt.js.map +1 -0
  8. package/dist/{esm/lib → lib}/parse-quantized-mesh.js +2 -2
  9. package/dist/lib/parse-quantized-mesh.js.map +1 -0
  10. package/dist/{esm/lib → lib}/parse-terrain.js +2 -2
  11. package/dist/lib/parse-terrain.js.map +1 -0
  12. package/dist/lib/utils/version.js +2 -0
  13. package/dist/lib/utils/version.js.map +1 -0
  14. package/dist/{esm/quantized-mesh-loader.js → quantized-mesh-loader.js} +1 -1
  15. package/dist/quantized-mesh-loader.js.map +1 -0
  16. package/dist/quantized-mesh-worker.js +133 -27
  17. package/dist/{esm/terrain-loader.js → terrain-loader.js} +1 -1
  18. package/dist/terrain-loader.js.map +1 -0
  19. package/dist/terrain-worker.js +133 -27
  20. package/dist/{esm/workers → workers}/quantized-mesh-worker.js +1 -1
  21. package/dist/workers/quantized-mesh-worker.js.map +1 -0
  22. package/dist/{esm/workers → workers}/terrain-worker.js +1 -1
  23. package/dist/workers/terrain-worker.js.map +1 -0
  24. package/package.json +17 -9
  25. package/dist/bundle.d.ts +0 -2
  26. package/dist/bundle.d.ts.map +0 -1
  27. package/dist/dist.min.js +0 -1186
  28. package/dist/es5/bundle.js +0 -6
  29. package/dist/es5/bundle.js.map +0 -1
  30. package/dist/es5/index.js +0 -88
  31. package/dist/es5/index.js.map +0 -1
  32. package/dist/es5/lib/decode-quantized-mesh.js +0 -250
  33. package/dist/es5/lib/decode-quantized-mesh.js.map +0 -1
  34. package/dist/es5/lib/delatin/index.js +0 -408
  35. package/dist/es5/lib/delatin/index.js.map +0 -1
  36. package/dist/es5/lib/helpers/skirt.js +0 -105
  37. package/dist/es5/lib/helpers/skirt.js.map +0 -1
  38. package/dist/es5/lib/parse-quantized-mesh.js +0 -95
  39. package/dist/es5/lib/parse-quantized-mesh.js.map +0 -1
  40. package/dist/es5/lib/parse-terrain.js +0 -152
  41. package/dist/es5/lib/parse-terrain.js.map +0 -1
  42. package/dist/es5/lib/utils/version.js +0 -9
  43. package/dist/es5/lib/utils/version.js.map +0 -1
  44. package/dist/es5/quantized-mesh-loader.js +0 -24
  45. package/dist/es5/quantized-mesh-loader.js.map +0 -1
  46. package/dist/es5/terrain-loader.js +0 -32
  47. package/dist/es5/terrain-loader.js.map +0 -1
  48. package/dist/es5/workers/quantized-mesh-worker.js +0 -6
  49. package/dist/es5/workers/quantized-mesh-worker.js.map +0 -1
  50. package/dist/es5/workers/terrain-worker.js +0 -6
  51. package/dist/es5/workers/terrain-worker.js.map +0 -1
  52. package/dist/esm/bundle.js +0 -4
  53. package/dist/esm/bundle.js.map +0 -1
  54. package/dist/esm/index.js.map +0 -1
  55. package/dist/esm/lib/decode-quantized-mesh.js.map +0 -1
  56. package/dist/esm/lib/delatin/index.js.map +0 -1
  57. package/dist/esm/lib/helpers/skirt.js.map +0 -1
  58. package/dist/esm/lib/parse-quantized-mesh.js.map +0 -1
  59. package/dist/esm/lib/parse-terrain.js.map +0 -1
  60. package/dist/esm/lib/utils/version.js +0 -2
  61. package/dist/esm/lib/utils/version.js.map +0 -1
  62. package/dist/esm/quantized-mesh-loader.js.map +0 -1
  63. package/dist/esm/terrain-loader.js.map +0 -1
  64. package/dist/esm/workers/quantized-mesh-worker.js.map +0 -1
  65. package/dist/esm/workers/terrain-worker.js.map +0 -1
  66. package/src/bundle.ts +0 -4
  67. /package/dist/{esm/lib → lib}/decode-quantized-mesh.js +0 -0
  68. /package/dist/{esm/lib → lib}/delatin/index.js +0 -0
  69. /package/dist/{esm/lib → lib}/helpers/skirt.js +0 -0
package/dist/dist.min.js DELETED
@@ -1,1186 +0,0 @@
1
- (() => {
2
- var __defProp = Object.defineProperty;
3
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
4
- var __esm = (fn, res) => function __init() {
5
- return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
6
- };
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
- var __export = (target, all) => {
11
- __markAsModule(target);
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
-
16
- // ../loader-utils/src/loader-types.ts
17
- async function parseFromContext(data, loaders, options, context) {
18
- return context._parse(data, loaders, options, context);
19
- }
20
- var init_loader_types = __esm({
21
- "../loader-utils/src/loader-types.ts"() {
22
- }
23
- });
24
-
25
- // ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
26
- function concatenateTypedArrays(...typedArrays) {
27
- const arrays = typedArrays;
28
- const TypedArrayConstructor = arrays && arrays.length > 1 && arrays[0].constructor || null;
29
- if (!TypedArrayConstructor) {
30
- throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types');
31
- }
32
- const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);
33
- const result = new TypedArrayConstructor(sumLength);
34
- let offset = 0;
35
- for (const array of arrays) {
36
- result.set(array, offset);
37
- offset += array.length;
38
- }
39
- return result;
40
- }
41
- var init_array_buffer_utils = __esm({
42
- "../loader-utils/src/lib/binary-utils/array-buffer-utils.ts"() {
43
- }
44
- });
45
-
46
- // ../loader-utils/src/index.ts
47
- var init_src = __esm({
48
- "../loader-utils/src/index.ts"() {
49
- init_loader_types();
50
- init_array_buffer_utils();
51
- }
52
- });
53
-
54
- // ../schema/src/lib/mesh/mesh-utils.ts
55
- function getMeshBoundingBox(attributes) {
56
- let minX = Infinity;
57
- let minY = Infinity;
58
- let minZ = Infinity;
59
- let maxX = -Infinity;
60
- let maxY = -Infinity;
61
- let maxZ = -Infinity;
62
- const positions = attributes.POSITION ? attributes.POSITION.value : [];
63
- const len = positions && positions.length;
64
- for (let i = 0; i < len; i += 3) {
65
- const x = positions[i];
66
- const y = positions[i + 1];
67
- const z = positions[i + 2];
68
- minX = x < minX ? x : minX;
69
- minY = y < minY ? y : minY;
70
- minZ = z < minZ ? z : minZ;
71
- maxX = x > maxX ? x : maxX;
72
- maxY = y > maxY ? y : maxY;
73
- maxZ = z > maxZ ? z : maxZ;
74
- }
75
- return [
76
- [minX, minY, minZ],
77
- [maxX, maxY, maxZ]
78
- ];
79
- }
80
- var init_mesh_utils = __esm({
81
- "../schema/src/lib/mesh/mesh-utils.ts"() {
82
- }
83
- });
84
-
85
- // ../schema/src/index.ts
86
- var init_src2 = __esm({
87
- "../schema/src/index.ts"() {
88
- init_mesh_utils();
89
- }
90
- });
91
-
92
- // src/lib/decode-quantized-mesh.ts
93
- function decodeZigZag(value) {
94
- return value >> 1 ^ -(value & 1);
95
- }
96
- function decodeHeader(dataView) {
97
- let position = 0;
98
- const header = {};
99
- for (const [key, bytesCount] of QUANTIZED_MESH_HEADER) {
100
- const getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;
101
- header[key] = getter.call(dataView, position, true);
102
- position += bytesCount;
103
- }
104
- return { header, headerEndPosition: position };
105
- }
106
- function decodeVertexData(dataView, headerEndPosition) {
107
- let position = headerEndPosition;
108
- const elementsPerVertex = 3;
109
- const vertexCount = dataView.getUint32(position, true);
110
- const vertexData = new Uint16Array(vertexCount * elementsPerVertex);
111
- position += Uint32Array.BYTES_PER_ELEMENT;
112
- const bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;
113
- const elementArrayLength = vertexCount * bytesPerArrayElement;
114
- const uArrayStartPosition = position;
115
- const vArrayStartPosition = uArrayStartPosition + elementArrayLength;
116
- const heightArrayStartPosition = vArrayStartPosition + elementArrayLength;
117
- let u = 0;
118
- let v = 0;
119
- let height = 0;
120
- for (let i = 0; i < vertexCount; i++) {
121
- u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));
122
- v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));
123
- height += decodeZigZag(dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true));
124
- vertexData[i] = u;
125
- vertexData[i + vertexCount] = v;
126
- vertexData[i + vertexCount * 2] = height;
127
- }
128
- position += elementArrayLength * 3;
129
- return { vertexData, vertexDataEndPosition: position };
130
- }
131
- function decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = true) {
132
- let indices;
133
- if (bytesPerIndex === 2) {
134
- indices = new Uint16Array(buffer, position, indicesCount);
135
- } else {
136
- indices = new Uint32Array(buffer, position, indicesCount);
137
- }
138
- if (!encoded) {
139
- return indices;
140
- }
141
- let highest = 0;
142
- for (let i = 0; i < indices.length; ++i) {
143
- const code = indices[i];
144
- indices[i] = highest - code;
145
- if (code === 0) {
146
- ++highest;
147
- }
148
- }
149
- return indices;
150
- }
151
- function decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {
152
- let position = vertexDataEndPosition;
153
- const elementsPerVertex = 3;
154
- const vertexCount = vertexData.length / elementsPerVertex;
155
- const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
156
- if (position % bytesPerIndex !== 0) {
157
- position += bytesPerIndex - position % bytesPerIndex;
158
- }
159
- const triangleCount = dataView.getUint32(position, true);
160
- position += Uint32Array.BYTES_PER_ELEMENT;
161
- const triangleIndicesCount = triangleCount * 3;
162
- const triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex);
163
- position += triangleIndicesCount * bytesPerIndex;
164
- return {
165
- triangleIndicesEndPosition: position,
166
- triangleIndices
167
- };
168
- }
169
- function decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {
170
- let position = triangleIndicesEndPosition;
171
- const elementsPerVertex = 3;
172
- const vertexCount = vertexData.length / elementsPerVertex;
173
- const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
174
- const westVertexCount = dataView.getUint32(position, true);
175
- position += Uint32Array.BYTES_PER_ELEMENT;
176
- const westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);
177
- position += westVertexCount * bytesPerIndex;
178
- const southVertexCount = dataView.getUint32(position, true);
179
- position += Uint32Array.BYTES_PER_ELEMENT;
180
- const southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false);
181
- position += southVertexCount * bytesPerIndex;
182
- const eastVertexCount = dataView.getUint32(position, true);
183
- position += Uint32Array.BYTES_PER_ELEMENT;
184
- const eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);
185
- position += eastVertexCount * bytesPerIndex;
186
- const northVertexCount = dataView.getUint32(position, true);
187
- position += Uint32Array.BYTES_PER_ELEMENT;
188
- const northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false);
189
- position += northVertexCount * bytesPerIndex;
190
- return {
191
- edgeIndicesEndPosition: position,
192
- westIndices,
193
- southIndices,
194
- eastIndices,
195
- northIndices
196
- };
197
- }
198
- function decodeVertexNormalsExtension(extensionDataView) {
199
- return new Uint8Array(extensionDataView.buffer, extensionDataView.byteOffset, extensionDataView.byteLength);
200
- }
201
- function decodeWaterMaskExtension(extensionDataView) {
202
- return extensionDataView.buffer.slice(extensionDataView.byteOffset, extensionDataView.byteOffset + extensionDataView.byteLength);
203
- }
204
- function decodeExtensions(dataView, indicesEndPosition) {
205
- const extensions = {};
206
- if (dataView.byteLength <= indicesEndPosition) {
207
- return { extensions, extensionsEndPosition: indicesEndPosition };
208
- }
209
- let position = indicesEndPosition;
210
- while (position < dataView.byteLength) {
211
- const extensionId = dataView.getUint8(position, true);
212
- position += Uint8Array.BYTES_PER_ELEMENT;
213
- const extensionLength = dataView.getUint32(position, true);
214
- position += Uint32Array.BYTES_PER_ELEMENT;
215
- const extensionView = new DataView(dataView.buffer, position, extensionLength);
216
- switch (extensionId) {
217
- case 1: {
218
- extensions.vertexNormals = decodeVertexNormalsExtension(extensionView);
219
- break;
220
- }
221
- case 2: {
222
- extensions.waterMask = decodeWaterMaskExtension(extensionView);
223
- break;
224
- }
225
- default: {
226
- }
227
- }
228
- position += extensionLength;
229
- }
230
- return { extensions, extensionsEndPosition: position };
231
- }
232
- function decode(data, userOptions) {
233
- const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
234
- const view = new DataView(data);
235
- const { header, headerEndPosition } = decodeHeader(view);
236
- if (options.maxDecodingStep < DECODING_STEPS.vertices) {
237
- return { header };
238
- }
239
- const { vertexData, vertexDataEndPosition } = decodeVertexData(view, headerEndPosition);
240
- if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {
241
- return { header, vertexData };
242
- }
243
- const { triangleIndices, triangleIndicesEndPosition } = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
244
- if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {
245
- return { header, vertexData, triangleIndices };
246
- }
247
- const { westIndices, southIndices, eastIndices, northIndices, edgeIndicesEndPosition } = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
248
- if (options.maxDecodingStep < DECODING_STEPS.extensions) {
249
- return {
250
- header,
251
- vertexData,
252
- triangleIndices,
253
- westIndices,
254
- northIndices,
255
- eastIndices,
256
- southIndices
257
- };
258
- }
259
- const { extensions } = decodeExtensions(view, edgeIndicesEndPosition);
260
- return {
261
- header,
262
- vertexData,
263
- triangleIndices,
264
- westIndices,
265
- northIndices,
266
- eastIndices,
267
- southIndices,
268
- extensions
269
- };
270
- }
271
- var QUANTIZED_MESH_HEADER, DECODING_STEPS, DEFAULT_OPTIONS;
272
- var init_decode_quantized_mesh = __esm({
273
- "src/lib/decode-quantized-mesh.ts"() {
274
- QUANTIZED_MESH_HEADER = new Map([
275
- ["centerX", Float64Array.BYTES_PER_ELEMENT],
276
- ["centerY", Float64Array.BYTES_PER_ELEMENT],
277
- ["centerZ", Float64Array.BYTES_PER_ELEMENT],
278
- ["minHeight", Float32Array.BYTES_PER_ELEMENT],
279
- ["maxHeight", Float32Array.BYTES_PER_ELEMENT],
280
- ["boundingSphereCenterX", Float64Array.BYTES_PER_ELEMENT],
281
- ["boundingSphereCenterY", Float64Array.BYTES_PER_ELEMENT],
282
- ["boundingSphereCenterZ", Float64Array.BYTES_PER_ELEMENT],
283
- ["boundingSphereRadius", Float64Array.BYTES_PER_ELEMENT],
284
- ["horizonOcclusionPointX", Float64Array.BYTES_PER_ELEMENT],
285
- ["horizonOcclusionPointY", Float64Array.BYTES_PER_ELEMENT],
286
- ["horizonOcclusionPointZ", Float64Array.BYTES_PER_ELEMENT]
287
- ]);
288
- DECODING_STEPS = {
289
- header: 0,
290
- vertices: 1,
291
- triangleIndices: 2,
292
- edgeIndices: 3,
293
- extensions: 4
294
- };
295
- DEFAULT_OPTIONS = {
296
- maxDecodingStep: DECODING_STEPS.extensions
297
- };
298
- }
299
- });
300
-
301
- // src/lib/helpers/skirt.ts
302
- function addSkirt(attributes, triangles, skirtHeight, outsideIndices) {
303
- const outsideEdges = outsideIndices ? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value) : getOutsideEdgesFromTriangles(triangles);
304
- const newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);
305
- const newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);
306
- const newTriangles = new triangles.constructor(outsideEdges.length * 6);
307
- for (let i = 0; i < outsideEdges.length; i++) {
308
- const edge = outsideEdges[i];
309
- updateAttributesForNewEdge({
310
- edge,
311
- edgeIndex: i,
312
- attributes,
313
- skirtHeight,
314
- newPosition,
315
- newTexcoord0,
316
- newTriangles
317
- });
318
- }
319
- attributes.POSITION.value = concatenateTypedArrays(attributes.POSITION.value, newPosition);
320
- attributes.TEXCOORD_0.value = concatenateTypedArrays(attributes.TEXCOORD_0.value, newTexcoord0);
321
- const resultTriangles = triangles instanceof Array ? triangles.concat(newTriangles) : concatenateTypedArrays(triangles, newTriangles);
322
- return {
323
- attributes,
324
- triangles: resultTriangles
325
- };
326
- }
327
- function getOutsideEdgesFromTriangles(triangles) {
328
- const edges = [];
329
- for (let i = 0; i < triangles.length; i += 3) {
330
- edges.push([triangles[i], triangles[i + 1]]);
331
- edges.push([triangles[i + 1], triangles[i + 2]]);
332
- edges.push([triangles[i + 2], triangles[i]]);
333
- }
334
- edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
335
- const outsideEdges = [];
336
- let index = 0;
337
- while (index < edges.length) {
338
- if (edges[index][0] === edges[index + 1]?.[1] && edges[index][1] === edges[index + 1]?.[0]) {
339
- index += 2;
340
- } else {
341
- outsideEdges.push(edges[index]);
342
- index++;
343
- }
344
- }
345
- return outsideEdges;
346
- }
347
- function getOutsideEdgesFromIndices(indices, position) {
348
- indices.westIndices.sort((a, b) => position[3 * a + 1] - position[3 * b + 1]);
349
- indices.eastIndices.sort((a, b) => position[3 * b + 1] - position[3 * a + 1]);
350
- indices.southIndices.sort((a, b) => position[3 * b] - position[3 * a]);
351
- indices.northIndices.sort((a, b) => position[3 * a] - position[3 * b]);
352
- const edges = [];
353
- for (const index in indices) {
354
- const indexGroup = indices[index];
355
- for (let i = 0; i < indexGroup.length - 1; i++) {
356
- edges.push([indexGroup[i], indexGroup[i + 1]]);
357
- }
358
- }
359
- return edges;
360
- }
361
- function updateAttributesForNewEdge({
362
- edge,
363
- edgeIndex,
364
- attributes,
365
- skirtHeight,
366
- newPosition,
367
- newTexcoord0,
368
- newTriangles
369
- }) {
370
- const positionsLength = attributes.POSITION.value.length;
371
- const vertex1Offset = edgeIndex * 2;
372
- const vertex2Offset = edgeIndex * 2 + 1;
373
- newPosition.set(attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), vertex1Offset * 3);
374
- newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight;
375
- newPosition.set(attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3), vertex2Offset * 3);
376
- newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight;
377
- newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2), vertex1Offset * 2);
378
- newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), vertex2Offset * 2);
379
- const triangle1Offset = edgeIndex * 2 * 3;
380
- newTriangles[triangle1Offset] = edge[0];
381
- newTriangles[triangle1Offset + 1] = positionsLength / 3 + vertex2Offset;
382
- newTriangles[triangle1Offset + 2] = edge[1];
383
- newTriangles[triangle1Offset + 3] = positionsLength / 3 + vertex2Offset;
384
- newTriangles[triangle1Offset + 4] = edge[0];
385
- newTriangles[triangle1Offset + 5] = positionsLength / 3 + vertex1Offset;
386
- }
387
- var init_skirt = __esm({
388
- "src/lib/helpers/skirt.ts"() {
389
- init_src();
390
- }
391
- });
392
-
393
- // src/lib/parse-quantized-mesh.ts
394
- function parseQuantizedMesh(arrayBuffer, options = {}) {
395
- const { bounds } = options;
396
- const {
397
- header,
398
- vertexData,
399
- triangleIndices: originalTriangleIndices,
400
- westIndices,
401
- northIndices,
402
- eastIndices,
403
- southIndices
404
- } = decode(arrayBuffer, DECODING_STEPS.triangleIndices);
405
- let triangleIndices = originalTriangleIndices;
406
- let attributes = getMeshAttributes(vertexData, header, bounds);
407
- const boundingBox = getMeshBoundingBox(attributes);
408
- if (options?.skirtHeight) {
409
- const { attributes: newAttributes, triangles: newTriangles } = addSkirt(attributes, triangleIndices, options.skirtHeight, {
410
- westIndices,
411
- northIndices,
412
- eastIndices,
413
- southIndices
414
- });
415
- attributes = newAttributes;
416
- triangleIndices = newTriangles;
417
- }
418
- return {
419
- loaderData: {
420
- header: {}
421
- },
422
- header: {
423
- vertexCount: triangleIndices.length,
424
- boundingBox
425
- },
426
- schema: void 0,
427
- topology: "triangle-list",
428
- mode: 4,
429
- indices: { value: triangleIndices, size: 1 },
430
- attributes
431
- };
432
- }
433
- function getMeshAttributes(vertexData, header, bounds) {
434
- const { minHeight, maxHeight } = header;
435
- const [minX, minY, maxX, maxY] = bounds || [0, 0, 1, 1];
436
- const xScale = maxX - minX;
437
- const yScale = maxY - minY;
438
- const zScale = maxHeight - minHeight;
439
- const nCoords = vertexData.length / 3;
440
- const positions = new Float32Array(nCoords * 3);
441
- const texCoords = new Float32Array(nCoords * 2);
442
- for (let i = 0; i < nCoords; i++) {
443
- const x = vertexData[i] / 32767;
444
- const y = vertexData[i + nCoords] / 32767;
445
- const z = vertexData[i + nCoords * 2] / 32767;
446
- positions[3 * i + 0] = x * xScale + minX;
447
- positions[3 * i + 1] = y * yScale + minY;
448
- positions[3 * i + 2] = z * zScale + minHeight;
449
- texCoords[2 * i + 0] = x;
450
- texCoords[2 * i + 1] = y;
451
- }
452
- return {
453
- POSITION: { value: positions, size: 3 },
454
- TEXCOORD_0: { value: texCoords, size: 2 }
455
- };
456
- }
457
- var init_parse_quantized_mesh = __esm({
458
- "src/lib/parse-quantized-mesh.ts"() {
459
- init_src2();
460
- init_decode_quantized_mesh();
461
- init_skirt();
462
- }
463
- });
464
-
465
- // ../../node_modules/@mapbox/martini/index.js
466
- var Martini, Tile;
467
- var init_martini = __esm({
468
- "../../node_modules/@mapbox/martini/index.js"() {
469
- Martini = class {
470
- constructor(gridSize = 257) {
471
- this.gridSize = gridSize;
472
- const tileSize = gridSize - 1;
473
- if (tileSize & tileSize - 1)
474
- throw new Error(`Expected grid size to be 2^n+1, got ${gridSize}.`);
475
- this.numTriangles = tileSize * tileSize * 2 - 2;
476
- this.numParentTriangles = this.numTriangles - tileSize * tileSize;
477
- this.indices = new Uint32Array(this.gridSize * this.gridSize);
478
- this.coords = new Uint16Array(this.numTriangles * 4);
479
- for (let i = 0; i < this.numTriangles; i++) {
480
- let id = i + 2;
481
- let ax = 0, ay = 0, bx = 0, by = 0, cx = 0, cy = 0;
482
- if (id & 1) {
483
- bx = by = cx = tileSize;
484
- } else {
485
- ax = ay = cy = tileSize;
486
- }
487
- while ((id >>= 1) > 1) {
488
- const mx = ax + bx >> 1;
489
- const my = ay + by >> 1;
490
- if (id & 1) {
491
- bx = ax;
492
- by = ay;
493
- ax = cx;
494
- ay = cy;
495
- } else {
496
- ax = bx;
497
- ay = by;
498
- bx = cx;
499
- by = cy;
500
- }
501
- cx = mx;
502
- cy = my;
503
- }
504
- const k = i * 4;
505
- this.coords[k + 0] = ax;
506
- this.coords[k + 1] = ay;
507
- this.coords[k + 2] = bx;
508
- this.coords[k + 3] = by;
509
- }
510
- }
511
- createTile(terrain) {
512
- return new Tile(terrain, this);
513
- }
514
- };
515
- Tile = class {
516
- constructor(terrain, martini) {
517
- const size = martini.gridSize;
518
- if (terrain.length !== size * size)
519
- throw new Error(`Expected terrain data of length ${size * size} (${size} x ${size}), got ${terrain.length}.`);
520
- this.terrain = terrain;
521
- this.martini = martini;
522
- this.errors = new Float32Array(terrain.length);
523
- this.update();
524
- }
525
- update() {
526
- const { numTriangles, numParentTriangles, coords, gridSize: size } = this.martini;
527
- const { terrain, errors } = this;
528
- for (let i = numTriangles - 1; i >= 0; i--) {
529
- const k = i * 4;
530
- const ax = coords[k + 0];
531
- const ay = coords[k + 1];
532
- const bx = coords[k + 2];
533
- const by = coords[k + 3];
534
- const mx = ax + bx >> 1;
535
- const my = ay + by >> 1;
536
- const cx = mx + my - ay;
537
- const cy = my + ax - mx;
538
- const interpolatedHeight = (terrain[ay * size + ax] + terrain[by * size + bx]) / 2;
539
- const middleIndex = my * size + mx;
540
- const middleError = Math.abs(interpolatedHeight - terrain[middleIndex]);
541
- errors[middleIndex] = Math.max(errors[middleIndex], middleError);
542
- if (i < numParentTriangles) {
543
- const leftChildIndex = (ay + cy >> 1) * size + (ax + cx >> 1);
544
- const rightChildIndex = (by + cy >> 1) * size + (bx + cx >> 1);
545
- errors[middleIndex] = Math.max(errors[middleIndex], errors[leftChildIndex], errors[rightChildIndex]);
546
- }
547
- }
548
- }
549
- getMesh(maxError = 0) {
550
- const { gridSize: size, indices } = this.martini;
551
- const { errors } = this;
552
- let numVertices = 0;
553
- let numTriangles = 0;
554
- const max = size - 1;
555
- indices.fill(0);
556
- function countElements(ax, ay, bx, by, cx, cy) {
557
- const mx = ax + bx >> 1;
558
- const my = ay + by >> 1;
559
- if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {
560
- countElements(cx, cy, ax, ay, mx, my);
561
- countElements(bx, by, cx, cy, mx, my);
562
- } else {
563
- indices[ay * size + ax] = indices[ay * size + ax] || ++numVertices;
564
- indices[by * size + bx] = indices[by * size + bx] || ++numVertices;
565
- indices[cy * size + cx] = indices[cy * size + cx] || ++numVertices;
566
- numTriangles++;
567
- }
568
- }
569
- countElements(0, 0, max, max, max, 0);
570
- countElements(max, max, 0, 0, 0, max);
571
- const vertices = new Uint16Array(numVertices * 2);
572
- const triangles = new Uint32Array(numTriangles * 3);
573
- let triIndex = 0;
574
- function processTriangle(ax, ay, bx, by, cx, cy) {
575
- const mx = ax + bx >> 1;
576
- const my = ay + by >> 1;
577
- if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {
578
- processTriangle(cx, cy, ax, ay, mx, my);
579
- processTriangle(bx, by, cx, cy, mx, my);
580
- } else {
581
- const a = indices[ay * size + ax] - 1;
582
- const b = indices[by * size + bx] - 1;
583
- const c = indices[cy * size + cx] - 1;
584
- vertices[2 * a] = ax;
585
- vertices[2 * a + 1] = ay;
586
- vertices[2 * b] = bx;
587
- vertices[2 * b + 1] = by;
588
- vertices[2 * c] = cx;
589
- vertices[2 * c + 1] = cy;
590
- triangles[triIndex++] = a;
591
- triangles[triIndex++] = b;
592
- triangles[triIndex++] = c;
593
- }
594
- }
595
- processTriangle(0, 0, max, max, max, 0);
596
- processTriangle(max, max, 0, 0, 0, max);
597
- return { vertices, triangles };
598
- }
599
- };
600
- }
601
- });
602
-
603
- // src/lib/delatin/index.ts
604
- function orient(ax, ay, bx, by, cx, cy) {
605
- return (bx - cx) * (ay - cy) - (by - cy) * (ax - cx);
606
- }
607
- function inCircle(ax, ay, bx, by, cx, cy, px, py) {
608
- const dx = ax - px;
609
- const dy = ay - py;
610
- const ex = bx - px;
611
- const ey = by - py;
612
- const fx = cx - px;
613
- const fy = cy - py;
614
- const ap = dx * dx + dy * dy;
615
- const bp = ex * ex + ey * ey;
616
- const cp = fx * fx + fy * fy;
617
- return dx * (ey * cp - bp * fy) - dy * (ex * cp - bp * fx) + ap * (ex * fy - ey * fx) < 0;
618
- }
619
- var Delatin;
620
- var init_delatin = __esm({
621
- "src/lib/delatin/index.ts"() {
622
- Delatin = class {
623
- constructor(data, width, height = width) {
624
- this.data = data;
625
- this.width = width;
626
- this.height = height;
627
- this.coords = [];
628
- this.triangles = [];
629
- this._halfedges = [];
630
- this._candidates = [];
631
- this._queueIndices = [];
632
- this._queue = [];
633
- this._errors = [];
634
- this._rms = [];
635
- this._pending = [];
636
- this._pendingLen = 0;
637
- this._rmsSum = 0;
638
- const x1 = width - 1;
639
- const y1 = height - 1;
640
- const p0 = this._addPoint(0, 0);
641
- const p1 = this._addPoint(x1, 0);
642
- const p2 = this._addPoint(0, y1);
643
- const p3 = this._addPoint(x1, y1);
644
- const t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);
645
- this._addTriangle(p0, p3, p1, t0, -1, -1);
646
- this._flush();
647
- }
648
- run(maxError = 1) {
649
- while (this.getMaxError() > maxError) {
650
- this.refine();
651
- }
652
- }
653
- refine() {
654
- this._step();
655
- this._flush();
656
- }
657
- getMaxError() {
658
- return this._errors[0];
659
- }
660
- getRMSD() {
661
- return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;
662
- }
663
- heightAt(x, y) {
664
- return this.data[this.width * y + x];
665
- }
666
- _flush() {
667
- const coords = this.coords;
668
- for (let i = 0; i < this._pendingLen; i++) {
669
- const t = this._pending[i];
670
- const a = 2 * this.triangles[t * 3 + 0];
671
- const b = 2 * this.triangles[t * 3 + 1];
672
- const c = 2 * this.triangles[t * 3 + 2];
673
- this._findCandidate(coords[a], coords[a + 1], coords[b], coords[b + 1], coords[c], coords[c + 1], t);
674
- }
675
- this._pendingLen = 0;
676
- }
677
- _findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {
678
- const minX = Math.min(p0x, p1x, p2x);
679
- const minY = Math.min(p0y, p1y, p2y);
680
- const maxX = Math.max(p0x, p1x, p2x);
681
- const maxY = Math.max(p0y, p1y, p2y);
682
- let w00 = orient(p1x, p1y, p2x, p2y, minX, minY);
683
- let w01 = orient(p2x, p2y, p0x, p0y, minX, minY);
684
- let w02 = orient(p0x, p0y, p1x, p1y, minX, minY);
685
- const a01 = p1y - p0y;
686
- const b01 = p0x - p1x;
687
- const a12 = p2y - p1y;
688
- const b12 = p1x - p2x;
689
- const a20 = p0y - p2y;
690
- const b20 = p2x - p0x;
691
- const a = orient(p0x, p0y, p1x, p1y, p2x, p2y);
692
- const z0 = this.heightAt(p0x, p0y) / a;
693
- const z1 = this.heightAt(p1x, p1y) / a;
694
- const z2 = this.heightAt(p2x, p2y) / a;
695
- let maxError = 0;
696
- let mx = 0;
697
- let my = 0;
698
- let rms = 0;
699
- for (let y = minY; y <= maxY; y++) {
700
- let dx = 0;
701
- if (w00 < 0 && a12 !== 0) {
702
- dx = Math.max(dx, Math.floor(-w00 / a12));
703
- }
704
- if (w01 < 0 && a20 !== 0) {
705
- dx = Math.max(dx, Math.floor(-w01 / a20));
706
- }
707
- if (w02 < 0 && a01 !== 0) {
708
- dx = Math.max(dx, Math.floor(-w02 / a01));
709
- }
710
- let w0 = w00 + a12 * dx;
711
- let w1 = w01 + a20 * dx;
712
- let w2 = w02 + a01 * dx;
713
- let wasInside = false;
714
- for (let x = minX + dx; x <= maxX; x++) {
715
- if (w0 >= 0 && w1 >= 0 && w2 >= 0) {
716
- wasInside = true;
717
- const z = z0 * w0 + z1 * w1 + z2 * w2;
718
- const dz = Math.abs(z - this.heightAt(x, y));
719
- rms += dz * dz;
720
- if (dz > maxError) {
721
- maxError = dz;
722
- mx = x;
723
- my = y;
724
- }
725
- } else if (wasInside) {
726
- break;
727
- }
728
- w0 += a12;
729
- w1 += a20;
730
- w2 += a01;
731
- }
732
- w00 += b12;
733
- w01 += b20;
734
- w02 += b01;
735
- }
736
- if (mx === p0x && my === p0y || mx === p1x && my === p1y || mx === p2x && my === p2y) {
737
- maxError = 0;
738
- }
739
- this._candidates[2 * t] = mx;
740
- this._candidates[2 * t + 1] = my;
741
- this._rms[t] = rms;
742
- this._queuePush(t, maxError, rms);
743
- }
744
- _step() {
745
- const t = this._queuePop();
746
- const e0 = t * 3 + 0;
747
- const e1 = t * 3 + 1;
748
- const e2 = t * 3 + 2;
749
- const p0 = this.triangles[e0];
750
- const p1 = this.triangles[e1];
751
- const p2 = this.triangles[e2];
752
- const ax = this.coords[2 * p0];
753
- const ay = this.coords[2 * p0 + 1];
754
- const bx = this.coords[2 * p1];
755
- const by = this.coords[2 * p1 + 1];
756
- const cx = this.coords[2 * p2];
757
- const cy = this.coords[2 * p2 + 1];
758
- const px = this._candidates[2 * t];
759
- const py = this._candidates[2 * t + 1];
760
- const pn = this._addPoint(px, py);
761
- if (orient(ax, ay, bx, by, px, py) === 0) {
762
- this._handleCollinear(pn, e0);
763
- } else if (orient(bx, by, cx, cy, px, py) === 0) {
764
- this._handleCollinear(pn, e1);
765
- } else if (orient(cx, cy, ax, ay, px, py) === 0) {
766
- this._handleCollinear(pn, e2);
767
- } else {
768
- const h0 = this._halfedges[e0];
769
- const h1 = this._halfedges[e1];
770
- const h2 = this._halfedges[e2];
771
- const t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);
772
- const t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);
773
- const t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);
774
- this._legalize(t0);
775
- this._legalize(t1);
776
- this._legalize(t2);
777
- }
778
- }
779
- _addPoint(x, y) {
780
- const i = this.coords.length >> 1;
781
- this.coords.push(x, y);
782
- return i;
783
- }
784
- _addTriangle(a, b, c, ab, bc, ca, e = this.triangles.length) {
785
- const t = e / 3;
786
- this.triangles[e + 0] = a;
787
- this.triangles[e + 1] = b;
788
- this.triangles[e + 2] = c;
789
- this._halfedges[e + 0] = ab;
790
- this._halfedges[e + 1] = bc;
791
- this._halfedges[e + 2] = ca;
792
- if (ab >= 0) {
793
- this._halfedges[ab] = e + 0;
794
- }
795
- if (bc >= 0) {
796
- this._halfedges[bc] = e + 1;
797
- }
798
- if (ca >= 0) {
799
- this._halfedges[ca] = e + 2;
800
- }
801
- this._candidates[2 * t + 0] = 0;
802
- this._candidates[2 * t + 1] = 0;
803
- this._queueIndices[t] = -1;
804
- this._rms[t] = 0;
805
- this._pending[this._pendingLen++] = t;
806
- return e;
807
- }
808
- _legalize(a) {
809
- const b = this._halfedges[a];
810
- if (b < 0) {
811
- return;
812
- }
813
- const a0 = a - a % 3;
814
- const b0 = b - b % 3;
815
- const al = a0 + (a + 1) % 3;
816
- const ar = a0 + (a + 2) % 3;
817
- const bl = b0 + (b + 2) % 3;
818
- const br = b0 + (b + 1) % 3;
819
- const p0 = this.triangles[ar];
820
- const pr = this.triangles[a];
821
- const pl = this.triangles[al];
822
- const p1 = this.triangles[bl];
823
- const coords = this.coords;
824
- 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])) {
825
- return;
826
- }
827
- const hal = this._halfedges[al];
828
- const har = this._halfedges[ar];
829
- const hbl = this._halfedges[bl];
830
- const hbr = this._halfedges[br];
831
- this._queueRemove(a0 / 3);
832
- this._queueRemove(b0 / 3);
833
- const t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);
834
- const t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);
835
- this._legalize(t0 + 1);
836
- this._legalize(t1 + 2);
837
- }
838
- _handleCollinear(pn, a) {
839
- const a0 = a - a % 3;
840
- const al = a0 + (a + 1) % 3;
841
- const ar = a0 + (a + 2) % 3;
842
- const p0 = this.triangles[ar];
843
- const pr = this.triangles[a];
844
- const pl = this.triangles[al];
845
- const hal = this._halfedges[al];
846
- const har = this._halfedges[ar];
847
- const b = this._halfedges[a];
848
- if (b < 0) {
849
- const t02 = this._addTriangle(pn, p0, pr, -1, har, -1, a0);
850
- const t12 = this._addTriangle(p0, pn, pl, t02, -1, hal);
851
- this._legalize(t02 + 1);
852
- this._legalize(t12 + 2);
853
- return;
854
- }
855
- const b0 = b - b % 3;
856
- const bl = b0 + (b + 2) % 3;
857
- const br = b0 + (b + 1) % 3;
858
- const p1 = this.triangles[bl];
859
- const hbl = this._halfedges[bl];
860
- const hbr = this._halfedges[br];
861
- this._queueRemove(b0 / 3);
862
- const t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);
863
- const t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);
864
- const t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);
865
- const t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);
866
- this._legalize(t0);
867
- this._legalize(t1);
868
- this._legalize(t2);
869
- this._legalize(t3);
870
- }
871
- _queuePush(t, error, rms) {
872
- const i = this._queue.length;
873
- this._queueIndices[t] = i;
874
- this._queue.push(t);
875
- this._errors.push(error);
876
- this._rmsSum += rms;
877
- this._queueUp(i);
878
- }
879
- _queuePop() {
880
- const n = this._queue.length - 1;
881
- this._queueSwap(0, n);
882
- this._queueDown(0, n);
883
- return this._queuePopBack();
884
- }
885
- _queuePopBack() {
886
- const t = this._queue.pop();
887
- this._errors.pop();
888
- this._rmsSum -= this._rms[t];
889
- this._queueIndices[t] = -1;
890
- return t;
891
- }
892
- _queueRemove(t) {
893
- const i = this._queueIndices[t];
894
- if (i < 0) {
895
- const it = this._pending.indexOf(t);
896
- if (it !== -1) {
897
- this._pending[it] = this._pending[--this._pendingLen];
898
- } else {
899
- throw new Error("Broken triangulation (something went wrong).");
900
- }
901
- return;
902
- }
903
- const n = this._queue.length - 1;
904
- if (n !== i) {
905
- this._queueSwap(i, n);
906
- if (!this._queueDown(i, n)) {
907
- this._queueUp(i);
908
- }
909
- }
910
- this._queuePopBack();
911
- }
912
- _queueLess(i, j) {
913
- return this._errors[i] > this._errors[j];
914
- }
915
- _queueSwap(i, j) {
916
- const pi = this._queue[i];
917
- const pj = this._queue[j];
918
- this._queue[i] = pj;
919
- this._queue[j] = pi;
920
- this._queueIndices[pi] = j;
921
- this._queueIndices[pj] = i;
922
- const e = this._errors[i];
923
- this._errors[i] = this._errors[j];
924
- this._errors[j] = e;
925
- }
926
- _queueUp(j0) {
927
- let j = j0;
928
- while (true) {
929
- const i = j - 1 >> 1;
930
- if (i === j || !this._queueLess(j, i)) {
931
- break;
932
- }
933
- this._queueSwap(i, j);
934
- j = i;
935
- }
936
- }
937
- _queueDown(i0, n) {
938
- let i = i0;
939
- while (true) {
940
- const j1 = 2 * i + 1;
941
- if (j1 >= n || j1 < 0) {
942
- break;
943
- }
944
- const j2 = j1 + 1;
945
- let j = j1;
946
- if (j2 < n && this._queueLess(j2, j1)) {
947
- j = j2;
948
- }
949
- if (!this._queueLess(j, i)) {
950
- break;
951
- }
952
- this._queueSwap(i, j);
953
- i = j;
954
- }
955
- return i > i0;
956
- }
957
- };
958
- }
959
- });
960
-
961
- // src/lib/parse-terrain.ts
962
- function makeTerrainMeshFromImage(terrainImage, terrainOptions) {
963
- const { meshMaxError, bounds, elevationDecoder } = terrainOptions;
964
- const { data, width, height } = terrainImage;
965
- let terrain;
966
- let mesh;
967
- switch (terrainOptions.tesselator) {
968
- case "martini":
969
- terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
970
- mesh = getMartiniTileMesh(meshMaxError, width, terrain);
971
- break;
972
- case "delatin":
973
- terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
974
- mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);
975
- break;
976
- default:
977
- if (width === height && !(height & width - 1)) {
978
- terrain = getTerrain(data, width, height, elevationDecoder, "martini");
979
- mesh = getMartiniTileMesh(meshMaxError, width, terrain);
980
- } else {
981
- terrain = getTerrain(data, width, height, elevationDecoder, "delatin");
982
- mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);
983
- }
984
- break;
985
- }
986
- const { vertices } = mesh;
987
- let { triangles } = mesh;
988
- let attributes = getMeshAttributes2(vertices, terrain, width, height, bounds);
989
- const boundingBox = getMeshBoundingBox(attributes);
990
- if (terrainOptions.skirtHeight) {
991
- const { attributes: newAttributes, triangles: newTriangles } = addSkirt(attributes, triangles, terrainOptions.skirtHeight);
992
- attributes = newAttributes;
993
- triangles = newTriangles;
994
- }
995
- return {
996
- loaderData: {
997
- header: {}
998
- },
999
- header: {
1000
- vertexCount: triangles.length,
1001
- boundingBox
1002
- },
1003
- mode: 4,
1004
- indices: { value: Uint32Array.from(triangles), size: 1 },
1005
- attributes
1006
- };
1007
- }
1008
- function getMartiniTileMesh(meshMaxError, width, terrain) {
1009
- const gridSize = width + 1;
1010
- const martini = new Martini(gridSize);
1011
- const tile = martini.createTile(terrain);
1012
- const { vertices, triangles } = tile.getMesh(meshMaxError);
1013
- return { vertices, triangles };
1014
- }
1015
- function getDelatinTileMesh(meshMaxError, width, height, terrain) {
1016
- const tin = new Delatin(terrain, width + 1, height + 1);
1017
- tin.run(meshMaxError);
1018
- const { coords, triangles } = tin;
1019
- const vertices = coords;
1020
- return { vertices, triangles };
1021
- }
1022
- function getTerrain(imageData, width, height, elevationDecoder, tesselator) {
1023
- const { rScaler, bScaler, gScaler, offset } = elevationDecoder;
1024
- const terrain = new Float32Array((width + 1) * (height + 1));
1025
- for (let i = 0, y = 0; y < height; y++) {
1026
- for (let x = 0; x < width; x++, i++) {
1027
- const k = i * 4;
1028
- const r = imageData[k + 0];
1029
- const g = imageData[k + 1];
1030
- const b = imageData[k + 2];
1031
- terrain[i + y] = r * rScaler + g * gScaler + b * bScaler + offset;
1032
- }
1033
- }
1034
- if (tesselator === "martini") {
1035
- for (let i = (width + 1) * width, x = 0; x < width; x++, i++) {
1036
- terrain[i] = terrain[i - width - 1];
1037
- }
1038
- for (let i = height, y = 0; y < height + 1; y++, i += height + 1) {
1039
- terrain[i] = terrain[i - 1];
1040
- }
1041
- }
1042
- return terrain;
1043
- }
1044
- function getMeshAttributes2(vertices, terrain, width, height, bounds) {
1045
- const gridSize = width + 1;
1046
- const numOfVerticies = vertices.length / 2;
1047
- const positions = new Float32Array(numOfVerticies * 3);
1048
- const texCoords = new Float32Array(numOfVerticies * 2);
1049
- const [minX, minY, maxX, maxY] = bounds || [0, 0, width, height];
1050
- const xScale = (maxX - minX) / width;
1051
- const yScale = (maxY - minY) / height;
1052
- for (let i = 0; i < numOfVerticies; i++) {
1053
- const x = vertices[i * 2];
1054
- const y = vertices[i * 2 + 1];
1055
- const pixelIdx = y * gridSize + x;
1056
- positions[3 * i + 0] = x * xScale + minX;
1057
- positions[3 * i + 1] = -y * yScale + maxY;
1058
- positions[3 * i + 2] = terrain[pixelIdx];
1059
- texCoords[2 * i + 0] = x / width;
1060
- texCoords[2 * i + 1] = y / height;
1061
- }
1062
- return {
1063
- POSITION: { value: positions, size: 3 },
1064
- TEXCOORD_0: { value: texCoords, size: 2 }
1065
- };
1066
- }
1067
- var init_parse_terrain = __esm({
1068
- "src/lib/parse-terrain.ts"() {
1069
- init_src2();
1070
- init_martini();
1071
- init_delatin();
1072
- init_skirt();
1073
- }
1074
- });
1075
-
1076
- // src/lib/utils/version.ts
1077
- var VERSION;
1078
- var init_version = __esm({
1079
- "src/lib/utils/version.ts"() {
1080
- VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1081
- }
1082
- });
1083
-
1084
- // src/terrain-loader.ts
1085
- var TerrainLoader;
1086
- var init_terrain_loader = __esm({
1087
- "src/terrain-loader.ts"() {
1088
- init_version();
1089
- TerrainLoader = {
1090
- name: "Terrain",
1091
- id: "terrain",
1092
- module: "terrain",
1093
- version: VERSION,
1094
- worker: true,
1095
- extensions: ["png", "pngraw", "jpg", "jpeg", "gif", "webp", "bmp"],
1096
- mimeTypes: ["image/png", "image/jpeg", "image/gif", "image/webp", "image/bmp"],
1097
- options: {
1098
- terrain: {
1099
- tesselator: "auto",
1100
- bounds: void 0,
1101
- meshMaxError: 10,
1102
- elevationDecoder: {
1103
- rScaler: 1,
1104
- gScaler: 0,
1105
- bScaler: 0,
1106
- offset: 0
1107
- },
1108
- skirtHeight: void 0
1109
- }
1110
- }
1111
- };
1112
- }
1113
- });
1114
-
1115
- // src/quantized-mesh-loader.ts
1116
- var QuantizedMeshLoader;
1117
- var init_quantized_mesh_loader = __esm({
1118
- "src/quantized-mesh-loader.ts"() {
1119
- init_version();
1120
- QuantizedMeshLoader = {
1121
- name: "Quantized Mesh",
1122
- id: "quantized-mesh",
1123
- module: "terrain",
1124
- version: VERSION,
1125
- worker: true,
1126
- extensions: ["terrain"],
1127
- mimeTypes: ["application/vnd.quantized-mesh"],
1128
- options: {
1129
- "quantized-mesh": {
1130
- bounds: [0, 0, 1, 1],
1131
- skirtHeight: null
1132
- }
1133
- }
1134
- };
1135
- }
1136
- });
1137
-
1138
- // src/index.ts
1139
- var src_exports = {};
1140
- __export(src_exports, {
1141
- QuantizedMeshLoader: () => QuantizedMeshLoader2,
1142
- QuantizedMeshWorkerLoader: () => QuantizedMeshLoader,
1143
- TerrainLoader: () => TerrainLoader2,
1144
- TerrainWorkerLoader: () => TerrainLoader,
1145
- parseTerrain: () => parseTerrain
1146
- });
1147
- async function parseTerrain(arrayBuffer, options, context) {
1148
- const loadImageOptions = {
1149
- ...options,
1150
- mimeType: "application/x.image",
1151
- image: { ...options?.image, type: "data" }
1152
- };
1153
- const image = await parseFromContext(arrayBuffer, [], loadImageOptions, context);
1154
- const terrainOptions = { ...TerrainLoader2.options.terrain, ...options?.terrain };
1155
- return makeTerrainMeshFromImage(image, terrainOptions);
1156
- }
1157
- var TerrainLoader2, QuantizedMeshLoader2;
1158
- var init_src3 = __esm({
1159
- "src/index.ts"() {
1160
- init_src();
1161
- init_parse_quantized_mesh();
1162
- init_parse_terrain();
1163
- init_terrain_loader();
1164
- init_quantized_mesh_loader();
1165
- TerrainLoader2 = {
1166
- ...TerrainLoader,
1167
- parse: parseTerrain
1168
- };
1169
- QuantizedMeshLoader2 = {
1170
- ...QuantizedMeshLoader,
1171
- parseSync: (arrayBuffer, options) => parseQuantizedMesh(arrayBuffer, options?.["quantized-mesh"]),
1172
- parse: async (arrayBuffer, options) => parseQuantizedMesh(arrayBuffer, options?.["quantized-mesh"])
1173
- };
1174
- }
1175
- });
1176
-
1177
- // src/bundle.ts
1178
- var require_bundle = __commonJS({
1179
- "src/bundle.ts"(exports, module) {
1180
- var moduleExports = (init_src3(), src_exports);
1181
- globalThis.loaders = globalThis.loaders || {};
1182
- module.exports = Object.assign(globalThis.loaders, moduleExports);
1183
- }
1184
- });
1185
- require_bundle();
1186
- })();