@loaders.gl/terrain 3.0.9 → 3.0.13
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.es5.min.js +1 -1
- package/dist/dist.es5.min.js.map +1 -1
- package/dist/dist.min.js +1 -1
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/bundle.js +2 -2
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +9 -43
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/decode-quantized-mesh.js +106 -128
- package/dist/es5/lib/decode-quantized-mesh.js.map +1 -1
- package/dist/es5/lib/delatin/index.js +346 -379
- package/dist/es5/lib/delatin/index.js.map +1 -1
- package/dist/es5/lib/helpers/skirt.js +41 -55
- package/dist/es5/lib/helpers/skirt.js.map +1 -1
- package/dist/es5/lib/parse-quantized-mesh.js +44 -54
- package/dist/es5/lib/parse-quantized-mesh.js.map +1 -1
- package/dist/es5/lib/parse-terrain.js +78 -105
- package/dist/es5/lib/parse-terrain.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/es5/quantized-mesh-loader.js +2 -2
- package/dist/es5/quantized-mesh-loader.js.map +1 -1
- package/dist/es5/terrain-loader.js +2 -2
- package/dist/es5/terrain-loader.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/quantized-mesh-worker.js +1 -1
- package/dist/quantized-mesh-worker.js.map +1 -1
- package/dist/terrain-worker.js +1 -1
- package/dist/terrain-worker.js.map +1 -1
- package/package.json +4 -4
package/dist/es5/index.js
CHANGED
|
@@ -7,24 +7,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
Object.defineProperty(exports, "TerrainWorkerLoader", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function
|
|
10
|
+
get: function () {
|
|
11
11
|
return _terrainLoader.TerrainLoader;
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
Object.defineProperty(exports, "QuantizedMeshWorkerLoader", {
|
|
15
15
|
enumerable: true,
|
|
16
|
-
get: function
|
|
16
|
+
get: function () {
|
|
17
17
|
return _quantizedMeshLoader.QuantizedMeshLoader;
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
exports._typecheckQuantizedMeshLoader = exports.QuantizedMeshLoader = exports._typecheckTerrainLoader = exports.TerrainLoader = void 0;
|
|
21
21
|
|
|
22
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
23
|
-
|
|
24
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
25
|
-
|
|
26
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
27
|
-
|
|
28
22
|
var _parseQuantizedMesh = _interopRequireDefault(require("./lib/parse-quantized-mesh"));
|
|
29
23
|
|
|
30
24
|
var _parseTerrain = _interopRequireDefault(require("./lib/parse-terrain"));
|
|
@@ -33,45 +27,17 @@ var _terrainLoader = require("./terrain-loader");
|
|
|
33
27
|
|
|
34
28
|
var _quantizedMeshLoader = require("./quantized-mesh-loader");
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
39
|
-
|
|
40
|
-
var TerrainLoader = _objectSpread(_objectSpread({}, _terrainLoader.TerrainLoader), {}, {
|
|
30
|
+
const TerrainLoader = { ..._terrainLoader.TerrainLoader,
|
|
41
31
|
parse: _parseTerrain.default
|
|
42
|
-
}
|
|
43
|
-
|
|
32
|
+
};
|
|
44
33
|
exports.TerrainLoader = TerrainLoader;
|
|
45
|
-
|
|
34
|
+
const _typecheckTerrainLoader = TerrainLoader;
|
|
46
35
|
exports._typecheckTerrainLoader = _typecheckTerrainLoader;
|
|
47
|
-
|
|
48
|
-
var QuantizedMeshLoader = _objectSpread(_objectSpread({}, _quantizedMeshLoader.QuantizedMeshLoader), {}, {
|
|
36
|
+
const QuantizedMeshLoader = { ..._quantizedMeshLoader.QuantizedMeshLoader,
|
|
49
37
|
parseSync: _parseQuantizedMesh.default,
|
|
50
|
-
parse:
|
|
51
|
-
|
|
52
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
53
|
-
while (1) {
|
|
54
|
-
switch (_context.prev = _context.next) {
|
|
55
|
-
case 0:
|
|
56
|
-
return _context.abrupt("return", (0, _parseQuantizedMesh.default)(arrayBuffer, options));
|
|
57
|
-
|
|
58
|
-
case 1:
|
|
59
|
-
case "end":
|
|
60
|
-
return _context.stop();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}, _callee);
|
|
64
|
-
}));
|
|
65
|
-
|
|
66
|
-
function parse(_x, _x2) {
|
|
67
|
-
return _parse.apply(this, arguments);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return parse;
|
|
71
|
-
}()
|
|
72
|
-
});
|
|
73
|
-
|
|
38
|
+
parse: async (arrayBuffer, options) => (0, _parseQuantizedMesh.default)(arrayBuffer, options)
|
|
39
|
+
};
|
|
74
40
|
exports.QuantizedMeshLoader = QuantizedMeshLoader;
|
|
75
|
-
|
|
41
|
+
const _typecheckQuantizedMeshLoader = QuantizedMeshLoader;
|
|
76
42
|
exports._typecheckQuantizedMeshLoader = _typecheckQuantizedMeshLoader;
|
|
77
43
|
//# sourceMappingURL=index.js.map
|
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["TerrainLoader","TerrainWorkerLoader","parse","loadTerrain","_typecheckTerrainLoader","QuantizedMeshLoader","QuantizedMeshWorkerLoader","parseSync","parseQuantizedMesh","arrayBuffer","options","_typecheckQuantizedMeshLoader"],"mappings":"
|
|
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"}
|
|
@@ -1,72 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.default = decode;
|
|
9
7
|
exports.DECODING_STEPS = void 0;
|
|
10
|
-
|
|
11
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
-
|
|
13
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
14
|
-
|
|
15
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
-
|
|
17
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
18
|
-
|
|
19
|
-
var 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]]);
|
|
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]]);
|
|
20
9
|
|
|
21
10
|
function decodeZigZag(value) {
|
|
22
11
|
return value >> 1 ^ -(value & 1);
|
|
23
12
|
}
|
|
24
13
|
|
|
25
14
|
function decodeHeader(dataView) {
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
let position = 0;
|
|
16
|
+
const header = {};
|
|
28
17
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
34
|
-
var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
|
|
35
|
-
key = _step$value[0],
|
|
36
|
-
bytesCount = _step$value[1];
|
|
37
|
-
|
|
38
|
-
var getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;
|
|
39
|
-
header[key] = getter.call(dataView, position, true);
|
|
40
|
-
position += bytesCount;
|
|
41
|
-
}
|
|
42
|
-
} catch (err) {
|
|
43
|
-
_iterator.e(err);
|
|
44
|
-
} finally {
|
|
45
|
-
_iterator.f();
|
|
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;
|
|
46
22
|
}
|
|
47
23
|
|
|
48
24
|
return {
|
|
49
|
-
header
|
|
25
|
+
header,
|
|
50
26
|
headerEndPosition: position
|
|
51
27
|
};
|
|
52
28
|
}
|
|
53
29
|
|
|
54
30
|
function decodeVertexData(dataView, headerEndPosition) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
31
|
+
let position = headerEndPosition;
|
|
32
|
+
const elementsPerVertex = 3;
|
|
33
|
+
const vertexCount = dataView.getUint32(position, true);
|
|
34
|
+
const vertexData = new Uint16Array(vertexCount * elementsPerVertex);
|
|
59
35
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
for (
|
|
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++) {
|
|
70
46
|
u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));
|
|
71
47
|
v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));
|
|
72
48
|
height += decodeZigZag(dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true));
|
|
@@ -77,14 +53,13 @@ function decodeVertexData(dataView, headerEndPosition) {
|
|
|
77
53
|
|
|
78
54
|
position += elementArrayLength * 3;
|
|
79
55
|
return {
|
|
80
|
-
vertexData
|
|
56
|
+
vertexData,
|
|
81
57
|
vertexDataEndPosition: position
|
|
82
58
|
};
|
|
83
59
|
}
|
|
84
60
|
|
|
85
|
-
function decodeIndex(buffer, position, indicesCount, bytesPerIndex) {
|
|
86
|
-
|
|
87
|
-
var indices;
|
|
61
|
+
function decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = true) {
|
|
62
|
+
let indices;
|
|
88
63
|
|
|
89
64
|
if (bytesPerIndex === 2) {
|
|
90
65
|
indices = new Uint16Array(buffer, position, indicesCount);
|
|
@@ -96,10 +71,10 @@ function decodeIndex(buffer, position, indicesCount, bytesPerIndex) {
|
|
|
96
71
|
return indices;
|
|
97
72
|
}
|
|
98
73
|
|
|
99
|
-
|
|
74
|
+
let highest = 0;
|
|
100
75
|
|
|
101
|
-
for (
|
|
102
|
-
|
|
76
|
+
for (let i = 0; i < indices.length; ++i) {
|
|
77
|
+
const code = indices[i];
|
|
103
78
|
indices[i] = highest - code;
|
|
104
79
|
|
|
105
80
|
if (code === 0) {
|
|
@@ -111,53 +86,53 @@ function decodeIndex(buffer, position, indicesCount, bytesPerIndex) {
|
|
|
111
86
|
}
|
|
112
87
|
|
|
113
88
|
function decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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;
|
|
118
93
|
|
|
119
94
|
if (position % bytesPerIndex !== 0) {
|
|
120
95
|
position += bytesPerIndex - position % bytesPerIndex;
|
|
121
96
|
}
|
|
122
97
|
|
|
123
|
-
|
|
98
|
+
const triangleCount = dataView.getUint32(position, true);
|
|
124
99
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
125
|
-
|
|
126
|
-
|
|
100
|
+
const triangleIndicesCount = triangleCount * 3;
|
|
101
|
+
const triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex);
|
|
127
102
|
position += triangleIndicesCount * bytesPerIndex;
|
|
128
103
|
return {
|
|
129
104
|
triangleIndicesEndPosition: position,
|
|
130
|
-
triangleIndices
|
|
105
|
+
triangleIndices
|
|
131
106
|
};
|
|
132
107
|
}
|
|
133
108
|
|
|
134
109
|
function decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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);
|
|
140
115
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
141
|
-
|
|
116
|
+
const westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);
|
|
142
117
|
position += westVertexCount * bytesPerIndex;
|
|
143
|
-
|
|
118
|
+
const southVertexCount = dataView.getUint32(position, true);
|
|
144
119
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
145
|
-
|
|
120
|
+
const southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false);
|
|
146
121
|
position += southVertexCount * bytesPerIndex;
|
|
147
|
-
|
|
122
|
+
const eastVertexCount = dataView.getUint32(position, true);
|
|
148
123
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
149
|
-
|
|
124
|
+
const eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);
|
|
150
125
|
position += eastVertexCount * bytesPerIndex;
|
|
151
|
-
|
|
126
|
+
const northVertexCount = dataView.getUint32(position, true);
|
|
152
127
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
153
|
-
|
|
128
|
+
const northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false);
|
|
154
129
|
position += northVertexCount * bytesPerIndex;
|
|
155
130
|
return {
|
|
156
131
|
edgeIndicesEndPosition: position,
|
|
157
|
-
westIndices
|
|
158
|
-
southIndices
|
|
159
|
-
eastIndices
|
|
160
|
-
northIndices
|
|
132
|
+
westIndices,
|
|
133
|
+
southIndices,
|
|
134
|
+
eastIndices,
|
|
135
|
+
northIndices
|
|
161
136
|
};
|
|
162
137
|
}
|
|
163
138
|
|
|
@@ -170,23 +145,23 @@ function decodeWaterMaskExtension(extensionDataView) {
|
|
|
170
145
|
}
|
|
171
146
|
|
|
172
147
|
function decodeExtensions(dataView, indicesEndPosition) {
|
|
173
|
-
|
|
148
|
+
const extensions = {};
|
|
174
149
|
|
|
175
150
|
if (dataView.byteLength <= indicesEndPosition) {
|
|
176
151
|
return {
|
|
177
|
-
extensions
|
|
152
|
+
extensions,
|
|
178
153
|
extensionsEndPosition: indicesEndPosition
|
|
179
154
|
};
|
|
180
155
|
}
|
|
181
156
|
|
|
182
|
-
|
|
157
|
+
let position = indicesEndPosition;
|
|
183
158
|
|
|
184
159
|
while (position < dataView.byteLength) {
|
|
185
|
-
|
|
160
|
+
const extensionId = dataView.getUint8(position, true);
|
|
186
161
|
position += Uint8Array.BYTES_PER_ELEMENT;
|
|
187
|
-
|
|
162
|
+
const extensionLength = dataView.getUint32(position, true);
|
|
188
163
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
189
|
-
|
|
164
|
+
const extensionView = new DataView(dataView.buffer, position, extensionLength);
|
|
190
165
|
|
|
191
166
|
switch (extensionId) {
|
|
192
167
|
case 1:
|
|
@@ -209,12 +184,12 @@ function decodeExtensions(dataView, indicesEndPosition) {
|
|
|
209
184
|
}
|
|
210
185
|
|
|
211
186
|
return {
|
|
212
|
-
extensions
|
|
187
|
+
extensions,
|
|
213
188
|
extensionsEndPosition: position
|
|
214
189
|
};
|
|
215
190
|
}
|
|
216
191
|
|
|
217
|
-
|
|
192
|
+
const DECODING_STEPS = {
|
|
218
193
|
header: 0,
|
|
219
194
|
vertices: 1,
|
|
220
195
|
triangleIndices: 2,
|
|
@@ -222,78 +197,81 @@ var DECODING_STEPS = {
|
|
|
222
197
|
extensions: 4
|
|
223
198
|
};
|
|
224
199
|
exports.DECODING_STEPS = DECODING_STEPS;
|
|
225
|
-
|
|
200
|
+
const DEFAULT_OPTIONS = {
|
|
226
201
|
maxDecodingStep: DECODING_STEPS.extensions
|
|
227
202
|
};
|
|
228
203
|
|
|
229
204
|
function decode(data, userOptions) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
205
|
+
const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
|
|
206
|
+
const view = new DataView(data);
|
|
207
|
+
const {
|
|
208
|
+
header,
|
|
209
|
+
headerEndPosition
|
|
210
|
+
} = decodeHeader(view);
|
|
236
211
|
|
|
237
212
|
if (options.maxDecodingStep < DECODING_STEPS.vertices) {
|
|
238
213
|
return {
|
|
239
|
-
header
|
|
214
|
+
header
|
|
240
215
|
};
|
|
241
216
|
}
|
|
242
217
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
218
|
+
const {
|
|
219
|
+
vertexData,
|
|
220
|
+
vertexDataEndPosition
|
|
221
|
+
} = decodeVertexData(view, headerEndPosition);
|
|
246
222
|
|
|
247
223
|
if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {
|
|
248
224
|
return {
|
|
249
|
-
header
|
|
250
|
-
vertexData
|
|
225
|
+
header,
|
|
226
|
+
vertexData
|
|
251
227
|
};
|
|
252
228
|
}
|
|
253
229
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
230
|
+
const {
|
|
231
|
+
triangleIndices,
|
|
232
|
+
triangleIndicesEndPosition
|
|
233
|
+
} = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
|
|
257
234
|
|
|
258
235
|
if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {
|
|
259
236
|
return {
|
|
260
|
-
header
|
|
261
|
-
vertexData
|
|
262
|
-
triangleIndices
|
|
237
|
+
header,
|
|
238
|
+
vertexData,
|
|
239
|
+
triangleIndices
|
|
263
240
|
};
|
|
264
241
|
}
|
|
265
242
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
243
|
+
const {
|
|
244
|
+
westIndices,
|
|
245
|
+
southIndices,
|
|
246
|
+
eastIndices,
|
|
247
|
+
northIndices,
|
|
248
|
+
edgeIndicesEndPosition
|
|
249
|
+
} = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
|
|
272
250
|
|
|
273
251
|
if (options.maxDecodingStep < DECODING_STEPS.extensions) {
|
|
274
252
|
return {
|
|
275
|
-
header
|
|
276
|
-
vertexData
|
|
277
|
-
triangleIndices
|
|
278
|
-
westIndices
|
|
279
|
-
northIndices
|
|
280
|
-
eastIndices
|
|
281
|
-
southIndices
|
|
253
|
+
header,
|
|
254
|
+
vertexData,
|
|
255
|
+
triangleIndices,
|
|
256
|
+
westIndices,
|
|
257
|
+
northIndices,
|
|
258
|
+
eastIndices,
|
|
259
|
+
southIndices
|
|
282
260
|
};
|
|
283
261
|
}
|
|
284
262
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
263
|
+
const {
|
|
264
|
+
extensions
|
|
265
|
+
} = decodeExtensions(view, edgeIndicesEndPosition);
|
|
288
266
|
return {
|
|
289
|
-
header
|
|
290
|
-
vertexData
|
|
291
|
-
triangleIndices
|
|
292
|
-
westIndices
|
|
293
|
-
northIndices
|
|
294
|
-
eastIndices
|
|
295
|
-
southIndices
|
|
296
|
-
extensions
|
|
267
|
+
header,
|
|
268
|
+
vertexData,
|
|
269
|
+
triangleIndices,
|
|
270
|
+
westIndices,
|
|
271
|
+
northIndices,
|
|
272
|
+
eastIndices,
|
|
273
|
+
southIndices,
|
|
274
|
+
extensions
|
|
297
275
|
};
|
|
298
276
|
}
|
|
299
277
|
//# sourceMappingURL=decode-quantized-mesh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/decode-quantized-mesh.js"],"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,IAAMA,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,YAAT,CAAsBC,KAAtB,EAA6B;AAC3B,SAAQA,KAAK,IAAI,CAAV,GAAe,EAAEA,KAAK,GAAG,CAA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WAAP;AAAA,MAAoBE,YAApB,sBAAoBA,YAApB;AAAA,MAAkCE,WAAlC,sBAAkCA,WAAlC;AAAA,MAA+CE,YAA/C,sBAA+CA,YAA/C;AAAA,MAA6DC,sBAA7D,sBAA6DA,sBAA7D;;AAGA,MAAI2B,OAAO,CAACJ,eAAR,GAA0BJ,cAAc,CAACT,UAA7C,EAAyD;AACvD,WAAO;AACL3D,MAAAA,MAAM,EAANA,MADK;AAELY,MAAAA,UAAU,EAAVA,UAFK;AAGL0B,MAAAA,eAAe,EAAfA,eAHK;AAILI,MAAAA,WAAW,EAAXA,WAJK;AAKLM,MAAAA,YAAY,EAAZA,YALK;AAMLF,MAAAA,WAAW,EAAXA,WANK;AAOLF,MAAAA,YAAY,EAAZA;AAPK,KAAP;AASD;;AAED,0BAAqBa,gBAAgB,CAACsB,IAAD,EAAO9B,sBAAP,CAArC;AAAA,MAAOU,UAAP,qBAAOA,UAAP;;AAEA,SAAO;AACL3D,IAAAA,MAAM,EAANA,MADK;AAELY,IAAAA,UAAU,EAAVA,UAFK;AAGL0B,IAAAA,eAAe,EAAfA,eAHK;AAILI,IAAAA,WAAW,EAAXA,WAJK;AAKLM,IAAAA,YAAY,EAAZA,YALK;AAMLF,IAAAA,WAAW,EAAXA,WANK;AAOLF,IAAAA,YAAY,EAAZA,YAPK;AAQLe,IAAAA,UAAU,EAAVA;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\nfunction decodeExtensions(dataView, indicesEndPosition) {\n const 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"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/decode-quantized-mesh.js"],"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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AqB0B,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\nfunction decodeExtensions(dataView, indicesEndPosition) {\n const 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"}
|