@loaders.gl/tile-converter 4.0.0-alpha.23 → 4.0.0-alpha.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -1
  2. package/dist/converter.min.js +97 -97
  3. package/dist/dist.min.js +237 -182
  4. package/dist/es5/3d-tiles-converter/helpers/load-i3s.js.map +1 -1
  5. package/dist/es5/deps-installer/deps-installer.js +1 -1
  6. package/dist/es5/i3s-converter/helpers/feature-attributes.js +6 -18
  7. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
  8. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +83 -44
  9. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  10. package/dist/es5/i3s-converter/helpers/geometry-converter.js +9 -7
  11. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  12. package/dist/es5/i3s-converter/types.js.map +1 -1
  13. package/dist/es5/pgm-loader.js +11 -3
  14. package/dist/es5/pgm-loader.js.map +1 -1
  15. package/dist/esm/3d-tiles-converter/helpers/load-i3s.js.map +1 -1
  16. package/dist/esm/deps-installer/deps-installer.js +1 -1
  17. package/dist/esm/i3s-converter/helpers/feature-attributes.js +5 -5
  18. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
  19. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +76 -34
  20. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  21. package/dist/esm/i3s-converter/helpers/geometry-converter.js +7 -5
  22. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  23. package/dist/esm/i3s-converter/types.js.map +1 -1
  24. package/dist/esm/pgm-loader.js +7 -4
  25. package/dist/esm/pgm-loader.js.map +1 -1
  26. package/dist/i3s-converter/helpers/feature-attributes.d.ts +6 -6
  27. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
  28. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  29. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  30. package/dist/i3s-converter/types.d.ts +7 -4
  31. package/dist/i3s-converter/types.d.ts.map +1 -1
  32. package/dist/pgm-loader.d.ts +9 -2
  33. package/dist/pgm-loader.d.ts.map +1 -1
  34. package/package.json +14 -14
  35. package/src/3d-tiles-converter/helpers/load-i3s.ts +1 -0
  36. package/src/i3s-converter/helpers/feature-attributes.ts +14 -11
  37. package/src/i3s-converter/helpers/geometry-attributes.ts +80 -50
  38. package/src/i3s-converter/helpers/geometry-converter.ts +18 -9
  39. package/src/i3s-converter/types.ts +8 -4
  40. package/src/pgm-loader.ts +15 -7
  41. package/dist/3d-tiles-converter/3d-tiles-converter.js +0 -279
  42. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +0 -271
  43. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -23
  44. package/dist/3d-tiles-converter/helpers/load-i3s.js +0 -42
  45. package/dist/3d-tiles-converter/helpers/texture-atlas.js +0 -54
  46. package/dist/3d-tiles-converter/json-templates/tileset.js +0 -43
  47. package/dist/bundle.js +0 -5
  48. package/dist/constants.js +0 -4
  49. package/dist/converter-cli.js +0 -222
  50. package/dist/deps-installer/deps-installer.js +0 -89
  51. package/dist/i3s-converter/helpers/batch-ids-extensions.js +0 -179
  52. package/dist/i3s-converter/helpers/coordinate-converter.js +0 -122
  53. package/dist/i3s-converter/helpers/create-scene-server-path.js +0 -28
  54. package/dist/i3s-converter/helpers/feature-attributes.js +0 -218
  55. package/dist/i3s-converter/helpers/geometry-attributes.js +0 -203
  56. package/dist/i3s-converter/helpers/geometry-converter.js +0 -1321
  57. package/dist/i3s-converter/helpers/gltf-attributes.js +0 -129
  58. package/dist/i3s-converter/helpers/load-3d-tiles.js +0 -99
  59. package/dist/i3s-converter/helpers/node-debug.js +0 -120
  60. package/dist/i3s-converter/helpers/node-index-document.js +0 -271
  61. package/dist/i3s-converter/helpers/node-pages.js +0 -316
  62. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +0 -100
  63. package/dist/i3s-converter/helpers/tileset-traversal.js +0 -29
  64. package/dist/i3s-converter/i3s-converter.js +0 -964
  65. package/dist/i3s-converter/json-templates/geometry-definitions.js +0 -87
  66. package/dist/i3s-converter/json-templates/layers.js +0 -139
  67. package/dist/i3s-converter/json-templates/metadata.js +0 -25
  68. package/dist/i3s-converter/json-templates/node.js +0 -89
  69. package/dist/i3s-converter/json-templates/scene-server.js +0 -31
  70. package/dist/i3s-converter/json-templates/shared-resources.js +0 -129
  71. package/dist/i3s-converter/json-templates/store.js +0 -103
  72. package/dist/i3s-converter/types.js +0 -17
  73. package/dist/i3s-server/app.js +0 -29
  74. package/dist/i3s-server/bin/www.js +0 -37
  75. package/dist/i3s-server/controllers/index-controller.js +0 -31
  76. package/dist/i3s-server/controllers/slpk-controller.js +0 -33
  77. package/dist/i3s-server/routes/index.js +0 -20
  78. package/dist/i3s-server/routes/slpk-router.js +0 -34
  79. package/dist/i3s-server/utils/create-scene-server.js +0 -22
  80. package/dist/i3s-server/utils/server-utils.js +0 -66
  81. package/dist/index.js +0 -10
  82. package/dist/lib/utils/cli-utils.js +0 -82
  83. package/dist/lib/utils/compress-util.js +0 -257
  84. package/dist/lib/utils/file-utils.js +0 -139
  85. package/dist/lib/utils/geometry-utils.js +0 -18
  86. package/dist/lib/utils/lod-conversion-utils.js +0 -76
  87. package/dist/lib/utils/queue.js +0 -18
  88. package/dist/lib/utils/statistic-utills.js +0 -64
  89. package/dist/lib/utils/write-queue.js +0 -80
  90. package/dist/pgm-loader.js +0 -24
  91. package/dist/slpk-extractor/slpk-extractor.js +0 -75
  92. package/dist/slpk-extractor-cli.js +0 -102
@@ -1,139 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAbsoluteFilePath = exports.removeFile = exports.removeDir = exports.isFileExists = exports.openJson = exports.writeFileForSlpk = exports.writeFile = void 0;
4
- const core_1 = require("@loaders.gl/core");
5
- const loader_utils_1 = require("@loaders.gl/loader-utils");
6
- const fs_1 = require("fs");
7
- const path_1 = require("path");
8
- const compress_util_1 = require("./compress-util");
9
- /**
10
- * Write a file with data and name fileName to path
11
- *
12
- * @param path - output path
13
- * @param data - file content
14
- * @param fileName - name of output file (default: index.json)
15
- */
16
- async function writeFile(path, data, fileName = 'index.json') {
17
- let toWriteData;
18
- if (data instanceof Promise) {
19
- toWriteData = new Uint8Array(await data);
20
- }
21
- else if (data instanceof ArrayBuffer) {
22
- toWriteData = new Uint8Array(data);
23
- }
24
- else {
25
- toWriteData = data;
26
- }
27
- await fs_1.promises.mkdir(path, { recursive: true });
28
- const pathFile = (0, path_1.join)(path, fileName);
29
- try {
30
- await fs_1.promises.writeFile(pathFile, toWriteData);
31
- }
32
- catch (err) {
33
- throw err;
34
- }
35
- console.log(`${pathFile} saved.`); // eslint-disable-line
36
- return pathFile;
37
- }
38
- exports.writeFile = writeFile;
39
- /**
40
- * Write a file with data and name fileName to path - specific one for further packaging into slpk
41
- *
42
- * @param path - output path
43
- * @param data - file content
44
- * @param fileName - name of output file (default: index.json)
45
- * @param compress - if need to compress file with gzip (default: true)
46
- * @param compressList - if set - the file should be added to this list and compressed in the end of conversion
47
- */
48
- async function writeFileForSlpk(path, data, fileName = 'index.json', compress = true, compressList) {
49
- const pathFile = await writeFile(path, data, fileName);
50
- if (compress) {
51
- if (compressList) {
52
- if (!compressList.includes(pathFile)) {
53
- compressList.push(pathFile);
54
- return `${pathFile}.gz`;
55
- }
56
- else {
57
- return null;
58
- }
59
- }
60
- else {
61
- const pathGzFile = await (0, compress_util_1.compressFileWithGzip)(pathFile);
62
- // After compression, we don't need an uncompressed file
63
- await removeFile(pathFile);
64
- return pathGzFile;
65
- }
66
- }
67
- return pathFile;
68
- }
69
- exports.writeFileForSlpk = writeFileForSlpk;
70
- /**
71
- * Open json file
72
- * @param path - path to the file
73
- * @param fileName - file name
74
- * @returns object
75
- */
76
- async function openJson(path, fileName) {
77
- return new Promise((resolve, reject) => {
78
- let count = 0;
79
- console.log(`load ${path}/${fileName}.`); // eslint-disable-line
80
- const intervalId = setInterval(() => {
81
- const pathFile = (0, path_1.join)(path, fileName);
82
- (0, core_1.load)(pathFile, loader_utils_1.JSONLoader)
83
- .then((result) => {
84
- clearInterval(intervalId);
85
- resolve(result);
86
- })
87
- .catch(() => {
88
- count++;
89
- if (count > 100) {
90
- clearInterval(intervalId);
91
- reject(new Error(`Cannon load ${path}/${fileName}.`));
92
- }
93
- });
94
- }, 200);
95
- });
96
- }
97
- exports.openJson = openJson;
98
- /**
99
- * Check if the file exists
100
- * @param fileName - full name of file
101
- * @returns true if file exists, otherwise - false
102
- */
103
- async function isFileExists(fileName) {
104
- try {
105
- await fs_1.promises.stat(fileName);
106
- return true;
107
- }
108
- catch {
109
- return false;
110
- }
111
- }
112
- exports.isFileExists = isFileExists;
113
- /**
114
- * Remove dir with path
115
- *
116
- * @param path
117
- */
118
- function removeDir(path) {
119
- // (node:35607) [DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead
120
- return fs_1.promises.rm(path, { recursive: true });
121
- }
122
- exports.removeDir = removeDir;
123
- /**
124
- * Remove file with path
125
- *
126
- * @param path
127
- */
128
- function removeFile(path) {
129
- return fs_1.promises.unlink(path);
130
- }
131
- exports.removeFile = removeFile;
132
- /**
133
- * Generates absolute file path
134
- * @param filePath
135
- */
136
- function getAbsoluteFilePath(filePath) {
137
- return (0, path_1.isAbsolute)(filePath) ? filePath : (0, path_1.join)(process.cwd(), filePath);
138
- }
139
- exports.getAbsoluteFilePath = getAbsoluteFilePath;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateSyntheticIndices = void 0;
4
- /**
5
- * luma.gl can not work without indices now:
6
- * https://github.com/visgl/luma.gl/blob/d8cad75b9f8ca3e578cf078ed9d19e619c2ddbc9/modules/experimental/src/gltf/gltf-instantiator.js#L115
7
- * This method generates syntetic indices array: [0, 1, 2, 3, .... , vertexCount-1]
8
- * @param {number} vertexCount - vertex count in the geometry
9
- * @returns {Uint32Array} indices array.
10
- */
11
- const generateSyntheticIndices = (vertexCount) => {
12
- const result = new Uint32Array(vertexCount);
13
- for (let index = 0; index < vertexCount; index++) {
14
- result[index] = index;
15
- }
16
- return result;
17
- };
18
- exports.generateSyntheticIndices = generateSyntheticIndices;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertScreenThresholdToGeometricError = exports.convertGeometricErrorToScreenThreshold = void 0;
4
- // https://cesium.com/docs/cesiumjs-ref-doc/Cesium3DTileset.html
5
- const DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR = 16;
6
- /**
7
- * Do conversion from geometric error to screen threshold
8
- *
9
- * In 3DTiles we have HLOD logic and parent tile also has bigger lodMetric value then its children.
10
- * In I3s we have reverse logic related to maxError. Parent has lower maxError than its child.
11
- * In nodes where are no children tile.lodMetricValue is 0. This is because of logic of HLOD in 3DTiles
12
- * 3DTiles spec:
13
- * https://github.com/CesiumGS/3d-tiles/tree/master/specification#geometric-error
14
- * I3S spec:
15
- * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/lodSelection.cmn.md
16
- * To avoid infinity values when we do calculations of maxError we shold replace 0 with value which allows us
17
- * to make child maxError bigger than his parent maxError.
18
- *
19
- * @param tile - 3d-tiles tile JSON
20
- * @param coordinates - node converted coordinates
21
- * @returns An array of LOD metrics in format compatible with i3s 3DNodeIndexDocument.lodSelection
22
- * @example
23
- * [
24
- {
25
- "metricType": "maxScreenThresholdSQ",
26
- "maxError": 870638.071285568
27
- },
28
- {
29
- "metricType": "maxScreenThreshold",
30
- "maxError": 1052.8679031638949
31
- }
32
- ]
33
- */
34
- function convertGeometricErrorToScreenThreshold(tile, coordinates) {
35
- const lodSelection = [];
36
- const boundingVolume = tile.boundingVolume;
37
- const lodMetricValue = tile.lodMetricValue || 0.1;
38
- const maxScreenThreshold = {
39
- metricType: 'maxScreenThreshold',
40
- maxError: (coordinates.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / lodMetricValue
41
- };
42
- const maxScreenThresholdSQ = {
43
- metricType: 'maxScreenThresholdSQ',
44
- maxError: Math.PI * 0.25 * maxScreenThreshold.maxError * maxScreenThreshold.maxError
45
- };
46
- if (boundingVolume.constructor.name === 'OrientedBoundingBox') {
47
- lodSelection.push(maxScreenThresholdSQ);
48
- lodSelection.push(maxScreenThreshold);
49
- }
50
- else {
51
- lodSelection.push(maxScreenThreshold);
52
- lodSelection.push(maxScreenThresholdSQ);
53
- }
54
- return lodSelection;
55
- }
56
- exports.convertGeometricErrorToScreenThreshold = convertGeometricErrorToScreenThreshold;
57
- /**
58
- * Convert LOD metric from "Screen Threshold" to "Screen Space Error"
59
- * @param node - i3s node data
60
- * @returns lod metric in 3d-tiles format
61
- */
62
- function convertScreenThresholdToGeometricError(node) {
63
- const metricData = node.lodSelection?.find((metric) => metric.metricType === 'maxScreenThreshold');
64
- let maxError = metricData?.maxError;
65
- if (!maxError) {
66
- const sqMetricData = node.lodSelection?.find((metric) => metric.metricType === 'maxScreenThresholdSQ');
67
- if (sqMetricData) {
68
- maxError = Math.sqrt(sqMetricData.maxError / (Math.PI * 0.25));
69
- }
70
- }
71
- if (!maxError) {
72
- maxError = DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR;
73
- }
74
- return (node.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / maxError;
75
- }
76
- exports.convertScreenThresholdToGeometricError = convertScreenThresholdToGeometricError;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Queue = void 0;
4
- class Queue extends Array {
5
- enqueue(val) {
6
- this.push(val);
7
- }
8
- dequeue() {
9
- return this.shift();
10
- }
11
- peek() {
12
- return this[0];
13
- }
14
- isEmpty() {
15
- return this.length === 0;
16
- }
17
- }
18
- exports.Queue = Queue;
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateFilesSize = exports.timeConverter = void 0;
4
- const path_1 = require("path");
5
- const fs_1 = require("fs");
6
- const file_utils_1 = require("./file-utils");
7
- function timeConverter(time) {
8
- const nanoSecondsInMillisecond = 1e6;
9
- let timeInSeconds = time[0];
10
- const hours = Math.floor(timeInSeconds / 3600);
11
- timeInSeconds = timeInSeconds - hours * 3600;
12
- const minutes = Math.floor(timeInSeconds / 60);
13
- timeInSeconds = timeInSeconds - minutes * 60;
14
- const seconds = Math.floor(timeInSeconds);
15
- const milliseconds = time[1] / nanoSecondsInMillisecond;
16
- let result = '';
17
- if (hours) {
18
- result += `${hours}h `;
19
- }
20
- if (minutes) {
21
- result += `${minutes}m `;
22
- }
23
- if (seconds) {
24
- result += `${seconds}s`;
25
- }
26
- if (!result) {
27
- result += `${milliseconds}ms`;
28
- }
29
- return result;
30
- }
31
- exports.timeConverter = timeConverter;
32
- async function calculateFilesSize(params) {
33
- const { slpk, outputPath, tilesetName } = params;
34
- const fullOutputPath = (0, file_utils_1.getAbsoluteFilePath)(outputPath);
35
- try {
36
- if (slpk) {
37
- const slpkPath = (0, path_1.join)(fullOutputPath, `${tilesetName}.slpk`);
38
- const stat = await fs_1.promises.stat(slpkPath);
39
- return stat.size;
40
- }
41
- const directoryPath = (0, path_1.join)(fullOutputPath, tilesetName);
42
- const totalSize = await getTotalFilesSize(directoryPath);
43
- return totalSize;
44
- }
45
- catch (error) {
46
- console.log('Calculate file sizes error: ', error); // eslint-disable-line
47
- return null;
48
- }
49
- }
50
- exports.calculateFilesSize = calculateFilesSize;
51
- async function getTotalFilesSize(dirPath) {
52
- let totalFileSize = 0;
53
- const files = await fs_1.promises.readdir(dirPath);
54
- for (const file of files) {
55
- const fileStat = await fs_1.promises.stat((0, path_1.join)(dirPath, file));
56
- if (fileStat.isDirectory()) {
57
- totalFileSize += await getTotalFilesSize((0, path_1.join)(dirPath, file));
58
- }
59
- else {
60
- totalFileSize += fileStat.size;
61
- }
62
- }
63
- return totalFileSize;
64
- }
@@ -1,80 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const queue_1 = require("./queue");
7
- const process_1 = __importDefault(require("process"));
8
- /** Memory limit size is based on testing */
9
- const MEMORY_LIMIT = 4 * 1024 * 1024 * 1024; // 4GB
10
- class WriteQueue extends queue_1.Queue {
11
- constructor(listeningInterval = 2000, writeConcurrency = 400) {
12
- super();
13
- this.writePromise = null;
14
- this.fileMap = {};
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_1.default.memoryUsage().rss > MEMORY_LIMIT) {
30
- await this.startWrite();
31
- }
32
- }
33
- }
34
- startListening() {
35
- this.intervalId = setInterval(this.startWrite.bind(this), this.listeningInterval);
36
- }
37
- stopListening() {
38
- if (this.intervalId) {
39
- clearInterval(this.intervalId);
40
- }
41
- }
42
- async startWrite() {
43
- if (!this.writePromise) {
44
- this.writePromise = this.doWrite();
45
- }
46
- await this.writePromise;
47
- this.writePromise = null;
48
- }
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
- for (let i = 0; i < this.writeConcurrency; i++) {
58
- const item = this.dequeue();
59
- if (!item) {
60
- break;
61
- }
62
- const { archiveKey, writePromise } = item;
63
- archiveKeys.push(archiveKey);
64
- const promise = writePromise();
65
- promises.push(promise);
66
- }
67
- const writeResults = await Promise.allSettled(promises);
68
- this.updateFileMap(archiveKeys, writeResults);
69
- }
70
- }
71
- updateFileMap(archiveKeys, writeResults) {
72
- for (let i = 0; i < archiveKeys.length; i++) {
73
- const archiveKey = archiveKeys[i];
74
- if (archiveKey && 'value' in writeResults[i]) {
75
- this.fileMap[archiveKey] = writeResults[i].value;
76
- }
77
- }
78
- }
79
- }
80
- exports.default = WriteQueue;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PGMLoader = void 0;
4
- const geoid_1 = require("@math.gl/geoid");
5
- // __VERSION__ is injected by babel-plugin-version-inline
6
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
- const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
8
- /**
9
- * Loader for PGM - Netpbm grayscale image format
10
- */
11
- exports.PGMLoader = {
12
- name: 'PGM - Netpbm grayscale image format',
13
- id: 'pgm',
14
- module: 'tile-converter',
15
- version: VERSION,
16
- mimeTypes: ['image/x-portable-graymap'],
17
- // @ts-expect-error LoaderOptions does not have cubic parameter
18
- parse: async (arrayBuffer, options) => (0, geoid_1.parsePGM)(new Uint8Array(arrayBuffer), options),
19
- extensions: ['pgm'],
20
- options: {
21
- // TODO - use pgm namespace
22
- cubic: false
23
- }
24
- };
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@loaders.gl/core");
4
- const constants_1 = require("../constants");
5
- const loader_utils_1 = require("@loaders.gl/loader-utils");
6
- const loader_utils_2 = require("@loaders.gl/loader-utils");
7
- const zip_1 = require("@loaders.gl/zip");
8
- const compression_1 = require("@loaders.gl/compression");
9
- const file_utils_1 = require("../lib/utils/file-utils");
10
- const indexNames = [
11
- '3dSceneLayer.json.gz',
12
- '3dNodeIndexDocument.json.gz',
13
- 'sharedResource.json.gz'
14
- ];
15
- /**
16
- * Converter from slpk to i3s
17
- */
18
- class SLPKExtractor {
19
- /**
20
- * Extract slpk to i3s
21
- * @param options
22
- * @param options.inputUrl the url to read SLPK file
23
- * @param options.outputPath the output filename
24
- */
25
- async extract(options) {
26
- if (core_1.isBrowser) {
27
- console.log(constants_1.BROWSER_ERROR_MESSAGE);
28
- return constants_1.BROWSER_ERROR_MESSAGE;
29
- }
30
- const { inputUrl } = options;
31
- const provider = await loader_utils_2.FileHandleFile.from(inputUrl);
32
- let localHeader = await (0, zip_1.parseZipLocalFileHeader)(0n, provider);
33
- while (localHeader) {
34
- await this.writeFile(await this.unGzip({
35
- name: this.correctIndexNames(localHeader.fileName),
36
- data: await provider.slice(localHeader.fileDataOffset, localHeader.fileDataOffset + localHeader.compressedSize)
37
- }), options.outputPath);
38
- localHeader = await (0, zip_1.parseZipLocalFileHeader)(localHeader.fileDataOffset + localHeader?.compressedSize, provider);
39
- }
40
- return 'success';
41
- }
42
- /**
43
- * Defines file name and path for i3s format
44
- * @param fileName initial file name and path
45
- */
46
- correctIndexNames(fileName) {
47
- if (indexNames.includes(loader_utils_1.path.filename(loader_utils_1.path.join('/', fileName)))) {
48
- return loader_utils_1.path.join(loader_utils_1.path.dirname(fileName), 'index.json.gz');
49
- }
50
- // finds path with name part and extention part
51
- let parts = /^(.*\/[^\/\.]*)(\..+)$/.exec(fileName);
52
- if (!parts) {
53
- return null;
54
- }
55
- return `${parts?.at(1)}/index${parts?.at(2)}`;
56
- }
57
- async unGzip(file) {
58
- if (/\.gz$/.test(file.name ?? '')) {
59
- const compression = new compression_1.GZipCompression();
60
- const decompressedData = await compression.decompress(file.data);
61
- return { data: decompressedData, name: (file.name ?? '').slice(0, -3) };
62
- }
63
- return Promise.resolve(file);
64
- }
65
- async writeFile(options, outputPath) {
66
- if (!options.name) {
67
- return;
68
- }
69
- const finalPath = loader_utils_1.path.join(outputPath, options.name);
70
- const dirName = loader_utils_1.path.dirname(finalPath);
71
- const fileName = loader_utils_1.path.filename(finalPath);
72
- await (0, file_utils_1.writeFile)(dirName, options.data, fileName);
73
- }
74
- }
75
- exports.default = SLPKExtractor;
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- /* eslint-disable no-console */
7
- require("@loaders.gl/polyfills");
8
- const slpk_extractor_1 = __importDefault(require("./slpk-extractor/slpk-extractor"));
9
- const cli_utils_1 = require("./lib/utils/cli-utils");
10
- /**
11
- * CLI entry
12
- * @returns
13
- */
14
- async function main() {
15
- const [, , ...args] = process.argv;
16
- if (args.length === 0) {
17
- printHelp();
18
- }
19
- const validatedOptionsArr = (0, cli_utils_1.validateOptionsWithEqual)(args);
20
- const options = parseOptions(validatedOptionsArr);
21
- const validatedOptions = validateOptions(options);
22
- await convert(validatedOptions);
23
- }
24
- main().catch((error) => {
25
- console.log(error);
26
- process.exit(1); // eslint-disable-line
27
- });
28
- /**
29
- * Output for `npx slpk-extractor --help`
30
- */
31
- function printHelp() {
32
- console.log('cli: converter slpk to I3S...');
33
- console.log('--output [Output folder, default: "data" folder]');
34
- console.log('--tileset [SLPK file]');
35
- process.exit(0); // eslint-disable-line
36
- }
37
- /**
38
- * Run extraction process
39
- * @param options validated slpk-extractor options
40
- */
41
- async function convert(options) {
42
- console.log(`------------------------------------------------`); // eslint-disable-line
43
- console.log(`Starting conversion of SLPK`); // eslint-disable-line
44
- console.log(`------------------------------------------------`); // eslint-disable-line
45
- const slpkExtractor = new slpk_extractor_1.default();
46
- slpkExtractor.extract({
47
- inputUrl: options.tileset,
48
- outputPath: options.output
49
- });
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
- */
57
- function validateOptions(options) {
58
- const mandatoryOptionsWithExceptions = {
59
- output: () => console.log('Missed: --output [Output path name]'),
60
- tileset: () => console.log('Missed: --tileset [SLPK file]')
61
- };
62
- const exceptions = [];
63
- for (const mandatoryOption in mandatoryOptionsWithExceptions) {
64
- const optionValue = options[mandatoryOption];
65
- if (!optionValue) {
66
- exceptions.push(mandatoryOptionsWithExceptions[mandatoryOption]);
67
- }
68
- }
69
- if (exceptions.length) {
70
- exceptions.forEach((exeption) => exeption());
71
- process.exit(1);
72
- }
73
- return options;
74
- }
75
- /**
76
- * Parse option from the cli arguments array
77
- * @param args
78
- * @returns
79
- */
80
- function parseOptions(args) {
81
- const opts = {};
82
- // eslint-disable-next-line complexity
83
- args.forEach((arg, index) => {
84
- if (arg.indexOf('--') === 0) {
85
- switch (arg) {
86
- case '--tileset':
87
- opts.tileset = (0, cli_utils_1.getURLValue)(index, args);
88
- break;
89
- case '--output':
90
- opts.output = (0, cli_utils_1.getURLValue)(index, args);
91
- break;
92
- case '--help':
93
- printHelp();
94
- break;
95
- default:
96
- console.warn(`Unknown option ${arg}`);
97
- process.exit(0); // eslint-disable-line
98
- }
99
- }
100
- });
101
- return opts;
102
- }