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