@loaders.gl/terrain 4.0.0-alpha.4 → 4.0.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.
Files changed (41) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/dist.min.js +1181 -0
  4. package/dist/index.d.ts +77 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/lib/decode-quantized-mesh.d.ts +59 -0
  7. package/dist/lib/decode-quantized-mesh.d.ts.map +1 -0
  8. package/dist/lib/delatin/index.d.ts +24 -0
  9. package/dist/lib/delatin/index.d.ts.map +1 -0
  10. package/dist/lib/delatin/index.js.map +1 -1
  11. package/dist/lib/helpers/skirt.d.ts +19 -0
  12. package/dist/lib/helpers/skirt.d.ts.map +1 -0
  13. package/dist/lib/parse-quantized-mesh.d.ts +25 -0
  14. package/dist/lib/parse-quantized-mesh.d.ts.map +1 -0
  15. package/dist/lib/parse-terrain.d.ts +25 -0
  16. package/dist/lib/parse-terrain.d.ts.map +1 -0
  17. package/dist/lib/parse-terrain.js.map +1 -1
  18. package/dist/lib/utils/version.d.ts +2 -0
  19. package/dist/lib/utils/version.d.ts.map +1 -0
  20. package/dist/lib/utils/version.js +1 -1
  21. package/dist/lib/utils/version.js.map +1 -1
  22. package/dist/quantized-mesh-loader.d.ts +21 -0
  23. package/dist/quantized-mesh-loader.d.ts.map +1 -0
  24. package/dist/quantized-mesh-worker.js +3 -3
  25. package/dist/terrain-loader.d.ts +32 -0
  26. package/dist/terrain-loader.d.ts.map +1 -0
  27. package/dist/terrain-worker.js +3 -3
  28. package/dist/workers/quantized-mesh-worker.d.ts +2 -0
  29. package/dist/workers/quantized-mesh-worker.d.ts.map +1 -0
  30. package/dist/workers/terrain-worker.d.ts +2 -0
  31. package/dist/workers/terrain-worker.d.ts.map +1 -0
  32. package/package.json +8 -8
  33. package/src/lib/delatin/{index.js → index.ts} +0 -0
  34. package/src/lib/parse-terrain.ts +1 -0
  35. package/src/lib/utils/{version.js → version.ts} +0 -0
  36. package/src/workers/quantized-mesh-worker.js +0 -1
  37. package/src/workers/terrain-worker.js +0 -1
  38. package/src/lib/decode-quantized-mesh.js +0 -320
  39. package/src/lib/helpers/skirt.js +0 -161
  40. package/src/lib/parse-quantized-mesh.js +0 -98
  41. package/src/lib/parse-terrain.js +0 -179
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/terrain",
3
- "version": "4.0.0-alpha.4",
3
+ "version": "4.0.0-alpha.5",
4
4
  "description": "Framework-independent loader for terrain raster formats",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -18,7 +18,7 @@
18
18
  "point cloud",
19
19
  "OBJ"
20
20
  ],
21
- "types": "src/index.ts",
21
+ "types": "dist/index.d.ts",
22
22
  "main": "dist/index.js",
23
23
  "module": "dist/index.js",
24
24
  "sideEffects": false,
@@ -29,15 +29,15 @@
29
29
  ],
30
30
  "scripts": {
31
31
  "pre-build": "npm run build-worker && npm run build-worker2 && npm run build-bundle",
32
- "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js",
33
- "build-worker": "esbuild src/workers/terrain-worker.js --bundle --outfile=dist/terrain-worker.js",
34
- "build-worker2": "esbuild src/workers/quantized-mesh-worker.js --bundle --outfile=dist/quantized-mesh-worker.js"
32
+ "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js",
33
+ "build-worker": "esbuild src/workers/terrain-worker.js --bundle --outfile=dist/terrain-worker.js --define:__VERSION__=\\\"$npm_package_version\\\"",
34
+ "build-worker2": "esbuild src/workers/quantized-mesh-worker.js --bundle --outfile=dist/quantized-mesh-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
35
35
  },
36
36
  "dependencies": {
37
37
  "@babel/runtime": "^7.3.1",
38
- "@loaders.gl/loader-utils": "4.0.0-alpha.4",
39
- "@loaders.gl/schema": "4.0.0-alpha.4",
38
+ "@loaders.gl/loader-utils": "4.0.0-alpha.5",
39
+ "@loaders.gl/schema": "4.0.0-alpha.5",
40
40
  "@mapbox/martini": "^0.2.0"
41
41
  },
42
- "gitHead": "53026061b3c8871f7e96d3a5826125cc6613bddc"
42
+ "gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
43
43
  }
File without changes
@@ -198,6 +198,7 @@ function getMartiniTileMesh(meshMaxError, width, terrain) {
198
198
  function getDelatinTileMesh(meshMaxError, width, height, terrain) {
199
199
  const tin = new Delatin(terrain, width + 1, height + 1);
200
200
  tin.run(meshMaxError);
201
+ // @ts-expect-error
201
202
  const {coords, triangles} = tin;
202
203
  const vertices = coords;
203
204
  return {vertices, triangles};
File without changes
@@ -1,4 +1,3 @@
1
1
  import {createLoaderWorker} from '@loaders.gl/loader-utils';
2
2
  import {QuantizedMeshLoader} from '../index';
3
-
4
3
  createLoaderWorker(QuantizedMeshLoader);
@@ -1,4 +1,3 @@
1
1
  import {createLoaderWorker} from '@loaders.gl/loader-utils';
2
2
  import {TerrainLoader} from '../index';
3
-
4
3
  createLoaderWorker(TerrainLoader);
@@ -1,320 +0,0 @@
1
- // Copyright (C) 2018-2019 HERE Europe B.V.
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy
4
- // of this software and associated documentation files (the "Software"), to deal
5
- // in the Software without restriction, including without limitation the rights
6
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- // copies of the Software, and to permit persons to whom the Software is
8
- // furnished to do so, subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in
11
- // all copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- // SOFTWARE.
20
-
21
- const QUANTIZED_MESH_HEADER = new Map([
22
- ['centerX', Float64Array.BYTES_PER_ELEMENT],
23
- ['centerY', Float64Array.BYTES_PER_ELEMENT],
24
- ['centerZ', Float64Array.BYTES_PER_ELEMENT],
25
-
26
- ['minHeight', Float32Array.BYTES_PER_ELEMENT],
27
- ['maxHeight', Float32Array.BYTES_PER_ELEMENT],
28
-
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
-
34
- ['horizonOcclusionPointX', Float64Array.BYTES_PER_ELEMENT],
35
- ['horizonOcclusionPointY', Float64Array.BYTES_PER_ELEMENT],
36
- ['horizonOcclusionPointZ', Float64Array.BYTES_PER_ELEMENT]
37
- ]);
38
-
39
- function decodeZigZag(value) {
40
- return (value >> 1) ^ -(value & 1);
41
- }
42
-
43
- function decodeHeader(dataView) {
44
- let position = 0;
45
- const header = {};
46
-
47
- for (const [key, bytesCount] of QUANTIZED_MESH_HEADER) {
48
- const getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;
49
-
50
- header[key] = getter.call(dataView, position, true);
51
- position += bytesCount;
52
- }
53
-
54
- return {header, headerEndPosition: position};
55
- }
56
-
57
- function decodeVertexData(dataView, headerEndPosition) {
58
- let position = headerEndPosition;
59
- const elementsPerVertex = 3;
60
- const vertexCount = dataView.getUint32(position, true);
61
- const vertexData = new Uint16Array(vertexCount * elementsPerVertex);
62
-
63
- position += Uint32Array.BYTES_PER_ELEMENT;
64
-
65
- const bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;
66
- const elementArrayLength = vertexCount * bytesPerArrayElement;
67
- const uArrayStartPosition = position;
68
- const vArrayStartPosition = uArrayStartPosition + elementArrayLength;
69
- const heightArrayStartPosition = vArrayStartPosition + elementArrayLength;
70
-
71
- let u = 0;
72
- let v = 0;
73
- let height = 0;
74
-
75
- for (let i = 0; i < vertexCount; i++) {
76
- u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));
77
- v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));
78
- height += decodeZigZag(
79
- dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true)
80
- );
81
-
82
- vertexData[i] = u;
83
- vertexData[i + vertexCount] = v;
84
- vertexData[i + vertexCount * 2] = height;
85
- }
86
-
87
- position += elementArrayLength * 3;
88
-
89
- return {vertexData, vertexDataEndPosition: position};
90
- }
91
-
92
- function decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = true) {
93
- let indices;
94
-
95
- if (bytesPerIndex === 2) {
96
- indices = new Uint16Array(buffer, position, indicesCount);
97
- } else {
98
- indices = new Uint32Array(buffer, position, indicesCount);
99
- }
100
-
101
- if (!encoded) {
102
- return indices;
103
- }
104
-
105
- let highest = 0;
106
-
107
- for (let i = 0; i < indices.length; ++i) {
108
- const code = indices[i];
109
-
110
- indices[i] = highest - code;
111
-
112
- if (code === 0) {
113
- ++highest;
114
- }
115
- }
116
-
117
- return indices;
118
- }
119
-
120
- function decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {
121
- let position = vertexDataEndPosition;
122
- const elementsPerVertex = 3;
123
- const vertexCount = vertexData.length / elementsPerVertex;
124
- const bytesPerIndex =
125
- vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
126
-
127
- if (position % bytesPerIndex !== 0) {
128
- position += bytesPerIndex - (position % bytesPerIndex);
129
- }
130
-
131
- const triangleCount = dataView.getUint32(position, true);
132
- position += Uint32Array.BYTES_PER_ELEMENT;
133
-
134
- const triangleIndicesCount = triangleCount * 3;
135
- const triangleIndices = decodeIndex(
136
- dataView.buffer,
137
- position,
138
- triangleIndicesCount,
139
- bytesPerIndex
140
- );
141
- position += triangleIndicesCount * bytesPerIndex;
142
-
143
- return {
144
- triangleIndicesEndPosition: position,
145
- triangleIndices
146
- };
147
- }
148
-
149
- function decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {
150
- let position = triangleIndicesEndPosition;
151
- const elementsPerVertex = 3;
152
- const vertexCount = vertexData.length / elementsPerVertex;
153
- const bytesPerIndex =
154
- vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
155
-
156
- const westVertexCount = dataView.getUint32(position, true);
157
- position += Uint32Array.BYTES_PER_ELEMENT;
158
-
159
- const westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);
160
- position += westVertexCount * bytesPerIndex;
161
-
162
- const southVertexCount = dataView.getUint32(position, true);
163
- position += Uint32Array.BYTES_PER_ELEMENT;
164
-
165
- const southIndices = decodeIndex(
166
- dataView.buffer,
167
- position,
168
- southVertexCount,
169
- bytesPerIndex,
170
- false
171
- );
172
- position += southVertexCount * bytesPerIndex;
173
-
174
- const eastVertexCount = dataView.getUint32(position, true);
175
- position += Uint32Array.BYTES_PER_ELEMENT;
176
-
177
- const eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);
178
- position += eastVertexCount * bytesPerIndex;
179
-
180
- const northVertexCount = dataView.getUint32(position, true);
181
- position += Uint32Array.BYTES_PER_ELEMENT;
182
-
183
- const northIndices = decodeIndex(
184
- dataView.buffer,
185
- position,
186
- northVertexCount,
187
- bytesPerIndex,
188
- false
189
- );
190
- position += northVertexCount * bytesPerIndex;
191
-
192
- return {
193
- edgeIndicesEndPosition: position,
194
- westIndices,
195
- southIndices,
196
- eastIndices,
197
- northIndices
198
- };
199
- }
200
-
201
- function decodeVertexNormalsExtension(extensionDataView) {
202
- return new Uint8Array(
203
- extensionDataView.buffer,
204
- extensionDataView.byteOffset,
205
- extensionDataView.byteLength
206
- );
207
- }
208
-
209
- function decodeWaterMaskExtension(extensionDataView) {
210
- return extensionDataView.buffer.slice(
211
- extensionDataView.byteOffset,
212
- extensionDataView.byteOffset + extensionDataView.byteLength
213
- );
214
- }
215
-
216
- function decodeExtensions(dataView, indicesEndPosition) {
217
- const extensions = {};
218
-
219
- if (dataView.byteLength <= indicesEndPosition) {
220
- return {extensions, extensionsEndPosition: indicesEndPosition};
221
- }
222
-
223
- let position = indicesEndPosition;
224
-
225
- while (position < dataView.byteLength) {
226
- const extensionId = dataView.getUint8(position, true);
227
- position += Uint8Array.BYTES_PER_ELEMENT;
228
-
229
- const extensionLength = dataView.getUint32(position, true);
230
- position += Uint32Array.BYTES_PER_ELEMENT;
231
-
232
- const extensionView = new DataView(dataView.buffer, position, extensionLength);
233
-
234
- switch (extensionId) {
235
- case 1: {
236
- extensions.vertexNormals = decodeVertexNormalsExtension(extensionView);
237
-
238
- break;
239
- }
240
- case 2: {
241
- extensions.waterMask = decodeWaterMaskExtension(extensionView);
242
-
243
- break;
244
- }
245
- default: {
246
- // console.warn(`Unknown extension with id ${extensionId}`)
247
- }
248
- }
249
-
250
- position += extensionLength;
251
- }
252
-
253
- return {extensions, extensionsEndPosition: position};
254
- }
255
-
256
- export const DECODING_STEPS = {
257
- header: 0,
258
- vertices: 1,
259
- triangleIndices: 2,
260
- edgeIndices: 3,
261
- extensions: 4
262
- };
263
-
264
- const DEFAULT_OPTIONS = {
265
- maxDecodingStep: DECODING_STEPS.extensions
266
- };
267
-
268
- export default function decode(data, userOptions) {
269
- const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
270
- const view = new DataView(data);
271
- const {header, headerEndPosition} = decodeHeader(view);
272
-
273
- if (options.maxDecodingStep < DECODING_STEPS.vertices) {
274
- return {header};
275
- }
276
-
277
- const {vertexData, vertexDataEndPosition} = decodeVertexData(view, headerEndPosition);
278
-
279
- if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {
280
- return {header, vertexData};
281
- }
282
-
283
- const {triangleIndices, triangleIndicesEndPosition} = decodeTriangleIndices(
284
- view,
285
- vertexData,
286
- vertexDataEndPosition
287
- );
288
-
289
- if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {
290
- return {header, vertexData, triangleIndices};
291
- }
292
-
293
- const {westIndices, southIndices, eastIndices, northIndices, edgeIndicesEndPosition} =
294
- decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
295
-
296
- if (options.maxDecodingStep < DECODING_STEPS.extensions) {
297
- return {
298
- header,
299
- vertexData,
300
- triangleIndices,
301
- westIndices,
302
- northIndices,
303
- eastIndices,
304
- southIndices
305
- };
306
- }
307
-
308
- const {extensions} = decodeExtensions(view, edgeIndicesEndPosition);
309
-
310
- return {
311
- header,
312
- vertexData,
313
- triangleIndices,
314
- westIndices,
315
- northIndices,
316
- eastIndices,
317
- southIndices,
318
- extensions
319
- };
320
- }
@@ -1,161 +0,0 @@
1
- import {concatenateTypedArrays} from '@loaders.gl/loader-utils';
2
-
3
- /**
4
- * Add skirt to existing mesh
5
- * @param {object} attributes - POSITION and TEXCOOD_0 attributes data
6
- * @param {any} triangles - indices array of the mesh geometry
7
- * @param {number} skirtHeight - height of the skirt geometry
8
- * @param {object} outsideIndices - edge indices from quantized mesh data
9
- * @returns - geometry data with added skirt
10
- */
11
- export function addSkirt(attributes, triangles, skirtHeight, outsideIndices = null) {
12
- const outsideEdges = outsideIndices
13
- ? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value)
14
- : getOutsideEdgesFromTriangles(triangles);
15
-
16
- // 2 new vertices for each outside edge
17
- const newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);
18
- const newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);
19
-
20
- // 2 new triangles for each outside edge
21
- const newTriangles = new triangles.constructor(outsideEdges.length * 6);
22
-
23
- for (let i = 0; i < outsideEdges.length; i++) {
24
- const edge = outsideEdges[i];
25
-
26
- updateAttributesForNewEdge({
27
- edge,
28
- edgeIndex: i,
29
- attributes,
30
- skirtHeight,
31
- newPosition,
32
- newTexcoord0,
33
- newTriangles
34
- });
35
- }
36
-
37
- attributes.POSITION.value = concatenateTypedArrays(attributes.POSITION.value, newPosition);
38
- attributes.TEXCOORD_0.value = concatenateTypedArrays(attributes.TEXCOORD_0.value, newTexcoord0);
39
- const resultTriangles =
40
- triangles instanceof Array
41
- ? triangles.concat(newTriangles)
42
- : concatenateTypedArrays(triangles, newTriangles);
43
-
44
- return {
45
- attributes,
46
- triangles: resultTriangles
47
- };
48
- }
49
-
50
- /**
51
- * Get geometry edges that located on a border of the mesh
52
- * @param {any} triangles - indices array of the mesh geometry
53
- * @returns {number[][]} - outside edges data
54
- */
55
- function getOutsideEdgesFromTriangles(triangles) {
56
- const edges = [];
57
- for (let i = 0; i < triangles.length; i += 3) {
58
- edges.push([triangles[i], triangles[i + 1]]);
59
- edges.push([triangles[i + 1], triangles[i + 2]]);
60
- edges.push([triangles[i + 2], triangles[i]]);
61
- }
62
-
63
- edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
64
-
65
- const outsideEdges = [];
66
- let index = 1;
67
- while (index < edges.length) {
68
- if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {
69
- index += 2;
70
- } else {
71
- outsideEdges.push(edges[index - 1]);
72
- index++;
73
- }
74
- }
75
- return outsideEdges;
76
- }
77
-
78
- /**
79
- * Get geometry edges that located on a border of the mesh
80
- * @param {object} indices - edge indices from quantized mesh data
81
- * @param {TypedArray} position - position attribute geometry data
82
- * @returns {number[][]} - outside edges data
83
- */
84
- function getOutsideEdgesFromIndices(indices, position) {
85
- // Sort skirt indices to create adjacent triangles
86
- indices.westIndices.sort((a, b) => position[3 * a + 1] - position[3 * b + 1]);
87
- // Reverse (b - a) to match triangle winding
88
- indices.eastIndices.sort((a, b) => position[3 * b + 1] - position[3 * a + 1]);
89
- indices.southIndices.sort((a, b) => position[3 * b] - position[3 * a]);
90
- // Reverse (b - a) to match triangle winding
91
- indices.northIndices.sort((a, b) => position[3 * a] - position[3 * b]);
92
-
93
- const edges = [];
94
- for (const index in indices) {
95
- const indexGroup = indices[index];
96
- for (let i = 0; i < indexGroup.length - 1; i++) {
97
- edges.push([indexGroup[i], indexGroup[i + 1]]);
98
- }
99
- }
100
- return edges;
101
- }
102
-
103
- /**
104
- * Get geometry edges that located on a border of the mesh
105
- * @param {object} args
106
- * @param {number[]} args.edge - edge indices in geometry
107
- * @param {number} args.edgeIndex - edge index in outsideEdges array
108
- * @param {object} args.attributes - POSITION and TEXCOORD_0 attributes
109
- * @param {number} args.skirtHeight - height of the skirt geometry
110
- * @param {TypedArray} args.newPosition - POSITION array for skirt data
111
- * @param {TypedArray} args.newTexcoord0 - TEXCOORD_0 array for skirt data
112
- * @param {TypedArray | Array} args.newTriangles - trinagle indices array for skirt data
113
- * @returns {void}
114
- */
115
- function updateAttributesForNewEdge({
116
- edge,
117
- edgeIndex,
118
- attributes,
119
- skirtHeight,
120
- newPosition,
121
- newTexcoord0,
122
- newTriangles
123
- }) {
124
- const positionsLength = attributes.POSITION.value.length;
125
- const vertex1Offset = edgeIndex * 2;
126
- const vertex2Offset = edgeIndex * 2 + 1;
127
-
128
- // Define POSITION for new 1st vertex
129
- newPosition.set(
130
- attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3),
131
- vertex1Offset * 3
132
- );
133
- newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight; // put down elevation on the skirt height
134
-
135
- // Define POSITION for new 2nd vertex
136
- newPosition.set(
137
- attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3),
138
- vertex2Offset * 3
139
- );
140
- newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight; // put down elevation on the skirt height
141
-
142
- // Use same TEXCOORDS for skirt vertices
143
- newTexcoord0.set(
144
- attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2),
145
- vertex1Offset * 2
146
- );
147
- newTexcoord0.set(
148
- attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2),
149
- vertex2Offset * 2
150
- );
151
-
152
- // Define new triangles
153
- const triangle1Offset = edgeIndex * 2 * 3;
154
- newTriangles[triangle1Offset] = edge[0];
155
- newTriangles[triangle1Offset + 1] = edge[1];
156
- newTriangles[triangle1Offset + 2] = positionsLength / 3 + vertex2Offset;
157
-
158
- newTriangles[triangle1Offset + 3] = positionsLength / 3 + vertex2Offset;
159
- newTriangles[triangle1Offset + 4] = positionsLength / 3 + vertex1Offset;
160
- newTriangles[triangle1Offset + 5] = edge[0];
161
- }
@@ -1,98 +0,0 @@
1
- import {getMeshBoundingBox} from '@loaders.gl/schema';
2
- import decode, {DECODING_STEPS} from './decode-quantized-mesh';
3
- import {addSkirt} from './helpers/skirt';
4
-
5
- function getMeshAttributes(vertexData, header, bounds) {
6
- const {minHeight, maxHeight} = header;
7
- const [minX, minY, maxX, maxY] = bounds || [0, 0, 1, 1];
8
- const xScale = maxX - minX;
9
- const yScale = maxY - minY;
10
- const zScale = maxHeight - minHeight;
11
-
12
- const nCoords = vertexData.length / 3;
13
- // vec3. x, y defined by bounds, z in meters
14
- const positions = new Float32Array(nCoords * 3);
15
-
16
- // vec2. 1 to 1 relationship with position. represents the uv on the texture image. 0,0 to 1,1.
17
- const texCoords = new Float32Array(nCoords * 2);
18
-
19
- // Data is not interleaved; all u, then all v, then all heights
20
- for (let i = 0; i < nCoords; i++) {
21
- const x = vertexData[i] / 32767;
22
- const y = vertexData[i + nCoords] / 32767;
23
- const z = vertexData[i + nCoords * 2] / 32767;
24
-
25
- positions[3 * i + 0] = x * xScale + minX;
26
- positions[3 * i + 1] = y * yScale + minY;
27
- positions[3 * i + 2] = z * zScale + minHeight;
28
-
29
- texCoords[2 * i + 0] = x;
30
- texCoords[2 * i + 1] = y;
31
- }
32
-
33
- return {
34
- POSITION: {value: positions, size: 3},
35
- TEXCOORD_0: {value: texCoords, size: 2}
36
- // TODO: Parse normals if they exist in the file
37
- // NORMAL: {}, - optional, but creates the high poly look with lighting
38
- };
39
- }
40
-
41
- function getTileMesh(arrayBuffer, options) {
42
- if (!arrayBuffer) {
43
- return null;
44
- }
45
- const {bounds} = options;
46
- // Don't parse edge indices or format extensions
47
- const {
48
- header,
49
- vertexData,
50
- triangleIndices: originalTriangleIndices,
51
- westIndices,
52
- northIndices,
53
- eastIndices,
54
- southIndices
55
- } = decode(arrayBuffer, DECODING_STEPS.triangleIndices);
56
- let triangleIndices = originalTriangleIndices;
57
- let attributes = getMeshAttributes(vertexData, header, bounds);
58
-
59
- // Compute bounding box before adding skirt so that z values are not skewed
60
- // TODO: Find bounding box from header, instead of doing extra pass over
61
- // vertices.
62
- const boundingBox = getMeshBoundingBox(attributes);
63
-
64
- if (options.skirtHeight) {
65
- const {attributes: newAttributes, triangles: newTriangles} = addSkirt(
66
- attributes,
67
- triangleIndices,
68
- options.skirtHeight,
69
- {
70
- westIndices,
71
- northIndices,
72
- eastIndices,
73
- southIndices
74
- }
75
- );
76
- attributes = newAttributes;
77
- triangleIndices = newTriangles;
78
- }
79
-
80
- return {
81
- // Data return by this loader implementation
82
- loaderData: {
83
- header: {}
84
- },
85
- header: {
86
- // @ts-ignore
87
- vertexCount: triangleIndices.length,
88
- boundingBox
89
- },
90
- mode: 4, // TRIANGLES
91
- indices: {value: triangleIndices, size: 1},
92
- attributes
93
- };
94
- }
95
-
96
- export default function loadQuantizedMesh(arrayBuffer, options) {
97
- return getTileMesh(arrayBuffer, options['quantized-mesh']);
98
- }