@loaders.gl/terrain 3.1.0-beta.6 → 3.1.2
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/bundle.js +5 -1181
- package/dist/dist.min.js +1181 -0
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +43 -9
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/decode-quantized-mesh.js +128 -106
- package/dist/es5/lib/decode-quantized-mesh.js.map +1 -1
- package/dist/es5/lib/delatin/index.js +379 -346
- package/dist/es5/lib/delatin/index.js.map +1 -1
- package/dist/es5/lib/helpers/skirt.js +53 -40
- package/dist/es5/lib/helpers/skirt.js.map +1 -1
- package/dist/es5/lib/parse-quantized-mesh.js +54 -44
- package/dist/es5/lib/parse-quantized-mesh.js.map +1 -1
- package/dist/es5/lib/parse-terrain.js +105 -78
- 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/package.json +5 -5
package/dist/es5/bundle.js
CHANGED
package/dist/es5/bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,
|
|
1
|
+
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,IAAMA,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/es5/index.js
CHANGED
|
@@ -7,18 +7,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
Object.defineProperty(exports, "TerrainWorkerLoader", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () {
|
|
10
|
+
get: function get() {
|
|
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 get() {
|
|
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
|
+
|
|
22
28
|
var _parseQuantizedMesh = _interopRequireDefault(require("./lib/parse-quantized-mesh"));
|
|
23
29
|
|
|
24
30
|
var _parseTerrain = _interopRequireDefault(require("./lib/parse-terrain"));
|
|
@@ -27,17 +33,45 @@ var _terrainLoader = require("./terrain-loader");
|
|
|
27
33
|
|
|
28
34
|
var _quantizedMeshLoader = require("./quantized-mesh-loader");
|
|
29
35
|
|
|
30
|
-
|
|
36
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
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), {}, {
|
|
31
41
|
parse: _parseTerrain.default
|
|
32
|
-
};
|
|
42
|
+
});
|
|
43
|
+
|
|
33
44
|
exports.TerrainLoader = TerrainLoader;
|
|
34
|
-
|
|
45
|
+
var _typecheckTerrainLoader = TerrainLoader;
|
|
35
46
|
exports._typecheckTerrainLoader = _typecheckTerrainLoader;
|
|
36
|
-
|
|
47
|
+
|
|
48
|
+
var QuantizedMeshLoader = _objectSpread(_objectSpread({}, _quantizedMeshLoader.QuantizedMeshLoader), {}, {
|
|
37
49
|
parseSync: _parseQuantizedMesh.default,
|
|
38
|
-
parse:
|
|
39
|
-
|
|
50
|
+
parse: function () {
|
|
51
|
+
var _parse = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer, options) {
|
|
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
|
+
|
|
40
74
|
exports.QuantizedMeshLoader = QuantizedMeshLoader;
|
|
41
|
-
|
|
75
|
+
var _typecheckQuantizedMeshLoader = QuantizedMeshLoader;
|
|
42
76
|
exports._typecheckQuantizedMeshLoader = _typecheckQuantizedMeshLoader;
|
|
43
77
|
//# 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,IAAMA,aAAa,mCACrBC,4BADqB;AAExBC,EAAAA,KAAK,EAAEC;AAFiB,EAAnB;;;AAKA,IAAMC,uBAAyC,GAAGJ,aAAlD;;;AASA,IAAMK,mBAAmB,mCAC3BC,wCAD2B;AAE9BC,EAAAA,SAAS,EAAEC,2BAFmB;AAG9BN,EAAAA,KAAK;AAAA,2EAAE,iBAAOO,WAAP,EAAoBC,OAApB;AAAA;AAAA;AAAA;AAAA;AAAA,+CAAgC,iCAAmBD,WAAnB,EAAgCC,OAAhC,CAAhC;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAAF;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAHyB,EAAzB;;;AAMA,IAAMC,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,48 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.default = decode;
|
|
7
9
|
exports.DECODING_STEPS = void 0;
|
|
8
|
-
|
|
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]]);
|
|
9
20
|
|
|
10
21
|
function decodeZigZag(value) {
|
|
11
22
|
return value >> 1 ^ -(value & 1);
|
|
12
23
|
}
|
|
13
24
|
|
|
14
25
|
function decodeHeader(dataView) {
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
var position = 0;
|
|
27
|
+
var header = {};
|
|
17
28
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
var _iterator = _createForOfIteratorHelper(QUANTIZED_MESH_HEADER),
|
|
30
|
+
_step;
|
|
31
|
+
|
|
32
|
+
try {
|
|
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();
|
|
22
46
|
}
|
|
23
47
|
|
|
24
48
|
return {
|
|
25
|
-
header,
|
|
49
|
+
header: header,
|
|
26
50
|
headerEndPosition: position
|
|
27
51
|
};
|
|
28
52
|
}
|
|
29
53
|
|
|
30
54
|
function decodeVertexData(dataView, headerEndPosition) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
var position = headerEndPosition;
|
|
56
|
+
var elementsPerVertex = 3;
|
|
57
|
+
var vertexCount = dataView.getUint32(position, true);
|
|
58
|
+
var vertexData = new Uint16Array(vertexCount * elementsPerVertex);
|
|
35
59
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
for (
|
|
60
|
+
var bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;
|
|
61
|
+
var elementArrayLength = vertexCount * bytesPerArrayElement;
|
|
62
|
+
var uArrayStartPosition = position;
|
|
63
|
+
var vArrayStartPosition = uArrayStartPosition + elementArrayLength;
|
|
64
|
+
var heightArrayStartPosition = vArrayStartPosition + elementArrayLength;
|
|
65
|
+
var u = 0;
|
|
66
|
+
var v = 0;
|
|
67
|
+
var height = 0;
|
|
68
|
+
|
|
69
|
+
for (var i = 0; i < vertexCount; i++) {
|
|
46
70
|
u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));
|
|
47
71
|
v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));
|
|
48
72
|
height += decodeZigZag(dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true));
|
|
@@ -53,13 +77,14 @@ function decodeVertexData(dataView, headerEndPosition) {
|
|
|
53
77
|
|
|
54
78
|
position += elementArrayLength * 3;
|
|
55
79
|
return {
|
|
56
|
-
vertexData,
|
|
80
|
+
vertexData: vertexData,
|
|
57
81
|
vertexDataEndPosition: position
|
|
58
82
|
};
|
|
59
83
|
}
|
|
60
84
|
|
|
61
|
-
function decodeIndex(buffer, position, indicesCount, bytesPerIndex
|
|
62
|
-
|
|
85
|
+
function decodeIndex(buffer, position, indicesCount, bytesPerIndex) {
|
|
86
|
+
var encoded = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
87
|
+
var indices;
|
|
63
88
|
|
|
64
89
|
if (bytesPerIndex === 2) {
|
|
65
90
|
indices = new Uint16Array(buffer, position, indicesCount);
|
|
@@ -71,10 +96,10 @@ function decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = tr
|
|
|
71
96
|
return indices;
|
|
72
97
|
}
|
|
73
98
|
|
|
74
|
-
|
|
99
|
+
var highest = 0;
|
|
75
100
|
|
|
76
|
-
for (
|
|
77
|
-
|
|
101
|
+
for (var i = 0; i < indices.length; ++i) {
|
|
102
|
+
var code = indices[i];
|
|
78
103
|
indices[i] = highest - code;
|
|
79
104
|
|
|
80
105
|
if (code === 0) {
|
|
@@ -86,53 +111,53 @@ function decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = tr
|
|
|
86
111
|
}
|
|
87
112
|
|
|
88
113
|
function decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
114
|
+
var position = vertexDataEndPosition;
|
|
115
|
+
var elementsPerVertex = 3;
|
|
116
|
+
var vertexCount = vertexData.length / elementsPerVertex;
|
|
117
|
+
var bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
|
|
93
118
|
|
|
94
119
|
if (position % bytesPerIndex !== 0) {
|
|
95
120
|
position += bytesPerIndex - position % bytesPerIndex;
|
|
96
121
|
}
|
|
97
122
|
|
|
98
|
-
|
|
123
|
+
var triangleCount = dataView.getUint32(position, true);
|
|
99
124
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
100
|
-
|
|
101
|
-
|
|
125
|
+
var triangleIndicesCount = triangleCount * 3;
|
|
126
|
+
var triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex);
|
|
102
127
|
position += triangleIndicesCount * bytesPerIndex;
|
|
103
128
|
return {
|
|
104
129
|
triangleIndicesEndPosition: position,
|
|
105
|
-
triangleIndices
|
|
130
|
+
triangleIndices: triangleIndices
|
|
106
131
|
};
|
|
107
132
|
}
|
|
108
133
|
|
|
109
134
|
function decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
135
|
+
var position = triangleIndicesEndPosition;
|
|
136
|
+
var elementsPerVertex = 3;
|
|
137
|
+
var vertexCount = vertexData.length / elementsPerVertex;
|
|
138
|
+
var bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
|
|
139
|
+
var westVertexCount = dataView.getUint32(position, true);
|
|
115
140
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
116
|
-
|
|
141
|
+
var westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);
|
|
117
142
|
position += westVertexCount * bytesPerIndex;
|
|
118
|
-
|
|
143
|
+
var southVertexCount = dataView.getUint32(position, true);
|
|
119
144
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
120
|
-
|
|
145
|
+
var southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false);
|
|
121
146
|
position += southVertexCount * bytesPerIndex;
|
|
122
|
-
|
|
147
|
+
var eastVertexCount = dataView.getUint32(position, true);
|
|
123
148
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
124
|
-
|
|
149
|
+
var eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);
|
|
125
150
|
position += eastVertexCount * bytesPerIndex;
|
|
126
|
-
|
|
151
|
+
var northVertexCount = dataView.getUint32(position, true);
|
|
127
152
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
128
|
-
|
|
153
|
+
var northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false);
|
|
129
154
|
position += northVertexCount * bytesPerIndex;
|
|
130
155
|
return {
|
|
131
156
|
edgeIndicesEndPosition: position,
|
|
132
|
-
westIndices,
|
|
133
|
-
southIndices,
|
|
134
|
-
eastIndices,
|
|
135
|
-
northIndices
|
|
157
|
+
westIndices: westIndices,
|
|
158
|
+
southIndices: southIndices,
|
|
159
|
+
eastIndices: eastIndices,
|
|
160
|
+
northIndices: northIndices
|
|
136
161
|
};
|
|
137
162
|
}
|
|
138
163
|
|
|
@@ -145,23 +170,23 @@ function decodeWaterMaskExtension(extensionDataView) {
|
|
|
145
170
|
}
|
|
146
171
|
|
|
147
172
|
function decodeExtensions(dataView, indicesEndPosition) {
|
|
148
|
-
|
|
173
|
+
var extensions = {};
|
|
149
174
|
|
|
150
175
|
if (dataView.byteLength <= indicesEndPosition) {
|
|
151
176
|
return {
|
|
152
|
-
extensions,
|
|
177
|
+
extensions: extensions,
|
|
153
178
|
extensionsEndPosition: indicesEndPosition
|
|
154
179
|
};
|
|
155
180
|
}
|
|
156
181
|
|
|
157
|
-
|
|
182
|
+
var position = indicesEndPosition;
|
|
158
183
|
|
|
159
184
|
while (position < dataView.byteLength) {
|
|
160
|
-
|
|
185
|
+
var extensionId = dataView.getUint8(position, true);
|
|
161
186
|
position += Uint8Array.BYTES_PER_ELEMENT;
|
|
162
|
-
|
|
187
|
+
var extensionLength = dataView.getUint32(position, true);
|
|
163
188
|
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
164
|
-
|
|
189
|
+
var extensionView = new DataView(dataView.buffer, position, extensionLength);
|
|
165
190
|
|
|
166
191
|
switch (extensionId) {
|
|
167
192
|
case 1:
|
|
@@ -184,12 +209,12 @@ function decodeExtensions(dataView, indicesEndPosition) {
|
|
|
184
209
|
}
|
|
185
210
|
|
|
186
211
|
return {
|
|
187
|
-
extensions,
|
|
212
|
+
extensions: extensions,
|
|
188
213
|
extensionsEndPosition: position
|
|
189
214
|
};
|
|
190
215
|
}
|
|
191
216
|
|
|
192
|
-
|
|
217
|
+
var DECODING_STEPS = {
|
|
193
218
|
header: 0,
|
|
194
219
|
vertices: 1,
|
|
195
220
|
triangleIndices: 2,
|
|
@@ -197,81 +222,78 @@ const DECODING_STEPS = {
|
|
|
197
222
|
extensions: 4
|
|
198
223
|
};
|
|
199
224
|
exports.DECODING_STEPS = DECODING_STEPS;
|
|
200
|
-
|
|
225
|
+
var DEFAULT_OPTIONS = {
|
|
201
226
|
maxDecodingStep: DECODING_STEPS.extensions
|
|
202
227
|
};
|
|
203
228
|
|
|
204
229
|
function decode(data, userOptions) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
230
|
+
var options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
|
|
231
|
+
var view = new DataView(data);
|
|
232
|
+
|
|
233
|
+
var _decodeHeader = decodeHeader(view),
|
|
234
|
+
header = _decodeHeader.header,
|
|
235
|
+
headerEndPosition = _decodeHeader.headerEndPosition;
|
|
211
236
|
|
|
212
237
|
if (options.maxDecodingStep < DECODING_STEPS.vertices) {
|
|
213
238
|
return {
|
|
214
|
-
header
|
|
239
|
+
header: header
|
|
215
240
|
};
|
|
216
241
|
}
|
|
217
242
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
} = decodeVertexData(view, headerEndPosition);
|
|
243
|
+
var _decodeVertexData = decodeVertexData(view, headerEndPosition),
|
|
244
|
+
vertexData = _decodeVertexData.vertexData,
|
|
245
|
+
vertexDataEndPosition = _decodeVertexData.vertexDataEndPosition;
|
|
222
246
|
|
|
223
247
|
if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {
|
|
224
248
|
return {
|
|
225
|
-
header,
|
|
226
|
-
vertexData
|
|
249
|
+
header: header,
|
|
250
|
+
vertexData: vertexData
|
|
227
251
|
};
|
|
228
252
|
}
|
|
229
253
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
} = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
|
|
254
|
+
var _decodeTriangleIndice = decodeTriangleIndices(view, vertexData, vertexDataEndPosition),
|
|
255
|
+
triangleIndices = _decodeTriangleIndice.triangleIndices,
|
|
256
|
+
triangleIndicesEndPosition = _decodeTriangleIndice.triangleIndicesEndPosition;
|
|
234
257
|
|
|
235
258
|
if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {
|
|
236
259
|
return {
|
|
237
|
-
header,
|
|
238
|
-
vertexData,
|
|
239
|
-
triangleIndices
|
|
260
|
+
header: header,
|
|
261
|
+
vertexData: vertexData,
|
|
262
|
+
triangleIndices: triangleIndices
|
|
240
263
|
};
|
|
241
264
|
}
|
|
242
265
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
} = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
|
|
266
|
+
var _decodeEdgeIndices = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition),
|
|
267
|
+
westIndices = _decodeEdgeIndices.westIndices,
|
|
268
|
+
southIndices = _decodeEdgeIndices.southIndices,
|
|
269
|
+
eastIndices = _decodeEdgeIndices.eastIndices,
|
|
270
|
+
northIndices = _decodeEdgeIndices.northIndices,
|
|
271
|
+
edgeIndicesEndPosition = _decodeEdgeIndices.edgeIndicesEndPosition;
|
|
250
272
|
|
|
251
273
|
if (options.maxDecodingStep < DECODING_STEPS.extensions) {
|
|
252
274
|
return {
|
|
253
|
-
header,
|
|
254
|
-
vertexData,
|
|
255
|
-
triangleIndices,
|
|
256
|
-
westIndices,
|
|
257
|
-
northIndices,
|
|
258
|
-
eastIndices,
|
|
259
|
-
southIndices
|
|
275
|
+
header: header,
|
|
276
|
+
vertexData: vertexData,
|
|
277
|
+
triangleIndices: triangleIndices,
|
|
278
|
+
westIndices: westIndices,
|
|
279
|
+
northIndices: northIndices,
|
|
280
|
+
eastIndices: eastIndices,
|
|
281
|
+
southIndices: southIndices
|
|
260
282
|
};
|
|
261
283
|
}
|
|
262
284
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
285
|
+
var _decodeExtensions = decodeExtensions(view, edgeIndicesEndPosition),
|
|
286
|
+
extensions = _decodeExtensions.extensions;
|
|
287
|
+
|
|
266
288
|
return {
|
|
267
|
-
header,
|
|
268
|
-
vertexData,
|
|
269
|
-
triangleIndices,
|
|
270
|
-
westIndices,
|
|
271
|
-
northIndices,
|
|
272
|
-
eastIndices,
|
|
273
|
-
southIndices,
|
|
274
|
-
extensions
|
|
289
|
+
header: header,
|
|
290
|
+
vertexData: vertexData,
|
|
291
|
+
triangleIndices: triangleIndices,
|
|
292
|
+
westIndices: westIndices,
|
|
293
|
+
northIndices: northIndices,
|
|
294
|
+
eastIndices: eastIndices,
|
|
295
|
+
southIndices: southIndices,
|
|
296
|
+
extensions: extensions
|
|
275
297
|
};
|
|
276
298
|
}
|
|
277
299
|
//# sourceMappingURL=decode-quantized-mesh.js.map
|
|
@@ -1 +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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;AAAT,KAAP;AACD;;AAED,QAAM;AAAC0B,IAAAA,eAAD;AAAkBC,IAAAA;AAAlB,MAAgDJ,qBAAqB,CACzE4C,IADyE,EAEzEnE,UAFyE,EAGzEa,qBAHyE,CAA3E;;AAMA,MAAImD,OAAO,CAACJ,eAAR,GAA0BJ,cAAc,CAACE,WAA7C,EAA0D;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"}
|
|
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,IAAMA,qBAAqB,GAAG,IAAIC,GAAJ,CAAQ,CACpC,CAAC,SAAD,EAAYC,YAAY,CAACC,iBAAzB,CADoC,EAEpC,CAAC,SAAD,EAAYD,YAAY,CAACC,iBAAzB,CAFoC,E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AAOA,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\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"}
|