@loaders.gl/terrain 3.1.3 → 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 (75) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/bundle.js.map +1 -0
  3. package/dist/index.js +14 -24
  4. package/dist/index.js.map +1 -0
  5. package/dist/lib/decode-quantized-mesh.js +241 -200
  6. package/dist/lib/decode-quantized-mesh.js.map +1 -0
  7. package/dist/lib/delatin/index.js +443 -397
  8. package/dist/lib/delatin/index.js.map +1 -0
  9. package/dist/lib/helpers/skirt.js +91 -119
  10. package/dist/lib/helpers/skirt.js.map +1 -0
  11. package/dist/lib/parse-quantized-mesh.js +90 -89
  12. package/dist/lib/parse-quantized-mesh.js.map +1 -0
  13. package/dist/lib/parse-terrain.js +166 -148
  14. package/dist/lib/parse-terrain.js.map +1 -0
  15. package/dist/lib/utils/version.js +2 -7
  16. package/dist/lib/utils/version.js.map +1 -0
  17. package/dist/quantized-mesh-loader.js +16 -21
  18. package/dist/quantized-mesh-loader.js.map +1 -0
  19. package/dist/quantized-mesh-worker.js +1 -1
  20. package/dist/terrain-loader.js +24 -32
  21. package/dist/terrain-loader.js.map +1 -0
  22. package/dist/terrain-worker.js +1 -1
  23. package/dist/workers/quantized-mesh-worker.js +4 -5
  24. package/dist/workers/quantized-mesh-worker.js.map +1 -0
  25. package/dist/workers/terrain-worker.js +4 -5
  26. package/dist/workers/terrain-worker.js.map +1 -0
  27. package/package.json +8 -8
  28. package/dist/es5/bundle.js +0 -7
  29. package/dist/es5/bundle.js.map +0 -1
  30. package/dist/es5/index.js +0 -77
  31. package/dist/es5/index.js.map +0 -1
  32. package/dist/es5/lib/decode-quantized-mesh.js +0 -299
  33. package/dist/es5/lib/decode-quantized-mesh.js.map +0 -1
  34. package/dist/es5/lib/delatin/index.js +0 -506
  35. package/dist/es5/lib/delatin/index.js.map +0 -1
  36. package/dist/es5/lib/helpers/skirt.js +0 -120
  37. package/dist/es5/lib/helpers/skirt.js.map +0 -1
  38. package/dist/es5/lib/parse-quantized-mesh.js +0 -119
  39. package/dist/es5/lib/parse-quantized-mesh.js.map +0 -1
  40. package/dist/es5/lib/parse-terrain.js +0 -219
  41. package/dist/es5/lib/parse-terrain.js.map +0 -1
  42. package/dist/es5/lib/utils/version.js +0 -9
  43. package/dist/es5/lib/utils/version.js.map +0 -1
  44. package/dist/es5/quantized-mesh-loader.js +0 -28
  45. package/dist/es5/quantized-mesh-loader.js.map +0 -1
  46. package/dist/es5/terrain-loader.js +0 -36
  47. package/dist/es5/terrain-loader.js.map +0 -1
  48. package/dist/es5/workers/quantized-mesh-worker.js +0 -8
  49. package/dist/es5/workers/quantized-mesh-worker.js.map +0 -1
  50. package/dist/es5/workers/terrain-worker.js +0 -8
  51. package/dist/es5/workers/terrain-worker.js.map +0 -1
  52. package/dist/esm/bundle.js +0 -5
  53. package/dist/esm/bundle.js.map +0 -1
  54. package/dist/esm/index.js +0 -16
  55. package/dist/esm/index.js.map +0 -1
  56. package/dist/esm/lib/decode-quantized-mesh.js +0 -268
  57. package/dist/esm/lib/decode-quantized-mesh.js.map +0 -1
  58. package/dist/esm/lib/delatin/index.js +0 -464
  59. package/dist/esm/lib/delatin/index.js.map +0 -1
  60. package/dist/esm/lib/helpers/skirt.js +0 -99
  61. package/dist/esm/lib/helpers/skirt.js.map +0 -1
  62. package/dist/esm/lib/parse-quantized-mesh.js +0 -96
  63. package/dist/esm/lib/parse-quantized-mesh.js.map +0 -1
  64. package/dist/esm/lib/parse-terrain.js +0 -180
  65. package/dist/esm/lib/parse-terrain.js.map +0 -1
  66. package/dist/esm/lib/utils/version.js +0 -2
  67. package/dist/esm/lib/utils/version.js.map +0 -1
  68. package/dist/esm/quantized-mesh-loader.js +0 -18
  69. package/dist/esm/quantized-mesh-loader.js.map +0 -1
  70. package/dist/esm/terrain-loader.js +0 -26
  71. package/dist/esm/terrain-loader.js.map +0 -1
  72. package/dist/esm/workers/quantized-mesh-worker.js +0 -4
  73. package/dist/esm/workers/quantized-mesh-worker.js.map +0 -1
  74. package/dist/esm/workers/terrain-worker.js +0 -4
  75. package/dist/esm/workers/terrain-worker.js.map +0 -1
package/dist/bundle.js CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";
2
- // @ts-nocheck
3
1
  const moduleExports = require('./index');
2
+
4
3
  globalThis.loaders = globalThis.loaders || {};
5
4
  module.exports = Object.assign(globalThis.loaders, moduleExports);
5
+ //# 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"}
package/dist/index.js CHANGED
@@ -1,26 +1,16 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ import parseQuantizedMesh from './lib/parse-quantized-mesh';
2
+ import loadTerrain from './lib/parse-terrain';
3
+ import { TerrainLoader as TerrainWorkerLoader } from './terrain-loader';
4
+ import { QuantizedMeshLoader as QuantizedMeshWorkerLoader } from './quantized-mesh-loader';
5
+ export { TerrainWorkerLoader };
6
+ export const TerrainLoader = { ...TerrainWorkerLoader,
7
+ parse: loadTerrain
4
8
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports._typecheckQuantizedMeshLoader = exports.QuantizedMeshLoader = exports.QuantizedMeshWorkerLoader = exports._typecheckTerrainLoader = exports.TerrainLoader = exports.TerrainWorkerLoader = void 0;
7
- const parse_quantized_mesh_1 = __importDefault(require("./lib/parse-quantized-mesh"));
8
- const parse_terrain_1 = __importDefault(require("./lib/parse-terrain"));
9
- const terrain_loader_1 = require("./terrain-loader");
10
- Object.defineProperty(exports, "TerrainWorkerLoader", { enumerable: true, get: function () { return terrain_loader_1.TerrainLoader; } });
11
- const quantized_mesh_loader_1 = require("./quantized-mesh-loader");
12
- Object.defineProperty(exports, "QuantizedMeshWorkerLoader", { enumerable: true, get: function () { return quantized_mesh_loader_1.QuantizedMeshLoader; } });
13
- exports.TerrainLoader = {
14
- ...terrain_loader_1.TerrainLoader,
15
- parse: parse_terrain_1.default
9
+ export const _typecheckTerrainLoader = TerrainLoader;
10
+ export { QuantizedMeshWorkerLoader };
11
+ export const QuantizedMeshLoader = { ...QuantizedMeshWorkerLoader,
12
+ parseSync: parseQuantizedMesh,
13
+ parse: async (arrayBuffer, options) => parseQuantizedMesh(arrayBuffer, options)
16
14
  };
17
- exports._typecheckTerrainLoader = exports.TerrainLoader; // eslint-disable-line
18
- /**
19
- * Loader for quantized meshes
20
- */
21
- exports.QuantizedMeshLoader = {
22
- ...quantized_mesh_loader_1.QuantizedMeshLoader,
23
- parseSync: parse_quantized_mesh_1.default,
24
- parse: async (arrayBuffer, options) => (0, parse_quantized_mesh_1.default)(arrayBuffer, options)
25
- };
26
- exports._typecheckQuantizedMeshLoader = exports.QuantizedMeshLoader;
15
+ export const _typecheckQuantizedMeshLoader = QuantizedMeshLoader;
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["parseQuantizedMesh","loadTerrain","TerrainLoader","TerrainWorkerLoader","QuantizedMeshLoader","QuantizedMeshWorkerLoader","parse","_typecheckTerrainLoader","parseSync","arrayBuffer","options","_typecheckQuantizedMeshLoader"],"mappings":"AACA,OAAOA,kBAAP,MAA+B,4BAA/B;AACA,OAAOC,WAAP,MAAwB,qBAAxB;AAEA,SAAQC,aAAa,IAAIC,mBAAzB,QAAmD,kBAAnD;AACA,SAAQC,mBAAmB,IAAIC,yBAA/B,QAA+D,yBAA/D;AAIA,SAAQF,mBAAR;AAEA,OAAO,MAAMD,aAAa,GAAG,EAC3B,GAAGC,mBADwB;AAE3BG,EAAAA,KAAK,EAAEL;AAFoB,CAAtB;AAKP,OAAO,MAAMM,uBAAyC,GAAGL,aAAlD;AAIP,SAAQG,yBAAR;AAKA,OAAO,MAAMD,mBAAmB,GAAG,EACjC,GAAGC,yBAD8B;AAEjCG,EAAAA,SAAS,EAAER,kBAFsB;AAGjCM,EAAAA,KAAK,EAAE,OAAOG,WAAP,EAAoBC,OAApB,KAAgCV,kBAAkB,CAACS,WAAD,EAAcC,OAAd;AAHxB,CAA5B;AAMP,OAAO,MAAMC,6BAA+C,GAAGP,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"}
@@ -1,227 +1,268 @@
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
- ]);
1
+ 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]]);
2
+
37
3
  function decodeZigZag(value) {
38
- return (value >> 1) ^ -(value & 1);
4
+ return value >> 1 ^ -(value & 1);
39
5
  }
6
+
40
7
  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 };
8
+ let position = 0;
9
+ const header = {};
10
+
11
+ for (const [key, bytesCount] of QUANTIZED_MESH_HEADER) {
12
+ const getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;
13
+ header[key] = getter.call(dataView, position, true);
14
+ position += bytesCount;
15
+ }
16
+
17
+ return {
18
+ header,
19
+ headerEndPosition: position
20
+ };
49
21
  }
22
+
50
23
  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 };
24
+ let position = headerEndPosition;
25
+ const elementsPerVertex = 3;
26
+ const vertexCount = dataView.getUint32(position, true);
27
+ const vertexData = new Uint16Array(vertexCount * elementsPerVertex);
28
+ position += Uint32Array.BYTES_PER_ELEMENT;
29
+ const bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;
30
+ const elementArrayLength = vertexCount * bytesPerArrayElement;
31
+ const uArrayStartPosition = position;
32
+ const vArrayStartPosition = uArrayStartPosition + elementArrayLength;
33
+ const heightArrayStartPosition = vArrayStartPosition + elementArrayLength;
34
+ let u = 0;
35
+ let v = 0;
36
+ let height = 0;
37
+
38
+ for (let i = 0; i < vertexCount; i++) {
39
+ u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));
40
+ v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));
41
+ height += decodeZigZag(dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true));
42
+ vertexData[i] = u;
43
+ vertexData[i + vertexCount] = v;
44
+ vertexData[i + vertexCount * 2] = height;
45
+ }
46
+
47
+ position += elementArrayLength * 3;
48
+ return {
49
+ vertexData,
50
+ vertexDataEndPosition: position
51
+ };
74
52
  }
53
+
75
54
  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
- }
55
+ let indices;
56
+
57
+ if (bytesPerIndex === 2) {
58
+ indices = new Uint16Array(buffer, position, indicesCount);
59
+ } else {
60
+ indices = new Uint32Array(buffer, position, indicesCount);
61
+ }
62
+
63
+ if (!encoded) {
94
64
  return indices;
65
+ }
66
+
67
+ let highest = 0;
68
+
69
+ for (let i = 0; i < indices.length; ++i) {
70
+ const code = indices[i];
71
+ indices[i] = highest - code;
72
+
73
+ if (code === 0) {
74
+ ++highest;
75
+ }
76
+ }
77
+
78
+ return indices;
95
79
  }
80
+
96
81
  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
- };
82
+ let position = vertexDataEndPosition;
83
+ const elementsPerVertex = 3;
84
+ const vertexCount = vertexData.length / elementsPerVertex;
85
+ const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
86
+
87
+ if (position % bytesPerIndex !== 0) {
88
+ position += bytesPerIndex - position % bytesPerIndex;
89
+ }
90
+
91
+ const triangleCount = dataView.getUint32(position, true);
92
+ position += Uint32Array.BYTES_PER_ELEMENT;
93
+ const triangleIndicesCount = triangleCount * 3;
94
+ const triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex);
95
+ position += triangleIndicesCount * bytesPerIndex;
96
+ return {
97
+ triangleIndicesEndPosition: position,
98
+ triangleIndices
99
+ };
113
100
  }
101
+
114
102
  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
- };
103
+ let position = triangleIndicesEndPosition;
104
+ const elementsPerVertex = 3;
105
+ const vertexCount = vertexData.length / elementsPerVertex;
106
+ const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
107
+ const westVertexCount = dataView.getUint32(position, true);
108
+ position += Uint32Array.BYTES_PER_ELEMENT;
109
+ const westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);
110
+ position += westVertexCount * bytesPerIndex;
111
+ const southVertexCount = dataView.getUint32(position, true);
112
+ position += Uint32Array.BYTES_PER_ELEMENT;
113
+ const southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false);
114
+ position += southVertexCount * bytesPerIndex;
115
+ const eastVertexCount = dataView.getUint32(position, true);
116
+ position += Uint32Array.BYTES_PER_ELEMENT;
117
+ const eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);
118
+ position += eastVertexCount * bytesPerIndex;
119
+ const northVertexCount = dataView.getUint32(position, true);
120
+ position += Uint32Array.BYTES_PER_ELEMENT;
121
+ const northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false);
122
+ position += northVertexCount * bytesPerIndex;
123
+ return {
124
+ edgeIndicesEndPosition: position,
125
+ westIndices,
126
+ southIndices,
127
+ eastIndices,
128
+ northIndices
129
+ };
142
130
  }
131
+
143
132
  function decodeVertexNormalsExtension(extensionDataView) {
144
- return new Uint8Array(extensionDataView.buffer, extensionDataView.byteOffset, extensionDataView.byteLength);
133
+ return new Uint8Array(extensionDataView.buffer, extensionDataView.byteOffset, extensionDataView.byteLength);
145
134
  }
135
+
146
136
  function decodeWaterMaskExtension(extensionDataView) {
147
- return extensionDataView.buffer.slice(extensionDataView.byteOffset, extensionDataView.byteOffset + extensionDataView.byteLength);
137
+ return extensionDataView.buffer.slice(extensionDataView.byteOffset, extensionDataView.byteOffset + extensionDataView.byteLength);
148
138
  }
139
+
149
140
  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
- }
141
+ const extensions = {};
142
+
143
+ if (dataView.byteLength <= indicesEndPosition) {
144
+ return {
145
+ extensions,
146
+ extensionsEndPosition: indicesEndPosition
147
+ };
148
+ }
149
+
150
+ let position = indicesEndPosition;
151
+
152
+ while (position < dataView.byteLength) {
153
+ const extensionId = dataView.getUint8(position, true);
154
+ position += Uint8Array.BYTES_PER_ELEMENT;
155
+ const extensionLength = dataView.getUint32(position, true);
156
+ position += Uint32Array.BYTES_PER_ELEMENT;
157
+ const extensionView = new DataView(dataView.buffer, position, extensionLength);
158
+
159
+ switch (extensionId) {
160
+ case 1:
161
+ {
162
+ extensions.vertexNormals = decodeVertexNormalsExtension(extensionView);
163
+ break;
164
+ }
165
+
166
+ case 2:
167
+ {
168
+ extensions.waterMask = decodeWaterMaskExtension(extensionView);
169
+ break;
173
170
  }
174
- position += extensionLength;
171
+
172
+ default:
173
+ {}
175
174
  }
176
- return { extensions, extensionsEndPosition: position };
175
+
176
+ position += extensionLength;
177
+ }
178
+
179
+ return {
180
+ extensions,
181
+ extensionsEndPosition: position
182
+ };
177
183
  }
178
- exports.DECODING_STEPS = {
179
- header: 0,
180
- vertices: 1,
181
- triangleIndices: 2,
182
- edgeIndices: 3,
183
- extensions: 4
184
+
185
+ export const DECODING_STEPS = {
186
+ header: 0,
187
+ vertices: 1,
188
+ triangleIndices: 2,
189
+ edgeIndices: 3,
190
+ extensions: 4
184
191
  };
185
192
  const DEFAULT_OPTIONS = {
186
- maxDecodingStep: exports.DECODING_STEPS.extensions
193
+ maxDecodingStep: DECODING_STEPS.extensions
187
194
  };
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);
195
+ export default function decode(data, userOptions) {
196
+ const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
197
+ const view = new DataView(data);
198
+ const {
199
+ header,
200
+ headerEndPosition
201
+ } = decodeHeader(view);
202
+
203
+ if (options.maxDecodingStep < DECODING_STEPS.vertices) {
204
+ return {
205
+ header
206
+ };
207
+ }
208
+
209
+ const {
210
+ vertexData,
211
+ vertexDataEndPosition
212
+ } = decodeVertexData(view, headerEndPosition);
213
+
214
+ if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {
215
+ return {
216
+ header,
217
+ vertexData
218
+ };
219
+ }
220
+
221
+ const {
222
+ triangleIndices,
223
+ triangleIndicesEndPosition
224
+ } = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
225
+
226
+ if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {
227
+ return {
228
+ header,
229
+ vertexData,
230
+ triangleIndices
231
+ };
232
+ }
233
+
234
+ const {
235
+ westIndices,
236
+ southIndices,
237
+ eastIndices,
238
+ northIndices,
239
+ edgeIndicesEndPosition
240
+ } = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
241
+
242
+ if (options.maxDecodingStep < DECODING_STEPS.extensions) {
216
243
  return {
217
- header,
218
- vertexData,
219
- triangleIndices,
220
- westIndices,
221
- northIndices,
222
- eastIndices,
223
- southIndices,
224
- extensions
244
+ header,
245
+ vertexData,
246
+ triangleIndices,
247
+ westIndices,
248
+ northIndices,
249
+ eastIndices,
250
+ southIndices
225
251
  };
252
+ }
253
+
254
+ const {
255
+ extensions
256
+ } = decodeExtensions(view, edgeIndicesEndPosition);
257
+ return {
258
+ header,
259
+ vertexData,
260
+ triangleIndices,
261
+ westIndices,
262
+ northIndices,
263
+ eastIndices,
264
+ southIndices,
265
+ extensions
266
+ };
226
267
  }
227
- exports.default = decode;
268
+ //# 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,EAAcC,YAAY,CAACD,iBAA3B,CANoC,EAQpC,CAAC,uBAAD,EAA0BD,YAAY,CAACC,iBAAvC,CARoC,EASpC,CAAC,uBAAD,EAA0BD,YAAY,CAACC,iBAAvC,CAToC,EAUpC,CAAC,uBAAD,EAA0BD,YAAY,CAACC,iBAAvC,CAVoC,EAWpC,CAAC,sBAAD,EAAyBD,YAAY,CAACC,iBAAtC,CAXoC,EAapC,CAAC,wBAAD,EAA2BD,YAAY,CAACC,iBAAxC,CAboC,EAcpC,CAAC,wBAAD,EAA2BD,YAAY,CAACC,iBAAxC,CAdoC,EAepC,CAAC,wBAAD,EAA2BD,YAAY,CAACC,iBAAxC,CAfoC,CAAR,CAA9B;;AAkBA,SAASE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JK;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"}