@loaders.gl/terrain 4.0.0-alpha.22 → 4.0.0-alpha.24

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.
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.VERSION = void 0;
7
- var VERSION = typeof "4.0.0-alpha.22" !== 'undefined' ? "4.0.0-alpha.22" : 'latest';
7
+ var VERSION = typeof "4.0.0-alpha.24" !== 'undefined' ? "4.0.0-alpha.24" : 'latest';
8
8
  exports.VERSION = VERSION;
9
9
  //# sourceMappingURL=version.js.map
@@ -1,2 +1,2 @@
1
- export const VERSION = typeof "4.0.0-alpha.22" !== 'undefined' ? "4.0.0-alpha.22" : 'latest';
1
+ export const VERSION = typeof "4.0.0-alpha.24" !== 'undefined' ? "4.0.0-alpha.24" : 'latest';
2
2
  //# sourceMappingURL=version.js.map
@@ -1187,7 +1187,7 @@
1187
1187
  }
1188
1188
 
1189
1189
  // src/lib/utils/version.ts
1190
- var VERSION = true ? "4.0.0-alpha.22" : "latest";
1190
+ var VERSION = true ? "4.0.0-alpha.24" : "latest";
1191
1191
 
1192
1192
  // src/terrain-loader.ts
1193
1193
  var TerrainLoader = {
@@ -1187,7 +1187,7 @@
1187
1187
  }
1188
1188
 
1189
1189
  // src/lib/utils/version.ts
1190
- var VERSION = true ? "4.0.0-alpha.22" : "latest";
1190
+ var VERSION = true ? "4.0.0-alpha.24" : "latest";
1191
1191
 
1192
1192
  // src/terrain-loader.ts
1193
1193
  var TerrainLoader = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/terrain",
3
- "version": "4.0.0-alpha.22",
3
+ "version": "4.0.0-alpha.24",
4
4
  "description": "Framework-independent loader for terrain raster formats",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@babel/runtime": "^7.3.1",
38
- "@loaders.gl/images": "4.0.0-alpha.22",
39
- "@loaders.gl/loader-utils": "4.0.0-alpha.22",
40
- "@loaders.gl/schema": "4.0.0-alpha.22",
38
+ "@loaders.gl/images": "4.0.0-alpha.24",
39
+ "@loaders.gl/loader-utils": "4.0.0-alpha.24",
40
+ "@loaders.gl/schema": "4.0.0-alpha.24",
41
41
  "@mapbox/martini": "^0.2.0"
42
42
  },
43
- "gitHead": "0da838c506d1275383f2fd3d244d9c72b25397d2"
43
+ "gitHead": "97a8990595c132fb14e3445a8768d9f4cb98ff05"
44
44
  }
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
package/dist/index.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QuantizedMeshLoader = exports.QuantizedMeshWorkerLoader = exports.parseTerrain = exports.TerrainLoader = exports.TerrainWorkerLoader = void 0;
4
- const loader_utils_1 = require("@loaders.gl/loader-utils");
5
- const parse_quantized_mesh_1 = require("./lib/parse-quantized-mesh");
6
- const parse_terrain_1 = require("./lib/parse-terrain");
7
- const terrain_loader_1 = require("./terrain-loader");
8
- Object.defineProperty(exports, "TerrainWorkerLoader", { enumerable: true, get: function () { return terrain_loader_1.TerrainLoader; } });
9
- const quantized_mesh_loader_1 = require("./quantized-mesh-loader");
10
- Object.defineProperty(exports, "QuantizedMeshWorkerLoader", { enumerable: true, get: function () { return quantized_mesh_loader_1.QuantizedMeshLoader; } });
11
- exports.TerrainLoader = {
12
- ...terrain_loader_1.TerrainLoader,
13
- parse: parseTerrain
14
- };
15
- async function parseTerrain(arrayBuffer, options, context) {
16
- const loadImageOptions = {
17
- ...options,
18
- mimeType: 'application/x.image',
19
- image: { ...options?.image, type: 'data' }
20
- };
21
- const image = await (0, loader_utils_1.parseFromContext)(arrayBuffer, [], loadImageOptions, context);
22
- // Extend function to support additional mesh generation options (square grid or delatin)
23
- const terrainOptions = { ...exports.TerrainLoader.options.terrain, ...options?.terrain };
24
- // @ts-expect-error sort out image typing asap
25
- return (0, parse_terrain_1.makeTerrainMeshFromImage)(image, terrainOptions);
26
- }
27
- exports.parseTerrain = parseTerrain;
28
- /**
29
- * Loader for quantized meshes
30
- */
31
- exports.QuantizedMeshLoader = {
32
- ...quantized_mesh_loader_1.QuantizedMeshLoader,
33
- parseSync: (arrayBuffer, options) => (0, parse_quantized_mesh_1.parseQuantizedMesh)(arrayBuffer, options?.['quantized-mesh']),
34
- parse: async (arrayBuffer, options) => (0, parse_quantized_mesh_1.parseQuantizedMesh)(arrayBuffer, options?.['quantized-mesh'])
35
- };
@@ -1,227 +0,0 @@
1
- "use strict";
2
- // Copyright (C) 2018-2019 HERE Europe B.V.
3
- //
4
- // Permission is hereby granted, free of charge, to any person obtaining a copy
5
- // of this software and associated documentation files (the "Software"), to deal
6
- // in the Software without restriction, including without limitation the rights
7
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- // copies of the Software, and to permit persons to whom the Software is
9
- // furnished to do so, subject to the following conditions:
10
- //
11
- // The above copyright notice and this permission notice shall be included in
12
- // all copies or substantial portions of the Software.
13
- //
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- // SOFTWARE.
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.DECODING_STEPS = void 0;
23
- const QUANTIZED_MESH_HEADER = new Map([
24
- ['centerX', Float64Array.BYTES_PER_ELEMENT],
25
- ['centerY', Float64Array.BYTES_PER_ELEMENT],
26
- ['centerZ', Float64Array.BYTES_PER_ELEMENT],
27
- ['minHeight', Float32Array.BYTES_PER_ELEMENT],
28
- ['maxHeight', Float32Array.BYTES_PER_ELEMENT],
29
- ['boundingSphereCenterX', Float64Array.BYTES_PER_ELEMENT],
30
- ['boundingSphereCenterY', Float64Array.BYTES_PER_ELEMENT],
31
- ['boundingSphereCenterZ', Float64Array.BYTES_PER_ELEMENT],
32
- ['boundingSphereRadius', Float64Array.BYTES_PER_ELEMENT],
33
- ['horizonOcclusionPointX', Float64Array.BYTES_PER_ELEMENT],
34
- ['horizonOcclusionPointY', Float64Array.BYTES_PER_ELEMENT],
35
- ['horizonOcclusionPointZ', Float64Array.BYTES_PER_ELEMENT]
36
- ]);
37
- function decodeZigZag(value) {
38
- return (value >> 1) ^ -(value & 1);
39
- }
40
- function decodeHeader(dataView) {
41
- let position = 0;
42
- const header = {};
43
- for (const [key, bytesCount] of QUANTIZED_MESH_HEADER) {
44
- const getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;
45
- header[key] = getter.call(dataView, position, true);
46
- position += bytesCount;
47
- }
48
- return { header, headerEndPosition: position };
49
- }
50
- function decodeVertexData(dataView, headerEndPosition) {
51
- let position = headerEndPosition;
52
- const elementsPerVertex = 3;
53
- const vertexCount = dataView.getUint32(position, true);
54
- const vertexData = new Uint16Array(vertexCount * elementsPerVertex);
55
- position += Uint32Array.BYTES_PER_ELEMENT;
56
- const bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;
57
- const elementArrayLength = vertexCount * bytesPerArrayElement;
58
- const uArrayStartPosition = position;
59
- const vArrayStartPosition = uArrayStartPosition + elementArrayLength;
60
- const heightArrayStartPosition = vArrayStartPosition + elementArrayLength;
61
- let u = 0;
62
- let v = 0;
63
- let height = 0;
64
- for (let i = 0; i < vertexCount; i++) {
65
- u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));
66
- v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));
67
- height += decodeZigZag(dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true));
68
- vertexData[i] = u;
69
- vertexData[i + vertexCount] = v;
70
- vertexData[i + vertexCount * 2] = height;
71
- }
72
- position += elementArrayLength * 3;
73
- return { vertexData, vertexDataEndPosition: position };
74
- }
75
- function decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = true) {
76
- let indices;
77
- if (bytesPerIndex === 2) {
78
- indices = new Uint16Array(buffer, position, indicesCount);
79
- }
80
- else {
81
- indices = new Uint32Array(buffer, position, indicesCount);
82
- }
83
- if (!encoded) {
84
- return indices;
85
- }
86
- let highest = 0;
87
- for (let i = 0; i < indices.length; ++i) {
88
- const code = indices[i];
89
- indices[i] = highest - code;
90
- if (code === 0) {
91
- ++highest;
92
- }
93
- }
94
- return indices;
95
- }
96
- function decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {
97
- let position = vertexDataEndPosition;
98
- const elementsPerVertex = 3;
99
- const vertexCount = vertexData.length / elementsPerVertex;
100
- const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
101
- if (position % bytesPerIndex !== 0) {
102
- position += bytesPerIndex - (position % bytesPerIndex);
103
- }
104
- const triangleCount = dataView.getUint32(position, true);
105
- position += Uint32Array.BYTES_PER_ELEMENT;
106
- const triangleIndicesCount = triangleCount * 3;
107
- const triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex);
108
- position += triangleIndicesCount * bytesPerIndex;
109
- return {
110
- triangleIndicesEndPosition: position,
111
- triangleIndices
112
- };
113
- }
114
- function decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {
115
- let position = triangleIndicesEndPosition;
116
- const elementsPerVertex = 3;
117
- const vertexCount = vertexData.length / elementsPerVertex;
118
- const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
119
- const westVertexCount = dataView.getUint32(position, true);
120
- position += Uint32Array.BYTES_PER_ELEMENT;
121
- const westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);
122
- position += westVertexCount * bytesPerIndex;
123
- const southVertexCount = dataView.getUint32(position, true);
124
- position += Uint32Array.BYTES_PER_ELEMENT;
125
- const southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false);
126
- position += southVertexCount * bytesPerIndex;
127
- const eastVertexCount = dataView.getUint32(position, true);
128
- position += Uint32Array.BYTES_PER_ELEMENT;
129
- const eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);
130
- position += eastVertexCount * bytesPerIndex;
131
- const northVertexCount = dataView.getUint32(position, true);
132
- position += Uint32Array.BYTES_PER_ELEMENT;
133
- const northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false);
134
- position += northVertexCount * bytesPerIndex;
135
- return {
136
- edgeIndicesEndPosition: position,
137
- westIndices,
138
- southIndices,
139
- eastIndices,
140
- northIndices
141
- };
142
- }
143
- function decodeVertexNormalsExtension(extensionDataView) {
144
- return new Uint8Array(extensionDataView.buffer, extensionDataView.byteOffset, extensionDataView.byteLength);
145
- }
146
- function decodeWaterMaskExtension(extensionDataView) {
147
- return extensionDataView.buffer.slice(extensionDataView.byteOffset, extensionDataView.byteOffset + extensionDataView.byteLength);
148
- }
149
- function decodeExtensions(dataView, indicesEndPosition) {
150
- const extensions = {};
151
- if (dataView.byteLength <= indicesEndPosition) {
152
- return { extensions, extensionsEndPosition: indicesEndPosition };
153
- }
154
- let position = indicesEndPosition;
155
- while (position < dataView.byteLength) {
156
- const extensionId = dataView.getUint8(position, true);
157
- position += Uint8Array.BYTES_PER_ELEMENT;
158
- const extensionLength = dataView.getUint32(position, true);
159
- position += Uint32Array.BYTES_PER_ELEMENT;
160
- const extensionView = new DataView(dataView.buffer, position, extensionLength);
161
- switch (extensionId) {
162
- case 1: {
163
- extensions.vertexNormals = decodeVertexNormalsExtension(extensionView);
164
- break;
165
- }
166
- case 2: {
167
- extensions.waterMask = decodeWaterMaskExtension(extensionView);
168
- break;
169
- }
170
- default: {
171
- // console.warn(`Unknown extension with id ${extensionId}`)
172
- }
173
- }
174
- position += extensionLength;
175
- }
176
- return { extensions, extensionsEndPosition: position };
177
- }
178
- exports.DECODING_STEPS = {
179
- header: 0,
180
- vertices: 1,
181
- triangleIndices: 2,
182
- edgeIndices: 3,
183
- extensions: 4
184
- };
185
- const DEFAULT_OPTIONS = {
186
- maxDecodingStep: exports.DECODING_STEPS.extensions
187
- };
188
- function decode(data, userOptions) {
189
- const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
190
- const view = new DataView(data);
191
- const { header, headerEndPosition } = decodeHeader(view);
192
- if (options.maxDecodingStep < exports.DECODING_STEPS.vertices) {
193
- return { header };
194
- }
195
- const { vertexData, vertexDataEndPosition } = decodeVertexData(view, headerEndPosition);
196
- if (options.maxDecodingStep < exports.DECODING_STEPS.triangleIndices) {
197
- return { header, vertexData };
198
- }
199
- const { triangleIndices, triangleIndicesEndPosition } = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
200
- if (options.maxDecodingStep < exports.DECODING_STEPS.edgeIndices) {
201
- return { header, vertexData, triangleIndices };
202
- }
203
- const { westIndices, southIndices, eastIndices, northIndices, edgeIndicesEndPosition } = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
204
- if (options.maxDecodingStep < exports.DECODING_STEPS.extensions) {
205
- return {
206
- header,
207
- vertexData,
208
- triangleIndices,
209
- westIndices,
210
- northIndices,
211
- eastIndices,
212
- southIndices
213
- };
214
- }
215
- const { extensions } = decodeExtensions(view, edgeIndicesEndPosition);
216
- return {
217
- header,
218
- vertexData,
219
- triangleIndices,
220
- westIndices,
221
- northIndices,
222
- eastIndices,
223
- southIndices,
224
- extensions
225
- };
226
- }
227
- exports.default = decode;
@@ -1,418 +0,0 @@
1
- "use strict";
2
- // ISC License
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- // Copyright(c) 2019, Michael Fogleman, Vladimir Agafonkin
5
- // Permission to use, copy, modify, and / or distribute this software for any purpose
6
- // with or without fee is hereby granted, provided that the above copyright notice
7
- // and this permission notice appear in all copies.
8
- // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
- // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
10
- // FITNESS.IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
- // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
12
- // OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
13
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
14
- // THIS SOFTWARE.
15
- // @ts-nocheck
16
- /* eslint-disable complexity, max-params, max-statements, max-depth, no-constant-condition */
17
- class Delatin {
18
- constructor(data, width, height = width) {
19
- this.data = data; // height data
20
- this.width = width;
21
- this.height = height;
22
- this.coords = []; // vertex coordinates (x, y)
23
- this.triangles = []; // mesh triangle indices
24
- // additional triangle data
25
- this._halfedges = [];
26
- this._candidates = [];
27
- this._queueIndices = [];
28
- this._queue = []; // queue of added triangles
29
- this._errors = [];
30
- this._rms = [];
31
- this._pending = []; // triangles pending addition to queue
32
- this._pendingLen = 0;
33
- this._rmsSum = 0;
34
- const x1 = width - 1;
35
- const y1 = height - 1;
36
- const p0 = this._addPoint(0, 0);
37
- const p1 = this._addPoint(x1, 0);
38
- const p2 = this._addPoint(0, y1);
39
- const p3 = this._addPoint(x1, y1);
40
- // add initial two triangles
41
- const t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);
42
- this._addTriangle(p0, p3, p1, t0, -1, -1);
43
- this._flush();
44
- }
45
- // refine the mesh until its maximum error gets below the given one
46
- run(maxError = 1) {
47
- while (this.getMaxError() > maxError) {
48
- this.refine();
49
- }
50
- }
51
- // refine the mesh with a single point
52
- refine() {
53
- this._step();
54
- this._flush();
55
- }
56
- // max error of the current mesh
57
- getMaxError() {
58
- return this._errors[0];
59
- }
60
- // root-mean-square deviation of the current mesh
61
- getRMSD() {
62
- return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;
63
- }
64
- // height value at a given position
65
- heightAt(x, y) {
66
- return this.data[this.width * y + x];
67
- }
68
- // rasterize and queue all triangles that got added or updated in _step
69
- _flush() {
70
- const coords = this.coords;
71
- for (let i = 0; i < this._pendingLen; i++) {
72
- const t = this._pending[i];
73
- // rasterize triangle to find maximum pixel error
74
- const a = 2 * this.triangles[t * 3 + 0];
75
- const b = 2 * this.triangles[t * 3 + 1];
76
- const c = 2 * this.triangles[t * 3 + 2];
77
- this._findCandidate(coords[a], coords[a + 1], coords[b], coords[b + 1], coords[c], coords[c + 1], t);
78
- }
79
- this._pendingLen = 0;
80
- }
81
- // rasterize a triangle, find its max error, and queue it for processing
82
- _findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {
83
- // triangle bounding box
84
- const minX = Math.min(p0x, p1x, p2x);
85
- const minY = Math.min(p0y, p1y, p2y);
86
- const maxX = Math.max(p0x, p1x, p2x);
87
- const maxY = Math.max(p0y, p1y, p2y);
88
- // forward differencing variables
89
- let w00 = orient(p1x, p1y, p2x, p2y, minX, minY);
90
- let w01 = orient(p2x, p2y, p0x, p0y, minX, minY);
91
- let w02 = orient(p0x, p0y, p1x, p1y, minX, minY);
92
- const a01 = p1y - p0y;
93
- const b01 = p0x - p1x;
94
- const a12 = p2y - p1y;
95
- const b12 = p1x - p2x;
96
- const a20 = p0y - p2y;
97
- const b20 = p2x - p0x;
98
- // pre-multiplied z values at vertices
99
- const a = orient(p0x, p0y, p1x, p1y, p2x, p2y);
100
- const z0 = this.heightAt(p0x, p0y) / a;
101
- const z1 = this.heightAt(p1x, p1y) / a;
102
- const z2 = this.heightAt(p2x, p2y) / a;
103
- // iterate over pixels in bounding box
104
- let maxError = 0;
105
- let mx = 0;
106
- let my = 0;
107
- let rms = 0;
108
- for (let y = minY; y <= maxY; y++) {
109
- // compute starting offset
110
- let dx = 0;
111
- if (w00 < 0 && a12 !== 0) {
112
- dx = Math.max(dx, Math.floor(-w00 / a12));
113
- }
114
- if (w01 < 0 && a20 !== 0) {
115
- dx = Math.max(dx, Math.floor(-w01 / a20));
116
- }
117
- if (w02 < 0 && a01 !== 0) {
118
- dx = Math.max(dx, Math.floor(-w02 / a01));
119
- }
120
- let w0 = w00 + a12 * dx;
121
- let w1 = w01 + a20 * dx;
122
- let w2 = w02 + a01 * dx;
123
- let wasInside = false;
124
- for (let x = minX + dx; x <= maxX; x++) {
125
- // check if inside triangle
126
- if (w0 >= 0 && w1 >= 0 && w2 >= 0) {
127
- wasInside = true;
128
- // compute z using barycentric coordinates
129
- const z = z0 * w0 + z1 * w1 + z2 * w2;
130
- const dz = Math.abs(z - this.heightAt(x, y));
131
- rms += dz * dz;
132
- if (dz > maxError) {
133
- maxError = dz;
134
- mx = x;
135
- my = y;
136
- }
137
- }
138
- else if (wasInside) {
139
- break;
140
- }
141
- w0 += a12;
142
- w1 += a20;
143
- w2 += a01;
144
- }
145
- w00 += b12;
146
- w01 += b20;
147
- w02 += b01;
148
- }
149
- if ((mx === p0x && my === p0y) || (mx === p1x && my === p1y) || (mx === p2x && my === p2y)) {
150
- maxError = 0;
151
- }
152
- // update triangle metadata
153
- this._candidates[2 * t] = mx;
154
- this._candidates[2 * t + 1] = my;
155
- this._rms[t] = rms;
156
- // add triangle to priority queue
157
- this._queuePush(t, maxError, rms);
158
- }
159
- // process the next triangle in the queue, splitting it with a new point
160
- _step() {
161
- // pop triangle with highest error from priority queue
162
- const t = this._queuePop();
163
- const e0 = t * 3 + 0;
164
- const e1 = t * 3 + 1;
165
- const e2 = t * 3 + 2;
166
- const p0 = this.triangles[e0];
167
- const p1 = this.triangles[e1];
168
- const p2 = this.triangles[e2];
169
- const ax = this.coords[2 * p0];
170
- const ay = this.coords[2 * p0 + 1];
171
- const bx = this.coords[2 * p1];
172
- const by = this.coords[2 * p1 + 1];
173
- const cx = this.coords[2 * p2];
174
- const cy = this.coords[2 * p2 + 1];
175
- const px = this._candidates[2 * t];
176
- const py = this._candidates[2 * t + 1];
177
- const pn = this._addPoint(px, py);
178
- if (orient(ax, ay, bx, by, px, py) === 0) {
179
- this._handleCollinear(pn, e0);
180
- }
181
- else if (orient(bx, by, cx, cy, px, py) === 0) {
182
- this._handleCollinear(pn, e1);
183
- }
184
- else if (orient(cx, cy, ax, ay, px, py) === 0) {
185
- this._handleCollinear(pn, e2);
186
- }
187
- else {
188
- const h0 = this._halfedges[e0];
189
- const h1 = this._halfedges[e1];
190
- const h2 = this._halfedges[e2];
191
- const t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);
192
- const t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);
193
- const t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);
194
- this._legalize(t0);
195
- this._legalize(t1);
196
- this._legalize(t2);
197
- }
198
- }
199
- // add coordinates for a new vertex
200
- _addPoint(x, y) {
201
- const i = this.coords.length >> 1;
202
- this.coords.push(x, y);
203
- return i;
204
- }
205
- // add or update a triangle in the mesh
206
- _addTriangle(a, b, c, ab, bc, ca, e = this.triangles.length) {
207
- const t = e / 3; // new triangle index
208
- // add triangle vertices
209
- this.triangles[e + 0] = a;
210
- this.triangles[e + 1] = b;
211
- this.triangles[e + 2] = c;
212
- // add triangle halfedges
213
- this._halfedges[e + 0] = ab;
214
- this._halfedges[e + 1] = bc;
215
- this._halfedges[e + 2] = ca;
216
- // link neighboring halfedges
217
- if (ab >= 0) {
218
- this._halfedges[ab] = e + 0;
219
- }
220
- if (bc >= 0) {
221
- this._halfedges[bc] = e + 1;
222
- }
223
- if (ca >= 0) {
224
- this._halfedges[ca] = e + 2;
225
- }
226
- // init triangle metadata
227
- this._candidates[2 * t + 0] = 0;
228
- this._candidates[2 * t + 1] = 0;
229
- this._queueIndices[t] = -1;
230
- this._rms[t] = 0;
231
- // add triangle to pending queue for later rasterization
232
- this._pending[this._pendingLen++] = t;
233
- // return first halfedge index
234
- return e;
235
- }
236
- _legalize(a) {
237
- // if the pair of triangles doesn't satisfy the Delaunay condition
238
- // (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
239
- // then do the same check/flip recursively for the new pair of triangles
240
- //
241
- // pl pl
242
- // /||\ / \
243
- // al/ || \bl al/ \a
244
- // / || \ / \
245
- // / a||b \ flip /___ar___\
246
- // p0\ || /p1 => p0\---bl---/p1
247
- // \ || / \ /
248
- // ar\ || /br b\ /br
249
- // \||/ \ /
250
- // pr pr
251
- const b = this._halfedges[a];
252
- if (b < 0) {
253
- return;
254
- }
255
- const a0 = a - (a % 3);
256
- const b0 = b - (b % 3);
257
- const al = a0 + ((a + 1) % 3);
258
- const ar = a0 + ((a + 2) % 3);
259
- const bl = b0 + ((b + 2) % 3);
260
- const br = b0 + ((b + 1) % 3);
261
- const p0 = this.triangles[ar];
262
- const pr = this.triangles[a];
263
- const pl = this.triangles[al];
264
- const p1 = this.triangles[bl];
265
- const coords = this.coords;
266
- 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])) {
267
- return;
268
- }
269
- const hal = this._halfedges[al];
270
- const har = this._halfedges[ar];
271
- const hbl = this._halfedges[bl];
272
- const hbr = this._halfedges[br];
273
- this._queueRemove(a0 / 3);
274
- this._queueRemove(b0 / 3);
275
- const t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);
276
- const t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);
277
- this._legalize(t0 + 1);
278
- this._legalize(t1 + 2);
279
- }
280
- // handle a case where new vertex is on the edge of a triangle
281
- _handleCollinear(pn, a) {
282
- const a0 = a - (a % 3);
283
- const al = a0 + ((a + 1) % 3);
284
- const ar = a0 + ((a + 2) % 3);
285
- const p0 = this.triangles[ar];
286
- const pr = this.triangles[a];
287
- const pl = this.triangles[al];
288
- const hal = this._halfedges[al];
289
- const har = this._halfedges[ar];
290
- const b = this._halfedges[a];
291
- if (b < 0) {
292
- const t0 = this._addTriangle(pn, p0, pr, -1, har, -1, a0);
293
- const t1 = this._addTriangle(p0, pn, pl, t0, -1, hal);
294
- this._legalize(t0 + 1);
295
- this._legalize(t1 + 2);
296
- return;
297
- }
298
- const b0 = b - (b % 3);
299
- const bl = b0 + ((b + 2) % 3);
300
- const br = b0 + ((b + 1) % 3);
301
- const p1 = this.triangles[bl];
302
- const hbl = this._halfedges[bl];
303
- const hbr = this._halfedges[br];
304
- this._queueRemove(b0 / 3);
305
- const t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);
306
- const t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);
307
- const t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);
308
- const t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);
309
- this._legalize(t0);
310
- this._legalize(t1);
311
- this._legalize(t2);
312
- this._legalize(t3);
313
- }
314
- // priority queue methods
315
- _queuePush(t, error, rms) {
316
- const i = this._queue.length;
317
- this._queueIndices[t] = i;
318
- this._queue.push(t);
319
- this._errors.push(error);
320
- this._rmsSum += rms;
321
- this._queueUp(i);
322
- }
323
- _queuePop() {
324
- const n = this._queue.length - 1;
325
- this._queueSwap(0, n);
326
- this._queueDown(0, n);
327
- return this._queuePopBack();
328
- }
329
- _queuePopBack() {
330
- const t = this._queue.pop();
331
- this._errors.pop();
332
- this._rmsSum -= this._rms[t];
333
- this._queueIndices[t] = -1;
334
- return t;
335
- }
336
- _queueRemove(t) {
337
- const i = this._queueIndices[t];
338
- if (i < 0) {
339
- const it = this._pending.indexOf(t);
340
- if (it !== -1) {
341
- this._pending[it] = this._pending[--this._pendingLen];
342
- }
343
- else {
344
- throw new Error('Broken triangulation (something went wrong).');
345
- }
346
- return;
347
- }
348
- const n = this._queue.length - 1;
349
- if (n !== i) {
350
- this._queueSwap(i, n);
351
- if (!this._queueDown(i, n)) {
352
- this._queueUp(i);
353
- }
354
- }
355
- this._queuePopBack();
356
- }
357
- _queueLess(i, j) {
358
- return this._errors[i] > this._errors[j];
359
- }
360
- _queueSwap(i, j) {
361
- const pi = this._queue[i];
362
- const pj = this._queue[j];
363
- this._queue[i] = pj;
364
- this._queue[j] = pi;
365
- this._queueIndices[pi] = j;
366
- this._queueIndices[pj] = i;
367
- const e = this._errors[i];
368
- this._errors[i] = this._errors[j];
369
- this._errors[j] = e;
370
- }
371
- _queueUp(j0) {
372
- let j = j0;
373
- while (true) {
374
- const i = (j - 1) >> 1;
375
- if (i === j || !this._queueLess(j, i)) {
376
- break;
377
- }
378
- this._queueSwap(i, j);
379
- j = i;
380
- }
381
- }
382
- _queueDown(i0, n) {
383
- let i = i0;
384
- while (true) {
385
- const j1 = 2 * i + 1;
386
- if (j1 >= n || j1 < 0) {
387
- break;
388
- }
389
- const j2 = j1 + 1;
390
- let j = j1;
391
- if (j2 < n && this._queueLess(j2, j1)) {
392
- j = j2;
393
- }
394
- if (!this._queueLess(j, i)) {
395
- break;
396
- }
397
- this._queueSwap(i, j);
398
- i = j;
399
- }
400
- return i > i0;
401
- }
402
- }
403
- exports.default = Delatin;
404
- function orient(ax, ay, bx, by, cx, cy) {
405
- return (bx - cx) * (ay - cy) - (by - cy) * (ax - cx);
406
- }
407
- function inCircle(ax, ay, bx, by, cx, cy, px, py) {
408
- const dx = ax - px;
409
- const dy = ay - py;
410
- const ex = bx - px;
411
- const ey = by - py;
412
- const fx = cx - px;
413
- const fy = cy - py;
414
- const ap = dx * dx + dy * dy;
415
- const bp = ex * ex + ey * ey;
416
- const cp = fx * fx + fy * fy;
417
- return dx * (ey * cp - bp * fy) - dy * (ex * cp - bp * fx) + ap * (ex * fy - ey * fx) < 0;
418
- }
@@ -1,127 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addSkirt = void 0;
4
- const loader_utils_1 = require("@loaders.gl/loader-utils");
5
- /**
6
- * Add skirt to existing mesh
7
- * @param {object} attributes - POSITION and TEXCOOD_0 attributes data
8
- * @param {any} triangles - indices array of the mesh geometry
9
- * @param skirtHeight - height of the skirt geometry
10
- * @param outsideIndices - edge indices from quantized mesh data
11
- * @returns - geometry data with added skirt
12
- */
13
- function addSkirt(attributes, triangles, skirtHeight, outsideIndices) {
14
- const outsideEdges = outsideIndices
15
- ? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value)
16
- : getOutsideEdgesFromTriangles(triangles);
17
- // 2 new vertices for each outside edge
18
- const newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);
19
- const newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);
20
- // 2 new triangles for each outside edge
21
- const newTriangles = new triangles.constructor(outsideEdges.length * 6);
22
- for (let i = 0; i < outsideEdges.length; i++) {
23
- const edge = outsideEdges[i];
24
- updateAttributesForNewEdge({
25
- edge,
26
- edgeIndex: i,
27
- attributes,
28
- skirtHeight,
29
- newPosition,
30
- newTexcoord0,
31
- newTriangles
32
- });
33
- }
34
- attributes.POSITION.value = (0, loader_utils_1.concatenateTypedArrays)(attributes.POSITION.value, newPosition);
35
- attributes.TEXCOORD_0.value = (0, loader_utils_1.concatenateTypedArrays)(attributes.TEXCOORD_0.value, newTexcoord0);
36
- const resultTriangles = triangles instanceof Array
37
- ? triangles.concat(newTriangles)
38
- : (0, loader_utils_1.concatenateTypedArrays)(triangles, newTriangles);
39
- return {
40
- attributes,
41
- triangles: resultTriangles
42
- };
43
- }
44
- exports.addSkirt = addSkirt;
45
- /**
46
- * Get geometry edges that located on a border of the mesh
47
- * @param {any} triangles - indices array of the mesh geometry
48
- * @returns {number[][]} - outside edges data
49
- */
50
- function getOutsideEdgesFromTriangles(triangles) {
51
- const edges = [];
52
- for (let i = 0; i < triangles.length; i += 3) {
53
- edges.push([triangles[i], triangles[i + 1]]);
54
- edges.push([triangles[i + 1], triangles[i + 2]]);
55
- edges.push([triangles[i + 2], triangles[i]]);
56
- }
57
- edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
58
- const outsideEdges = [];
59
- let index = 0;
60
- while (index < edges.length) {
61
- if (edges[index][0] === edges[index + 1]?.[1] && edges[index][1] === edges[index + 1]?.[0]) {
62
- index += 2;
63
- }
64
- else {
65
- outsideEdges.push(edges[index]);
66
- index++;
67
- }
68
- }
69
- return outsideEdges;
70
- }
71
- /**
72
- * Get geometry edges that located on a border of the mesh
73
- * @param {object} indices - edge indices from quantized mesh data
74
- * @param {TypedArray} position - position attribute geometry data
75
- * @returns {number[][]} - outside edges data
76
- */
77
- function getOutsideEdgesFromIndices(indices, position) {
78
- // Sort skirt indices to create adjacent triangles
79
- indices.westIndices.sort((a, b) => position[3 * a + 1] - position[3 * b + 1]);
80
- // Reverse (b - a) to match triangle winding
81
- indices.eastIndices.sort((a, b) => position[3 * b + 1] - position[3 * a + 1]);
82
- indices.southIndices.sort((a, b) => position[3 * b] - position[3 * a]);
83
- // Reverse (b - a) to match triangle winding
84
- indices.northIndices.sort((a, b) => position[3 * a] - position[3 * b]);
85
- const edges = [];
86
- for (const index in indices) {
87
- const indexGroup = indices[index];
88
- for (let i = 0; i < indexGroup.length - 1; i++) {
89
- edges.push([indexGroup[i], indexGroup[i + 1]]);
90
- }
91
- }
92
- return edges;
93
- }
94
- /**
95
- * Get geometry edges that located on a border of the mesh
96
- * @param {object} args
97
- * @param {number[]} args.edge - edge indices in geometry
98
- * @param {number} args.edgeIndex - edge index in outsideEdges array
99
- * @param {object} args.attributes - POSITION and TEXCOORD_0 attributes
100
- * @param {number} args.skirtHeight - height of the skirt geometry
101
- * @param {TypedArray} args.newPosition - POSITION array for skirt data
102
- * @param {TypedArray} args.newTexcoord0 - TEXCOORD_0 array for skirt data
103
- * @param {TypedArray | Array} args.newTriangles - trinagle indices array for skirt data
104
- * @returns {void}
105
- */
106
- function updateAttributesForNewEdge({ edge, edgeIndex, attributes, skirtHeight, newPosition, newTexcoord0, newTriangles }) {
107
- const positionsLength = attributes.POSITION.value.length;
108
- const vertex1Offset = edgeIndex * 2;
109
- const vertex2Offset = edgeIndex * 2 + 1;
110
- // Define POSITION for new 1st vertex
111
- newPosition.set(attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), vertex1Offset * 3);
112
- newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight; // put down elevation on the skirt height
113
- // Define POSITION for new 2nd vertex
114
- newPosition.set(attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3), vertex2Offset * 3);
115
- newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight; // put down elevation on the skirt height
116
- // Use same TEXCOORDS for skirt vertices
117
- newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2), vertex1Offset * 2);
118
- newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), vertex2Offset * 2);
119
- // Define new triangles
120
- const triangle1Offset = edgeIndex * 2 * 3;
121
- newTriangles[triangle1Offset] = edge[0];
122
- newTriangles[triangle1Offset + 1] = positionsLength / 3 + vertex2Offset;
123
- newTriangles[triangle1Offset + 2] = edge[1];
124
- newTriangles[triangle1Offset + 3] = positionsLength / 3 + vertex2Offset;
125
- newTriangles[triangle1Offset + 4] = edge[0];
126
- newTriangles[triangle1Offset + 5] = positionsLength / 3 + vertex1Offset;
127
- }
@@ -1,97 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.parseQuantizedMesh = void 0;
27
- const schema_1 = require("@loaders.gl/schema");
28
- const decode_quantized_mesh_1 = __importStar(require("./decode-quantized-mesh"));
29
- const skirt_1 = require("./helpers/skirt");
30
- function parseQuantizedMesh(arrayBuffer, options = {}) {
31
- const { bounds } = options;
32
- // Don't parse edge indices or format extensions
33
- const { header, vertexData, triangleIndices: originalTriangleIndices, westIndices, northIndices, eastIndices, southIndices } = (0, decode_quantized_mesh_1.default)(arrayBuffer, decode_quantized_mesh_1.DECODING_STEPS.triangleIndices);
34
- let triangleIndices = originalTriangleIndices;
35
- let attributes = getMeshAttributes(vertexData, header, bounds);
36
- // Compute bounding box before adding skirt so that z values are not skewed
37
- // TODO: Find bounding box from header, instead of doing extra pass over
38
- // vertices.
39
- const boundingBox = (0, schema_1.getMeshBoundingBox)(attributes);
40
- if (options?.skirtHeight) {
41
- const { attributes: newAttributes, triangles: newTriangles } = (0, skirt_1.addSkirt)(attributes, triangleIndices, options.skirtHeight, {
42
- westIndices,
43
- northIndices,
44
- eastIndices,
45
- southIndices
46
- });
47
- attributes = newAttributes;
48
- triangleIndices = newTriangles;
49
- }
50
- return {
51
- // Data return by this loader implementation
52
- loaderData: {
53
- header: {}
54
- },
55
- header: {
56
- // @ts-ignore
57
- vertexCount: triangleIndices.length,
58
- boundingBox
59
- },
60
- // TODO
61
- schema: undefined,
62
- topology: 'triangle-list',
63
- mode: 4,
64
- indices: { value: triangleIndices, size: 1 },
65
- attributes
66
- };
67
- }
68
- exports.parseQuantizedMesh = parseQuantizedMesh;
69
- function getMeshAttributes(vertexData, header, bounds) {
70
- const { minHeight, maxHeight } = header;
71
- const [minX, minY, maxX, maxY] = bounds || [0, 0, 1, 1];
72
- const xScale = maxX - minX;
73
- const yScale = maxY - minY;
74
- const zScale = maxHeight - minHeight;
75
- const nCoords = vertexData.length / 3;
76
- // vec3. x, y defined by bounds, z in meters
77
- const positions = new Float32Array(nCoords * 3);
78
- // vec2. 1 to 1 relationship with position. represents the uv on the texture image. 0,0 to 1,1.
79
- const texCoords = new Float32Array(nCoords * 2);
80
- // Data is not interleaved; all u, then all v, then all heights
81
- for (let i = 0; i < nCoords; i++) {
82
- const x = vertexData[i] / 32767;
83
- const y = vertexData[i + nCoords] / 32767;
84
- const z = vertexData[i + nCoords * 2] / 32767;
85
- positions[3 * i + 0] = x * xScale + minX;
86
- positions[3 * i + 1] = y * yScale + minY;
87
- positions[3 * i + 2] = z * zScale + minHeight;
88
- texCoords[2 * i + 0] = x;
89
- texCoords[2 * i + 1] = y;
90
- }
91
- return {
92
- POSITION: { value: positions, size: 3 },
93
- TEXCOORD_0: { value: texCoords, size: 2 }
94
- // TODO: Parse normals if they exist in the file
95
- // NORMAL: {}, - optional, but creates the high poly look with lighting
96
- };
97
- }
@@ -1,154 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.makeTerrainMeshFromImage = void 0;
8
- const schema_1 = require("@loaders.gl/schema");
9
- const martini_1 = __importDefault(require("@mapbox/martini"));
10
- const delatin_1 = __importDefault(require("./delatin"));
11
- const skirt_1 = require("./helpers/skirt");
12
- /**
13
- * Returns generated mesh object from image data
14
- *
15
- * @param terrainImage terrain image data
16
- * @param terrainOptions terrain options
17
- * @returns mesh object
18
- */
19
- function makeTerrainMeshFromImage(terrainImage, terrainOptions) {
20
- const { meshMaxError, bounds, elevationDecoder } = terrainOptions;
21
- const { data, width, height } = terrainImage;
22
- let terrain;
23
- let mesh;
24
- switch (terrainOptions.tesselator) {
25
- case 'martini':
26
- terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
27
- mesh = getMartiniTileMesh(meshMaxError, width, terrain);
28
- break;
29
- case 'delatin':
30
- terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
31
- mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);
32
- break;
33
- // auto
34
- default:
35
- if (width === height && !(height & (width - 1))) {
36
- terrain = getTerrain(data, width, height, elevationDecoder, 'martini');
37
- mesh = getMartiniTileMesh(meshMaxError, width, terrain);
38
- }
39
- else {
40
- terrain = getTerrain(data, width, height, elevationDecoder, 'delatin');
41
- mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);
42
- }
43
- break;
44
- }
45
- const { vertices } = mesh;
46
- let { triangles } = mesh;
47
- let attributes = getMeshAttributes(vertices, terrain, width, height, bounds);
48
- // Compute bounding box before adding skirt so that z values are not skewed
49
- const boundingBox = (0, schema_1.getMeshBoundingBox)(attributes);
50
- if (terrainOptions.skirtHeight) {
51
- const { attributes: newAttributes, triangles: newTriangles } = (0, skirt_1.addSkirt)(attributes, triangles, terrainOptions.skirtHeight);
52
- attributes = newAttributes;
53
- triangles = newTriangles;
54
- }
55
- return {
56
- // Data return by this loader implementation
57
- loaderData: {
58
- header: {}
59
- },
60
- header: {
61
- vertexCount: triangles.length,
62
- boundingBox
63
- },
64
- mode: 4,
65
- indices: { value: Uint32Array.from(triangles), size: 1 },
66
- attributes
67
- };
68
- }
69
- exports.makeTerrainMeshFromImage = makeTerrainMeshFromImage;
70
- /**
71
- * Get Martini generated vertices and triangles
72
- *
73
- * @param {number} meshMaxError threshold for simplifying mesh
74
- * @param {number} width width of the input data
75
- * @param {number[] | Float32Array} terrain elevation data
76
- * @returns {{vertices: Uint16Array, triangles: Uint32Array}} vertices and triangles data
77
- */
78
- function getMartiniTileMesh(meshMaxError, width, terrain) {
79
- const gridSize = width + 1;
80
- const martini = new martini_1.default(gridSize);
81
- const tile = martini.createTile(terrain);
82
- const { vertices, triangles } = tile.getMesh(meshMaxError);
83
- return { vertices, triangles };
84
- }
85
- /**
86
- * Get Delatin generated vertices and triangles
87
- *
88
- * @param {number} meshMaxError threshold for simplifying mesh
89
- * @param {number} width width of the input data array
90
- * @param {number} height height of the input data array
91
- * @param {number[] | Float32Array} terrain elevation data
92
- * @returns {{vertices: number[], triangles: number[]}} vertices and triangles data
93
- */
94
- function getDelatinTileMesh(meshMaxError, width, height, terrain) {
95
- const tin = new delatin_1.default(terrain, width + 1, height + 1);
96
- tin.run(meshMaxError);
97
- // @ts-expect-error
98
- const { coords, triangles } = tin;
99
- const vertices = coords;
100
- return { vertices, triangles };
101
- }
102
- function getTerrain(imageData, width, height, elevationDecoder, tesselator) {
103
- const { rScaler, bScaler, gScaler, offset } = elevationDecoder;
104
- // From Martini demo
105
- // https://observablehq.com/@mourner/martin-real-time-rtin-terrain-mesh
106
- const terrain = new Float32Array((width + 1) * (height + 1));
107
- // decode terrain values
108
- for (let i = 0, y = 0; y < height; y++) {
109
- for (let x = 0; x < width; x++, i++) {
110
- const k = i * 4;
111
- const r = imageData[k + 0];
112
- const g = imageData[k + 1];
113
- const b = imageData[k + 2];
114
- terrain[i + y] = r * rScaler + g * gScaler + b * bScaler + offset;
115
- }
116
- }
117
- if (tesselator === 'martini') {
118
- // backfill bottom border
119
- for (let i = (width + 1) * width, x = 0; x < width; x++, i++) {
120
- terrain[i] = terrain[i - width - 1];
121
- }
122
- // backfill right border
123
- for (let i = height, y = 0; y < height + 1; y++, i += height + 1) {
124
- terrain[i] = terrain[i - 1];
125
- }
126
- }
127
- return terrain;
128
- }
129
- function getMeshAttributes(vertices, terrain, width, height, bounds) {
130
- const gridSize = width + 1;
131
- const numOfVerticies = vertices.length / 2;
132
- // vec3. x, y in pixels, z in meters
133
- const positions = new Float32Array(numOfVerticies * 3);
134
- // vec2. 1 to 1 relationship with position. represents the uv on the texture image. 0,0 to 1,1.
135
- const texCoords = new Float32Array(numOfVerticies * 2);
136
- const [minX, minY, maxX, maxY] = bounds || [0, 0, width, height];
137
- const xScale = (maxX - minX) / width;
138
- const yScale = (maxY - minY) / height;
139
- for (let i = 0; i < numOfVerticies; i++) {
140
- const x = vertices[i * 2];
141
- const y = vertices[i * 2 + 1];
142
- const pixelIdx = y * gridSize + x;
143
- positions[3 * i + 0] = x * xScale + minX;
144
- positions[3 * i + 1] = -y * yScale + maxY;
145
- positions[3 * i + 2] = terrain[pixelIdx];
146
- texCoords[2 * i + 0] = x / width;
147
- texCoords[2 * i + 1] = y / height;
148
- }
149
- return {
150
- POSITION: { value: positions, size: 3 },
151
- TEXCOORD_0: { value: texCoords, size: 2 }
152
- // NORMAL: {}, - optional, but creates the high poly look with lighting
153
- };
154
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VERSION = void 0;
4
- // Version constant cannot be imported, it needs to correspond to the build version of **this** module.
5
- // __VERSION__ is injected by babel-plugin-version-inline
6
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
- exports.VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QuantizedMeshLoader = void 0;
4
- const version_1 = require("./lib/utils/version");
5
- /**
6
- * Worker loader for quantized meshes
7
- */
8
- exports.QuantizedMeshLoader = {
9
- name: 'Quantized Mesh',
10
- id: 'quantized-mesh',
11
- module: 'terrain',
12
- version: version_1.VERSION,
13
- worker: true,
14
- extensions: ['terrain'],
15
- mimeTypes: ['application/vnd.quantized-mesh'],
16
- options: {
17
- 'quantized-mesh': {
18
- bounds: [0, 0, 1, 1],
19
- skirtHeight: null
20
- }
21
- }
22
- };
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TerrainLoader = void 0;
4
- const version_1 = require("./lib/utils/version");
5
- /**
6
- * Worker loader for image encoded terrain
7
- */
8
- exports.TerrainLoader = {
9
- name: 'Terrain',
10
- id: 'terrain',
11
- module: 'terrain',
12
- version: version_1.VERSION,
13
- worker: true,
14
- extensions: ['png', 'pngraw', 'jpg', 'jpeg', 'gif', 'webp', 'bmp'],
15
- mimeTypes: ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/bmp'],
16
- options: {
17
- terrain: {
18
- tesselator: 'auto',
19
- bounds: undefined,
20
- meshMaxError: 10,
21
- elevationDecoder: {
22
- rScaler: 1,
23
- gScaler: 0,
24
- bScaler: 0,
25
- offset: 0
26
- },
27
- skirtHeight: undefined
28
- }
29
- }
30
- };
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const loader_utils_1 = require("@loaders.gl/loader-utils");
4
- const index_1 = require("../index");
5
- (0, loader_utils_1.createLoaderWorker)(index_1.QuantizedMeshLoader);
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const loader_utils_1 = require("@loaders.gl/loader-utils");
4
- const index_1 = require("../index");
5
- (0, loader_utils_1.createLoaderWorker)(index_1.TerrainLoader);