@loaders.gl/terrain 4.2.0-alpha.3 → 4.2.0-alpha.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/dist/dist.dev.js CHANGED
@@ -2,14 +2,19 @@
2
2
  if (typeof exports === 'object' && typeof module === 'object')
3
3
  module.exports = factory();
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
- else if (typeof exports === 'object') exports['loader'] = factory();
6
- else root['loader'] = factory();})(globalThis, function () {
5
+ else if (typeof exports === 'object') exports['loaders'] = factory();
6
+ else root['loaders'] = factory();})(globalThis, function () {
7
7
  "use strict";
8
8
  var __exports__ = (() => {
9
+ var __create = Object.create;
9
10
  var __defProp = Object.defineProperty;
10
11
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __getProtoOf = Object.getPrototypeOf;
12
14
  var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __commonJS = (cb, mod) => function __require() {
16
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
+ };
13
18
  var __export = (target, all) => {
14
19
  for (var name in all)
15
20
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -22,17 +27,34 @@ var __exports__ = (() => {
22
27
  }
23
28
  return to;
24
29
  };
30
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
+ // If the importer is in node compatibility mode or this is not an ESM
33
+ // file that has been converted to a CommonJS file using a Babel-
34
+ // compatible transform (i.e. "__esModule" has not been set), then set
35
+ // "default" to the CommonJS "module.exports" for node compatibility.
36
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
+ mod
38
+ ));
25
39
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
40
 
27
- // src/index.ts
28
- var src_exports = {};
29
- __export(src_exports, {
41
+ // external-global-plugin:@loaders.gl/core
42
+ var require_core = __commonJS({
43
+ "external-global-plugin:@loaders.gl/core"(exports, module) {
44
+ module.exports = globalThis.loaders;
45
+ }
46
+ });
47
+
48
+ // bundle.ts
49
+ var bundle_exports = {};
50
+ __export(bundle_exports, {
30
51
  QuantizedMeshLoader: () => QuantizedMeshLoader2,
31
52
  QuantizedMeshWorkerLoader: () => QuantizedMeshLoader,
32
53
  TerrainLoader: () => TerrainLoader2,
33
54
  TerrainWorkerLoader: () => TerrainLoader,
34
55
  parseTerrain: () => parseTerrain
35
56
  });
57
+ __reExport(bundle_exports, __toESM(require_core(), 1));
36
58
 
37
59
  // ../loader-utils/src/loader-types.ts
38
60
  async function parseFromContext(data, loaders, options, context) {
@@ -44,7 +66,9 @@ var __exports__ = (() => {
44
66
  const arrays = typedArrays;
45
67
  const TypedArrayConstructor = arrays && arrays.length > 1 && arrays[0].constructor || null;
46
68
  if (!TypedArrayConstructor) {
47
- throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types');
69
+ throw new Error(
70
+ '"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types'
71
+ );
48
72
  }
49
73
  const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);
50
74
  const result = new TypedArrayConstructor(sumLength);
@@ -77,11 +101,27 @@ var __exports__ = (() => {
77
101
  maxY = y > maxY ? y : maxY;
78
102
  maxZ = z > maxZ ? z : maxZ;
79
103
  }
80
- return [[minX, minY, minZ], [maxX, maxY, maxZ]];
104
+ return [
105
+ [minX, minY, minZ],
106
+ [maxX, maxY, maxZ]
107
+ ];
81
108
  }
82
109
 
83
110
  // src/lib/decode-quantized-mesh.ts
84
- var QUANTIZED_MESH_HEADER = /* @__PURE__ */ new Map([["centerX", Float64Array.BYTES_PER_ELEMENT], ["centerY", Float64Array.BYTES_PER_ELEMENT], ["centerZ", Float64Array.BYTES_PER_ELEMENT], ["minHeight", Float32Array.BYTES_PER_ELEMENT], ["maxHeight", Float32Array.BYTES_PER_ELEMENT], ["boundingSphereCenterX", Float64Array.BYTES_PER_ELEMENT], ["boundingSphereCenterY", Float64Array.BYTES_PER_ELEMENT], ["boundingSphereCenterZ", Float64Array.BYTES_PER_ELEMENT], ["boundingSphereRadius", Float64Array.BYTES_PER_ELEMENT], ["horizonOcclusionPointX", Float64Array.BYTES_PER_ELEMENT], ["horizonOcclusionPointY", Float64Array.BYTES_PER_ELEMENT], ["horizonOcclusionPointZ", Float64Array.BYTES_PER_ELEMENT]]);
111
+ var QUANTIZED_MESH_HEADER = /* @__PURE__ */ new Map([
112
+ ["centerX", Float64Array.BYTES_PER_ELEMENT],
113
+ ["centerY", Float64Array.BYTES_PER_ELEMENT],
114
+ ["centerZ", Float64Array.BYTES_PER_ELEMENT],
115
+ ["minHeight", Float32Array.BYTES_PER_ELEMENT],
116
+ ["maxHeight", Float32Array.BYTES_PER_ELEMENT],
117
+ ["boundingSphereCenterX", Float64Array.BYTES_PER_ELEMENT],
118
+ ["boundingSphereCenterY", Float64Array.BYTES_PER_ELEMENT],
119
+ ["boundingSphereCenterZ", Float64Array.BYTES_PER_ELEMENT],
120
+ ["boundingSphereRadius", Float64Array.BYTES_PER_ELEMENT],
121
+ ["horizonOcclusionPointX", Float64Array.BYTES_PER_ELEMENT],
122
+ ["horizonOcclusionPointY", Float64Array.BYTES_PER_ELEMENT],
123
+ ["horizonOcclusionPointZ", Float64Array.BYTES_PER_ELEMENT]
124
+ ]);
85
125
  function decodeZigZag(value) {
86
126
  return value >> 1 ^ -(value & 1);
87
127
  }
@@ -93,10 +133,7 @@ var __exports__ = (() => {
93
133
  header[key] = getter.call(dataView, position, true);
94
134
  position += bytesCount;
95
135
  }
96
- return {
97
- header,
98
- headerEndPosition: position
99
- };
136
+ return { header, headerEndPosition: position };
100
137
  }
101
138
  function decodeVertexData(dataView, headerEndPosition) {
102
139
  let position = headerEndPosition;
@@ -115,16 +152,15 @@ var __exports__ = (() => {
115
152
  for (let i = 0; i < vertexCount; i++) {
116
153
  u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));
117
154
  v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));
118
- height += decodeZigZag(dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true));
155
+ height += decodeZigZag(
156
+ dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true)
157
+ );
119
158
  vertexData[i] = u;
120
159
  vertexData[i + vertexCount] = v;
121
160
  vertexData[i + vertexCount * 2] = height;
122
161
  }
123
162
  position += elementArrayLength * 3;
124
- return {
125
- vertexData,
126
- vertexDataEndPosition: position
127
- };
163
+ return { vertexData, vertexDataEndPosition: position };
128
164
  }
129
165
  function decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = true) {
130
166
  let indices;
@@ -157,7 +193,12 @@ var __exports__ = (() => {
157
193
  const triangleCount = dataView.getUint32(position, true);
158
194
  position += Uint32Array.BYTES_PER_ELEMENT;
159
195
  const triangleIndicesCount = triangleCount * 3;
160
- const triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex);
196
+ const triangleIndices = decodeIndex(
197
+ dataView.buffer,
198
+ position,
199
+ triangleIndicesCount,
200
+ bytesPerIndex
201
+ );
161
202
  position += triangleIndicesCount * bytesPerIndex;
162
203
  return {
163
204
  triangleIndicesEndPosition: position,
@@ -175,7 +216,13 @@ var __exports__ = (() => {
175
216
  position += westVertexCount * bytesPerIndex;
176
217
  const southVertexCount = dataView.getUint32(position, true);
177
218
  position += Uint32Array.BYTES_PER_ELEMENT;
178
- const southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false);
219
+ const southIndices = decodeIndex(
220
+ dataView.buffer,
221
+ position,
222
+ southVertexCount,
223
+ bytesPerIndex,
224
+ false
225
+ );
179
226
  position += southVertexCount * bytesPerIndex;
180
227
  const eastVertexCount = dataView.getUint32(position, true);
181
228
  position += Uint32Array.BYTES_PER_ELEMENT;
@@ -183,7 +230,13 @@ var __exports__ = (() => {
183
230
  position += eastVertexCount * bytesPerIndex;
184
231
  const northVertexCount = dataView.getUint32(position, true);
185
232
  position += Uint32Array.BYTES_PER_ELEMENT;
186
- const northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false);
233
+ const northIndices = decodeIndex(
234
+ dataView.buffer,
235
+ position,
236
+ northVertexCount,
237
+ bytesPerIndex,
238
+ false
239
+ );
187
240
  position += northVertexCount * bytesPerIndex;
188
241
  return {
189
242
  edgeIndicesEndPosition: position,
@@ -194,18 +247,22 @@ var __exports__ = (() => {
194
247
  };
195
248
  }
196
249
  function decodeVertexNormalsExtension(extensionDataView) {
197
- return new Uint8Array(extensionDataView.buffer, extensionDataView.byteOffset, extensionDataView.byteLength);
250
+ return new Uint8Array(
251
+ extensionDataView.buffer,
252
+ extensionDataView.byteOffset,
253
+ extensionDataView.byteLength
254
+ );
198
255
  }
199
256
  function decodeWaterMaskExtension(extensionDataView) {
200
- return extensionDataView.buffer.slice(extensionDataView.byteOffset, extensionDataView.byteOffset + extensionDataView.byteLength);
257
+ return extensionDataView.buffer.slice(
258
+ extensionDataView.byteOffset,
259
+ extensionDataView.byteOffset + extensionDataView.byteLength
260
+ );
201
261
  }
202
262
  function decodeExtensions(dataView, indicesEndPosition) {
203
263
  const extensions = {};
204
264
  if (dataView.byteLength <= indicesEndPosition) {
205
- return {
206
- extensions,
207
- extensionsEndPosition: indicesEndPosition
208
- };
265
+ return { extensions, extensionsEndPosition: indicesEndPosition };
209
266
  }
210
267
  let position = indicesEndPosition;
211
268
  while (position < dataView.byteLength) {
@@ -228,10 +285,7 @@ var __exports__ = (() => {
228
285
  }
229
286
  position += extensionLength;
230
287
  }
231
- return {
232
- extensions,
233
- extensionsEndPosition: position
234
- };
288
+ return { extensions, extensionsEndPosition: position };
235
289
  }
236
290
  var DECODING_STEPS = {
237
291
  header: 0,
@@ -246,43 +300,23 @@ var __exports__ = (() => {
246
300
  function decode(data, userOptions) {
247
301
  const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
248
302
  const view = new DataView(data);
249
- const {
250
- header,
251
- headerEndPosition
252
- } = decodeHeader(view);
303
+ const { header, headerEndPosition } = decodeHeader(view);
253
304
  if (options.maxDecodingStep < DECODING_STEPS.vertices) {
254
- return {
255
- header
256
- };
305
+ return { header };
257
306
  }
258
- const {
259
- vertexData,
260
- vertexDataEndPosition
261
- } = decodeVertexData(view, headerEndPosition);
307
+ const { vertexData, vertexDataEndPosition } = decodeVertexData(view, headerEndPosition);
262
308
  if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {
263
- return {
264
- header,
265
- vertexData
266
- };
309
+ return { header, vertexData };
267
310
  }
268
- const {
269
- triangleIndices,
270
- triangleIndicesEndPosition
271
- } = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
311
+ const { triangleIndices, triangleIndicesEndPosition } = decodeTriangleIndices(
312
+ view,
313
+ vertexData,
314
+ vertexDataEndPosition
315
+ );
272
316
  if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {
273
- return {
274
- header,
275
- vertexData,
276
- triangleIndices
277
- };
317
+ return { header, vertexData, triangleIndices };
278
318
  }
279
- const {
280
- westIndices,
281
- southIndices,
282
- eastIndices,
283
- northIndices,
284
- edgeIndicesEndPosition
285
- } = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
319
+ const { westIndices, southIndices, eastIndices, northIndices, edgeIndicesEndPosition } = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
286
320
  if (options.maxDecodingStep < DECODING_STEPS.extensions) {
287
321
  return {
288
322
  header,
@@ -294,9 +328,7 @@ var __exports__ = (() => {
294
328
  southIndices
295
329
  };
296
330
  }
297
- const {
298
- extensions
299
- } = decodeExtensions(view, edgeIndicesEndPosition);
331
+ const { extensions } = decodeExtensions(view, edgeIndicesEndPosition);
300
332
  return {
301
333
  header,
302
334
  vertexData,
@@ -381,12 +413,24 @@ var __exports__ = (() => {
381
413
  const positionsLength = attributes.POSITION.value.length;
382
414
  const vertex1Offset = edgeIndex * 2;
383
415
  const vertex2Offset = edgeIndex * 2 + 1;
384
- newPosition.set(attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), vertex1Offset * 3);
416
+ newPosition.set(
417
+ attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3),
418
+ vertex1Offset * 3
419
+ );
385
420
  newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight;
386
- newPosition.set(attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3), vertex2Offset * 3);
421
+ newPosition.set(
422
+ attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3),
423
+ vertex2Offset * 3
424
+ );
387
425
  newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight;
388
- newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2), vertex1Offset * 2);
389
- newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), vertex2Offset * 2);
426
+ newTexcoord0.set(
427
+ attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2),
428
+ vertex1Offset * 2
429
+ );
430
+ newTexcoord0.set(
431
+ attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2),
432
+ vertex2Offset * 2
433
+ );
390
434
  const triangle1Offset = edgeIndex * 2 * 3;
391
435
  newTriangles[triangle1Offset] = edge[0];
392
436
  newTriangles[triangle1Offset + 1] = positionsLength / 3 + vertex2Offset;
@@ -398,9 +442,7 @@ var __exports__ = (() => {
398
442
 
399
443
  // src/lib/parse-quantized-mesh.ts
400
444
  function parseQuantizedMesh(arrayBuffer, options = {}) {
401
- const {
402
- bounds
403
- } = options;
445
+ const { bounds } = options;
404
446
  const {
405
447
  header,
406
448
  vertexData,
@@ -414,41 +456,41 @@ var __exports__ = (() => {
414
456
  let attributes = getMeshAttributes(vertexData, header, bounds);
415
457
  const boundingBox = getMeshBoundingBox(attributes);
416
458
  if (options?.skirtHeight) {
417
- const {
418
- attributes: newAttributes,
419
- triangles: newTriangles
420
- } = addSkirt(attributes, triangleIndices, options.skirtHeight, {
421
- westIndices,
422
- northIndices,
423
- eastIndices,
424
- southIndices
425
- });
459
+ const { attributes: newAttributes, triangles: newTriangles } = addSkirt(
460
+ attributes,
461
+ triangleIndices,
462
+ options.skirtHeight,
463
+ {
464
+ westIndices,
465
+ northIndices,
466
+ eastIndices,
467
+ southIndices
468
+ }
469
+ );
426
470
  attributes = newAttributes;
427
471
  triangleIndices = newTriangles;
428
472
  }
429
473
  return {
474
+ // Data return by this loader implementation
430
475
  loaderData: {
431
476
  header: {}
432
477
  },
433
478
  header: {
479
+ // @ts-ignore
434
480
  vertexCount: triangleIndices.length,
435
481
  boundingBox
436
482
  },
483
+ // TODO
437
484
  schema: void 0,
438
485
  topology: "triangle-list",
439
486
  mode: 4,
440
- indices: {
441
- value: triangleIndices,
442
- size: 1
443
- },
487
+ // TRIANGLES
488
+ indices: { value: triangleIndices, size: 1 },
444
489
  attributes
445
490
  };
446
491
  }
447
492
  function getMeshAttributes(vertexData, header, bounds) {
448
- const {
449
- minHeight,
450
- maxHeight
451
- } = header;
493
+ const { minHeight, maxHeight } = header;
452
494
  const [minX, minY, maxX, maxY] = bounds || [0, 0, 1, 1];
453
495
  const xScale = maxX - minX;
454
496
  const yScale = maxY - minY;
@@ -467,14 +509,10 @@ var __exports__ = (() => {
467
509
  texCoords[2 * i + 1] = y;
468
510
  }
469
511
  return {
470
- POSITION: {
471
- value: positions,
472
- size: 3
473
- },
474
- TEXCOORD_0: {
475
- value: texCoords,
476
- size: 2
477
- }
512
+ POSITION: { value: positions, size: 3 },
513
+ TEXCOORD_0: { value: texCoords, size: 2 }
514
+ // TODO: Parse normals if they exist in the file
515
+ // NORMAL: {}, - optional, but creates the high poly look with lighting
478
516
  };
479
517
  }
480
518
 
@@ -642,24 +680,30 @@ var __exports__ = (() => {
642
680
  this._addTriangle(p0, p3, p1, t0, -1, -1);
643
681
  this._flush();
644
682
  }
683
+ // refine the mesh until its maximum error gets below the given one
645
684
  run(maxError = 1) {
646
685
  while (this.getMaxError() > maxError) {
647
686
  this.refine();
648
687
  }
649
688
  }
689
+ // refine the mesh with a single point
650
690
  refine() {
651
691
  this._step();
652
692
  this._flush();
653
693
  }
694
+ // max error of the current mesh
654
695
  getMaxError() {
655
696
  return this._errors[0];
656
697
  }
698
+ // root-mean-square deviation of the current mesh
657
699
  getRMSD() {
658
700
  return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;
659
701
  }
702
+ // height value at a given position
660
703
  heightAt(x, y) {
661
704
  return this.data[this.width * y + x];
662
705
  }
706
+ // rasterize and queue all triangles that got added or updated in _step
663
707
  _flush() {
664
708
  const coords = this.coords;
665
709
  for (let i = 0; i < this._pendingLen; i++) {
@@ -667,10 +711,19 @@ var __exports__ = (() => {
667
711
  const a = 2 * this.triangles[t * 3 + 0];
668
712
  const b = 2 * this.triangles[t * 3 + 1];
669
713
  const c = 2 * this.triangles[t * 3 + 2];
670
- this._findCandidate(coords[a], coords[a + 1], coords[b], coords[b + 1], coords[c], coords[c + 1], t);
714
+ this._findCandidate(
715
+ coords[a],
716
+ coords[a + 1],
717
+ coords[b],
718
+ coords[b + 1],
719
+ coords[c],
720
+ coords[c + 1],
721
+ t
722
+ );
671
723
  }
672
724
  this._pendingLen = 0;
673
725
  }
726
+ // rasterize a triangle, find its max error, and queue it for processing
674
727
  _findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {
675
728
  const minX = Math.min(p0x, p1x, p2x);
676
729
  const minY = Math.min(p0y, p1y, p2y);
@@ -738,6 +791,7 @@ var __exports__ = (() => {
738
791
  this._rms[t] = rms;
739
792
  this._queuePush(t, maxError, rms);
740
793
  }
794
+ // process the next triangle in the queue, splitting it with a new point
741
795
  _step() {
742
796
  const t = this._queuePop();
743
797
  const e0 = t * 3 + 0;
@@ -773,11 +827,13 @@ var __exports__ = (() => {
773
827
  this._legalize(t2);
774
828
  }
775
829
  }
830
+ // add coordinates for a new vertex
776
831
  _addPoint(x, y) {
777
832
  const i = this.coords.length >> 1;
778
833
  this.coords.push(x, y);
779
834
  return i;
780
835
  }
836
+ // add or update a triangle in the mesh
781
837
  _addTriangle(a, b, c, ab, bc, ca, e = this.triangles.length) {
782
838
  const t = e / 3;
783
839
  this.triangles[e + 0] = a;
@@ -818,7 +874,16 @@ var __exports__ = (() => {
818
874
  const pl = this.triangles[al];
819
875
  const p1 = this.triangles[bl];
820
876
  const coords = this.coords;
821
- 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])) {
877
+ if (!inCircle(
878
+ coords[2 * p0],
879
+ coords[2 * p0 + 1],
880
+ coords[2 * pr],
881
+ coords[2 * pr + 1],
882
+ coords[2 * pl],
883
+ coords[2 * pl + 1],
884
+ coords[2 * p1],
885
+ coords[2 * p1 + 1]
886
+ )) {
822
887
  return;
823
888
  }
824
889
  const hal = this._halfedges[al];
@@ -832,6 +897,7 @@ var __exports__ = (() => {
832
897
  this._legalize(t0 + 1);
833
898
  this._legalize(t1 + 2);
834
899
  }
900
+ // handle a case where new vertex is on the edge of a triangle
835
901
  _handleCollinear(pn, a) {
836
902
  const a0 = a - a % 3;
837
903
  const al = a0 + (a + 1) % 3;
@@ -865,6 +931,7 @@ var __exports__ = (() => {
865
931
  this._legalize(t2);
866
932
  this._legalize(t3);
867
933
  }
934
+ // priority queue methods
868
935
  _queuePush(t, error, rms) {
869
936
  const i = this._queue.length;
870
937
  this._queueIndices[t] = i;
@@ -970,16 +1037,8 @@ var __exports__ = (() => {
970
1037
 
971
1038
  // src/lib/parse-terrain.ts
972
1039
  function makeTerrainMeshFromImage(terrainImage, terrainOptions) {
973
- const {
974
- meshMaxError,
975
- bounds,
976
- elevationDecoder
977
- } = terrainOptions;
978
- const {
979
- data,
980
- width,
981
- height
982
- } = terrainImage;
1040
+ const { meshMaxError, bounds, elevationDecoder } = terrainOptions;
1041
+ const { data, width, height } = terrainImage;
983
1042
  let terrain;
984
1043
  let mesh;
985
1044
  switch (terrainOptions.tesselator) {
@@ -1001,23 +1060,21 @@ var __exports__ = (() => {
1001
1060
  }
1002
1061
  break;
1003
1062
  }
1004
- const {
1005
- vertices
1006
- } = mesh;
1007
- let {
1008
- triangles
1009
- } = mesh;
1063
+ const { vertices } = mesh;
1064
+ let { triangles } = mesh;
1010
1065
  let attributes = getMeshAttributes2(vertices, terrain, width, height, bounds);
1011
1066
  const boundingBox = getMeshBoundingBox(attributes);
1012
1067
  if (terrainOptions.skirtHeight) {
1013
- const {
1014
- attributes: newAttributes,
1015
- triangles: newTriangles
1016
- } = addSkirt(attributes, triangles, terrainOptions.skirtHeight);
1068
+ const { attributes: newAttributes, triangles: newTriangles } = addSkirt(
1069
+ attributes,
1070
+ triangles,
1071
+ terrainOptions.skirtHeight
1072
+ );
1017
1073
  attributes = newAttributes;
1018
1074
  triangles = newTriangles;
1019
1075
  }
1020
1076
  return {
1077
+ // Data return by this loader implementation
1021
1078
  loaderData: {
1022
1079
  header: {}
1023
1080
  },
@@ -1026,10 +1083,8 @@ var __exports__ = (() => {
1026
1083
  boundingBox
1027
1084
  },
1028
1085
  mode: 4,
1029
- indices: {
1030
- value: Uint32Array.from(triangles),
1031
- size: 1
1032
- },
1086
+ // TRIANGLES
1087
+ indices: { value: Uint32Array.from(triangles), size: 1 },
1033
1088
  attributes
1034
1089
  };
1035
1090
  }
@@ -1037,35 +1092,18 @@ var __exports__ = (() => {
1037
1092
  const gridSize = width + 1;
1038
1093
  const martini = new Martini(gridSize);
1039
1094
  const tile = martini.createTile(terrain);
1040
- const {
1041
- vertices,
1042
- triangles
1043
- } = tile.getMesh(meshMaxError);
1044
- return {
1045
- vertices,
1046
- triangles
1047
- };
1095
+ const { vertices, triangles } = tile.getMesh(meshMaxError);
1096
+ return { vertices, triangles };
1048
1097
  }
1049
1098
  function getDelatinTileMesh(meshMaxError, width, height, terrain) {
1050
1099
  const tin = new Delatin(terrain, width + 1, height + 1);
1051
1100
  tin.run(meshMaxError);
1052
- const {
1053
- coords,
1054
- triangles
1055
- } = tin;
1101
+ const { coords, triangles } = tin;
1056
1102
  const vertices = coords;
1057
- return {
1058
- vertices,
1059
- triangles
1060
- };
1103
+ return { vertices, triangles };
1061
1104
  }
1062
1105
  function getTerrain(imageData, width, height, elevationDecoder, tesselator) {
1063
- const {
1064
- rScaler,
1065
- bScaler,
1066
- gScaler,
1067
- offset
1068
- } = elevationDecoder;
1106
+ const { rScaler, bScaler, gScaler, offset } = elevationDecoder;
1069
1107
  const terrain = new Float32Array((width + 1) * (height + 1));
1070
1108
  for (let i = 0, y = 0; y < height; y++) {
1071
1109
  for (let x = 0; x < width; x++, i++) {
@@ -1105,19 +1143,14 @@ var __exports__ = (() => {
1105
1143
  texCoords[2 * i + 1] = y / height;
1106
1144
  }
1107
1145
  return {
1108
- POSITION: {
1109
- value: positions,
1110
- size: 3
1111
- },
1112
- TEXCOORD_0: {
1113
- value: texCoords,
1114
- size: 2
1115
- }
1146
+ POSITION: { value: positions, size: 3 },
1147
+ TEXCOORD_0: { value: texCoords, size: 2 }
1148
+ // NORMAL: {}, - optional, but creates the high poly look with lighting
1116
1149
  };
1117
1150
  }
1118
1151
 
1119
1152
  // src/lib/utils/version.ts
1120
- var VERSION = true ? "4.2.0-alpha.3" : "latest";
1153
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1121
1154
 
1122
1155
  // src/terrain-loader.ts
1123
1156
  var TerrainLoader = {
@@ -1170,16 +1203,10 @@ var __exports__ = (() => {
1170
1203
  const loadImageOptions = {
1171
1204
  ...options,
1172
1205
  mimeType: "application/x.image",
1173
- image: {
1174
- ...options?.image,
1175
- type: "data"
1176
- }
1206
+ image: { ...options?.image, type: "data" }
1177
1207
  };
1178
1208
  const image = await parseFromContext(arrayBuffer, [], loadImageOptions, context);
1179
- const terrainOptions = {
1180
- ...TerrainLoader2.options.terrain,
1181
- ...options?.terrain
1182
- };
1209
+ const terrainOptions = { ...TerrainLoader2.options.terrain, ...options?.terrain };
1183
1210
  return makeTerrainMeshFromImage(image, terrainOptions);
1184
1211
  }
1185
1212
  var QuantizedMeshLoader2 = {
@@ -1187,7 +1214,7 @@ var __exports__ = (() => {
1187
1214
  parseSync: (arrayBuffer, options) => parseQuantizedMesh(arrayBuffer, options?.["quantized-mesh"]),
1188
1215
  parse: async (arrayBuffer, options) => parseQuantizedMesh(arrayBuffer, options?.["quantized-mesh"])
1189
1216
  };
1190
- return __toCommonJS(src_exports);
1217
+ return __toCommonJS(bundle_exports);
1191
1218
  })();
1192
1219
  return __exports__;
1193
1220
  });