@loaders.gl/tile-converter 3.4.13 → 3.4.15
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/3d-tiles-attributes-worker.js +1 -1
- package/dist/converter.min.js +78 -77
- package/dist/dist.min.js +2081 -1557
- package/dist/es5/3d-tiles-attributes-worker.js +3 -3
- package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +203 -417
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +197 -266
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +4 -6
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +12 -12
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js +35 -51
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/constants.js +1 -1
- package/dist/es5/constants.js.map +1 -1
- package/dist/es5/converter-cli.js +78 -133
- package/dist/es5/converter-cli.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +38 -110
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-attributes-worker.js +3 -3
- package/dist/es5/i3s-attributes-worker.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +31 -36
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +23 -23
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +9 -27
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/feature-attributes.js +27 -42
- package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +97 -114
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +524 -799
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js +24 -25
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-debug.js +27 -25
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-index-document.js +165 -461
- package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-pages.js +169 -474
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +663 -1401
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/geometry-definitions.js +82 -92
- package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/layers.js +130 -152
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/metadata.js +21 -23
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/node.js +78 -89
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/scene-server.js +27 -31
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +110 -152
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/store.js +2 -4
- package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/es5/i3s-server/app.js +6 -6
- package/dist/es5/i3s-server/app.js.map +1 -1
- package/dist/es5/i3s-server/controllers/index-controller.js +20 -49
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/es5/i3s-server/routes/index.js +14 -33
- package/dist/es5/i3s-server/routes/index.js.map +1 -1
- package/dist/es5/index.js +2 -2
- package/dist/es5/lib/utils/compress-util.js +127 -295
- package/dist/es5/lib/utils/compress-util.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +65 -174
- package/dist/es5/lib/utils/file-utils.js.map +1 -1
- package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/es5/lib/utils/queue.js +13 -38
- package/dist/es5/lib/utils/queue.js.map +1 -1
- package/dist/es5/lib/utils/statistic-utills.js +39 -117
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
- package/dist/es5/lib/utils/write-queue.js +74 -195
- package/dist/es5/lib/utils/write-queue.js.map +1 -1
- package/dist/es5/pgm-loader.js +3 -22
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/es5/workers/3d-tiles-attributes-worker.js +5 -22
- package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/es5/workers/i3s-attributes-worker.js +4 -25
- package/dist/es5/workers/i3s-attributes-worker.js.map +1 -1
- package/dist/esm/3d-tiles-attributes-worker.js +1 -1
- package/dist/esm/deps-installer/deps-installer.js +1 -1
- package/dist/esm/i3s-attributes-worker.js +1 -1
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/i3s-attributes-worker.js +2 -2
- package/dist/i3s-attributes-worker.js.map +3 -3
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/i3s-converter/helpers/batch-ids-extensions.ts +1 -1
- package/src/i3s-converter/helpers/geometry-converter.ts +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statistic-utills.js","names":["_path","require","_fs","_fileUtils","
|
|
1
|
+
{"version":3,"file":"statistic-utills.js","names":["_path","require","_fs","_fileUtils","timeConverter","time","nanoSecondsInMillisecond","timeInSeconds","hours","Math","floor","minutes","seconds","milliseconds","result","concat","calculateFilesSize","params","slpk","outputPath","tilesetName","fullOutputPath","getAbsoluteFilePath","slpkPath","join","stat","fs","size","directoryPath","totalSize","getTotalFilesSize","error","console","log","dirPath","totalFileSize","files","readdir","file","fileStat","isDirectory"],"sources":["../../../../src/lib/utils/statistic-utills.ts"],"sourcesContent":["import {join} from 'path';\nimport {promises as fs} from 'fs';\nimport {getAbsoluteFilePath} from './file-utils';\n\nexport function timeConverter(time) {\n const nanoSecondsInMillisecond = 1e6;\n let timeInSeconds = time[0];\n const hours = Math.floor(timeInSeconds / 3600);\n timeInSeconds = timeInSeconds - hours * 3600;\n const minutes = Math.floor(timeInSeconds / 60);\n timeInSeconds = timeInSeconds - minutes * 60;\n const seconds = Math.floor(timeInSeconds);\n const milliseconds = time[1] / nanoSecondsInMillisecond;\n let result = '';\n\n if (hours) {\n result += `${hours}h `;\n }\n\n if (minutes) {\n result += `${minutes}m `;\n }\n\n if (seconds) {\n result += `${seconds}s`;\n }\n\n if (!result) {\n result += `${milliseconds}ms`;\n }\n\n return result;\n}\n\nexport async function calculateFilesSize(params) {\n const {slpk, outputPath, tilesetName} = params;\n const fullOutputPath = getAbsoluteFilePath(outputPath);\n\n try {\n if (slpk) {\n const slpkPath = join(fullOutputPath, `${tilesetName}.slpk`);\n const stat = await fs.stat(slpkPath);\n return stat.size;\n }\n\n const directoryPath = join(fullOutputPath, tilesetName);\n const totalSize = await getTotalFilesSize(directoryPath);\n return totalSize;\n } catch (error) {\n console.log('Calculate file sizes error: ', error); // eslint-disable-line\n return null;\n }\n}\n\nasync function getTotalFilesSize(dirPath) {\n let totalFileSize = 0;\n\n const files = await fs.readdir(dirPath);\n\n for (const file of files) {\n const fileStat = await fs.stat(join(dirPath, file));\n if (fileStat.isDirectory()) {\n totalFileSize += await getTotalFilesSize(join(dirPath, file));\n } else {\n totalFileSize += fileStat.size;\n }\n }\n return totalFileSize;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,GAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEO,SAASG,aAAaA,CAACC,IAAI,EAAE;EAClC,MAAMC,wBAAwB,GAAG,GAAG;EACpC,IAAIC,aAAa,GAAGF,IAAI,CAAC,CAAC,CAAC;EAC3B,MAAMG,KAAK,GAAGC,IAAI,CAACC,KAAK,CAACH,aAAa,GAAG,IAAI,CAAC;EAC9CA,aAAa,GAAGA,aAAa,GAAGC,KAAK,GAAG,IAAI;EAC5C,MAAMG,OAAO,GAAGF,IAAI,CAACC,KAAK,CAACH,aAAa,GAAG,EAAE,CAAC;EAC9CA,aAAa,GAAGA,aAAa,GAAGI,OAAO,GAAG,EAAE;EAC5C,MAAMC,OAAO,GAAGH,IAAI,CAACC,KAAK,CAACH,aAAa,CAAC;EACzC,MAAMM,YAAY,GAAGR,IAAI,CAAC,CAAC,CAAC,GAAGC,wBAAwB;EACvD,IAAIQ,MAAM,GAAG,EAAE;EAEf,IAAIN,KAAK,EAAE;IACTM,MAAM,OAAAC,MAAA,CAAOP,KAAK,OAAI;EACxB;EAEA,IAAIG,OAAO,EAAE;IACXG,MAAM,OAAAC,MAAA,CAAOJ,OAAO,OAAI;EAC1B;EAEA,IAAIC,OAAO,EAAE;IACXE,MAAM,OAAAC,MAAA,CAAOH,OAAO,MAAG;EACzB;EAEA,IAAI,CAACE,MAA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II,QAAQ,CAACZ,IAAI;IAChC;EACF;EACA,OAAOQ,aAAa;AACtB"}
|
|
@@ -5,210 +5,89 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
13
|
-
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
14
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
16
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
17
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
9
|
var _queue = require("./queue");
|
|
19
10
|
var _process = _interopRequireDefault(require("process"));
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
(0,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "writePromise", null);
|
|
34
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "fileMap", {});
|
|
35
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "listeningInterval", void 0);
|
|
36
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "writeConcurrency", void 0);
|
|
37
|
-
_this.listeningInterval = listeningInterval;
|
|
38
|
-
_this.writeConcurrency = writeConcurrency;
|
|
39
|
-
return _this;
|
|
11
|
+
const MEMORY_LIMIT = 4 * 1024 * 1024 * 1024;
|
|
12
|
+
class WriteQueue extends _queue.Queue {
|
|
13
|
+
constructor() {
|
|
14
|
+
let listeningInterval = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2000;
|
|
15
|
+
let writeConcurrency = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 400;
|
|
16
|
+
super();
|
|
17
|
+
(0, _defineProperty2.default)(this, "intervalId", void 0);
|
|
18
|
+
(0, _defineProperty2.default)(this, "writePromise", null);
|
|
19
|
+
(0, _defineProperty2.default)(this, "fileMap", {});
|
|
20
|
+
(0, _defineProperty2.default)(this, "listeningInterval", void 0);
|
|
21
|
+
(0, _defineProperty2.default)(this, "writeConcurrency", void 0);
|
|
22
|
+
this.listeningInterval = listeningInterval;
|
|
23
|
+
this.writeConcurrency = writeConcurrency;
|
|
40
24
|
}
|
|
41
|
-
(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
52
|
-
while (1) switch (_context.prev = _context.next) {
|
|
53
|
-
case 0:
|
|
54
|
-
writeImmediately = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
|
|
55
|
-
if (!writeImmediately) {
|
|
56
|
-
_context.next = 9;
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
_ref = val, archiveKey = _ref.archiveKey, writePromise = _ref.writePromise;
|
|
60
|
-
_context.next = 5;
|
|
61
|
-
return writePromise();
|
|
62
|
-
case 5:
|
|
63
|
-
result = _context.sent;
|
|
64
|
-
if (archiveKey && result) {
|
|
65
|
-
this.fileMap[archiveKey] = result;
|
|
66
|
-
}
|
|
67
|
-
_context.next = 13;
|
|
68
|
-
break;
|
|
69
|
-
case 9:
|
|
70
|
-
(0, _get2.default)((0, _getPrototypeOf2.default)(WriteQueue.prototype), "enqueue", this).call(this, val);
|
|
71
|
-
if (!(_process.default.memoryUsage().rss > MEMORY_LIMIT)) {
|
|
72
|
-
_context.next = 13;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
_context.next = 13;
|
|
76
|
-
return this.startWrite();
|
|
77
|
-
case 13:
|
|
78
|
-
case "end":
|
|
79
|
-
return _context.stop();
|
|
80
|
-
}
|
|
81
|
-
}, _callee, this);
|
|
82
|
-
}));
|
|
83
|
-
function enqueue(_x) {
|
|
84
|
-
return _enqueue.apply(this, arguments);
|
|
25
|
+
async enqueue(val) {
|
|
26
|
+
let writeImmediately = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
27
|
+
if (writeImmediately) {
|
|
28
|
+
const {
|
|
29
|
+
archiveKey,
|
|
30
|
+
writePromise
|
|
31
|
+
} = val;
|
|
32
|
+
const result = await writePromise();
|
|
33
|
+
if (archiveKey && result) {
|
|
34
|
+
this.fileMap[archiveKey] = result;
|
|
85
35
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
value: function startListening() {
|
|
91
|
-
this.intervalId = setInterval(this.startWrite.bind(this), this.listeningInterval);
|
|
92
|
-
}
|
|
93
|
-
}, {
|
|
94
|
-
key: "stopListening",
|
|
95
|
-
value: function stopListening() {
|
|
96
|
-
if (this.intervalId) {
|
|
97
|
-
clearInterval(this.intervalId);
|
|
36
|
+
} else {
|
|
37
|
+
super.enqueue(val);
|
|
38
|
+
if (_process.default.memoryUsage().rss > MEMORY_LIMIT) {
|
|
39
|
+
await this.startWrite();
|
|
98
40
|
}
|
|
99
41
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
var _finalize = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3() {
|
|
129
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
130
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
131
|
-
case 0:
|
|
132
|
-
this.stopListening();
|
|
133
|
-
_context3.next = 3;
|
|
134
|
-
return this.startWrite();
|
|
135
|
-
case 3:
|
|
136
|
-
case "end":
|
|
137
|
-
return _context3.stop();
|
|
138
|
-
}
|
|
139
|
-
}, _callee3, this);
|
|
140
|
-
}));
|
|
141
|
-
function finalize() {
|
|
142
|
-
return _finalize.apply(this, arguments);
|
|
143
|
-
}
|
|
144
|
-
return finalize;
|
|
145
|
-
}()
|
|
146
|
-
}, {
|
|
147
|
-
key: "doWrite",
|
|
148
|
-
value: function () {
|
|
149
|
-
var _doWrite = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee4() {
|
|
150
|
-
var promises, archiveKeys, i, item, _ref2, archiveKey, writePromise, promise, writeResults;
|
|
151
|
-
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
152
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
153
|
-
case 0:
|
|
154
|
-
if (!this.length) {
|
|
155
|
-
_context4.next = 21;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
promises = [];
|
|
159
|
-
archiveKeys = [];
|
|
160
|
-
i = 0;
|
|
161
|
-
case 4:
|
|
162
|
-
if (!(i < this.writeConcurrency)) {
|
|
163
|
-
_context4.next = 15;
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
item = this.dequeue();
|
|
167
|
-
if (item) {
|
|
168
|
-
_context4.next = 8;
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
return _context4.abrupt("break", 15);
|
|
172
|
-
case 8:
|
|
173
|
-
_ref2 = item, archiveKey = _ref2.archiveKey, writePromise = _ref2.writePromise;
|
|
174
|
-
archiveKeys.push(archiveKey);
|
|
175
|
-
promise = writePromise();
|
|
176
|
-
promises.push(promise);
|
|
177
|
-
case 12:
|
|
178
|
-
i++;
|
|
179
|
-
_context4.next = 4;
|
|
180
|
-
break;
|
|
181
|
-
case 15:
|
|
182
|
-
_context4.next = 17;
|
|
183
|
-
return Promise.allSettled(promises);
|
|
184
|
-
case 17:
|
|
185
|
-
writeResults = _context4.sent;
|
|
186
|
-
this.updateFileMap(archiveKeys, writeResults);
|
|
187
|
-
_context4.next = 0;
|
|
188
|
-
break;
|
|
189
|
-
case 21:
|
|
190
|
-
case "end":
|
|
191
|
-
return _context4.stop();
|
|
192
|
-
}
|
|
193
|
-
}, _callee4, this);
|
|
194
|
-
}));
|
|
195
|
-
function doWrite() {
|
|
196
|
-
return _doWrite.apply(this, arguments);
|
|
197
|
-
}
|
|
198
|
-
return doWrite;
|
|
199
|
-
}()
|
|
200
|
-
}, {
|
|
201
|
-
key: "updateFileMap",
|
|
202
|
-
value: function updateFileMap(archiveKeys, writeResults) {
|
|
203
|
-
for (var i = 0; i < archiveKeys.length; i++) {
|
|
204
|
-
var archiveKey = archiveKeys[i];
|
|
205
|
-
if (archiveKey && 'value' in writeResults[i]) {
|
|
206
|
-
this.fileMap[archiveKey] = writeResults[i].value;
|
|
42
|
+
}
|
|
43
|
+
startListening() {
|
|
44
|
+
this.intervalId = setInterval(this.startWrite.bind(this), this.listeningInterval);
|
|
45
|
+
}
|
|
46
|
+
stopListening() {
|
|
47
|
+
if (this.intervalId) {
|
|
48
|
+
clearInterval(this.intervalId);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async startWrite() {
|
|
52
|
+
if (!this.writePromise) {
|
|
53
|
+
this.writePromise = this.doWrite();
|
|
54
|
+
}
|
|
55
|
+
await this.writePromise;
|
|
56
|
+
this.writePromise = null;
|
|
57
|
+
}
|
|
58
|
+
async finalize() {
|
|
59
|
+
this.stopListening();
|
|
60
|
+
await this.startWrite();
|
|
61
|
+
}
|
|
62
|
+
async doWrite() {
|
|
63
|
+
while (this.length) {
|
|
64
|
+
const promises = [];
|
|
65
|
+
const archiveKeys = [];
|
|
66
|
+
for (let i = 0; i < this.writeConcurrency; i++) {
|
|
67
|
+
const item = this.dequeue();
|
|
68
|
+
if (!item) {
|
|
69
|
+
break;
|
|
207
70
|
}
|
|
71
|
+
const {
|
|
72
|
+
archiveKey,
|
|
73
|
+
writePromise
|
|
74
|
+
} = item;
|
|
75
|
+
archiveKeys.push(archiveKey);
|
|
76
|
+
const promise = writePromise();
|
|
77
|
+
promises.push(promise);
|
|
208
78
|
}
|
|
79
|
+
const writeResults = await Promise.allSettled(promises);
|
|
80
|
+
this.updateFileMap(archiveKeys, writeResults);
|
|
209
81
|
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
82
|
+
}
|
|
83
|
+
updateFileMap(archiveKeys, writeResults) {
|
|
84
|
+
for (let i = 0; i < archiveKeys.length; i++) {
|
|
85
|
+
const archiveKey = archiveKeys[i];
|
|
86
|
+
if (archiveKey && 'value' in writeResults[i]) {
|
|
87
|
+
this.fileMap[archiveKey] = writeResults[i].value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
213
92
|
exports.default = WriteQueue;
|
|
214
93
|
//# sourceMappingURL=write-queue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-queue.js","names":["_queue","require","_process","_interopRequireDefault","_createSuper","Derived","hasNativeReflectConstruct","_isNativeReflectConstruct","_createSuperInternal","Super","_getPrototypeOf2","default","result","NewTarget","constructor","Reflect","construct","arguments","apply","_possibleConstructorReturn2","sham","Proxy","Boolean","prototype","valueOf","call","e","MEMORY_LIMIT","WriteQueue","_Queue","_inherits2","_super","_this","listeningInterval","length","undefined","writeConcurrency","_classCallCheck2","_defineProperty2","_assertThisInitialized2","_createClass2","key","value","_enqueue","_asyncToGenerator2","_regenerator","mark","_callee","val","writeImmediately","_ref","archiveKey","writePromise","_args","wrap","_callee$","_context","prev","next","sent","fileMap","_get2","process","memoryUsage","rss","startWrite","stop","enqueue","_x","startListening","intervalId","setInterval","bind","stopListening","clearInterval","_startWrite","_callee2","_callee2$","_context2","doWrite","_finalize","_callee3","_callee3$","_context3","finalize","_doWrite","_callee4","promises","archiveKeys","i","item","_ref2","promise","writeResults","_callee4$","_context4","dequeue","abrupt","push","Promise","allSettled","updateFileMap","Queue","exports"],"sources":["../../../../src/lib/utils/write-queue.ts"],"sourcesContent":["import {Queue} from './queue';\nimport process from 'process';\n\n/** Memory limit size is based on testing */\nconst MEMORY_LIMIT = 4 * 1024 * 1024 * 1024; // 4GB\n\nexport type WriteQueueItem = {\n archiveKey?: string;\n /**\n * writePromise() returns a Promise that will be awaited in Promise.allSettled(promises);\n * Arguments for this call are specified in writeQueue.enqueue call like this:\n * await writeQueue.enqueue({\n * archiveKey: `nodePages/xxx.json.gz`,\n * writePromise: () => writeFileForSlpk(slpkPath, data, `xxx.json`)\n * });\n * Note, a function like writeFileForSlpk should NOT be called when initializing the object for enqueue().\n * If he function is called, the promise will be created\n * and the function will allocate resources (file descriptors) for file writing.\n * It will be done for ALL items in the queue, which is not supposed to happen.\n * That's why the function should be passed as\n * writePromise: () => writeFileForSlpk(slpkPath, content, `xxx.json`)\n * instead of\n * writePromise: writeFileForSlpk(slpkPath, content, `xxx.json`) // INCORRECT !\n */\n writePromise: () => Promise<string | null>;\n};\n\nexport default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {\n private intervalId?: NodeJS.Timeout;\n public writePromise: Promise<void> | null = null;\n public fileMap: {[key: string]: string} = {};\n public listeningInterval: number;\n public writeConcurrency: number;\n\n constructor(listeningInterval: number = 2000, writeConcurrency: number = 400) {\n super();\n this.listeningInterval = listeningInterval;\n this.writeConcurrency = writeConcurrency;\n }\n\n async enqueue(val: T, writeImmediately: boolean = false) {\n if (writeImmediately) {\n const {archiveKey, writePromise} = val as WriteQueueItem;\n const result = await writePromise();\n if (archiveKey && result) {\n this.fileMap[archiveKey] = result;\n }\n } else {\n super.enqueue(val);\n /** https://nodejs.org/docs/latest-v14.x/api/process.html#process_process_memoryusage */\n if (process.memoryUsage().rss > MEMORY_LIMIT) {\n await this.startWrite();\n }\n }\n }\n\n startListening() {\n this.intervalId = setInterval(this.startWrite.bind(this), this.listeningInterval);\n }\n\n stopListening() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n }\n\n async startWrite(): Promise<void> {\n if (!this.writePromise) {\n this.writePromise = this.doWrite();\n }\n await this.writePromise;\n this.writePromise = null;\n }\n\n async finalize(): Promise<void> {\n this.stopListening();\n await this.startWrite();\n }\n\n private async doWrite(): Promise<void> {\n while (this.length) {\n const promises: Promise<string | null>[] = [];\n const archiveKeys: (string | undefined)[] = [];\n for (let i = 0; i < this.writeConcurrency; i++) {\n const item = this.dequeue();\n if (!item) {\n break;\n }\n const {archiveKey, writePromise} = item as WriteQueueItem;\n archiveKeys.push(archiveKey);\n const promise = writePromise();\n promises.push(promise);\n }\n const writeResults = await Promise.allSettled(promises);\n this.updateFileMap(archiveKeys, writeResults);\n }\n }\n\n private updateFileMap(\n archiveKeys: (string | undefined)[],\n writeResults: PromiseSettledResult<string | null>[]\n ) {\n for (let i = 0; i < archiveKeys.length; i++) {\n const archiveKey = archiveKeys[i];\n if (archiveKey && 'value' in writeResults[i]) {\n this.fileMap[archiveKey] = (writeResults[i] as PromiseFulfilledResult<string>).value;\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,O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B,QAAA;MAAA,CAEjD;MAAA,SAAAP,QAAA;QAAA,OAAAM,QAAA,CAAAnE,KAAA,OAAAD,SAAA;MAAA;MAAA,OAAA8D,OAAA;IAAA;EAAA;IAAAtC,GAAA;IAAAC,KAAA,EAED,SAAA2D,cACEb,WAAmC,EACnCK,YAAmD,EACnD;MACA,KAAK,IAAIJ,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,WAAW,CAACtD,MAAM,EAAEuD,CAAC,EAAE,EAAE;QAC3C,IAAMtC,UAAU,GAAGqC,WAAW,CAACC,CAAC,CAAC;QACjC,IAAItC,UAAU,IAAI,OAAO,IAAI0C,YAAY,CAACJ,CAAC,CAAC,EAAE;UAC5C,IAAI,CAAC7B,OAAO,CAACT,UAAU,CAAC,GAAI0C,YAAY,CAACJ,CAAC,CAAC,CAAoC/C,KAAK;QACtF;MACF;IACF;EAAC;EAAA,OAAAd,UAAA;AAAA,EAjF+D0E,YAAK;AAAAC,OAAA,CAAA5F,OAAA,GAAAiB,UAAA"}
|
|
1
|
+
{"version":3,"file":"write-queue.js","names":["_queue","require","_process","_interopRequireDefault","MEMORY_LIMIT","WriteQueue","Queue","constructor","listeningInterval","arguments","length","undefined","writeConcurrency","_defineProperty2","default","enqueue","val","writeImmediately","archiveKey","writePromise","result","fileMap","process","memoryUsage","rss","startWrite","startListening","intervalId","setInterval","bind","stopListening","clearInterval","doWrite","finalize","promises","archiveKeys","i","item","dequeue","push","promise","writeResults","Promise","allSettled","updateFileMap","value","exports"],"sources":["../../../../src/lib/utils/write-queue.ts"],"sourcesContent":["import {Queue} from './queue';\nimport process from 'process';\n\n/** Memory limit size is based on testing */\nconst MEMORY_LIMIT = 4 * 1024 * 1024 * 1024; // 4GB\n\nexport type WriteQueueItem = {\n archiveKey?: string;\n /**\n * writePromise() returns a Promise that will be awaited in Promise.allSettled(promises);\n * Arguments for this call are specified in writeQueue.enqueue call like this:\n * await writeQueue.enqueue({\n * archiveKey: `nodePages/xxx.json.gz`,\n * writePromise: () => writeFileForSlpk(slpkPath, data, `xxx.json`)\n * });\n * Note, a function like writeFileForSlpk should NOT be called when initializing the object for enqueue().\n * If he function is called, the promise will be created\n * and the function will allocate resources (file descriptors) for file writing.\n * It will be done for ALL items in the queue, which is not supposed to happen.\n * That's why the function should be passed as\n * writePromise: () => writeFileForSlpk(slpkPath, content, `xxx.json`)\n * instead of\n * writePromise: writeFileForSlpk(slpkPath, content, `xxx.json`) // INCORRECT !\n */\n writePromise: () => Promise<string | null>;\n};\n\nexport default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {\n private intervalId?: NodeJS.Timeout;\n public writePromise: Promise<void> | null = null;\n public fileMap: {[key: string]: string} = {};\n public listeningInterval: number;\n public writeConcurrency: number;\n\n constructor(listeningInterval: number = 2000, writeConcurrency: number = 400) {\n super();\n this.listeningInterval = listeningInterval;\n this.writeConcurrency = writeConcurrency;\n }\n\n async enqueue(val: T, writeImmediately: boolean = false) {\n if (writeImmediately) {\n const {archiveKey, writePromise} = val as WriteQueueItem;\n const result = await writePromise();\n if (archiveKey && result) {\n this.fileMap[archiveKey] = result;\n }\n } else {\n super.enqueue(val);\n /** https://nodejs.org/docs/latest-v14.x/api/process.html#process_process_memoryusage */\n if (process.memoryUsage().rss > MEMORY_LIMIT) {\n await this.startWrite();\n }\n }\n }\n\n startListening() {\n this.intervalId = setInterval(this.startWrite.bind(this), this.listeningInterval);\n }\n\n stopListening() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n }\n\n async startWrite(): Promise<void> {\n if (!this.writePromise) {\n this.writePromise = this.doWrite();\n }\n await this.writePromise;\n this.writePromise = null;\n }\n\n async finalize(): Promise<void> {\n this.stopListening();\n await this.startWrite();\n }\n\n private async doWrite(): Promise<void> {\n while (this.length) {\n const promises: Promise<string | null>[] = [];\n const archiveKeys: (string | undefined)[] = [];\n for (let i = 0; i < this.writeConcurrency; i++) {\n const item = this.dequeue();\n if (!item) {\n break;\n }\n const {archiveKey, writePromise} = item as WriteQueueItem;\n archiveKeys.push(archiveKey);\n const promise = writePromise();\n promises.push(promise);\n }\n const writeResults = await Promise.allSettled(promises);\n this.updateFileMap(archiveKeys, writeResults);\n }\n }\n\n private updateFileMap(\n archiveKeys: (string | undefined)[],\n writeResults: PromiseSettledResult<string | null>[]\n ) {\n for (let i = 0; i < archiveKeys.length; i++) {\n const archiveKey = archiveKeys[i];\n if (archiveKey && 'value' in writeResults[i]) {\n this.fileMap[archiveKey] = (writeResults[i] as PromiseFulfilledResult<string>).value;\n }\n }\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AAGA,MAAMG,YAAY,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI;AAuB5B,MAAMC,UAAU,SAAmCC,YAAK,CAAI;EAOzEC,WAAWA,CAAA,EAAmE;IAAA,IAAlEC,iBAAyB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;IAAA,IAAEG,gBAAwB,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,GAAG;IAC1E,KAAK,CAAC,CAAC;IAAC,IAAAI,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA,wBANkC,IAAI;IAAA,IAAAD,gBAAA,CAAAC,OAAA,mBACN,CAAC,CAAC;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAM1C,IAAI,CAACN,iBAAiB,GAAGA,iBAAiB;IAC1C,IAAI,CAACI,gBAAgB,GAAGA,gBAAgB;EAC1C;EAEA,MAAMG,OAAOA,CAACC,GAAM,EAAqC;IAAA,IAAnCC,gBAAyB,GAAAR,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,KAAK;IACrD,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I,CAACxB,gBAAgB,EAAEwB,CAAC,EAAE,EAAE;QAC9C,MAAMC,IAAI,GAAG,IAAI,CAACC,OAAO,CAAC,CAAC;QAC3B,IAAI,CAACD,IAAI,EAAE;UACT;QACF;QACA,MAAM;UAACnB,UAAU;UAAEC;QAAY,CAAC,GAAGkB,IAAsB;QACzDF,WAAW,CAACI,IAAI,CAACrB,UAAU,CAAC;QAC5B,MAAMsB,OAAO,GAAGrB,YAAY,CAAC,CAAC;QAC9Be,QAAQ,CAACK,IAAI,CAACC,OAAO,CAAC;MACxB;MACA,MAAMC,YAAY,GAAG,MAAMC,OAAO,CAACC,UAAU,CAACT,QAAQ,CAAC;MACvD,IAAI,CAACU,aAAa,CAACT,WAAW,EAAEM,YAAY,CAAC;IAC/C;EACF;EAEQG,aAAaA,CACnBT,WAAmC,EACnCM,YAAmD,EACnD;IACA,KAAK,IAAIL,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,WAAW,CAACzB,MAAM,EAAE0B,CAAC,EAAE,EAAE;MAC3C,MAAMlB,UAAU,GAAGiB,WAAW,CAACC,CAAC,CAAC;MACjC,IAAIlB,UAAU,IAAI,OAAO,IAAIuB,YAAY,CAACL,CAAC,CAAC,EAAE;QAC5C,IAAI,CAACf,OAAO,CAACH,UAAU,CAAC,GAAIuB,YAAY,CAACL,CAAC,CAAC,CAAoCS,KAAK;MACtF;IACF;EACF;AACF;AAACC,OAAA,CAAAhC,OAAA,GAAAT,UAAA"}
|
package/dist/es5/pgm-loader.js
CHANGED
|
@@ -1,37 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.PGMLoader = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
7
|
var _geoid = require("@math.gl/geoid");
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : 'latest';
|
|
9
|
+
const PGMLoader = {
|
|
13
10
|
name: 'PGM - Netpbm grayscale image format',
|
|
14
11
|
id: 'pgm',
|
|
15
12
|
module: 'tile-converter',
|
|
16
13
|
version: VERSION,
|
|
17
14
|
mimeTypes: ['image/x-portable-graymap'],
|
|
18
|
-
parse:
|
|
19
|
-
var _parse = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer, options) {
|
|
20
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
21
|
-
while (1) switch (_context.prev = _context.next) {
|
|
22
|
-
case 0:
|
|
23
|
-
return _context.abrupt("return", (0, _geoid.parsePGM)(new Uint8Array(arrayBuffer), options));
|
|
24
|
-
case 1:
|
|
25
|
-
case "end":
|
|
26
|
-
return _context.stop();
|
|
27
|
-
}
|
|
28
|
-
}, _callee);
|
|
29
|
-
}));
|
|
30
|
-
function parse(_x, _x2) {
|
|
31
|
-
return _parse.apply(this, arguments);
|
|
32
|
-
}
|
|
33
|
-
return parse;
|
|
34
|
-
}(),
|
|
15
|
+
parse: async (arrayBuffer, options) => (0, _geoid.parsePGM)(new Uint8Array(arrayBuffer), options),
|
|
35
16
|
extensions: ['pgm'],
|
|
36
17
|
options: {
|
|
37
18
|
cubic: false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgm-loader.js","names":["_geoid","require","VERSION","PGMLoader","name","id","module","version","mimeTypes","parse","
|
|
1
|
+
{"version":3,"file":"pgm-loader.js","names":["_geoid","require","VERSION","PGMLoader","name","id","module","version","mimeTypes","parse","arrayBuffer","options","parsePGM","Uint8Array","extensions","cubic","exports"],"sources":["../../src/pgm-loader.ts"],"sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {parsePGM} from '@math.gl/geoid';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Loader for PGM - Netpbm grayscale image format\n */\nexport const PGMLoader: LoaderWithParser = {\n name: 'PGM - Netpbm grayscale image format',\n id: 'pgm',\n module: 'tile-converter',\n version: VERSION,\n mimeTypes: ['image/x-portable-graymap'],\n // @ts-expect-error LoaderOptions does not have cubic parameter\n parse: async (arrayBuffer, options) => parsePGM(new Uint8Array(arrayBuffer), options),\n extensions: ['pgm'],\n options: {\n // TODO - use pgm namespace\n cubic: false\n }\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAIA,MAAMC,OAAO,GAAG,eAAkB,KAAK,WAAW,cAAiB,QAAQ;AAKpE,MAAMC,SAA2B,GAAG;EACzCC,IAAI,EAAE,qCAAqC;EAC3CC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,gBAAgB;EACxBC,OAAO,EAAEL,OAAO;EAChBM,SAAS,EAAE,CAAC,0BAA0B,CAAC;EAEvCC,KAAK,EAAE,MAAAA,CAAOC,WAAW,EAAEC,OAAO,KAAK,IAAAC,eAAQ,EAAC,IAAIC,UAAU,CAACH,WAAW,CAAC,EAAEC,OAAO,CAAC;EACrFG,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBH,OAAO,EAAE;IAEPI,KAAK,EAAE;EACT;AACF,CAAC;AAACC,OAAA,CAAAb,SAAA,GAAAA,SAAA"}
|
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
5
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
6
4
|
var _workerUtils = require("@loaders.gl/worker-utils");
|
|
7
5
|
var _b3dmConverter = _interopRequireDefault(require("../3d-tiles-converter/helpers/b3dm-converter"));
|
|
8
|
-
|
|
9
|
-
(0, _workerUtils.createWorker)(function () {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
14
|
-
while (1) switch (_context.prev = _context.next) {
|
|
15
|
-
case 0:
|
|
16
|
-
options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
|
|
17
|
-
return _context.abrupt("return", b3dmConverter.convert(data, options.featureAttributes));
|
|
18
|
-
case 2:
|
|
19
|
-
case "end":
|
|
20
|
-
return _context.stop();
|
|
21
|
-
}
|
|
22
|
-
}, _callee);
|
|
23
|
-
}));
|
|
24
|
-
return function (_x) {
|
|
25
|
-
return _ref.apply(this, arguments);
|
|
26
|
-
};
|
|
27
|
-
}());
|
|
6
|
+
const b3dmConverter = new _b3dmConverter.default();
|
|
7
|
+
(0, _workerUtils.createWorker)(async function (data) {
|
|
8
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
9
|
+
return b3dmConverter.convert(data, options.featureAttributes);
|
|
10
|
+
});
|
|
28
11
|
//# sourceMappingURL=3d-tiles-attributes-worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"3d-tiles-attributes-worker.js","names":["_workerUtils","require","_b3dmConverter","_interopRequireDefault","b3dmConverter","B3dmConverter","createWorker","
|
|
1
|
+
{"version":3,"file":"3d-tiles-attributes-worker.js","names":["_workerUtils","require","_b3dmConverter","_interopRequireDefault","b3dmConverter","B3dmConverter","createWorker","data","options","arguments","length","undefined","convert","featureAttributes"],"sources":["../../../src/workers/3d-tiles-attributes-worker.ts"],"sourcesContent":["import {createWorker} from '@loaders.gl/worker-utils';\nimport B3dmConverter from '../3d-tiles-converter/helpers/b3dm-converter';\n\nconst b3dmConverter = new B3dmConverter();\n\ncreateWorker(async (data, options = {}) => b3dmConverter.convert(data, options.featureAttributes));\n"],"mappings":";;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,MAAMG,aAAa,GAAG,IAAIC,sBAAa,CAAC,CAAC;AAEzC,IAAAC,yBAAY,EAAC,gBAAOC,IAAI;EAAA,IAAEC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAAA,OAAKL,aAAa,CAACQ,OAAO,CAACL,IAAI,EAAEC,OAAO,CAACK,iBAAiB,CAAC;AAAA,EAAC"}
|
|
@@ -1,30 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
5
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
6
3
|
var _workerUtils = require("@loaders.gl/worker-utils");
|
|
7
4
|
var _geometryConverter = require("../i3s-converter/helpers/geometry-converter");
|
|
8
|
-
(0, _workerUtils.createWorker)(function () {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
13
|
-
while (1) switch (_context.prev = _context.next) {
|
|
14
|
-
case 0:
|
|
15
|
-
options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
|
|
16
|
-
_context.next = 3;
|
|
17
|
-
return (0, _geometryConverter.convertAttributes)(data, options.materialAndTextureList, options.useCartesianPositions);
|
|
18
|
-
case 3:
|
|
19
|
-
return _context.abrupt("return", _context.sent);
|
|
20
|
-
case 4:
|
|
21
|
-
case "end":
|
|
22
|
-
return _context.stop();
|
|
23
|
-
}
|
|
24
|
-
}, _callee);
|
|
25
|
-
}));
|
|
26
|
-
return function (_x) {
|
|
27
|
-
return _ref.apply(this, arguments);
|
|
28
|
-
};
|
|
29
|
-
}());
|
|
5
|
+
(0, _workerUtils.createWorker)(async function (data) {
|
|
6
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
7
|
+
return await (0, _geometryConverter.convertAttributes)(data, options.materialAndTextureList, options.useCartesianPositions);
|
|
8
|
+
});
|
|
30
9
|
//# sourceMappingURL=i3s-attributes-worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i3s-attributes-worker.js","names":["_workerUtils","require","_geometryConverter","createWorker","
|
|
1
|
+
{"version":3,"file":"i3s-attributes-worker.js","names":["_workerUtils","require","_geometryConverter","createWorker","data","options","arguments","length","undefined","convertAttributes","materialAndTextureList","useCartesianPositions"],"sources":["../../../src/workers/i3s-attributes-worker.ts"],"sourcesContent":["import {createWorker} from '@loaders.gl/worker-utils';\nimport {convertAttributes} from '../i3s-converter/helpers/geometry-converter';\n\ncreateWorker(\n async (data, options = {}) =>\n await convertAttributes(data, options.materialAndTextureList, options.useCartesianPositions)\n);\n"],"mappings":";;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA;AAEA,IAAAE,yBAAY,EACV,gBAAOC,IAAI;EAAA,IAAEC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAAA,OACvB,MAAM,IAAAG,oCAAiB,EAACL,IAAI,EAAEC,OAAO,CAACK,sBAAsB,EAAEL,OAAO,CAACM,qBAAqB,CAAC;AAAA,CAChG,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { processOnWorker } from '@loaders.gl/worker-utils';
|
|
2
|
-
const VERSION = typeof "3.4.
|
|
2
|
+
const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : 'latest';
|
|
3
3
|
export const Tile3dAttributesWorker = {
|
|
4
4
|
id: '3d-tiles-attributes',
|
|
5
5
|
name: '3DTiles Attributes Worker',
|
|
@@ -3,7 +3,7 @@ import { ZipLoader } from '@loaders.gl/zip';
|
|
|
3
3
|
import { writeFile } from '../lib/utils/file-utils';
|
|
4
4
|
import { join } from 'path';
|
|
5
5
|
import { ChildProcessProxy } from '@loaders.gl/worker-utils';
|
|
6
|
-
const VERSION = typeof "3.4.
|
|
6
|
+
const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : 'latest';
|
|
7
7
|
const PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';
|
|
8
8
|
export class DepsInstaller {
|
|
9
9
|
async install() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { processOnWorker } from '@loaders.gl/worker-utils';
|
|
2
|
-
const VERSION = typeof "3.4.
|
|
2
|
+
const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : 'latest';
|
|
3
3
|
export const I3SAttributesWorker = {
|
|
4
4
|
id: 'i3s-attributes',
|
|
5
5
|
name: 'I3S Attributes Worker',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-ids-extensions.js","names":["EXT_MESH_FEATURES","EXT_FEATURE_METADATA","handleBatchIdsExtensions","attributes","primitive","images","extensions","extensionName","extensionData","Object","entries","handleExtFeatureMetadataExtension","console","warn","extFeatureMetadata","_extFeatureMetadata$f","_featureIdAttribute$f","_featureIdAttribute$f2","_featureIdAttribute$f3","featureIdAttribute","featureIdAttributes","featureIds","attribute","batchIdsAttribute","value","hasOwnProperty","_attributes$POSITIONS","featuresCount","POSITIONS","length","generateImplicitFeatureIds","constant","divisor","featureIdTexture","featureIdTextures","_featureIdTexture$fea","_featureIdTexture$fea2","textureAttributeIndex","texture","texCoord","textCoordAttribute","concat","textureCoordinates","generateBatchIdsFromTexture","featureTexture","featureTextures","arguments","undefined","currentValue","devisorCounter","index","push","Array","fill","_featureIdTexture$fea3","_featureIdTexture$fea4","_featureIdTexture$fea5","CHANNELS_MAP","r","g","b","a","textureIndex","featureChannel","channels","image","batchIds","compressed","u","v","tx","Math","min","emod","width","ty","height","offset","components","batchId","Uint8Array","data","mimeType","n"],"sources":["../../../../src/i3s-converter/helpers/batch-ids-extensions.ts"],"sourcesContent":["import {\n GLTFAccessorPostprocessed,\n GLTFImagePostprocessed,\n GLTFMeshPrimitivePostprocessed\n} from '@loaders.gl/gltf';\nimport type {\n GLTF_EXT_feature_metadata_attribute,\n GLTF_EXT_feature_metadata_primitive\n} from 'modules/gltf/src/lib/types/gltf-json-schema';\n\nconst EXT_MESH_FEATURES = 'EXT_mesh_features';\nconst EXT_FEATURE_METADATA = 'EXT_feature_metadata';\n\n/**\n * Getting batchIds from 3DTilesNext extensions.\n * @param attributes - gltf accessors\n * @param primitive - gltf primitive data\n * @param images - gltf texture images\n */\nexport function handleBatchIdsExtensions(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n primitive: GLTFMeshPrimitivePostprocessed,\n images: GLTFImagePostprocessed[]\n): number[] {\n const extensions = primitive?.extensions;\n\n if (!extensions) {\n return [];\n }\n\n for (const [extensionName, extensionData] of Object.entries(extensions || {})) {\n switch (extensionName) {\n case EXT_FEATURE_METADATA:\n return handleExtFeatureMetadataExtension(\n attributes,\n extensionData as GLTF_EXT_feature_metadata_primitive,\n images\n );\n case EXT_MESH_FEATURES:\n console.warn('EXT_mesh_features extension is not supported yet');\n return [];\n default:\n return [];\n }\n }\n\n return [];\n}\n\n/**\n * Get batchIds from EXT_feature_metadata extension.\n * Docs - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata\n * @param attributes\n * @param extFeatureMetadata\n * @param textures\n */\nfunction handleExtFeatureMetadataExtension(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n extFeatureMetadata: GLTF_EXT_feature_metadata_primitive,\n images: GLTFImagePostprocessed[]\n): number[] {\n // Take only first extension object to get batchIds attribute name.\n const featureIdAttribute = extFeatureMetadata?.featureIdAttributes?.[0];\n\n if (featureIdAttribute?.featureIds?.attribute) {\n const batchIdsAttribute = attributes[featureIdAttribute.featureIds.attribute];\n return batchIdsAttribute.value;\n }\n\n if (\n featureIdAttribute?.featureIds?.hasOwnProperty('constant') &&\n featureIdAttribute?.featureIds?.hasOwnProperty('divisor')\n ) {\n const featuresCount = attributes?.POSITIONS?.value.length / 3 || 0;\n return generateImplicitFeatureIds(\n featuresCount,\n featureIdAttribute.featureIds.constant,\n featureIdAttribute.featureIds.divisor\n );\n }\n\n // Take only first extension object to get batchIds attribute name.\n const featureIdTexture =\n extFeatureMetadata?.featureIdTextures && extFeatureMetadata?.featureIdTextures[0];\n\n if (featureIdTexture) {\n const textureAttributeIndex = featureIdTexture?.featureIds?.texture?.texCoord || 0;\n const textCoordAttribute = `TEXCOORD_${textureAttributeIndex}`;\n const textureCoordinates = attributes[textCoordAttribute].value;\n return generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images);\n }\n\n // Take only first extension texture to get batchIds from the root EXT_feature_metadata object.\n const featureTexture =\n extFeatureMetadata?.featureTextures && extFeatureMetadata?.featureTextures[0];\n\n /**\n * TODO need to get batchIds from root extension\n */\n if (featureTexture) {\n console.warn(\"EXT_feature_metadata doesn't yet support featureTextures in primitive\");\n return [];\n }\n\n return [];\n}\n\n/**\n * Generates implicit feature ids\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#implicit-feature-ids\n * @param featuresCount\n * @param constant\n * @param devisor\n */\nfunction generateImplicitFeatureIds(\n featuresCount: number,\n constant: number = 0,\n divisor: number = 0\n): number[] {\n let featureIds: number[] = [];\n\n if (divisor > 0) {\n let currentValue = constant;\n let devisorCounter = divisor;\n\n for (let index = 0; index < featuresCount; index++) {\n featureIds.push(currentValue);\n\n devisorCounter -= 1;\n\n if (devisorCounter === 0) {\n currentValue++;\n devisorCounter = divisor;\n }\n }\n } else {\n featureIds = Array<number>(featuresCount).fill(constant, 0, featuresCount);\n }\n\n return featureIds;\n}\n\n/**\n * Get batchIds from texture.\n * @param primitive\n * @param featureIdTextures\n */\nfunction generateBatchIdsFromTexture(\n featureIdTexture: GLTF_EXT_feature_metadata_attribute,\n textureCoordinates: Float32Array,\n images: GLTFImagePostprocessed[]\n) {\n if (!images?.length) {\n return [];\n }\n\n const CHANNELS_MAP = {\n r: 0,\n g: 1,\n b: 2,\n a: 3\n };\n\n const textureIndex = featureIdTexture?.featureIds?.texture?.index;\n const featureChannel = featureIdTexture?.featureIds?.channels;\n\n if (!featureChannel || textureIndex === undefined) {\n return [];\n }\n\n const image = images[textureIndex];\n const batchIds: number[] = [];\n const channels = CHANNELS_MAP[featureChannel];\n\n if (!image.compressed) {\n for (let index = 0; index < textureCoordinates.length; index += 2) {\n const u = textureCoordinates[index];\n const v = textureCoordinates[index + 1];\n\n const tx = Math.min((emod(u) * image.width) | 0, image.width - 1);\n const ty = Math.min((emod(v) * image.height) | 0, image.height - 1);\n\n const offset = (ty * image.width + tx) * image.components + channels;\n const batchId = new Uint8Array(image.data)[offset];\n\n batchIds.push(batchId);\n }\n } else {\n console.warn(`Can't get batch Ids from ${image.mimeType} compressed texture`);\n }\n\n return batchIds;\n}\n\n/**\n * Handle UVs if they are out of range [0,1].\n * @param n\n * @param m\n */\nfunction emod(n: number): number {\n return ((n % 1) + 1) % 1;\n}\n"],"mappings":"AAUA,MAAMA,iBAAiB,GAAG,mBAAmB;AAC7C,MAAMC,oBAAoB,GAAG,sBAAsB;AAQnD,OAAO,SAASC,wBAAwBA,CACtCC,UAEC,EACDC,SAAyC,EACzCC,MAAgC,EACtB;EACV,MAAMC,UAAU,GAAGF,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEE,UAAU;EAExC,IAAI,CAACA,UAAU,EAAE;IACf,OAAO,EAAE;EACX;EAEA,KAAK,MAAM,CAACC,aAAa,EAAEC,aAAa,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,UAAU,I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AC,CAACJ,MAAM,CAAC;MAElDX,QAAQ,CAACf,IAAI,CAAC4B,OAAO,CAAC;IACxB;EACF,CAAC,MAAM;IACLnE,OAAO,CAACC,IAAI,6BAAA4B,MAAA,CAA6BwB,KAAK,CAACiB,QAAQ,wBAAqB,CAAC;EAC/E;EAEA,OAAOhB,QAAQ;AACjB;AAOA,SAASO,IAAIA,CAACU,CAAS,EAAU;EAC/B,OAAO,CAAEA,CAAC,GAAG,CAAC,GAAI,CAAC,IAAI,CAAC;AAC1B"}
|
|
1
|
+
{"version":3,"file":"batch-ids-extensions.js","names":["EXT_MESH_FEATURES","EXT_FEATURE_METADATA","handleBatchIdsExtensions","attributes","primitive","images","extensions","extensionName","extensionData","Object","entries","handleExtFeatureMetadataExtension","console","warn","extFeatureMetadata","_extFeatureMetadata$f","_featureIdAttribute$f","_featureIdAttribute$f2","_featureIdAttribute$f3","featureIdAttribute","featureIdAttributes","featureIds","attribute","batchIdsAttribute","value","hasOwnProperty","_attributes$POSITIONS","featuresCount","POSITIONS","length","generateImplicitFeatureIds","constant","divisor","featureIdTexture","featureIdTextures","_featureIdTexture$fea","_featureIdTexture$fea2","textureAttributeIndex","texture","texCoord","textCoordAttribute","concat","textureCoordinates","generateBatchIdsFromTexture","featureTexture","featureTextures","arguments","undefined","currentValue","devisorCounter","index","push","Array","fill","_featureIdTexture$fea3","_featureIdTexture$fea4","_featureIdTexture$fea5","CHANNELS_MAP","r","g","b","a","textureIndex","featureChannel","channels","image","batchIds","compressed","u","v","tx","Math","min","emod","width","ty","height","offset","components","batchId","Uint8Array","data","mimeType","n"],"sources":["../../../../src/i3s-converter/helpers/batch-ids-extensions.ts"],"sourcesContent":["import {\n GLTFAccessorPostprocessed,\n GLTFImagePostprocessed,\n GLTFMeshPrimitivePostprocessed\n} from '@loaders.gl/gltf';\nimport type {\n GLTF_EXT_feature_metadata_attribute,\n GLTF_EXT_feature_metadata_primitive\n} from '@loaders.gl/gltf';\n\nconst EXT_MESH_FEATURES = 'EXT_mesh_features';\nconst EXT_FEATURE_METADATA = 'EXT_feature_metadata';\n\n/**\n * Getting batchIds from 3DTilesNext extensions.\n * @param attributes - gltf accessors\n * @param primitive - gltf primitive data\n * @param images - gltf texture images\n */\nexport function handleBatchIdsExtensions(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n primitive: GLTFMeshPrimitivePostprocessed,\n images: GLTFImagePostprocessed[]\n): number[] {\n const extensions = primitive?.extensions;\n\n if (!extensions) {\n return [];\n }\n\n for (const [extensionName, extensionData] of Object.entries(extensions || {})) {\n switch (extensionName) {\n case EXT_FEATURE_METADATA:\n return handleExtFeatureMetadataExtension(\n attributes,\n extensionData as GLTF_EXT_feature_metadata_primitive,\n images\n );\n case EXT_MESH_FEATURES:\n console.warn('EXT_mesh_features extension is not supported yet');\n return [];\n default:\n return [];\n }\n }\n\n return [];\n}\n\n/**\n * Get batchIds from EXT_feature_metadata extension.\n * Docs - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata\n * @param attributes\n * @param extFeatureMetadata\n * @param textures\n */\nfunction handleExtFeatureMetadataExtension(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n extFeatureMetadata: GLTF_EXT_feature_metadata_primitive,\n images: GLTFImagePostprocessed[]\n): number[] {\n // Take only first extension object to get batchIds attribute name.\n const featureIdAttribute = extFeatureMetadata?.featureIdAttributes?.[0];\n\n if (featureIdAttribute?.featureIds?.attribute) {\n const batchIdsAttribute = attributes[featureIdAttribute.featureIds.attribute];\n return batchIdsAttribute.value;\n }\n\n if (\n featureIdAttribute?.featureIds?.hasOwnProperty('constant') &&\n featureIdAttribute?.featureIds?.hasOwnProperty('divisor')\n ) {\n const featuresCount = attributes?.POSITIONS?.value.length / 3 || 0;\n return generateImplicitFeatureIds(\n featuresCount,\n featureIdAttribute.featureIds.constant,\n featureIdAttribute.featureIds.divisor\n );\n }\n\n // Take only first extension object to get batchIds attribute name.\n const featureIdTexture =\n extFeatureMetadata?.featureIdTextures && extFeatureMetadata?.featureIdTextures[0];\n\n if (featureIdTexture) {\n const textureAttributeIndex = featureIdTexture?.featureIds?.texture?.texCoord || 0;\n const textCoordAttribute = `TEXCOORD_${textureAttributeIndex}`;\n const textureCoordinates = attributes[textCoordAttribute].value;\n return generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images);\n }\n\n // Take only first extension texture to get batchIds from the root EXT_feature_metadata object.\n const featureTexture =\n extFeatureMetadata?.featureTextures && extFeatureMetadata?.featureTextures[0];\n\n /**\n * TODO need to get batchIds from root extension\n */\n if (featureTexture) {\n console.warn(\"EXT_feature_metadata doesn't yet support featureTextures in primitive\");\n return [];\n }\n\n return [];\n}\n\n/**\n * Generates implicit feature ids\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#implicit-feature-ids\n * @param featuresCount\n * @param constant\n * @param devisor\n */\nfunction generateImplicitFeatureIds(\n featuresCount: number,\n constant: number = 0,\n divisor: number = 0\n): number[] {\n let featureIds: number[] = [];\n\n if (divisor > 0) {\n let currentValue = constant;\n let devisorCounter = divisor;\n\n for (let index = 0; index < featuresCount; index++) {\n featureIds.push(currentValue);\n\n devisorCounter -= 1;\n\n if (devisorCounter === 0) {\n currentValue++;\n devisorCounter = divisor;\n }\n }\n } else {\n featureIds = Array<number>(featuresCount).fill(constant, 0, featuresCount);\n }\n\n return featureIds;\n}\n\n/**\n * Get batchIds from texture.\n * @param primitive\n * @param featureIdTextures\n */\nfunction generateBatchIdsFromTexture(\n featureIdTexture: GLTF_EXT_feature_metadata_attribute,\n textureCoordinates: Float32Array,\n images: GLTFImagePostprocessed[]\n) {\n if (!images?.length) {\n return [];\n }\n\n const CHANNELS_MAP = {\n r: 0,\n g: 1,\n b: 2,\n a: 3\n };\n\n const textureIndex = featureIdTexture?.featureIds?.texture?.index;\n const featureChannel = featureIdTexture?.featureIds?.channels;\n\n if (!featureChannel || textureIndex === undefined) {\n return [];\n }\n\n const image = images[textureIndex];\n const batchIds: number[] = [];\n const channels = CHANNELS_MAP[featureChannel];\n\n if (!image.compressed) {\n for (let index = 0; index < textureCoordinates.length; index += 2) {\n const u = textureCoordinates[index];\n const v = textureCoordinates[index + 1];\n\n const tx = Math.min((emod(u) * image.width) | 0, image.width - 1);\n const ty = Math.min((emod(v) * image.height) | 0, image.height - 1);\n\n const offset = (ty * image.width + tx) * image.components + channels;\n const batchId = new Uint8Array(image.data)[offset];\n\n batchIds.push(batchId);\n }\n } else {\n console.warn(`Can't get batch Ids from ${image.mimeType} compressed texture`);\n }\n\n return batchIds;\n}\n\n/**\n * Handle UVs if they are out of range [0,1].\n * @param n\n * @param m\n */\nfunction emod(n: number): number {\n return ((n % 1) + 1) % 1;\n}\n"],"mappings":"AAUA,MAAMA,iBAAiB,GAAG,mBAAmB;AAC7C,MAAMC,oBAAoB,GAAG,sBAAsB;AAQnD,OAAO,SAASC,wBAAwBA,CACtCC,UAEC,EACDC,SAAyC,EACzCC,MAAgC,EACtB;EACV,MAAMC,UAAU,GAAGF,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEE,UAAU;EAExC,IAAI,CAACA,UAAU,EAAE;IACf,OAAO,EAAE;EACX;EAEA,KAAK,MAAM,CAACC,aAAa,EAAEC,aAAa,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,UAAU,IAAI,CAAC,CAAC,CAAC,EAAE;IAC7E,QAAQC,aAAa;MACnB,KAAKN,oBAAoB;QACvB,OAAOU,iCAAiC,CACtCR,UAAU,EACVK,aAAa,EACbH,MACF,CAAC;MACH,KAAKL,iBAAiB;QACpBY,OAAO,CAACC,IAAI,CAAC,kDAAkD,CAAC;QAChE,OAAO,EAAE;MACX;QACE,OAAO,EAAE;IACb;EACF;EAEA,OAAO,EAAE;AACX;AASA,SAASF,iCAAiCA,CACxCR,UAEC,EACDW,kBAAuD,EACvDT,MAAgC,EACtB;EAAA,IAAAU,qBAAA,EAAAC,qBAAA,EAAAC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