@loaders.gl/tile-converter 4.2.0-alpha.4 → 4.2.0-alpha.6
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-converter/3d-tiles-converter.d.ts +4 -4
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js +349 -293
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +261 -200
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +14 -5
- package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -1
- package/dist/3d-tiles-converter/helpers/load-i3s.js +83 -77
- package/dist/3d-tiles-converter/helpers/texture-atlas.js +44 -21
- package/dist/3d-tiles-converter/json-templates/tileset.js +32 -33
- package/dist/constants.js +0 -1
- package/dist/converter-cli.js +257 -234
- package/dist/converter.min.cjs +95 -105
- package/dist/deps-installer/deps-installer.d.ts.map +1 -1
- package/dist/deps-installer/deps-installer.js +78 -59
- package/dist/i3s-converter/helpers/attribute-metadata-info.js +210 -153
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +146 -103
- package/dist/i3s-converter/helpers/coordinate-converter.js +100 -65
- package/dist/i3s-converter/helpers/create-scene-server-path.js +14 -9
- package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/feature-attributes.js +170 -105
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js +205 -212
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +17 -3
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.js +1189 -830
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js +109 -97
- package/dist/i3s-converter/helpers/load-3d-tiles.js +103 -66
- package/dist/i3s-converter/helpers/node-debug.js +98 -54
- package/dist/i3s-converter/helpers/node-index-document.d.ts +11 -4
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-index-document.js +255 -177
- package/dist/i3s-converter/helpers/node-pages.d.ts +1 -1
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-pages.js +299 -193
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +92 -60
- package/dist/i3s-converter/helpers/progress.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/progress.js +139 -83
- package/dist/i3s-converter/helpers/tileset-traversal.d.ts +9 -2
- package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/tileset-traversal.js +33 -13
- package/dist/i3s-converter/i3s-converter.d.ts +7 -7
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +1165 -895
- package/dist/i3s-converter/json-templates/geometry-definitions.js +70 -79
- package/dist/i3s-converter/json-templates/layers.js +120 -121
- package/dist/i3s-converter/json-templates/metadata.js +19 -20
- package/dist/i3s-converter/json-templates/node.js +73 -71
- package/dist/i3s-converter/json-templates/scene-server.js +25 -26
- package/dist/i3s-converter/json-templates/shared-resources.js +107 -108
- package/dist/i3s-converter/json-templates/store.js +96 -94
- package/dist/i3s-converter/types.js +35 -23
- package/dist/i3s-server/app.js +15 -12
- package/dist/i3s-server/bin/i3s-server.min.cjs +69 -69
- package/dist/i3s-server/bin/www.js +16 -7
- package/dist/i3s-server/controllers/index-controller.js +18 -15
- package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -1
- package/dist/i3s-server/controllers/slpk-controller.js +24 -11
- package/dist/i3s-server/routes/index.js +13 -9
- package/dist/i3s-server/routes/slpk-router.d.ts.map +1 -1
- package/dist/i3s-server/routes/slpk-router.js +26 -19
- package/dist/i3s-server/utils/create-scene-server.js +15 -10
- package/dist/i3s-server/utils/server-utils.d.ts.map +1 -1
- package/dist/i3s-server/utils/server-utils.js +52 -32
- package/dist/index.cjs +616 -967
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/lib/json-schemas/conversion-dump-json-schema.js +243 -421
- package/dist/lib/utils/cli-utils.d.ts.map +1 -1
- package/dist/lib/utils/cli-utils.js +65 -36
- package/dist/lib/utils/compress-util.js +20 -15
- package/dist/lib/utils/conversion-dump.d.ts +10 -2
- package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
- package/dist/lib/utils/conversion-dump.js +242 -197
- package/dist/lib/utils/file-utils.d.ts +1 -1
- package/dist/lib/utils/file-utils.d.ts.map +1 -1
- package/dist/lib/utils/file-utils.js +120 -74
- package/dist/lib/utils/geometry-utils.js +13 -7
- package/dist/lib/utils/lod-conversion-utils.js +65 -33
- package/dist/lib/utils/queue.js +12 -13
- package/dist/lib/utils/statistic-utills.d.ts +6 -23
- package/dist/lib/utils/statistic-utills.d.ts.map +1 -1
- package/dist/lib/utils/statistic-utills.js +58 -55
- package/dist/lib/utils/write-queue.d.ts +2 -2
- package/dist/lib/utils/write-queue.d.ts.map +1 -1
- package/dist/lib/utils/write-queue.js +72 -86
- package/dist/pgm-loader.js +17 -13
- package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -1
- package/dist/slpk-extractor/slpk-extractor.js +60 -50
- package/dist/slpk-extractor-cli.d.ts.map +1 -1
- package/dist/slpk-extractor-cli.js +90 -59
- package/dist/slpk-extractor.min.cjs +1 -1
- package/package.json +27 -26
- package/src/3d-tiles-converter/3d-tiles-converter.ts +21 -10
- package/src/3d-tiles-converter/helpers/b3dm-converter.ts +1 -0
- package/src/3d-tiles-converter/helpers/load-i3s.ts +3 -27
- package/src/converter-cli.ts +4 -2
- package/src/deps-installer/deps-installer.ts +7 -0
- package/src/i3s-converter/helpers/attribute-metadata-info.ts +1 -1
- package/src/i3s-converter/helpers/batch-ids-extensions.ts +3 -1
- package/src/i3s-converter/helpers/coordinate-converter.ts +2 -2
- package/src/i3s-converter/helpers/feature-attributes.ts +5 -2
- package/src/i3s-converter/helpers/geometry-attributes.ts +6 -5
- package/src/i3s-converter/helpers/geometry-converter.ts +118 -72
- package/src/i3s-converter/helpers/gltf-attributes.ts +12 -13
- package/src/i3s-converter/helpers/node-index-document.ts +18 -10
- package/src/i3s-converter/helpers/node-pages.ts +27 -29
- package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +1 -0
- package/src/i3s-converter/helpers/progress.ts +1 -0
- package/src/i3s-converter/helpers/tileset-traversal.ts +22 -13
- package/src/i3s-converter/i3s-converter.ts +173 -114
- package/src/i3s-converter/json-templates/node.ts +1 -1
- package/src/i3s-server/bin/www.ts +6 -4
- package/src/i3s-server/controllers/slpk-controller.ts +4 -2
- package/src/i3s-server/routes/index.ts +10 -7
- package/src/i3s-server/routes/slpk-router.ts +22 -16
- package/src/i3s-server/utils/server-utils.ts +6 -4
- package/src/lib/utils/cli-utils.ts +2 -0
- package/src/lib/utils/conversion-dump.ts +35 -20
- package/src/lib/utils/file-utils.ts +11 -11
- package/src/lib/utils/statistic-utills.ts +5 -6
- package/src/lib/utils/write-queue.ts +2 -2
- package/src/slpk-extractor/slpk-extractor.ts +2 -1
- package/src/slpk-extractor-cli.ts +16 -8
- package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/load-i3s.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
- package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/converter-cli.js.map +0 -1
- package/dist/deps-installer/deps-installer.js.map +0 -1
- package/dist/i3s-converter/helpers/attribute-metadata-info.js.map +0 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.js.map +0 -1
- package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
- package/dist/i3s-converter/helpers/feature-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/load-3d-tiles.js.map +0 -1
- package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
- package/dist/i3s-converter/helpers/node-index-document.js.map +0 -1
- package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js.map +0 -1
- package/dist/i3s-converter/helpers/progress.js.map +0 -1
- package/dist/i3s-converter/helpers/tileset-traversal.js.map +0 -1
- package/dist/i3s-converter/i3s-converter.js.map +0 -1
- package/dist/i3s-converter/json-templates/geometry-definitions.js.map +0 -1
- package/dist/i3s-converter/json-templates/layers.js.map +0 -1
- package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
- package/dist/i3s-converter/json-templates/node.js.map +0 -1
- package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
- package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
- package/dist/i3s-converter/json-templates/store.js.map +0 -1
- package/dist/i3s-converter/types.js.map +0 -1
- package/dist/i3s-server/README.md +0 -63
- package/dist/i3s-server/app.js.map +0 -1
- package/dist/i3s-server/bin/www.js.map +0 -1
- package/dist/i3s-server/certs/cert.pem +0 -19
- package/dist/i3s-server/certs/key.pem +0 -27
- package/dist/i3s-server/controllers/index-controller.js.map +0 -1
- package/dist/i3s-server/controllers/slpk-controller.js.map +0 -1
- package/dist/i3s-server/routes/index.js.map +0 -1
- package/dist/i3s-server/routes/slpk-router.js.map +0 -1
- package/dist/i3s-server/utils/create-scene-server.js.map +0 -1
- package/dist/i3s-server/utils/server-utils.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/json-schemas/conversion-dump-json-schema.js.map +0 -1
- package/dist/lib/utils/cli-utils.js.map +0 -1
- package/dist/lib/utils/compress-util.js.map +0 -1
- package/dist/lib/utils/conversion-dump.js.map +0 -1
- package/dist/lib/utils/file-utils.js.map +0 -1
- package/dist/lib/utils/geometry-utils.js.map +0 -1
- package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
- package/dist/lib/utils/queue.js.map +0 -1
- package/dist/lib/utils/statistic-utills.js.map +0 -1
- package/dist/lib/utils/write-queue.js.map +0 -1
- package/dist/pgm-loader.js.map +0 -1
- package/dist/slpk-extractor/slpk-extractor.js.map +0 -1
- package/dist/slpk-extractor-cli.js.map +0 -1
- package/src/lib/utils/statistic-utills.d.ts +0 -25
|
@@ -1,96 +1,82 @@
|
|
|
1
1
|
import { Queue } from "./queue.js";
|
|
2
2
|
import process from 'process';
|
|
3
|
-
|
|
3
|
+
/** Memory limit size is based on testing */
|
|
4
|
+
const MEMORY_LIMIT = 4 * 1024 * 1024 * 1024; // 4GB
|
|
4
5
|
export default class WriteQueue extends Queue {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
6
|
+
intervalId; // eslint-disable-line no-undef
|
|
7
|
+
conversionDump;
|
|
8
|
+
writePromise = null;
|
|
9
|
+
fileMap = {};
|
|
10
|
+
listeningInterval;
|
|
11
|
+
writeConcurrency;
|
|
12
|
+
constructor(conversionDump, listeningInterval = 2000, writeConcurrency = 400) {
|
|
13
|
+
super();
|
|
14
|
+
this.conversionDump = conversionDump;
|
|
15
|
+
this.listeningInterval = listeningInterval;
|
|
16
|
+
this.writeConcurrency = writeConcurrency;
|
|
17
|
+
}
|
|
18
|
+
async enqueue(val, writeImmediately = false) {
|
|
19
|
+
if (writeImmediately) {
|
|
20
|
+
const { archiveKey, writePromise } = val;
|
|
21
|
+
const result = await writePromise();
|
|
22
|
+
if (archiveKey && result) {
|
|
23
|
+
this.fileMap[archiveKey] = result;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
super.enqueue(val);
|
|
28
|
+
/** https://nodejs.org/docs/latest-v14.x/api/process.html#process_process_memoryusage */
|
|
29
|
+
if (process.memoryUsage().rss > MEMORY_LIMIT) {
|
|
30
|
+
await this.startWrite();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
startListening() {
|
|
35
|
+
this.intervalId = setInterval(() => this.startWrite.bind(this), this.listeningInterval);
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
stopListening() {
|
|
41
|
-
if (this.intervalId) {
|
|
42
|
-
clearInterval(this.intervalId);
|
|
37
|
+
stopListening() {
|
|
38
|
+
if (this.intervalId) {
|
|
39
|
+
clearInterval(this.intervalId);
|
|
40
|
+
}
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
async startWrite() {
|
|
43
|
+
if (!this.writePromise) {
|
|
44
|
+
this.writePromise = this.doWrite();
|
|
45
|
+
}
|
|
46
|
+
await this.writePromise;
|
|
47
|
+
this.writePromise = null;
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
async finalize() {
|
|
50
|
+
this.stopListening();
|
|
51
|
+
await this.startWrite();
|
|
52
|
+
}
|
|
53
|
+
async doWrite() {
|
|
54
|
+
while (this.length) {
|
|
55
|
+
const promises = [];
|
|
56
|
+
const archiveKeys = [];
|
|
57
|
+
const changedRecords = [];
|
|
58
|
+
for (let i = 0; i < this.writeConcurrency; i++) {
|
|
59
|
+
const item = this.dequeue();
|
|
60
|
+
if (!item) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
const { archiveKey, sourceId, outputId, resourceType, writePromise } = item;
|
|
64
|
+
archiveKeys.push(archiveKey);
|
|
65
|
+
changedRecords.push({ sourceId, outputId, resourceType });
|
|
66
|
+
const promise = writePromise();
|
|
67
|
+
promises.push(promise);
|
|
68
|
+
}
|
|
69
|
+
const writeResults = await Promise.allSettled(promises);
|
|
70
|
+
this.updateFileMap(archiveKeys, writeResults);
|
|
71
|
+
await this.conversionDump.updateConvertedTilesDump(changedRecords, writeResults);
|
|
65
72
|
}
|
|
66
|
-
const {
|
|
67
|
-
archiveKey,
|
|
68
|
-
sourceId,
|
|
69
|
-
outputId,
|
|
70
|
-
resourceType,
|
|
71
|
-
writePromise
|
|
72
|
-
} = item;
|
|
73
|
-
archiveKeys.push(archiveKey);
|
|
74
|
-
changedRecords.push({
|
|
75
|
-
sourceId,
|
|
76
|
-
outputId,
|
|
77
|
-
resourceType
|
|
78
|
-
});
|
|
79
|
-
const promise = writePromise();
|
|
80
|
-
promises.push(promise);
|
|
81
|
-
}
|
|
82
|
-
const writeResults = await Promise.allSettled(promises);
|
|
83
|
-
this.updateFileMap(archiveKeys, writeResults);
|
|
84
|
-
await this.conversionDump.updateConvertedTilesDump(changedRecords, writeResults);
|
|
85
73
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
74
|
+
updateFileMap(archiveKeys, writeResults) {
|
|
75
|
+
for (let i = 0; i < archiveKeys.length; i++) {
|
|
76
|
+
const archiveKey = archiveKeys[i];
|
|
77
|
+
if (archiveKey && 'value' in writeResults[i]) {
|
|
78
|
+
this.fileMap[archiveKey] = writeResults[i].value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
93
81
|
}
|
|
94
|
-
}
|
|
95
82
|
}
|
|
96
|
-
//# sourceMappingURL=write-queue.js.map
|
package/dist/pgm-loader.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { Geoid, parsePGM } from '@math.gl/geoid';
|
|
2
|
-
|
|
2
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
3
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
4
|
+
const VERSION = typeof "4.2.0-alpha.5" !== 'undefined' ? "4.2.0-alpha.5" : 'latest';
|
|
3
5
|
export { Geoid };
|
|
6
|
+
/**
|
|
7
|
+
* Loader for PGM - Netpbm grayscale image format
|
|
8
|
+
*/
|
|
4
9
|
export const PGMLoader = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
name: 'PGM - Netpbm grayscale image format',
|
|
11
|
+
id: 'pgm',
|
|
12
|
+
module: 'tile-converter',
|
|
13
|
+
version: VERSION,
|
|
14
|
+
mimeTypes: ['image/x-portable-graymap'],
|
|
15
|
+
parse: async (arrayBuffer, options) => parsePGM(new Uint8Array(arrayBuffer), options?.pgm || {}),
|
|
16
|
+
extensions: ['pgm'],
|
|
17
|
+
options: {
|
|
18
|
+
pgm: {
|
|
19
|
+
cubic: false
|
|
20
|
+
}
|
|
15
21
|
}
|
|
16
|
-
}
|
|
17
22
|
};
|
|
18
|
-
//# sourceMappingURL=pgm-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slpk-extractor.d.ts","sourceRoot":"","sources":["../../src/slpk-extractor/slpk-extractor.ts"],"names":[],"mappings":"AAuBA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;;;;OAKG;IACU,OAAO,CAAC,OAAO,EAAE;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"slpk-extractor.d.ts","sourceRoot":"","sources":["../../src/slpk-extractor/slpk-extractor.ts"],"names":[],"mappings":"AAuBA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;;;;OAKG;IACU,OAAO,CAAC,OAAO,EAAE;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IA+BtF;;;OAGG;IAEH,OAAO,CAAC,iBAAiB;YAYX,MAAM;YAWN,SAAS;CASxB"}
|
|
@@ -5,59 +5,69 @@ import { FileHandleFile } from '@loaders.gl/loader-utils';
|
|
|
5
5
|
import { parseZipLocalFileHeader } from '@loaders.gl/zip';
|
|
6
6
|
import { GZipCompression } from '@loaders.gl/compression';
|
|
7
7
|
import { writeFile } from "../lib/utils/file-utils.js";
|
|
8
|
-
const indexNames = [
|
|
8
|
+
const indexNames = [
|
|
9
|
+
'3dSceneLayer.json.gz',
|
|
10
|
+
'3dNodeIndexDocument.json.gz',
|
|
11
|
+
'sharedResource.json.gz'
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* Converter from slpk to i3s
|
|
15
|
+
*/
|
|
9
16
|
export default class SLPKExtractor {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Extract slpk to i3s
|
|
19
|
+
* @param options
|
|
20
|
+
* @param options.inputUrl the url to read SLPK file
|
|
21
|
+
* @param options.outputPath the output filename
|
|
22
|
+
*/
|
|
23
|
+
async extract(options) {
|
|
24
|
+
if (isBrowser) {
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
console.log(BROWSER_ERROR_MESSAGE);
|
|
27
|
+
return BROWSER_ERROR_MESSAGE;
|
|
28
|
+
}
|
|
29
|
+
const { inputUrl } = options;
|
|
30
|
+
const provider = new FileHandleFile(inputUrl);
|
|
31
|
+
let localHeader = await parseZipLocalFileHeader(0n, provider);
|
|
32
|
+
while (localHeader) {
|
|
33
|
+
await this.writeFile(await this.unGzip({
|
|
34
|
+
name: this.correctIndexNames(localHeader.fileName),
|
|
35
|
+
data: await provider.slice(localHeader.fileDataOffset, localHeader.fileDataOffset + localHeader.compressedSize)
|
|
36
|
+
}), options.outputPath);
|
|
37
|
+
localHeader = await parseZipLocalFileHeader(localHeader.fileDataOffset + localHeader?.compressedSize, provider);
|
|
38
|
+
}
|
|
39
|
+
return 'success';
|
|
14
40
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
name
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Defines file name and path for i3s format
|
|
43
|
+
* @param fileName initial file name and path
|
|
44
|
+
*/
|
|
45
|
+
correctIndexNames(fileName) {
|
|
46
|
+
if (indexNames.includes(path.filename(path.join('/', fileName)))) {
|
|
47
|
+
return path.join(path.dirname(fileName), 'index.json.gz');
|
|
48
|
+
}
|
|
49
|
+
// finds path with name part and extention part
|
|
50
|
+
const parts = /^(.*\/[^\/\.]*)(\..+)$/.exec(fileName);
|
|
51
|
+
if (!parts) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return `${parts?.at(1)}/index${parts?.at(2)}`;
|
|
27
55
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
56
|
+
async unGzip(file) {
|
|
57
|
+
if (/\.gz$/.test(file.name ?? '')) {
|
|
58
|
+
const compression = new GZipCompression();
|
|
59
|
+
const decompressedData = await compression.decompress(file.data);
|
|
60
|
+
return { data: decompressedData, name: (file.name ?? '').slice(0, -3) };
|
|
61
|
+
}
|
|
62
|
+
return Promise.resolve(file);
|
|
33
63
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
64
|
+
async writeFile(options, outputPath) {
|
|
65
|
+
if (!options.name) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const finalPath = path.join(outputPath, options.name);
|
|
69
|
+
const dirName = path.dirname(finalPath);
|
|
70
|
+
const fileName = path.filename(finalPath);
|
|
71
|
+
await writeFile(dirName, options.data, fileName);
|
|
37
72
|
}
|
|
38
|
-
return `${parts === null || parts === void 0 ? void 0 : parts.at(1)}/index${parts === null || parts === void 0 ? void 0 : parts.at(2)}`;
|
|
39
|
-
}
|
|
40
|
-
async unGzip(file) {
|
|
41
|
-
var _file$name;
|
|
42
|
-
if (/\.gz$/.test((_file$name = file.name) !== null && _file$name !== void 0 ? _file$name : '')) {
|
|
43
|
-
var _file$name2;
|
|
44
|
-
const compression = new GZipCompression();
|
|
45
|
-
const decompressedData = await compression.decompress(file.data);
|
|
46
|
-
return {
|
|
47
|
-
data: decompressedData,
|
|
48
|
-
name: ((_file$name2 = file.name) !== null && _file$name2 !== void 0 ? _file$name2 : '').slice(0, -3)
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
return Promise.resolve(file);
|
|
52
|
-
}
|
|
53
|
-
async writeFile(options, outputPath) {
|
|
54
|
-
if (!options.name) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const finalPath = path.join(outputPath, options.name);
|
|
58
|
-
const dirName = path.dirname(finalPath);
|
|
59
|
-
const fileName = path.filename(finalPath);
|
|
60
|
-
await writeFile(dirName, options.data, fileName);
|
|
61
|
-
}
|
|
62
73
|
}
|
|
63
|
-
//# sourceMappingURL=slpk-extractor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slpk-extractor-cli.d.ts","sourceRoot":"","sources":["../src/slpk-extractor-cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"slpk-extractor-cli.d.ts","sourceRoot":"","sources":["../src/slpk-extractor-cli.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAI/B,KAAK,qBAAqB,GAAG;IAC3B,wFAAwF;IACxF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;gCAC4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAGF,MAAM,MAAM,8BAA8B,GAAG,qBAAqB,GAAG;IACnE,gBAAgB;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB;gCAC4B;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
|
@@ -1,74 +1,105 @@
|
|
|
1
1
|
import '@loaders.gl/polyfills';
|
|
2
2
|
import SLPKExtractor from "./slpk-extractor/slpk-extractor.js";
|
|
3
3
|
import { getURLValue, validateOptionsWithEqual } from "./lib/utils/cli-utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* CLI entry
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
4
8
|
async function main() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const [, , ...args] = process.argv;
|
|
10
|
+
if (args.length === 0) {
|
|
11
|
+
printHelp();
|
|
12
|
+
}
|
|
13
|
+
const validatedOptionsArr = validateOptionsWithEqual(args);
|
|
14
|
+
const options = parseOptions(validatedOptionsArr);
|
|
15
|
+
const validatedOptions = validateOptions(options);
|
|
16
|
+
await convert(validatedOptions);
|
|
13
17
|
}
|
|
14
|
-
main().catch(error => {
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
main().catch((error) => {
|
|
19
|
+
console.log(error); // eslint-disable-line no-console
|
|
20
|
+
process.exit(1); // eslint-disable-line no-process-exit
|
|
17
21
|
});
|
|
22
|
+
/**
|
|
23
|
+
* Output for `npx slpk-extractor --help`
|
|
24
|
+
*/
|
|
18
25
|
function printHelp() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.log('cli: converter slpk to I3S...');
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.log('--output [Output folder, default: "data" folder]');
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.log('--tileset [SLPK file]');
|
|
32
|
+
process.exit(0); // eslint-disable-line no-process-exit
|
|
23
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Run extraction process
|
|
36
|
+
* @param options validated slpk-extractor options
|
|
37
|
+
*/
|
|
24
38
|
async function convert(options) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.log('------------------------------------------------');
|
|
41
|
+
// eslint-disable-next-line no-console
|
|
42
|
+
console.log('Starting conversion of SLPK');
|
|
43
|
+
// eslint-disable-next-line no-console
|
|
44
|
+
console.log('------------------------------------------------');
|
|
45
|
+
const slpkExtractor = new SLPKExtractor();
|
|
46
|
+
slpkExtractor.extract({
|
|
47
|
+
inputUrl: options.tileset,
|
|
48
|
+
outputPath: options.output
|
|
49
|
+
});
|
|
33
50
|
}
|
|
51
|
+
// OPTIONS
|
|
52
|
+
/**
|
|
53
|
+
* Validate input options of the CLI command
|
|
54
|
+
* @param options - input options of the CLI command
|
|
55
|
+
* @returns validated options
|
|
56
|
+
*/
|
|
34
57
|
function validateOptions(options) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
58
|
+
const mandatoryOptionsWithExceptions = {
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
output: () => console.log('Missed: --output [Output path name]'),
|
|
61
|
+
// eslint-disable-next-line no-console
|
|
62
|
+
tileset: () => console.log('Missed: --tileset [SLPK file]')
|
|
63
|
+
};
|
|
64
|
+
const exceptions = [];
|
|
65
|
+
for (const mandatoryOption in mandatoryOptionsWithExceptions) {
|
|
66
|
+
const optionValue = options[mandatoryOption];
|
|
67
|
+
if (!optionValue) {
|
|
68
|
+
exceptions.push(mandatoryOptionsWithExceptions[mandatoryOption]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (exceptions.length) {
|
|
72
|
+
exceptions.forEach((exeption) => exeption());
|
|
73
|
+
process.exit(1); // eslint-disable-line no-process-exit
|
|
44
74
|
}
|
|
45
|
-
|
|
46
|
-
if (exceptions.length) {
|
|
47
|
-
exceptions.forEach(exeption => exeption());
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
return options;
|
|
75
|
+
return options;
|
|
51
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Parse option from the cli arguments array
|
|
79
|
+
* @param args
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
52
82
|
function parseOptions(args) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
const opts = {};
|
|
84
|
+
// eslint-disable-next-line complexity
|
|
85
|
+
args.forEach((arg, index) => {
|
|
86
|
+
if (arg.indexOf('--') === 0) {
|
|
87
|
+
switch (arg) {
|
|
88
|
+
case '--tileset':
|
|
89
|
+
opts.tileset = getURLValue(index, args);
|
|
90
|
+
break;
|
|
91
|
+
case '--output':
|
|
92
|
+
opts.output = getURLValue(index, args);
|
|
93
|
+
break;
|
|
94
|
+
case '--help':
|
|
95
|
+
printHelp();
|
|
96
|
+
break;
|
|
97
|
+
default:
|
|
98
|
+
// eslint-disable-next-line no-console
|
|
99
|
+
console.warn(`Unknown option ${arg}`);
|
|
100
|
+
process.exit(0); // eslint-disable-line
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return opts;
|
|
73
105
|
}
|
|
74
|
-
//# sourceMappingURL=slpk-extractor-cli.js.map
|