@loaders.gl/terrain 3.1.0-alpha.2 → 3.1.0-beta.1

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 (112) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +1179 -5
  4. package/dist/es5/bundle.js +7 -0
  5. package/dist/es5/bundle.js.map +1 -0
  6. package/dist/es5/index.js +43 -0
  7. package/dist/es5/index.js.map +1 -0
  8. package/dist/es5/lib/decode-quantized-mesh.js +277 -0
  9. package/dist/es5/lib/decode-quantized-mesh.js.map +1 -0
  10. package/dist/es5/lib/delatin/index.js +473 -0
  11. package/dist/es5/lib/delatin/index.js.map +1 -0
  12. package/dist/es5/lib/helpers/skirt.js +107 -0
  13. package/dist/es5/lib/helpers/skirt.js.map +1 -0
  14. package/dist/es5/lib/parse-quantized-mesh.js +109 -0
  15. package/dist/es5/lib/parse-quantized-mesh.js.map +1 -0
  16. package/dist/es5/lib/parse-terrain.js +192 -0
  17. package/dist/es5/lib/parse-terrain.js.map +1 -0
  18. package/dist/es5/lib/utils/version.js +9 -0
  19. package/dist/es5/lib/utils/version.js.map +1 -0
  20. package/dist/es5/quantized-mesh-loader.js +28 -0
  21. package/dist/es5/quantized-mesh-loader.js.map +1 -0
  22. package/dist/es5/terrain-loader.js +36 -0
  23. package/dist/es5/terrain-loader.js.map +1 -0
  24. package/dist/es5/workers/quantized-mesh-worker.js +8 -0
  25. package/dist/es5/workers/quantized-mesh-worker.js.map +1 -0
  26. package/dist/es5/workers/terrain-worker.js +8 -0
  27. package/dist/es5/workers/terrain-worker.js.map +1 -0
  28. package/dist/esm/bundle.js +5 -0
  29. package/dist/esm/bundle.js.map +1 -0
  30. package/dist/esm/index.js +16 -0
  31. package/dist/esm/index.js.map +1 -0
  32. package/dist/esm/lib/decode-quantized-mesh.js +268 -0
  33. package/dist/esm/lib/decode-quantized-mesh.js.map +1 -0
  34. package/dist/esm/lib/delatin/index.js +464 -0
  35. package/dist/esm/lib/delatin/index.js.map +1 -0
  36. package/dist/esm/lib/helpers/skirt.js +99 -0
  37. package/dist/esm/lib/helpers/skirt.js.map +1 -0
  38. package/dist/esm/lib/parse-quantized-mesh.js +96 -0
  39. package/dist/esm/lib/parse-quantized-mesh.js.map +1 -0
  40. package/dist/esm/lib/parse-terrain.js +180 -0
  41. package/dist/esm/lib/parse-terrain.js.map +1 -0
  42. package/dist/esm/lib/utils/version.js +2 -0
  43. package/dist/esm/lib/utils/version.js.map +1 -0
  44. package/dist/esm/quantized-mesh-loader.js +18 -0
  45. package/dist/esm/quantized-mesh-loader.js.map +1 -0
  46. package/dist/esm/terrain-loader.js +26 -0
  47. package/dist/esm/terrain-loader.js.map +1 -0
  48. package/dist/esm/workers/quantized-mesh-worker.js +4 -0
  49. package/dist/esm/workers/quantized-mesh-worker.js.map +1 -0
  50. package/dist/esm/workers/terrain-worker.js +4 -0
  51. package/dist/esm/workers/terrain-worker.js.map +1 -0
  52. package/dist/index.d.ts +77 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +24 -14
  55. package/dist/lib/decode-quantized-mesh.d.ts +59 -0
  56. package/dist/lib/decode-quantized-mesh.d.ts.map +1 -0
  57. package/dist/lib/decode-quantized-mesh.js +200 -241
  58. package/dist/lib/delatin/index.d.ts +24 -0
  59. package/dist/lib/delatin/index.d.ts.map +1 -0
  60. package/dist/lib/delatin/index.js +397 -443
  61. package/dist/lib/helpers/skirt.d.ts +19 -0
  62. package/dist/lib/helpers/skirt.d.ts.map +1 -0
  63. package/dist/lib/helpers/skirt.js +119 -91
  64. package/dist/lib/parse-quantized-mesh.d.ts +25 -0
  65. package/dist/lib/parse-quantized-mesh.d.ts.map +1 -0
  66. package/dist/lib/parse-quantized-mesh.js +89 -90
  67. package/dist/lib/parse-terrain.d.ts +25 -0
  68. package/dist/lib/parse-terrain.d.ts.map +1 -0
  69. package/dist/lib/parse-terrain.js +148 -166
  70. package/dist/lib/utils/version.d.ts +2 -0
  71. package/dist/lib/utils/version.d.ts.map +1 -0
  72. package/dist/lib/utils/version.js +7 -2
  73. package/dist/quantized-mesh-loader.d.ts +21 -0
  74. package/dist/quantized-mesh-loader.d.ts.map +1 -0
  75. package/dist/quantized-mesh-loader.js +21 -16
  76. package/dist/quantized-mesh-worker.js +1218 -2
  77. package/dist/terrain-loader.d.ts +32 -0
  78. package/dist/terrain-loader.d.ts.map +1 -0
  79. package/dist/terrain-loader.js +32 -24
  80. package/dist/terrain-worker.js +1218 -2
  81. package/dist/workers/quantized-mesh-worker.d.ts +2 -0
  82. package/dist/workers/quantized-mesh-worker.d.ts.map +1 -0
  83. package/dist/workers/quantized-mesh-worker.js +5 -4
  84. package/dist/workers/terrain-worker.d.ts +2 -0
  85. package/dist/workers/terrain-worker.d.ts.map +1 -0
  86. package/dist/workers/terrain-worker.js +5 -4
  87. package/package.json +10 -10
  88. package/src/bundle.ts +2 -3
  89. package/src/lib/{decode-quantized-mesh.js → decode-quantized-mesh.ts} +6 -1
  90. package/src/lib/delatin/{index.js → index.ts} +2 -0
  91. package/src/lib/helpers/{skirt.js → skirt.ts} +14 -7
  92. package/src/lib/{parse-quantized-mesh.js → parse-quantized-mesh.ts} +0 -0
  93. package/src/lib/{parse-terrain.js → parse-terrain.ts} +37 -3
  94. package/src/lib/utils/{version.js → version.ts} +0 -0
  95. package/src/workers/quantized-mesh-worker.js +0 -1
  96. package/src/workers/quantized-mesh-worker.ts +4 -0
  97. package/src/workers/terrain-worker.js +0 -1
  98. package/src/workers/terrain-worker.ts +4 -0
  99. package/dist/bundle.js.map +0 -1
  100. package/dist/dist.min.js +0 -2
  101. package/dist/dist.min.js.map +0 -1
  102. package/dist/index.js.map +0 -1
  103. package/dist/lib/decode-quantized-mesh.js.map +0 -1
  104. package/dist/lib/delatin/index.js.map +0 -1
  105. package/dist/lib/helpers/skirt.js.map +0 -1
  106. package/dist/lib/parse-quantized-mesh.js.map +0 -1
  107. package/dist/lib/parse-terrain.js.map +0 -1
  108. package/dist/lib/utils/version.js.map +0 -1
  109. package/dist/quantized-mesh-loader.js.map +0 -1
  110. package/dist/quantized-mesh-worker.js.map +0 -1
  111. package/dist/terrain-loader.js.map +0 -1
  112. package/dist/terrain-worker.js.map +0 -1
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ const moduleExports = require('./index');
4
+
5
+ globalThis.loaders = globalThis.loaders || {};
6
+ module.exports = Object.assign(globalThis.loaders, moduleExports);
7
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ Object.defineProperty(exports, "TerrainWorkerLoader", {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _terrainLoader.TerrainLoader;
12
+ }
13
+ });
14
+ Object.defineProperty(exports, "QuantizedMeshWorkerLoader", {
15
+ enumerable: true,
16
+ get: function () {
17
+ return _quantizedMeshLoader.QuantizedMeshLoader;
18
+ }
19
+ });
20
+ exports._typecheckQuantizedMeshLoader = exports.QuantizedMeshLoader = exports._typecheckTerrainLoader = exports.TerrainLoader = void 0;
21
+
22
+ var _parseQuantizedMesh = _interopRequireDefault(require("./lib/parse-quantized-mesh"));
23
+
24
+ var _parseTerrain = _interopRequireDefault(require("./lib/parse-terrain"));
25
+
26
+ var _terrainLoader = require("./terrain-loader");
27
+
28
+ var _quantizedMeshLoader = require("./quantized-mesh-loader");
29
+
30
+ const TerrainLoader = { ..._terrainLoader.TerrainLoader,
31
+ parse: _parseTerrain.default
32
+ };
33
+ exports.TerrainLoader = TerrainLoader;
34
+ const _typecheckTerrainLoader = TerrainLoader;
35
+ exports._typecheckTerrainLoader = _typecheckTerrainLoader;
36
+ const QuantizedMeshLoader = { ..._quantizedMeshLoader.QuantizedMeshLoader,
37
+ parseSync: _parseQuantizedMesh.default,
38
+ parse: async (arrayBuffer, options) => (0, _parseQuantizedMesh.default)(arrayBuffer, options)
39
+ };
40
+ exports.QuantizedMeshLoader = QuantizedMeshLoader;
41
+ const _typecheckQuantizedMeshLoader = QuantizedMeshLoader;
42
+ exports._typecheckQuantizedMeshLoader = _typecheckQuantizedMeshLoader;
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"names":["TerrainLoader","TerrainWorkerLoader","parse","loadTerrain","_typecheckTerrainLoader","QuantizedMeshLoader","QuantizedMeshWorkerLoader","parseSync","parseQuantizedMesh","arrayBuffer","options","_typecheckQuantizedMeshLoader"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;AACA;;AAEA;;AACA;;AAMO,MAAMA,aAAa,GAAG,EAC3B,GAAGC,4BADwB;AAE3BC,EAAAA,KAAK,EAAEC;AAFoB,CAAtB;;AAKA,MAAMC,uBAAyC,GAAGJ,aAAlD;;AASA,MAAMK,mBAAmB,GAAG,EACjC,GAAGC,wCAD8B;AAEjCC,EAAAA,SAAS,EAAEC,2BAFsB;AAGjCN,EAAAA,KAAK,EAAE,OAAOO,WAAP,EAAoBC,OAApB,KAAgC,iCAAmBD,WAAnB,EAAgCC,OAAhC;AAHN,CAA5B;;AAMA,MAAMC,6BAA+C,GAAGN,mBAAxD","sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport parseQuantizedMesh from './lib/parse-quantized-mesh';\nimport loadTerrain from './lib/parse-terrain';\n\nimport {TerrainLoader as TerrainWorkerLoader} from './terrain-loader';\nimport {QuantizedMeshLoader as QuantizedMeshWorkerLoader} from './quantized-mesh-loader';\n\n// TerrainLoader\n\nexport {TerrainWorkerLoader};\n\nexport const TerrainLoader = {\n ...TerrainWorkerLoader,\n parse: loadTerrain\n};\n\nexport const _typecheckTerrainLoader: LoaderWithParser = TerrainLoader; // eslint-disable-line\n\n// QuantizedMeshLoader\n\nexport {QuantizedMeshWorkerLoader};\n\n/**\n * Loader for quantized meshes\n */\nexport const QuantizedMeshLoader = {\n ...QuantizedMeshWorkerLoader,\n parseSync: parseQuantizedMesh,\n parse: async (arrayBuffer, options) => parseQuantizedMesh(arrayBuffer, options)\n};\n\nexport const _typecheckQuantizedMeshLoader: LoaderWithParser = QuantizedMeshLoader;\n"],"file":"index.js"}
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = decode;
7
+ exports.DECODING_STEPS = void 0;
8
+ const QUANTIZED_MESH_HEADER = 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]]);
9
+
10
+ function decodeZigZag(value) {
11
+ return value >> 1 ^ -(value & 1);
12
+ }
13
+
14
+ function decodeHeader(dataView) {
15
+ let position = 0;
16
+ const header = {};
17
+
18
+ for (const [key, bytesCount] of QUANTIZED_MESH_HEADER) {
19
+ const getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;
20
+ header[key] = getter.call(dataView, position, true);
21
+ position += bytesCount;
22
+ }
23
+
24
+ return {
25
+ header,
26
+ headerEndPosition: position
27
+ };
28
+ }
29
+
30
+ function decodeVertexData(dataView, headerEndPosition) {
31
+ let position = headerEndPosition;
32
+ const elementsPerVertex = 3;
33
+ const vertexCount = dataView.getUint32(position, true);
34
+ const vertexData = new Uint16Array(vertexCount * elementsPerVertex);
35
+ position += Uint32Array.BYTES_PER_ELEMENT;
36
+ const bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;
37
+ const elementArrayLength = vertexCount * bytesPerArrayElement;
38
+ const uArrayStartPosition = position;
39
+ const vArrayStartPosition = uArrayStartPosition + elementArrayLength;
40
+ const heightArrayStartPosition = vArrayStartPosition + elementArrayLength;
41
+ let u = 0;
42
+ let v = 0;
43
+ let height = 0;
44
+
45
+ for (let i = 0; i < vertexCount; i++) {
46
+ u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));
47
+ v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));
48
+ height += decodeZigZag(dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true));
49
+ vertexData[i] = u;
50
+ vertexData[i + vertexCount] = v;
51
+ vertexData[i + vertexCount * 2] = height;
52
+ }
53
+
54
+ position += elementArrayLength * 3;
55
+ return {
56
+ vertexData,
57
+ vertexDataEndPosition: position
58
+ };
59
+ }
60
+
61
+ function decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = true) {
62
+ let indices;
63
+
64
+ if (bytesPerIndex === 2) {
65
+ indices = new Uint16Array(buffer, position, indicesCount);
66
+ } else {
67
+ indices = new Uint32Array(buffer, position, indicesCount);
68
+ }
69
+
70
+ if (!encoded) {
71
+ return indices;
72
+ }
73
+
74
+ let highest = 0;
75
+
76
+ for (let i = 0; i < indices.length; ++i) {
77
+ const code = indices[i];
78
+ indices[i] = highest - code;
79
+
80
+ if (code === 0) {
81
+ ++highest;
82
+ }
83
+ }
84
+
85
+ return indices;
86
+ }
87
+
88
+ function decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {
89
+ let position = vertexDataEndPosition;
90
+ const elementsPerVertex = 3;
91
+ const vertexCount = vertexData.length / elementsPerVertex;
92
+ const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
93
+
94
+ if (position % bytesPerIndex !== 0) {
95
+ position += bytesPerIndex - position % bytesPerIndex;
96
+ }
97
+
98
+ const triangleCount = dataView.getUint32(position, true);
99
+ position += Uint32Array.BYTES_PER_ELEMENT;
100
+ const triangleIndicesCount = triangleCount * 3;
101
+ const triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex);
102
+ position += triangleIndicesCount * bytesPerIndex;
103
+ return {
104
+ triangleIndicesEndPosition: position,
105
+ triangleIndices
106
+ };
107
+ }
108
+
109
+ function decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {
110
+ let position = triangleIndicesEndPosition;
111
+ const elementsPerVertex = 3;
112
+ const vertexCount = vertexData.length / elementsPerVertex;
113
+ const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
114
+ const westVertexCount = dataView.getUint32(position, true);
115
+ position += Uint32Array.BYTES_PER_ELEMENT;
116
+ const westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);
117
+ position += westVertexCount * bytesPerIndex;
118
+ const southVertexCount = dataView.getUint32(position, true);
119
+ position += Uint32Array.BYTES_PER_ELEMENT;
120
+ const southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false);
121
+ position += southVertexCount * bytesPerIndex;
122
+ const eastVertexCount = dataView.getUint32(position, true);
123
+ position += Uint32Array.BYTES_PER_ELEMENT;
124
+ const eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);
125
+ position += eastVertexCount * bytesPerIndex;
126
+ const northVertexCount = dataView.getUint32(position, true);
127
+ position += Uint32Array.BYTES_PER_ELEMENT;
128
+ const northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false);
129
+ position += northVertexCount * bytesPerIndex;
130
+ return {
131
+ edgeIndicesEndPosition: position,
132
+ westIndices,
133
+ southIndices,
134
+ eastIndices,
135
+ northIndices
136
+ };
137
+ }
138
+
139
+ function decodeVertexNormalsExtension(extensionDataView) {
140
+ return new Uint8Array(extensionDataView.buffer, extensionDataView.byteOffset, extensionDataView.byteLength);
141
+ }
142
+
143
+ function decodeWaterMaskExtension(extensionDataView) {
144
+ return extensionDataView.buffer.slice(extensionDataView.byteOffset, extensionDataView.byteOffset + extensionDataView.byteLength);
145
+ }
146
+
147
+ function decodeExtensions(dataView, indicesEndPosition) {
148
+ const extensions = {};
149
+
150
+ if (dataView.byteLength <= indicesEndPosition) {
151
+ return {
152
+ extensions,
153
+ extensionsEndPosition: indicesEndPosition
154
+ };
155
+ }
156
+
157
+ let position = indicesEndPosition;
158
+
159
+ while (position < dataView.byteLength) {
160
+ const extensionId = dataView.getUint8(position, true);
161
+ position += Uint8Array.BYTES_PER_ELEMENT;
162
+ const extensionLength = dataView.getUint32(position, true);
163
+ position += Uint32Array.BYTES_PER_ELEMENT;
164
+ const extensionView = new DataView(dataView.buffer, position, extensionLength);
165
+
166
+ switch (extensionId) {
167
+ case 1:
168
+ {
169
+ extensions.vertexNormals = decodeVertexNormalsExtension(extensionView);
170
+ break;
171
+ }
172
+
173
+ case 2:
174
+ {
175
+ extensions.waterMask = decodeWaterMaskExtension(extensionView);
176
+ break;
177
+ }
178
+
179
+ default:
180
+ {}
181
+ }
182
+
183
+ position += extensionLength;
184
+ }
185
+
186
+ return {
187
+ extensions,
188
+ extensionsEndPosition: position
189
+ };
190
+ }
191
+
192
+ const DECODING_STEPS = {
193
+ header: 0,
194
+ vertices: 1,
195
+ triangleIndices: 2,
196
+ edgeIndices: 3,
197
+ extensions: 4
198
+ };
199
+ exports.DECODING_STEPS = DECODING_STEPS;
200
+ const DEFAULT_OPTIONS = {
201
+ maxDecodingStep: DECODING_STEPS.extensions
202
+ };
203
+
204
+ function decode(data, userOptions) {
205
+ const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
206
+ const view = new DataView(data);
207
+ const {
208
+ header,
209
+ headerEndPosition
210
+ } = decodeHeader(view);
211
+
212
+ if (options.maxDecodingStep < DECODING_STEPS.vertices) {
213
+ return {
214
+ header
215
+ };
216
+ }
217
+
218
+ const {
219
+ vertexData,
220
+ vertexDataEndPosition
221
+ } = decodeVertexData(view, headerEndPosition);
222
+
223
+ if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {
224
+ return {
225
+ header,
226
+ vertexData
227
+ };
228
+ }
229
+
230
+ const {
231
+ triangleIndices,
232
+ triangleIndicesEndPosition
233
+ } = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
234
+
235
+ if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {
236
+ return {
237
+ header,
238
+ vertexData,
239
+ triangleIndices
240
+ };
241
+ }
242
+
243
+ const {
244
+ westIndices,
245
+ southIndices,
246
+ eastIndices,
247
+ northIndices,
248
+ edgeIndicesEndPosition
249
+ } = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
250
+
251
+ if (options.maxDecodingStep < DECODING_STEPS.extensions) {
252
+ return {
253
+ header,
254
+ vertexData,
255
+ triangleIndices,
256
+ westIndices,
257
+ northIndices,
258
+ eastIndices,
259
+ southIndices
260
+ };
261
+ }
262
+
263
+ const {
264
+ extensions
265
+ } = decodeExtensions(view, edgeIndicesEndPosition);
266
+ return {
267
+ header,
268
+ vertexData,
269
+ triangleIndices,
270
+ westIndices,
271
+ northIndices,
272
+ eastIndices,
273
+ southIndices,
274
+ extensions
275
+ };
276
+ }
277
+ //# sourceMappingURL=decode-quantized-mesh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/decode-quantized-mesh.ts"],"names":["QUANTIZED_MESH_HEADER","Map","Float64Array","BYTES_PER_ELEMENT","Float32Array","decodeZigZag","value","decodeHeader","dataView","position","header","key","bytesCount","getter","getFloat64","getFloat32","call","headerEndPosition","decodeVertexData","elementsPerVertex","vertexCount","getUint32","vertexData","Uint16Array","Uint32Array","bytesPerArrayElement","elementArrayLength","uArrayStartPosition","vArrayStartPosition","heightArrayStartPosition","u","v","height","i","getUint16","vertexDataEndPosition","decodeIndex","buffer","indicesCount","bytesPerIndex","encoded","indices","highest","length","code","decodeTriangleIndices","triangleCount","triangleIndicesCount","triangleIndices","triangleIndicesEndPosition","decodeEdgeIndices","westVertexCount","westIndices","southVertexCount","southIndices","eastVertexCount","eastIndices","northVertexCount","northIndices","edgeIndicesEndPosition","decodeVertexNormalsExtension","extensionDataView","Uint8Array","byteOffset","byteLength","decodeWaterMaskExtension","slice","decodeExtensions","indicesEndPosition","extensions","extensionsEndPosition","extensionId","getUint8","extensionLength","extensionView","DataView","vertexNormals","waterMask","DECODING_STEPS","vertices","edgeIndices","DEFAULT_OPTIONS","maxDecodingStep","decode","data","userOptions","options","Object","assign","view"],"mappings":";;;;;;;AAoBA,MAAMA,qBAAqB,GAAG,IAAIC,GAAJ,CAAQ,CACpC,CAAC,SAAD,EAAYC,YAAY,CAACC,iBAAzB,CADoC,EAEpC,CAAC,SAAD,EAAYD,YAAY,CAACC,iBAAzB,CAFoC,EAGpC,CAAC,SAAD,EAAYD,YAAY,CAACC,iBAAzB,CAHoC,EAKpC,CAAC,WAAD,EAAcC,YAAY,CAACD,iBAA3B,CALoC,EAMpC,CAAC,WAAD,EAAc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A0D;AACxD,WAAO;AAACtE,MAAAA,MAAD;AAASY,MAAAA,UAAT;AAAqB0B,MAAAA;AAArB,KAAP;AACD;;AAED,QAAM;AAACI,IAAAA,WAAD;AAAcE,IAAAA,YAAd;AAA4BE,IAAAA,WAA5B;AAAyCE,IAAAA,YAAzC;AAAuDC,IAAAA;AAAvD,MACJT,iBAAiB,CAACuC,IAAD,EAAOnE,UAAP,EAAmB2B,0BAAnB,CADnB;;AAGA,MAAIqC,OAAO,CAACJ,eAAR,GAA0BJ,cAAc,CAACT,UAA7C,EAAyD;AACvD,WAAO;AACL3D,MAAAA,MADK;AAELY,MAAAA,UAFK;AAGL0B,MAAAA,eAHK;AAILI,MAAAA,WAJK;AAKLM,MAAAA,YALK;AAMLF,MAAAA,WANK;AAOLF,MAAAA;AAPK,KAAP;AASD;;AAED,QAAM;AAACe,IAAAA;AAAD,MAAeF,gBAAgB,CAACsB,IAAD,EAAO9B,sBAAP,CAArC;AAEA,SAAO;AACLjD,IAAAA,MADK;AAELY,IAAAA,UAFK;AAGL0B,IAAAA,eAHK;AAILI,IAAAA,WAJK;AAKLM,IAAAA,YALK;AAMLF,IAAAA,WANK;AAOLF,IAAAA,YAPK;AAQLe,IAAAA;AARK,GAAP;AAUD","sourcesContent":["// Copyright (C) 2018-2019 HERE Europe B.V.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nconst QUANTIZED_MESH_HEADER = new Map([\n ['centerX', Float64Array.BYTES_PER_ELEMENT],\n ['centerY', Float64Array.BYTES_PER_ELEMENT],\n ['centerZ', Float64Array.BYTES_PER_ELEMENT],\n\n ['minHeight', Float32Array.BYTES_PER_ELEMENT],\n ['maxHeight', Float32Array.BYTES_PER_ELEMENT],\n\n ['boundingSphereCenterX', Float64Array.BYTES_PER_ELEMENT],\n ['boundingSphereCenterY', Float64Array.BYTES_PER_ELEMENT],\n ['boundingSphereCenterZ', Float64Array.BYTES_PER_ELEMENT],\n ['boundingSphereRadius', Float64Array.BYTES_PER_ELEMENT],\n\n ['horizonOcclusionPointX', Float64Array.BYTES_PER_ELEMENT],\n ['horizonOcclusionPointY', Float64Array.BYTES_PER_ELEMENT],\n ['horizonOcclusionPointZ', Float64Array.BYTES_PER_ELEMENT]\n]);\n\nfunction decodeZigZag(value) {\n return (value >> 1) ^ -(value & 1);\n}\n\nfunction decodeHeader(dataView) {\n let position = 0;\n const header = {};\n\n for (const [key, bytesCount] of QUANTIZED_MESH_HEADER) {\n const getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;\n\n header[key] = getter.call(dataView, position, true);\n position += bytesCount;\n }\n\n return {header, headerEndPosition: position};\n}\n\nfunction decodeVertexData(dataView, headerEndPosition) {\n let position = headerEndPosition;\n const elementsPerVertex = 3;\n const vertexCount = dataView.getUint32(position, true);\n const vertexData = new Uint16Array(vertexCount * elementsPerVertex);\n\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;\n const elementArrayLength = vertexCount * bytesPerArrayElement;\n const uArrayStartPosition = position;\n const vArrayStartPosition = uArrayStartPosition + elementArrayLength;\n const heightArrayStartPosition = vArrayStartPosition + elementArrayLength;\n\n let u = 0;\n let v = 0;\n let height = 0;\n\n for (let i = 0; i < vertexCount; i++) {\n u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));\n v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));\n height += decodeZigZag(\n dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true)\n );\n\n vertexData[i] = u;\n vertexData[i + vertexCount] = v;\n vertexData[i + vertexCount * 2] = height;\n }\n\n position += elementArrayLength * 3;\n\n return {vertexData, vertexDataEndPosition: position};\n}\n\nfunction decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = true) {\n let indices;\n\n if (bytesPerIndex === 2) {\n indices = new Uint16Array(buffer, position, indicesCount);\n } else {\n indices = new Uint32Array(buffer, position, indicesCount);\n }\n\n if (!encoded) {\n return indices;\n }\n\n let highest = 0;\n\n for (let i = 0; i < indices.length; ++i) {\n const code = indices[i];\n\n indices[i] = highest - code;\n\n if (code === 0) {\n ++highest;\n }\n }\n\n return indices;\n}\n\nfunction decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {\n let position = vertexDataEndPosition;\n const elementsPerVertex = 3;\n const vertexCount = vertexData.length / elementsPerVertex;\n const bytesPerIndex =\n vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;\n\n if (position % bytesPerIndex !== 0) {\n position += bytesPerIndex - (position % bytesPerIndex);\n }\n\n const triangleCount = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const triangleIndicesCount = triangleCount * 3;\n const triangleIndices = decodeIndex(\n dataView.buffer,\n position,\n triangleIndicesCount,\n bytesPerIndex\n );\n position += triangleIndicesCount * bytesPerIndex;\n\n return {\n triangleIndicesEndPosition: position,\n triangleIndices\n };\n}\n\nfunction decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {\n let position = triangleIndicesEndPosition;\n const elementsPerVertex = 3;\n const vertexCount = vertexData.length / elementsPerVertex;\n const bytesPerIndex =\n vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;\n\n const westVertexCount = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);\n position += westVertexCount * bytesPerIndex;\n\n const southVertexCount = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const southIndices = decodeIndex(\n dataView.buffer,\n position,\n southVertexCount,\n bytesPerIndex,\n false\n );\n position += southVertexCount * bytesPerIndex;\n\n const eastVertexCount = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);\n position += eastVertexCount * bytesPerIndex;\n\n const northVertexCount = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const northIndices = decodeIndex(\n dataView.buffer,\n position,\n northVertexCount,\n bytesPerIndex,\n false\n );\n position += northVertexCount * bytesPerIndex;\n\n return {\n edgeIndicesEndPosition: position,\n westIndices,\n southIndices,\n eastIndices,\n northIndices\n };\n}\n\nfunction decodeVertexNormalsExtension(extensionDataView) {\n return new Uint8Array(\n extensionDataView.buffer,\n extensionDataView.byteOffset,\n extensionDataView.byteLength\n );\n}\n\nfunction decodeWaterMaskExtension(extensionDataView) {\n return extensionDataView.buffer.slice(\n extensionDataView.byteOffset,\n extensionDataView.byteOffset + extensionDataView.byteLength\n );\n}\n\ntype Extensions = {\n vertexNormals?: any;\n waterMask?: any;\n};\n\nfunction decodeExtensions(dataView, indicesEndPosition) {\n const extensions: Extensions = {};\n\n if (dataView.byteLength <= indicesEndPosition) {\n return {extensions, extensionsEndPosition: indicesEndPosition};\n }\n\n let position = indicesEndPosition;\n\n while (position < dataView.byteLength) {\n const extensionId = dataView.getUint8(position, true);\n position += Uint8Array.BYTES_PER_ELEMENT;\n\n const extensionLength = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const extensionView = new DataView(dataView.buffer, position, extensionLength);\n\n switch (extensionId) {\n case 1: {\n extensions.vertexNormals = decodeVertexNormalsExtension(extensionView);\n\n break;\n }\n case 2: {\n extensions.waterMask = decodeWaterMaskExtension(extensionView);\n\n break;\n }\n default: {\n // console.warn(`Unknown extension with id ${extensionId}`)\n }\n }\n\n position += extensionLength;\n }\n\n return {extensions, extensionsEndPosition: position};\n}\n\nexport const DECODING_STEPS = {\n header: 0,\n vertices: 1,\n triangleIndices: 2,\n edgeIndices: 3,\n extensions: 4\n};\n\nconst DEFAULT_OPTIONS = {\n maxDecodingStep: DECODING_STEPS.extensions\n};\n\nexport default function decode(data, userOptions) {\n const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);\n const view = new DataView(data);\n const {header, headerEndPosition} = decodeHeader(view);\n\n if (options.maxDecodingStep < DECODING_STEPS.vertices) {\n return {header};\n }\n\n const {vertexData, vertexDataEndPosition} = decodeVertexData(view, headerEndPosition);\n\n if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {\n return {header, vertexData};\n }\n\n const {triangleIndices, triangleIndicesEndPosition} = decodeTriangleIndices(\n view,\n vertexData,\n vertexDataEndPosition\n );\n\n if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {\n return {header, vertexData, triangleIndices};\n }\n\n const {westIndices, southIndices, eastIndices, northIndices, edgeIndicesEndPosition} =\n decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);\n\n if (options.maxDecodingStep < DECODING_STEPS.extensions) {\n return {\n header,\n vertexData,\n triangleIndices,\n westIndices,\n northIndices,\n eastIndices,\n southIndices\n };\n }\n\n const {extensions} = decodeExtensions(view, edgeIndicesEndPosition);\n\n return {\n header,\n vertexData,\n triangleIndices,\n westIndices,\n northIndices,\n eastIndices,\n southIndices,\n extensions\n };\n}\n"],"file":"decode-quantized-mesh.js"}