@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 +189 -162
- package/dist/dist.min.js +9 -0
- package/dist/index.cjs +39 -122
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -20
- package/dist/lib/decode-quantized-mesh.js +198 -203
- package/dist/lib/delatin/index.js +386 -333
- package/dist/lib/helpers/skirt.js +116 -79
- package/dist/lib/parse-quantized-mesh.js +66 -78
- package/dist/lib/parse-terrain.js +132 -134
- package/dist/lib/utils/version.js +7 -2
- package/dist/quantized-mesh-loader.js +18 -13
- package/dist/quantized-mesh-worker.js +1 -1
- package/dist/terrain-loader.d.ts +1 -1
- package/dist/terrain-loader.d.ts.map +1 -1
- package/dist/terrain-loader.js +26 -21
- package/dist/terrain-worker.js +1 -1
- package/dist/workers/quantized-mesh-worker.js +3 -1
- package/dist/workers/terrain-worker.js +3 -1
- package/package.json +11 -8
- package/src/lib/parse-terrain.ts +1 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/decode-quantized-mesh.js.map +0 -1
- package/dist/lib/delatin/index.js.map +0 -1
- package/dist/lib/helpers/skirt.js.map +0 -1
- package/dist/lib/parse-quantized-mesh.js.map +0 -1
- package/dist/lib/parse-terrain.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/quantized-mesh-loader.js.map +0 -1
- package/dist/terrain-loader.js.map +0 -1
- package/dist/workers/quantized-mesh-worker.js.map +0 -1
- package/dist/workers/terrain-worker.js.map +0 -1
|
@@ -1,231 +1,226 @@
|
|
|
1
|
-
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// Copyright (C) 2018-2019 HERE Europe B.V.
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in
|
|
14
|
+
// all copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
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
|
+
]);
|
|
2
37
|
function decodeZigZag(value) {
|
|
3
|
-
|
|
38
|
+
return (value >> 1) ^ -(value & 1);
|
|
4
39
|
}
|
|
5
40
|
function decodeHeader(dataView) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
header,
|
|
15
|
-
headerEndPosition: position
|
|
16
|
-
};
|
|
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 };
|
|
17
49
|
}
|
|
18
50
|
function decodeVertexData(dataView, headerEndPosition) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
vertexData,
|
|
43
|
-
vertexDataEndPosition: position
|
|
44
|
-
};
|
|
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 };
|
|
45
74
|
}
|
|
46
|
-
function decodeIndex(buffer, position, indicesCount, bytesPerIndex) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
if (!encoded) {
|
|
55
|
-
return indices;
|
|
56
|
-
}
|
|
57
|
-
let highest = 0;
|
|
58
|
-
for (let i = 0; i < indices.length; ++i) {
|
|
59
|
-
const code = indices[i];
|
|
60
|
-
indices[i] = highest - code;
|
|
61
|
-
if (code === 0) {
|
|
62
|
-
++highest;
|
|
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);
|
|
63
82
|
}
|
|
64
|
-
|
|
65
|
-
|
|
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;
|
|
66
95
|
}
|
|
67
96
|
function decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
+
};
|
|
84
113
|
}
|
|
85
114
|
function decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
+
};
|
|
113
142
|
}
|
|
114
143
|
function decodeVertexNormalsExtension(extensionDataView) {
|
|
115
|
-
|
|
144
|
+
return new Uint8Array(extensionDataView.buffer, extensionDataView.byteOffset, extensionDataView.byteLength);
|
|
116
145
|
}
|
|
117
146
|
function decodeWaterMaskExtension(extensionDataView) {
|
|
118
|
-
|
|
147
|
+
return extensionDataView.buffer.slice(extensionDataView.byteOffset, extensionDataView.byteOffset + extensionDataView.byteLength);
|
|
119
148
|
}
|
|
120
149
|
function decodeExtensions(dataView, indicesEndPosition) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
break;
|
|
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
|
+
}
|
|
145
173
|
}
|
|
146
|
-
|
|
147
|
-
{}
|
|
174
|
+
position += extensionLength;
|
|
148
175
|
}
|
|
149
|
-
position
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
extensions,
|
|
153
|
-
extensionsEndPosition: position
|
|
154
|
-
};
|
|
176
|
+
return { extensions, extensionsEndPosition: position };
|
|
155
177
|
}
|
|
156
178
|
export const DECODING_STEPS = {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
179
|
+
header: 0,
|
|
180
|
+
vertices: 1,
|
|
181
|
+
triangleIndices: 2,
|
|
182
|
+
edgeIndices: 3,
|
|
183
|
+
extensions: 4
|
|
162
184
|
};
|
|
163
185
|
const DEFAULT_OPTIONS = {
|
|
164
|
-
|
|
186
|
+
maxDecodingStep: DECODING_STEPS.extensions
|
|
165
187
|
};
|
|
166
188
|
export default function decode(data, userOptions) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
header,
|
|
195
|
-
vertexData,
|
|
196
|
-
triangleIndices
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
const {
|
|
200
|
-
westIndices,
|
|
201
|
-
southIndices,
|
|
202
|
-
eastIndices,
|
|
203
|
-
northIndices,
|
|
204
|
-
edgeIndicesEndPosition
|
|
205
|
-
} = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
|
|
206
|
-
if (options.maxDecodingStep < DECODING_STEPS.extensions) {
|
|
189
|
+
const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
|
|
190
|
+
const view = new DataView(data);
|
|
191
|
+
const { header, headerEndPosition } = decodeHeader(view);
|
|
192
|
+
if (options.maxDecodingStep < DECODING_STEPS.vertices) {
|
|
193
|
+
return { header };
|
|
194
|
+
}
|
|
195
|
+
const { vertexData, vertexDataEndPosition } = decodeVertexData(view, headerEndPosition);
|
|
196
|
+
if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {
|
|
197
|
+
return { header, vertexData };
|
|
198
|
+
}
|
|
199
|
+
const { triangleIndices, triangleIndicesEndPosition } = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
|
|
200
|
+
if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {
|
|
201
|
+
return { header, vertexData, triangleIndices };
|
|
202
|
+
}
|
|
203
|
+
const { westIndices, southIndices, eastIndices, northIndices, edgeIndicesEndPosition } = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
|
|
204
|
+
if (options.maxDecodingStep < 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);
|
|
207
216
|
return {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
217
|
+
header,
|
|
218
|
+
vertexData,
|
|
219
|
+
triangleIndices,
|
|
220
|
+
westIndices,
|
|
221
|
+
northIndices,
|
|
222
|
+
eastIndices,
|
|
223
|
+
southIndices,
|
|
224
|
+
extensions
|
|
215
225
|
};
|
|
216
|
-
}
|
|
217
|
-
const {
|
|
218
|
-
extensions
|
|
219
|
-
} = decodeExtensions(view, edgeIndicesEndPosition);
|
|
220
|
-
return {
|
|
221
|
-
header,
|
|
222
|
-
vertexData,
|
|
223
|
-
triangleIndices,
|
|
224
|
-
westIndices,
|
|
225
|
-
northIndices,
|
|
226
|
-
eastIndices,
|
|
227
|
-
southIndices,
|
|
228
|
-
extensions
|
|
229
|
-
};
|
|
230
226
|
}
|
|
231
|
-
//# sourceMappingURL=decode-quantized-mesh.js.map
|