@loaders.gl/tile-converter 3.1.6 → 3.2.0-alpha.1

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 (117) hide show
  1. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +78 -0
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -0
  3. package/dist/3d-tiles-converter/3d-tiles-converter.js +242 -0
  4. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +83 -0
  5. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -0
  6. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +278 -0
  7. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +13 -0
  8. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts.map +1 -0
  9. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +23 -0
  10. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +9 -0
  11. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -0
  12. package/dist/3d-tiles-converter/helpers/texture-atlas.js +52 -0
  13. package/dist/3d-tiles-converter/json-templates/tileset.d.ts +15 -0
  14. package/dist/3d-tiles-converter/json-templates/tileset.d.ts.map +1 -0
  15. package/dist/3d-tiles-converter/json-templates/tileset.js +43 -0
  16. package/dist/bundle.d.ts +2 -0
  17. package/dist/bundle.d.ts.map +1 -0
  18. package/dist/bundle.js +5 -0
  19. package/dist/converter.min.js +21 -21
  20. package/dist/deps-installer/deps-installer.d.ts +4 -0
  21. package/dist/deps-installer/deps-installer.d.ts.map +1 -0
  22. package/dist/deps-installer/deps-installer.js +21 -0
  23. package/dist/dist.min.js +1913 -908
  24. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +2 -1
  25. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  26. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +14 -21
  27. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/node-pages.js +78 -35
  29. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  30. package/dist/es5/i3s-converter/i3s-converter.js +35 -25
  31. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  32. package/dist/es5/pgm-loader.js +1 -1
  33. package/dist/es5/pgm-loader.js.map +1 -1
  34. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +2 -1
  35. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  36. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +7 -5
  37. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  38. package/dist/esm/i3s-converter/helpers/node-pages.js +2 -7
  39. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  40. package/dist/esm/i3s-converter/i3s-converter.js +10 -0
  41. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  42. package/dist/esm/pgm-loader.js +1 -1
  43. package/dist/esm/pgm-loader.js.map +1 -1
  44. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +41 -0
  45. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -0
  46. package/dist/i3s-converter/helpers/coordinate-converter.js +118 -0
  47. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +9 -0
  48. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -0
  49. package/dist/i3s-converter/helpers/create-scene-server-path.js +28 -0
  50. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +8 -0
  51. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -0
  52. package/dist/i3s-converter/helpers/geometry-attributes.js +176 -0
  53. package/dist/i3s-converter/helpers/geometry-converter.d.ts +12 -0
  54. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -0
  55. package/dist/i3s-converter/helpers/geometry-converter.js +791 -0
  56. package/dist/i3s-converter/helpers/node-debug.d.ts +8 -0
  57. package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -0
  58. package/dist/i3s-converter/helpers/node-debug.js +114 -0
  59. package/dist/i3s-converter/helpers/node-pages.d.ts +116 -0
  60. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -0
  61. package/dist/i3s-converter/helpers/node-pages.js +203 -0
  62. package/dist/i3s-converter/i3s-converter.d.ts +321 -0
  63. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -0
  64. package/dist/i3s-converter/i3s-converter.js +994 -0
  65. package/dist/i3s-converter/json-templates/layers.d.ts +95 -0
  66. package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -0
  67. package/dist/i3s-converter/json-templates/layers.js +199 -0
  68. package/dist/i3s-converter/json-templates/metadata.d.ts +22 -0
  69. package/dist/i3s-converter/json-templates/metadata.d.ts.map +1 -0
  70. package/dist/i3s-converter/json-templates/metadata.js +25 -0
  71. package/dist/i3s-converter/json-templates/node.d.ts +61 -0
  72. package/dist/i3s-converter/json-templates/node.d.ts.map +1 -0
  73. package/dist/i3s-converter/json-templates/node.js +89 -0
  74. package/dist/i3s-converter/json-templates/scene-server.d.ts +28 -0
  75. package/dist/i3s-converter/json-templates/scene-server.d.ts.map +1 -0
  76. package/dist/i3s-converter/json-templates/scene-server.js +31 -0
  77. package/dist/i3s-converter/json-templates/shared-resources.d.ts +14 -0
  78. package/dist/i3s-converter/json-templates/shared-resources.d.ts.map +1 -0
  79. package/dist/i3s-converter/json-templates/shared-resources.js +129 -0
  80. package/dist/i3s-converter/json-templates/store.d.ts +95 -0
  81. package/dist/i3s-converter/json-templates/store.d.ts.map +1 -0
  82. package/dist/i3s-converter/json-templates/store.js +103 -0
  83. package/dist/i3s-converter/types.d.ts +39 -0
  84. package/dist/i3s-converter/types.d.ts.map +1 -0
  85. package/dist/i3s-converter/types.js +2 -0
  86. package/dist/i3s-server/app.d.ts +3 -0
  87. package/dist/i3s-server/app.d.ts.map +1 -0
  88. package/dist/i3s-server/app.js +14 -0
  89. package/dist/i3s-server/controllers/index-controller.d.ts +2 -0
  90. package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -0
  91. package/dist/i3s-server/controllers/index-controller.js +23 -0
  92. package/dist/i3s-server/routes/index.d.ts +3 -0
  93. package/dist/i3s-server/routes/index.d.ts.map +1 -0
  94. package/dist/i3s-server/routes/index.js +16 -0
  95. package/dist/index.d.ts +5 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +14 -0
  98. package/dist/lib/utils/compress-util.d.ts +6 -0
  99. package/dist/lib/utils/compress-util.d.ts.map +1 -0
  100. package/dist/lib/utils/compress-util.js +190 -0
  101. package/dist/lib/utils/file-utils.d.ts +6 -0
  102. package/dist/lib/utils/file-utils.d.ts.map +1 -0
  103. package/dist/lib/utils/file-utils.js +42 -0
  104. package/dist/lib/utils/lod-conversion-utils.d.ts +20 -0
  105. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -0
  106. package/dist/lib/utils/lod-conversion-utils.js +57 -0
  107. package/dist/lib/utils/statistic-utills.d.ts +3 -0
  108. package/dist/lib/utils/statistic-utills.d.ts.map +1 -0
  109. package/dist/lib/utils/statistic-utills.js +64 -0
  110. package/dist/pgm-loader.d.ts +6 -0
  111. package/dist/pgm-loader.d.ts.map +1 -0
  112. package/dist/pgm-loader.js +23 -0
  113. package/package.json +16 -17
  114. package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -1
  115. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +6 -5
  116. package/src/i3s-converter/helpers/node-pages.ts +6 -6
  117. package/src/i3s-converter/i3s-converter.ts +12 -0
@@ -0,0 +1,190 @@
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
+ exports.addFileToZip = exports.generateHash128FromZip = exports.compressWithChildProcess = exports.compressFilesWithZip = exports.compressFileWithGzip = void 0;
7
+ const zlib_1 = require("zlib");
8
+ const path_1 = require("path");
9
+ const fs_1 = require("fs");
10
+ const archiver_1 = __importDefault(require("archiver"));
11
+ const file_utils_1 = require("./file-utils");
12
+ const worker_utils_1 = require("@loaders.gl/worker-utils");
13
+ const jszip_1 = __importDefault(require("jszip"));
14
+ const crypto_1 = require("@loaders.gl/crypto");
15
+ const crypt_1 = __importDefault(require("crypt"));
16
+ const file_utils_2 = require("./file-utils");
17
+ function compressFileWithGzip(pathFile) {
18
+ const compressedPathFile = `${pathFile}.gz`;
19
+ const gzip = (0, zlib_1.createGzip)();
20
+ const input = (0, fs_1.createReadStream)(pathFile);
21
+ const output = (0, fs_1.createWriteStream)(compressedPathFile);
22
+ return new Promise((resolve, reject) => {
23
+ input.on('end', () => {
24
+ console.log(`${compressedPathFile} compressed and saved.`); // eslint-disable-line no-undef,no-console
25
+ resolve(compressedPathFile);
26
+ });
27
+ input.on('error', (error) => {
28
+ console.log(`${compressedPathFile}: compression error!`); // eslint-disable-line no-undef,no-console
29
+ reject(error);
30
+ });
31
+ input.pipe(gzip).pipe(output);
32
+ });
33
+ }
34
+ exports.compressFileWithGzip = compressFileWithGzip;
35
+ async function compressFilesWithZip(fileMap, outputFile, level = 0) {
36
+ // Before creating a new file, we need to delete the old file
37
+ try {
38
+ await (0, file_utils_1.removeFile)(outputFile);
39
+ }
40
+ catch (e) {
41
+ // Do nothing if old file doesn't exist
42
+ }
43
+ const output = (0, fs_1.createWriteStream)(outputFile);
44
+ const archive = (0, archiver_1.default)('zip', {
45
+ zlib: { level } // Sets the compression level.
46
+ });
47
+ return new Promise(async (resolve, reject) => {
48
+ // listen for all archive data to be writte
49
+ // 'close' event is fired only when a file descriptor is involved
50
+ output.on('close', function () {
51
+ console.log(`${outputFile} saved.`); // eslint-disable-line no-undef,no-console
52
+ console.log(`${archive.pointer()} total bytes`); // eslint-disable-line no-undef,no-console
53
+ resolve(null);
54
+ });
55
+ // This event is fired when the data source is drained no matter what was the data source.
56
+ // It is not part of this library but rather from the NodeJS Stream API.
57
+ // @see: https://nodejs.org/api/stream.html#stream_event_end
58
+ output.on('end', function () {
59
+ console.log('Data has been drained'); // eslint-disable-line no-undef,no-console
60
+ resolve(null);
61
+ });
62
+ // good practice to catch warnings (ie stat failures and other non-blocking errors)
63
+ archive.on('warning', function (err) {
64
+ console.log(err); // eslint-disable-line no-undef,no-console
65
+ reject(err);
66
+ });
67
+ // good practice to catch this error explicitly
68
+ archive.on('error', function (err) {
69
+ reject(err);
70
+ });
71
+ // pipe archive data to the file
72
+ archive.pipe(output);
73
+ for (const subFileName in fileMap) {
74
+ const subFileData = fileMap[subFileName];
75
+ await appendFileToArchive(archive, subFileName, subFileData);
76
+ }
77
+ // finalize the archive (ie we are done appending files but streams have to finish yet)
78
+ archive.finalize();
79
+ });
80
+ }
81
+ exports.compressFilesWithZip = compressFilesWithZip;
82
+ async function compressWithChildProcess() {
83
+ // eslint-disable-next-line no-undef
84
+ if (process.platform === 'win32') {
85
+ await compressWithChildProcessWindows(...arguments);
86
+ }
87
+ else {
88
+ await compressWithChildProcessUnix(...arguments);
89
+ }
90
+ }
91
+ exports.compressWithChildProcess = compressWithChildProcess;
92
+ async function compressWithChildProcessUnix(inputFolder, outputFile, level = 0, inputFiles = '.') {
93
+ const fullOutputFile = (0, file_utils_2.getAbsoluteFilePath)(outputFile);
94
+ const args = [`-${level}`, '-r', fullOutputFile, inputFiles];
95
+ const childProcess = new worker_utils_1.ChildProcessProxy();
96
+ await childProcess.start({
97
+ command: 'zip',
98
+ arguments: args,
99
+ spawn: {
100
+ cwd: inputFolder
101
+ },
102
+ wait: 0
103
+ });
104
+ }
105
+ async function compressWithChildProcessWindows(inputFolder, outputFile, level = 0, inputFiles = (0, path_1.join)('.', '*'), sevenZipExe) {
106
+ // Workaround for @listfile issue. In 7z.exe @-leading files are handled as listfiles
107
+ // https://sevenzip.osdn.jp/chm/cmdline/syntax.htm
108
+ if (inputFiles[0] === '@') {
109
+ inputFiles = `*${inputFiles.substr(1)}`;
110
+ }
111
+ const fullOutputFile = (0, file_utils_2.getAbsoluteFilePath)(outputFile);
112
+ const args = ['a', '-tzip', `-mx=${level}`, fullOutputFile, inputFiles];
113
+ const childProcess = new worker_utils_1.ChildProcessProxy();
114
+ await childProcess.start({
115
+ command: sevenZipExe,
116
+ arguments: args,
117
+ spawn: {
118
+ cwd: `${inputFolder}`
119
+ },
120
+ wait: 0
121
+ });
122
+ }
123
+ async function generateHash128FromZip(inputZipFile, outputFile) {
124
+ const input = await fs_1.promises.readFile(inputZipFile);
125
+ const zip = await jszip_1.default.loadAsync(input);
126
+ const hashTable = [];
127
+ const zipFiles = zip.files;
128
+ for (const relativePath in zipFiles) {
129
+ const zipEntry = zipFiles[relativePath];
130
+ // Had to use a workaround because the correct string is getting the wrong data
131
+ // const content = await zipEntry.async('nodebuffer');
132
+ // _data isn't described in the interface, so lint thought it was wrong
133
+ const _data = '_data';
134
+ const content = zipEntry[_data].compressedContent;
135
+ if (zipEntry.dir)
136
+ continue; // eslint-disable-line no-continue
137
+ // eslint-disable-next-line no-undef
138
+ const hash = await new crypto_1.MD5Hash().hash(Buffer.from(relativePath.toLowerCase()));
139
+ // eslint-disable-next-line no-undef
140
+ hashTable.push({ key: atob(hash), value: content.byteOffset });
141
+ }
142
+ hashTable.sort((prev, next) => {
143
+ if (prev.key === next.key) {
144
+ return prev.value < next.value ? -1 : 1;
145
+ }
146
+ return prev.key < next.key ? -1 : 1;
147
+ });
148
+ const output = (0, fs_1.createWriteStream)(outputFile);
149
+ return new Promise((resolve, reject) => {
150
+ output.on('close', function () {
151
+ console.log(`${outputFile} generated and saved`); // eslint-disable-line
152
+ resolve(null);
153
+ });
154
+ output.on('error', function (err) {
155
+ console.log(err); // eslint-disable-line
156
+ reject(err);
157
+ });
158
+ for (const key in hashTable) {
159
+ const item = hashTable[key];
160
+ const value = _longToByteArray(item.value);
161
+ // TODO: perhaps you need to wait for the 'drain' event if the write returns 'false'
162
+ // eslint-disable-next-line no-undef
163
+ output.write(Buffer.from(crypt_1.default.hexToBytes(item.key).concat(value)));
164
+ }
165
+ output.close();
166
+ });
167
+ }
168
+ exports.generateHash128FromZip = generateHash128FromZip;
169
+ function _longToByteArray(long) {
170
+ const buffer = new ArrayBuffer(8); // JS numbers are 8 bytes long, or 64 bits
171
+ const longNum = new Float64Array(buffer); // so equivalent to Float64
172
+ longNum[0] = long;
173
+ return Array.from(new Uint8Array(buffer)).reverse(); // reverse to get little endian
174
+ }
175
+ async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {
176
+ await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);
177
+ console.log(`${fileName} added to ${zipFile}.`); // eslint-disable-line
178
+ }
179
+ exports.addFileToZip = addFileToZip;
180
+ function appendFileToArchive(archive, subFileName, subFileData) {
181
+ return new Promise((resolve) => {
182
+ const fileStream = (0, fs_1.createReadStream)(subFileData);
183
+ console.log(`Compression start: ${subFileName}`); // eslint-disable-line no-undef,no-console
184
+ fileStream.on('close', () => {
185
+ console.log(`Compression finish: ${subFileName}`); // eslint-disable-line no-undef,no-console
186
+ resolve(null);
187
+ });
188
+ archive.append(fileStream, { name: subFileName });
189
+ });
190
+ }
@@ -0,0 +1,6 @@
1
+ export function writeFile(path: any, data: any, fileName?: string): Promise<string>;
2
+ export function writeFileForSlpk(path: any, data: any, fileName?: string, compress?: boolean): Promise<string>;
3
+ export function removeDir(path: any): Promise<void>;
4
+ export function removeFile(path: any): Promise<void>;
5
+ export function getAbsoluteFilePath(filePath: any): any;
6
+ //# sourceMappingURL=file-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/file-utils.js"],"names":[],"mappings":"AAIA,oFAUC;AAED,+GASC;AAED,oDAEC;AAED,qDAEC;AAED,wDAEC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAbsoluteFilePath = exports.removeFile = exports.removeDir = exports.writeFileForSlpk = exports.writeFile = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const compress_util_1 = require("./compress-util");
7
+ async function writeFile(path, data, fileName = 'index.json') {
8
+ await fs_1.promises.mkdir(path, { recursive: true });
9
+ const pathFile = (0, path_1.join)(path, fileName);
10
+ try {
11
+ await fs_1.promises.writeFile(pathFile, data);
12
+ }
13
+ catch (err) {
14
+ throw err;
15
+ }
16
+ console.log(`${pathFile} saved.`); // eslint-disable-line
17
+ return pathFile;
18
+ }
19
+ exports.writeFile = writeFile;
20
+ async function writeFileForSlpk(path, data, fileName = 'index.json', compress = true) {
21
+ const pathFile = await writeFile(path, data, fileName);
22
+ if (compress) {
23
+ const pathGzFile = await (0, compress_util_1.compressFileWithGzip)(pathFile);
24
+ // After compression, we don't need an uncompressed file
25
+ await removeFile(pathFile);
26
+ return pathGzFile;
27
+ }
28
+ return pathFile;
29
+ }
30
+ exports.writeFileForSlpk = writeFileForSlpk;
31
+ function removeDir(path) {
32
+ return fs_1.promises.rmdir(path, { recursive: true });
33
+ }
34
+ exports.removeDir = removeDir;
35
+ function removeFile(path) {
36
+ return fs_1.promises.unlink(path);
37
+ }
38
+ exports.removeFile = removeFile;
39
+ function getAbsoluteFilePath(filePath) {
40
+ return (0, path_1.isAbsolute)(filePath) ? filePath : (0, path_1.join)(process.cwd(), filePath); // eslint-disable-line no-undef
41
+ }
42
+ exports.getAbsoluteFilePath = getAbsoluteFilePath;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Do conversion from geometric error to screen threshold
3
+ * @param {Object} tile
4
+ * @param {Object} coordinates
5
+ * In 3DTiles we have HLOD logic and parent tile also has bigger lodMetric value then its children.
6
+ * In I3s we have reverse logic related to maxError. Parent has lower maxError than its child.
7
+ * In nodes where are no children tile.lodMetricValue is 0. This is because of logic of HLOD in 3DTiles
8
+ * 3DTiles spec:
9
+ * https://github.com/CesiumGS/3d-tiles/tree/master/specification#geometric-error
10
+ * I3S spec:
11
+ * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/lodSelection.cmn.md
12
+ * To avoid infinity values when we do calculations of maxError we shold replace 0 with value which allows us
13
+ * to make child maxError bigger than his parent maxError.
14
+ */
15
+ export function convertGeometricErrorToScreenThreshold(tile: any, coordinates: any): {
16
+ metricType: string;
17
+ maxError: number;
18
+ }[];
19
+ export function convertScreenThresholdToGeometricError(node: any): number;
20
+ //# sourceMappingURL=lod-conversion-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lod-conversion-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/lod-conversion-utils.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH;;;IAsBC;AAED,0EAeC"}
@@ -0,0 +1,57 @@
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
+ * @param {Object} tile
9
+ * @param {Object} coordinates
10
+ * In 3DTiles we have HLOD logic and parent tile also has bigger lodMetric value then its children.
11
+ * In I3s we have reverse logic related to maxError. Parent has lower maxError than its child.
12
+ * In nodes where are no children tile.lodMetricValue is 0. This is because of logic of HLOD in 3DTiles
13
+ * 3DTiles spec:
14
+ * https://github.com/CesiumGS/3d-tiles/tree/master/specification#geometric-error
15
+ * I3S spec:
16
+ * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/lodSelection.cmn.md
17
+ * To avoid infinity values when we do calculations of maxError we shold replace 0 with value which allows us
18
+ * to make child maxError bigger than his parent maxError.
19
+ */
20
+ function convertGeometricErrorToScreenThreshold(tile, coordinates) {
21
+ const lodSelection = [];
22
+ const boundingVolume = tile.boundingVolume;
23
+ const lodMetricValue = tile.lodMetricValue || 0.1;
24
+ const maxScreenThreshold = {
25
+ metricType: 'maxScreenThreshold',
26
+ maxError: (coordinates.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / lodMetricValue
27
+ };
28
+ const maxScreenThresholdSQ = {
29
+ metricType: 'maxScreenThresholdSQ',
30
+ maxError: Math.PI * 0.25 * maxScreenThreshold.maxError * maxScreenThreshold.maxError
31
+ };
32
+ if (boundingVolume.constructor.name === 'OrientedBoundingBox') {
33
+ lodSelection.push(maxScreenThresholdSQ);
34
+ lodSelection.push(maxScreenThreshold);
35
+ }
36
+ else {
37
+ lodSelection.push(maxScreenThreshold);
38
+ lodSelection.push(maxScreenThresholdSQ);
39
+ }
40
+ return lodSelection;
41
+ }
42
+ exports.convertGeometricErrorToScreenThreshold = convertGeometricErrorToScreenThreshold;
43
+ function convertScreenThresholdToGeometricError(node) {
44
+ const metricData = node.header.lodSelection.maxScreenThreshold || {};
45
+ let maxError = metricData.maxError;
46
+ if (!maxError) {
47
+ const sqMetricData = node.header.lodSelection.maxScreenThresholdSQ;
48
+ if (sqMetricData) {
49
+ maxError = Math.sqrt(sqMetricData.maxError / (Math.PI * 0.25));
50
+ }
51
+ }
52
+ if (!maxError) {
53
+ maxError = DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR;
54
+ }
55
+ return (node.header.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / maxError;
56
+ }
57
+ exports.convertScreenThresholdToGeometricError = convertScreenThresholdToGeometricError;
@@ -0,0 +1,3 @@
1
+ export function timeConverter(time: any): string;
2
+ export function calculateFilesSize(params: any): Promise<number | null>;
3
+ //# sourceMappingURL=statistic-utills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statistic-utills.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/statistic-utills.js"],"names":[],"mappings":"AAIA,iDA4BC;AAED,wEAkBC"}
@@ -0,0 +1,64 @@
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
+ }
@@ -0,0 +1,6 @@
1
+ import type { LoaderWithParser } from '@loaders.gl/loader-utils';
2
+ /**
3
+ * Loader for PGM - Netpbm grayscale image format
4
+ */
5
+ export declare const PGMLoader: LoaderWithParser;
6
+ //# sourceMappingURL=pgm-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pgm-loader.d.ts","sourceRoot":"","sources":["../src/pgm-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAQ/D;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAYvB,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PGMLoader = void 0;
4
+ // __VERSION__ is injected by babel-plugin-version-inline
5
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
7
+ const geoid_1 = require("@math.gl/geoid");
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
+ parse: async (arrayBuffer, options) => (0, geoid_1.parsePGM)(new Uint8Array(arrayBuffer), options),
18
+ extensions: ['pgm'],
19
+ options: {
20
+ // TODO - use pgm namespace
21
+ cubic: false
22
+ }
23
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/tile-converter",
3
- "version": "3.1.6",
3
+ "version": "3.2.0-alpha.1",
4
4
  "description": "Converter",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -33,25 +33,24 @@
33
33
  "fs": false
34
34
  },
35
35
  "scripts": {
36
- "pre-build": "npm run build-bundle",
37
- "post-build": "npm run build-converter-bundle",
36
+ "pre-build": "npm run build-bundle && npm run build-converter-bundle",
38
37
  "build-bundle": "esbuild ./src/index.ts --bundle --outfile=dist/dist.min.js --platform=node",
39
38
  "build-converter-bundle": "webpack --display errors-only --config ./converter-webpack/bundle.js",
40
39
  "build-bin": "BABEL_ENV=es5 babel scripts --config-file ../../babel.config.js --out-dir dist/scripts"
41
40
  },
42
41
  "dependencies": {
43
- "@loaders.gl/3d-tiles": "3.1.6",
44
- "@loaders.gl/crypto": "3.1.6",
45
- "@loaders.gl/draco": "3.1.6",
46
- "@loaders.gl/gltf": "3.1.6",
47
- "@loaders.gl/i3s": "3.1.6",
48
- "@loaders.gl/images": "3.1.6",
49
- "@loaders.gl/loader-utils": "3.1.6",
50
- "@loaders.gl/polyfills": "3.1.6",
51
- "@loaders.gl/textures": "3.1.6",
52
- "@loaders.gl/tiles": "3.1.6",
53
- "@loaders.gl/worker-utils": "3.1.6",
54
- "@loaders.gl/zip": "3.1.6",
42
+ "@loaders.gl/3d-tiles": "3.2.0-alpha.1",
43
+ "@loaders.gl/crypto": "3.2.0-alpha.1",
44
+ "@loaders.gl/draco": "3.2.0-alpha.1",
45
+ "@loaders.gl/gltf": "3.2.0-alpha.1",
46
+ "@loaders.gl/i3s": "3.2.0-alpha.1",
47
+ "@loaders.gl/images": "3.2.0-alpha.1",
48
+ "@loaders.gl/loader-utils": "3.2.0-alpha.1",
49
+ "@loaders.gl/polyfills": "3.2.0-alpha.1",
50
+ "@loaders.gl/textures": "3.2.0-alpha.1",
51
+ "@loaders.gl/tiles": "3.2.0-alpha.1",
52
+ "@loaders.gl/worker-utils": "3.2.0-alpha.1",
53
+ "@loaders.gl/zip": "3.2.0-alpha.1",
55
54
  "@luma.gl/engine": "^8.5.4",
56
55
  "@math.gl/core": "^3.5.1",
57
56
  "@math.gl/culling": "^3.5.1",
@@ -69,7 +68,7 @@
69
68
  "uuid": "^8.1.0"
70
69
  },
71
70
  "peerDependencies": {
72
- "@loaders.gl/core": "3.1.0"
71
+ "@loaders.gl/core": "4.0.0-alpha.4"
73
72
  },
74
- "gitHead": "4fe0724b942697a95ff3eb3af47b7a7c18556c52"
73
+ "gitHead": "423a2815092b08dcf93ad5b7dc2940b167305afe"
75
74
  }
@@ -67,8 +67,11 @@ export default class Tiles3DConverter {
67
67
  console.log('Loading egm file completed!'); // eslint-disable-line
68
68
 
69
69
  const sourceTilesetJson = await load(inputUrl, I3SLoader, {});
70
+
70
71
  this.sourceTileset = new Tileset3D(sourceTilesetJson, {
71
- loadOptions: {i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS}}
72
+ loadOptions: {
73
+ i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false}
74
+ }
72
75
  });
73
76
 
74
77
  const rootNode = this.sourceTileset.root!;
@@ -1,7 +1,6 @@
1
- import {encode, encodeSync} from '@loaders.gl/core';
1
+ import {encodeSync} from '@loaders.gl/core';
2
2
  import {GLTFScenegraph, GLTFWriter} from '@loaders.gl/gltf';
3
3
  import {Tile3DWriter} from '@loaders.gl/3d-tiles';
4
- import {ImageWriter} from '@loaders.gl/images';
5
4
  import {Matrix4, Vector3} from '@math.gl/core';
6
5
  import {Ellipsoid} from '@math.gl/geospatial';
7
6
  import {convertTextureAtlas} from './texture-atlas';
@@ -81,7 +80,8 @@ export default class B3dmConverter {
81
80
  const meshIndex = gltfBuilder.addMesh({
82
81
  attributes,
83
82
  indices,
84
- material: materialIndex
83
+ material: materialIndex,
84
+ mode: 4
85
85
  });
86
86
  const transformMatrix = this._generateTransformMatrix(cartesianOrigin);
87
87
  const nodeIndex = gltfBuilder.addNode({meshIndex, matrix: transformMatrix});
@@ -116,8 +116,7 @@ export default class B3dmConverter {
116
116
  }
117
117
  if (selectedTexture) {
118
118
  const mimeType = this._deduceMimeTypeFromFormat(textureFormat);
119
- const imageBuffer = await encode(selectedTexture, ImageWriter);
120
- const imageIndex = gltfBuilder.addImage(imageBuffer, mimeType);
119
+ const imageIndex = gltfBuilder.addImage(selectedTexture, mimeType);
121
120
  textureIndex = gltfBuilder.addTexture({imageIndex});
122
121
  delete attributes.colors;
123
122
  }
@@ -210,6 +209,8 @@ export default class B3dmConverter {
210
209
  return 'image/jpeg';
211
210
  case 'png':
212
211
  return 'image/png';
212
+ case 'ktx2':
213
+ return 'image/ktx2';
213
214
  default:
214
215
  console.warn(`Unexpected texture format in I3S: ${format}`); // eslint-disable-line no-console, no-undef
215
216
  return 'image/jpeg';
@@ -194,13 +194,15 @@ export default class NodePages {
194
194
  * @return {promise}
195
195
  */
196
196
  async save(layers0Path: string, fileMap: Object, slpk: boolean = false): Promise<void> {
197
- const promises: Promise<any>[] = [];
198
197
  if (slpk) {
199
198
  for (const [index, nodePage] of this.nodePages.entries()) {
200
199
  const nodePageStr = JSON.stringify(nodePage);
201
200
  const slpkPath = join(layers0Path, 'nodepages');
202
- promises.push(this.writeFile(slpkPath, nodePageStr, `${index.toString()}.json`));
203
- fileMap[`nodePages/${index.toString()}.json.gz`] = `${slpkPath}.json.gz`;
201
+ fileMap[`nodePages/${index.toString()}.json.gz`] = await this.writeFile(
202
+ slpkPath,
203
+ nodePageStr,
204
+ `${index.toString()}.json`
205
+ );
204
206
  }
205
207
  const metadata = transform({nodeCount: this.nodesCounter}, metadataTemplate());
206
208
  const compress = false;
@@ -214,10 +216,8 @@ export default class NodePages {
214
216
  for (const [index, nodePage] of this.nodePages.entries()) {
215
217
  const nodePageStr = JSON.stringify(nodePage);
216
218
  const nodePagePath = join(layers0Path, 'nodepages', index.toString());
217
- promises.push(this.writeFile(nodePagePath, nodePageStr));
219
+ await this.writeFile(nodePagePath, nodePageStr);
218
220
  }
219
221
  }
220
-
221
- await Promise.all(promises);
222
222
  }
223
223
  }
@@ -96,6 +96,7 @@ export default class I3SConverter {
96
96
  Loader: LoaderWithParser = Tiles3DLoader;
97
97
  generateTextures: boolean;
98
98
  generateBoundingVolumes: boolean;
99
+ layersHasTexture: boolean;
99
100
 
100
101
  constructor() {
101
102
  this.nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE);
@@ -114,6 +115,7 @@ export default class I3SConverter {
114
115
  this.validate = false;
115
116
  this.generateTextures = false;
116
117
  this.generateBoundingVolumes = false;
118
+ this.layersHasTexture = false;
117
119
  }
118
120
 
119
121
  /**
@@ -226,6 +228,14 @@ export default class I3SConverter {
226
228
  await this._convertNodesTree(root0, sourceRootTile, parentId, boundingVolumes);
227
229
 
228
230
  this.layers0!.materialDefinitions = this.materialDefinitions;
231
+
232
+ if (this.layersHasTexture === false) {
233
+ this.layers0!.store.defaultGeometrySchema.ordering =
234
+ this.layers0!.store.defaultGeometrySchema.ordering.filter(
235
+ (attribute) => attribute !== 'uv0'
236
+ );
237
+ }
238
+
229
239
  await this._writeLayers0();
230
240
  createSceneServerPath(tilesetName, this.layers0!, tilesetPath);
231
241
  await this._writeNodeIndexDocument(root0, 'root', join(this.layers0Path, 'nodes', 'root'));
@@ -556,6 +566,8 @@ export default class I3SConverter {
556
566
  };
557
567
 
558
568
  for (const resources of resourcesData || [emptyResources]) {
569
+ this.layersHasTexture = this.layersHasTexture || Boolean(resources.texture);
570
+
559
571
  if (this.generateBoundingVolumes && resources.boundingVolumes) {
560
572
  boundingVolumes = resources.boundingVolumes;
561
573
  }