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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/dist/3d-tiles-attributes-worker.d.ts +28 -0
  2. package/dist/3d-tiles-attributes-worker.d.ts.map +1 -0
  3. package/dist/3d-tiles-attributes-worker.js +4 -0
  4. package/dist/3d-tiles-attributes-worker.js.map +7 -0
  5. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +4 -0
  6. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  7. package/dist/3d-tiles-converter/3d-tiles-converter.js +29 -3
  8. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +5 -4
  9. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  10. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +10 -10
  11. package/dist/converter.min.js +20 -20
  12. package/dist/dist.min.js +789 -645
  13. package/dist/es5/3d-tiles-attributes-worker.js +29 -0
  14. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -0
  15. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +102 -43
  16. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  17. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +21 -23
  18. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  19. package/dist/es5/i3s-attributes-worker.js +29 -0
  20. package/dist/es5/i3s-attributes-worker.js.map +1 -0
  21. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +19 -11
  22. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  23. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +2 -2
  24. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  25. package/dist/es5/i3s-converter/helpers/geometry-converter.js +267 -178
  26. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  27. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +71 -0
  28. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  29. package/dist/es5/i3s-converter/helpers/node-pages.js +47 -99
  30. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  31. package/dist/es5/i3s-converter/i3s-converter.js +230 -195
  32. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  33. package/dist/es5/index.js +8 -0
  34. package/dist/es5/index.js.map +1 -1
  35. package/dist/es5/lib/utils/compress-util.js +14 -17
  36. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  37. package/dist/es5/lib/utils/file-utils.js +39 -14
  38. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  39. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  40. package/dist/es5/lib/utils/queue.js +61 -0
  41. package/dist/es5/lib/utils/queue.js.map +1 -0
  42. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  43. package/dist/es5/lib/utils/write-queue.js +225 -0
  44. package/dist/es5/lib/utils/write-queue.js.map +1 -0
  45. package/dist/es5/pgm-loader.js +1 -1
  46. package/dist/es5/workers/3d-tiles-attributes-worker.js +37 -0
  47. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -0
  48. package/dist/es5/workers/i3s-attributes-worker.js +40 -0
  49. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -0
  50. package/dist/esm/3d-tiles-attributes-worker.js +16 -0
  51. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -0
  52. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +30 -4
  53. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  54. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +16 -18
  55. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  56. package/dist/esm/i3s-attributes-worker.js +16 -0
  57. package/dist/esm/i3s-attributes-worker.js.map +1 -0
  58. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +19 -11
  59. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  60. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +2 -2
  61. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  62. package/dist/esm/i3s-converter/helpers/geometry-converter.js +117 -58
  63. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  64. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +54 -0
  65. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  66. package/dist/esm/i3s-converter/helpers/node-pages.js +12 -4
  67. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  68. package/dist/esm/i3s-converter/i3s-converter.js +105 -28
  69. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  70. package/dist/esm/index.js +1 -0
  71. package/dist/esm/index.js.map +1 -1
  72. package/dist/esm/lib/utils/compress-util.js +6 -8
  73. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  74. package/dist/esm/lib/utils/file-utils.js +11 -1
  75. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  76. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  77. package/dist/esm/lib/utils/queue.js +19 -0
  78. package/dist/esm/lib/utils/queue.js.map +1 -0
  79. package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
  80. package/dist/esm/lib/utils/write-queue.js +88 -0
  81. package/dist/esm/lib/utils/write-queue.js.map +1 -0
  82. package/dist/esm/pgm-loader.js +1 -1
  83. package/dist/esm/workers/3d-tiles-attributes-worker.js +5 -0
  84. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -0
  85. package/dist/esm/workers/i3s-attributes-worker.js +4 -0
  86. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -0
  87. package/dist/i3s-attributes-worker.d.ts +33 -0
  88. package/dist/i3s-attributes-worker.d.ts.map +1 -0
  89. package/dist/i3s-attributes-worker.js +10 -0
  90. package/dist/i3s-attributes-worker.js.map +7 -0
  91. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +7 -7
  92. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
  93. package/dist/i3s-converter/helpers/coordinate-converter.js +25 -21
  94. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +2 -2
  95. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  96. package/dist/i3s-converter/helpers/geometry-attributes.js +2 -1
  97. package/dist/i3s-converter/helpers/geometry-converter.d.ts +28 -11
  98. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  99. package/dist/i3s-converter/helpers/geometry-converter.js +220 -110
  100. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +9 -0
  101. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -0
  102. package/dist/i3s-converter/helpers/gltf-attributes.js +56 -0
  103. package/dist/i3s-converter/helpers/node-pages.d.ts +6 -5
  104. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  105. package/dist/i3s-converter/helpers/node-pages.js +13 -8
  106. package/dist/i3s-converter/i3s-converter.d.ts +7 -3
  107. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  108. package/dist/i3s-converter/i3s-converter.js +88 -26
  109. package/dist/i3s-converter/types.d.ts +83 -8
  110. package/dist/i3s-converter/types.d.ts.map +1 -1
  111. package/dist/index.d.ts +1 -0
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js +3 -1
  114. package/dist/lib/utils/compress-util.d.ts +44 -5
  115. package/dist/lib/utils/compress-util.d.ts.map +1 -1
  116. package/dist/lib/utils/compress-util.js +73 -6
  117. package/dist/lib/utils/file-utils.d.ts +34 -5
  118. package/dist/lib/utils/file-utils.d.ts.map +1 -1
  119. package/dist/lib/utils/file-utils.js +40 -1
  120. package/dist/lib/utils/lod-conversion-utils.d.ts +25 -4
  121. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -1
  122. package/dist/lib/utils/lod-conversion-utils.js +21 -2
  123. package/dist/lib/utils/queue.d.ts +7 -0
  124. package/dist/lib/utils/queue.d.ts.map +1 -0
  125. package/dist/lib/utils/queue.js +18 -0
  126. package/dist/lib/utils/statistic-utills.d.ts +2 -2
  127. package/dist/lib/utils/statistic-utills.d.ts.map +1 -1
  128. package/dist/lib/utils/write-queue.d.ts +22 -0
  129. package/dist/lib/utils/write-queue.d.ts.map +1 -0
  130. package/dist/lib/utils/write-queue.js +62 -0
  131. package/dist/workers/3d-tiles-attributes-worker.d.ts +2 -0
  132. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +1 -0
  133. package/dist/workers/3d-tiles-attributes-worker.js +9 -0
  134. package/dist/workers/i3s-attributes-worker.d.ts +2 -0
  135. package/dist/workers/i3s-attributes-worker.d.ts.map +1 -0
  136. package/dist/workers/i3s-attributes-worker.js +5 -0
  137. package/package.json +20 -17
  138. package/src/3d-tiles-attributes-worker.ts +43 -0
  139. package/src/3d-tiles-converter/3d-tiles-converter.ts +44 -4
  140. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +15 -13
  141. package/src/i3s-attributes-worker.ts +46 -0
  142. package/src/i3s-converter/helpers/coordinate-converter.ts +29 -24
  143. package/src/i3s-converter/helpers/geometry-attributes.ts +4 -3
  144. package/src/i3s-converter/helpers/{geometry-converter.js → geometry-converter.ts} +421 -175
  145. package/src/i3s-converter/helpers/gltf-attributes.ts +68 -0
  146. package/src/i3s-converter/helpers/node-pages.ts +25 -17
  147. package/src/i3s-converter/i3s-converter.ts +112 -69
  148. package/src/i3s-converter/types.ts +90 -8
  149. package/src/index.ts +1 -0
  150. package/src/lib/utils/{compress-util.js → compress-util.ts} +105 -18
  151. package/src/lib/utils/file-utils.ts +84 -0
  152. package/src/lib/utils/{lod-conversion-utils.js → lod-conversion-utils.ts} +27 -5
  153. package/src/lib/utils/queue.ts +17 -0
  154. package/src/lib/utils/{statistic-utills.js → statistic-utills.ts} +0 -0
  155. package/src/lib/utils/write-queue.ts +75 -0
  156. package/src/workers/3d-tiles-attributes-worker.ts +6 -0
  157. package/src/workers/i3s-attributes-worker.ts +6 -0
  158. package/dist/es5/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  159. package/dist/es5/lib/utils/compress-util.d.ts +0 -53
  160. package/dist/es5/lib/utils/file-utils.d.ts +0 -43
  161. package/dist/es5/lib/utils/lod-conversion-utils.d.ts +0 -32
  162. package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  163. package/dist/esm/lib/utils/compress-util.d.ts +0 -53
  164. package/dist/esm/lib/utils/file-utils.d.ts +0 -43
  165. package/dist/esm/lib/utils/lod-conversion-utils.d.ts +0 -32
  166. package/src/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  167. package/src/lib/utils/compress-util.d.ts +0 -53
  168. package/src/lib/utils/file-utils.d.ts +0 -43
  169. package/src/lib/utils/file-utils.js +0 -38
  170. package/src/lib/utils/lod-conversion-utils.d.ts +0 -32
@@ -9,7 +9,13 @@ import {MD5Hash} from '@loaders.gl/crypto';
9
9
  import crypt from 'crypt';
10
10
  import {getAbsoluteFilePath} from './file-utils';
11
11
 
12
- export function compressFileWithGzip(pathFile) {
12
+ /**
13
+ * Compress file to gzip file
14
+ *
15
+ * @param pathFile - the path to the file
16
+ * @return the path to the gzip file
17
+ */
18
+ export function compressFileWithGzip(pathFile: string): Promise<string> {
13
19
  const compressedPathFile = `${pathFile}.gz`;
14
20
  const gzip = createGzip();
15
21
  const input = createReadStream(pathFile);
@@ -28,7 +34,18 @@ export function compressFileWithGzip(pathFile) {
28
34
  });
29
35
  }
30
36
 
31
- export async function compressFilesWithZip(fileMap, outputFile, level = 0) {
37
+ /**
38
+ * Compress files from map into slpk file
39
+ *
40
+ * @param fileMap - map with file paths (key: output path, value: input path)
41
+ * @param outputFile - output slpk file
42
+ * @param level - compression level
43
+ */
44
+ export async function compressFilesWithZip(
45
+ fileMap: {[key: string]: string},
46
+ outputFile: string,
47
+ level: number = 0
48
+ ) {
32
49
  // Before creating a new file, we need to delete the old file
33
50
  try {
34
51
  await removeFile(outputFile);
@@ -82,16 +99,44 @@ export async function compressFilesWithZip(fileMap, outputFile, level = 0) {
82
99
  });
83
100
  }
84
101
 
85
- export async function compressWithChildProcess() {
102
+ /**
103
+ * Compress files using external tool 'zip'/'7z'
104
+ *
105
+ * @param inputFolder - folder to archive - for cwd option
106
+ * @param outputFile - output slpk file
107
+ * @param level - compression level
108
+ * @param inputFiles - input files path to pass to the executable as option
109
+ * @param sevenZipExe - path to 7z.exe executable
110
+ */
111
+ export async function compressWithChildProcess(
112
+ inputFolder: string,
113
+ outputFile: string,
114
+ level: number,
115
+ inputFiles: string,
116
+ sevenZipExe: string
117
+ ) {
86
118
  // eslint-disable-next-line no-undef
87
119
  if (process.platform === 'win32') {
88
- await compressWithChildProcessWindows(...arguments);
120
+ await compressWithChildProcessWindows(inputFolder, outputFile, level, inputFiles, sevenZipExe);
89
121
  } else {
90
- await compressWithChildProcessUnix(...arguments);
122
+ await compressWithChildProcessUnix(inputFolder, outputFile, level, inputFiles);
91
123
  }
92
124
  }
93
125
 
94
- async function compressWithChildProcessUnix(inputFolder, outputFile, level = 0, inputFiles = '.') {
126
+ /**
127
+ * Compress files using external linux tool 'zip'
128
+ *
129
+ * @param inputFolder - folder to archive - for cwd option
130
+ * @param outputFile - output slpk file
131
+ * @param level - compression level
132
+ * @param inputFiles - input files path to pass to the executable as option
133
+ */
134
+ async function compressWithChildProcessUnix(
135
+ inputFolder: string,
136
+ outputFile: string,
137
+ level: number = 0,
138
+ inputFiles: string = '.'
139
+ ) {
95
140
  const fullOutputFile = getAbsoluteFilePath(outputFile);
96
141
  const args = [`-${level}`, '-r', fullOutputFile, inputFiles];
97
142
  const childProcess = new ChildProcessProxy();
@@ -105,12 +150,21 @@ async function compressWithChildProcessUnix(inputFolder, outputFile, level = 0,
105
150
  });
106
151
  }
107
152
 
153
+ /**
154
+ * Compress files using windows external tool '7z'
155
+ *
156
+ * @param inputFolder - folder to archive - for cwd option
157
+ * @param outputFile - output slpk file
158
+ * @param level - compression level
159
+ * @param inputFiles - input files path to pass to the executable as option
160
+ * @param sevenZipExe - path to 7z.exe executable
161
+ */
108
162
  async function compressWithChildProcessWindows(
109
- inputFolder,
110
- outputFile,
111
- level = 0,
112
- inputFiles = join('.', '*'),
113
- sevenZipExe
163
+ inputFolder: string,
164
+ outputFile: string,
165
+ level: number = 0,
166
+ inputFiles: string = join('.', '*'),
167
+ sevenZipExe: string
114
168
  ) {
115
169
  // Workaround for @listfile issue. In 7z.exe @-leading files are handled as listfiles
116
170
  // https://sevenzip.osdn.jp/chm/cmdline/syntax.htm
@@ -131,10 +185,17 @@ async function compressWithChildProcessWindows(
131
185
  });
132
186
  }
133
187
 
134
- export async function generateHash128FromZip(inputZipFile, outputFile) {
188
+ /**
189
+ * Generate hash file from zip archive
190
+ * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/slpk_hashtable.cmn.md
191
+ *
192
+ * @param inputZipFile
193
+ * @param outputFile
194
+ */
195
+ export async function generateHash128FromZip(inputZipFile: string, outputFile: string) {
135
196
  const input = await fs.readFile(inputZipFile);
136
197
  const zip = await JSZip.loadAsync(input);
137
- const hashTable = [];
198
+ const hashTable: {key: string; value: string}[] = [];
138
199
  const zipFiles = zip.files;
139
200
  for (const relativePath in zipFiles) {
140
201
  const zipEntry = zipFiles[relativePath];
@@ -169,7 +230,7 @@ export async function generateHash128FromZip(inputZipFile, outputFile) {
169
230
  });
170
231
  for (const key in hashTable) {
171
232
  const item = hashTable[key];
172
- const value = _longToByteArray(item.value);
233
+ const value = longToByteArray(item.value);
173
234
  // TODO: perhaps you need to wait for the 'drain' event if the write returns 'false'
174
235
  // eslint-disable-next-line no-undef
175
236
  output.write(Buffer.from(crypt.hexToBytes(item.key).concat(value)));
@@ -178,19 +239,45 @@ export async function generateHash128FromZip(inputZipFile, outputFile) {
178
239
  });
179
240
  }
180
241
 
181
- function _longToByteArray(long) {
242
+ /**
243
+ * Encode 64 bit value to byte array
244
+ *
245
+ * @param long - stringified number
246
+ * @returns
247
+ */
248
+ function longToByteArray(long: string): number[] {
182
249
  const buffer = new ArrayBuffer(8); // JS numbers are 8 bytes long, or 64 bits
183
250
  const longNum = new Float64Array(buffer); // so equivalent to Float64
184
- longNum[0] = long;
251
+ longNum[0] = parseInt(long);
185
252
  return Array.from(new Uint8Array(buffer)).reverse(); // reverse to get little endian
186
253
  }
187
254
 
188
- export async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {
255
+ /**
256
+ * Add file to zip archive
257
+ *
258
+ * @param inputFile
259
+ * @param fileName
260
+ * @param zipFile
261
+ * @param sevenZipExe
262
+ */
263
+ export async function addFileToZip(
264
+ inputFolder: string,
265
+ fileName: string,
266
+ zipFile: string,
267
+ sevenZipExe: string
268
+ ) {
189
269
  await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);
190
270
  console.log(`${fileName} added to ${zipFile}.`); // eslint-disable-line
191
271
  }
192
272
 
193
- function appendFileToArchive(archive, subFileName, subFileData) {
273
+ /**
274
+ *
275
+ * @param archive zip archive instance
276
+ * @param subFileName file path inside archive
277
+ * @param subFileData source file path
278
+ * @returns
279
+ */
280
+ function appendFileToArchive(archive: any, subFileName: string, subFileData: string) {
194
281
  return new Promise((resolve) => {
195
282
  const fileStream = createReadStream(subFileData);
196
283
  console.log(`Compression start: ${subFileName}`); // eslint-disable-line no-undef,no-console
@@ -0,0 +1,84 @@
1
+ import {promises as fs} from 'fs';
2
+ import {isAbsolute, join} from 'path';
3
+ import {compressFileWithGzip} from './compress-util';
4
+
5
+ /**
6
+ * Write a file with data and name fileName to path
7
+ *
8
+ * @param path - output path
9
+ * @param data - file content
10
+ * @param fileName - name of output file (default: index.json)
11
+ */
12
+ export async function writeFile(
13
+ path: string,
14
+ data: string | Uint8Array | ArrayBuffer | Promise<ArrayBuffer>,
15
+ fileName: string = 'index.json'
16
+ ): Promise<string> {
17
+ let toWriteData: string | Uint8Array;
18
+ if (data instanceof Promise) {
19
+ toWriteData = new Uint8Array(await data);
20
+ } else if (data instanceof ArrayBuffer) {
21
+ toWriteData = new Uint8Array(data as ArrayBuffer);
22
+ } else {
23
+ toWriteData = data;
24
+ }
25
+ await fs.mkdir(path, {recursive: true});
26
+ const pathFile = join(path, fileName);
27
+ try {
28
+ await fs.writeFile(pathFile, toWriteData);
29
+ } catch (err) {
30
+ throw err;
31
+ }
32
+ console.log(`${pathFile} saved.`); // eslint-disable-line
33
+ return pathFile;
34
+ }
35
+
36
+ /**
37
+ * Write a file with data and name fileName to path - specific one for further packaging into slpk
38
+ *
39
+ * @param path - output path
40
+ * @param data - file content
41
+ * @param fileName - name of output file (default: index.json)
42
+ * @param compress - if need to compress file with gzip (default: true)
43
+ */
44
+ export async function writeFileForSlpk(
45
+ path: string,
46
+ data: string | Uint8Array | ArrayBuffer | Promise<ArrayBuffer>,
47
+ fileName: string = 'index.json',
48
+ compress: boolean = true
49
+ ): Promise<string> {
50
+ const pathFile = await writeFile(path, data, fileName);
51
+ if (compress) {
52
+ const pathGzFile = await compressFileWithGzip(pathFile);
53
+ // After compression, we don't need an uncompressed file
54
+ await removeFile(pathFile);
55
+ return pathGzFile;
56
+ }
57
+ return pathFile;
58
+ }
59
+
60
+ /**
61
+ * Remove dir with path
62
+ *
63
+ * @param path
64
+ */
65
+ export function removeDir(path: string) {
66
+ return fs.rmdir(path, {recursive: true});
67
+ }
68
+
69
+ /**
70
+ * Remove file with path
71
+ *
72
+ * @param path
73
+ */
74
+ export function removeFile(path: string) {
75
+ return fs.unlink(path);
76
+ }
77
+
78
+ /**
79
+ * Generates absolute file path
80
+ * @param filePath
81
+ */
82
+ export function getAbsoluteFilePath(filePath: string) {
83
+ return isAbsolute(filePath) ? filePath : join(process.cwd(), filePath); // eslint-disable-line no-undef
84
+ }
@@ -1,9 +1,11 @@
1
+ import {BoundingVolumes} from '@loaders.gl/i3s';
2
+ import {Tile3D} from '@loaders.gl/tiles';
3
+
1
4
  // https://cesium.com/docs/cesiumjs-ref-doc/Cesium3DTileset.html
2
5
  const DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR = 16;
3
6
  /**
4
7
  * Do conversion from geometric error to screen threshold
5
- * @param {Object} tile
6
- * @param {Object} coordinates
8
+ *
7
9
  * In 3DTiles we have HLOD logic and parent tile also has bigger lodMetric value then its children.
8
10
  * In I3s we have reverse logic related to maxError. Parent has lower maxError than its child.
9
11
  * In nodes where are no children tile.lodMetricValue is 0. This is because of logic of HLOD in 3DTiles
@@ -13,9 +15,24 @@ const DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR = 16;
13
15
  * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/lodSelection.cmn.md
14
16
  * To avoid infinity values when we do calculations of maxError we shold replace 0 with value which allows us
15
17
  * to make child maxError bigger than his parent maxError.
18
+ *
19
+ * @param tile - 3d-tiles tile Object
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
+ ]
16
33
  */
17
- export function convertGeometricErrorToScreenThreshold(tile, coordinates) {
18
- const lodSelection = [];
34
+ export function convertGeometricErrorToScreenThreshold(tile: Tile3D, coordinates: BoundingVolumes) {
35
+ const lodSelection: {metricType: string; maxError: number}[] = [];
19
36
  const boundingVolume = tile.boundingVolume;
20
37
  const lodMetricValue = tile.lodMetricValue || 0.1;
21
38
  const maxScreenThreshold = {
@@ -38,7 +55,12 @@ export function convertGeometricErrorToScreenThreshold(tile, coordinates) {
38
55
  return lodSelection;
39
56
  }
40
57
 
41
- export function convertScreenThresholdToGeometricError(node) {
58
+ /**
59
+ * Convert LOD metric from "Screen Threshold" to "Screen Space Error"
60
+ * @param node - i3s node data
61
+ * @returns lod metric in 3d-tiles format
62
+ */
63
+ export function convertScreenThresholdToGeometricError(node: Tile3D): number {
42
64
  const metricData = node.header.lodSelection.maxScreenThreshold || {};
43
65
  let maxError = metricData.maxError;
44
66
  if (!maxError) {
@@ -0,0 +1,17 @@
1
+ export class Queue<T> extends Array<T> {
2
+ enqueue(val: T) {
3
+ this.push(val);
4
+ }
5
+
6
+ dequeue(): T | undefined {
7
+ return this.shift();
8
+ }
9
+
10
+ peek(): T {
11
+ return this[0];
12
+ }
13
+
14
+ isEmpty() {
15
+ return this.length === 0;
16
+ }
17
+ }
@@ -0,0 +1,75 @@
1
+ import {Queue} from './queue';
2
+
3
+ export type WriteQueueItem = {
4
+ archiveKey?: string;
5
+ writePromise: Promise<string>;
6
+ };
7
+
8
+ export default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {
9
+ private intervalId?: NodeJS.Timeout;
10
+ public writePromise: Promise<void> | null = null;
11
+ public fileMap: {[key: string]: string} = {};
12
+ public listeningInterval: number;
13
+ public writeConcurrency: number;
14
+
15
+ constructor(listeningInterval: number = 2000, writeConcurrency: number = 400) {
16
+ super();
17
+ this.listeningInterval = listeningInterval;
18
+ this.writeConcurrency = writeConcurrency;
19
+ }
20
+
21
+ startListening() {
22
+ this.intervalId = setInterval(this.startWrite.bind(this), this.listeningInterval);
23
+ }
24
+
25
+ stopListening() {
26
+ if (this.intervalId) {
27
+ clearInterval(this.intervalId);
28
+ }
29
+ }
30
+
31
+ async startWrite(): Promise<void> {
32
+ if (this.writePromise) {
33
+ await this.writePromise;
34
+ this.writePromise = null;
35
+ return;
36
+ }
37
+ this.writePromise = this.doWrite();
38
+ await this.writePromise;
39
+ this.writePromise = null;
40
+ }
41
+
42
+ async finalize(): Promise<void> {
43
+ this.stopListening();
44
+ await this.startWrite();
45
+ }
46
+
47
+ private async doWrite(): Promise<void> {
48
+ while (this.length) {
49
+ const promises: Promise<string>[] = [];
50
+ const archiveKeys: (string | undefined)[] = [];
51
+ for (let i = 0; i < this.writeConcurrency; i++) {
52
+ const item = this.dequeue();
53
+ if (!item) {
54
+ break;
55
+ }
56
+ const {archiveKey, writePromise} = item as WriteQueueItem;
57
+ archiveKeys.push(archiveKey);
58
+ promises.push(writePromise);
59
+ }
60
+ const writeResults = await Promise.all(promises);
61
+ this.updateFileMap(archiveKeys, writeResults);
62
+ }
63
+ this.writePromise = null;
64
+ }
65
+
66
+ private updateFileMap(archiveKeys: (string | undefined)[], writeResults: string[]) {
67
+ for (let i = 0; i < archiveKeys.length; i++) {
68
+ const archiveKey = archiveKeys[i];
69
+ if (!archiveKey) {
70
+ continue;
71
+ }
72
+ this.fileMap[archiveKey] = writeResults[i];
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,6 @@
1
+ import {createWorker} from '@loaders.gl/worker-utils';
2
+ import B3dmConverter from '../3d-tiles-converter/helpers/b3dm-converter';
3
+
4
+ const b3dmConverter = new B3dmConverter();
5
+
6
+ createWorker(async (data, options = {}) => b3dmConverter.convert(data, options.attributes));
@@ -0,0 +1,6 @@
1
+ import {createWorker} from '@loaders.gl/worker-utils';
2
+ import {convertAttributes} from '../i3s-converter/helpers/geometry-converter';
3
+
4
+ createWorker(
5
+ async (data, options = {}) => await convertAttributes(data, options.useCartesianPositions)
6
+ );
@@ -1,44 +0,0 @@
1
- import {Vector3, Matrix4} from '@math.gl/core';
2
- import {GeoidHeightModel} from '../../lib/geoid-height-model';
3
- /**
4
- * Convert binary data from b3dm file to i3s resources
5
- *
6
- * @param tileContent - 3d tile content
7
- * @param options - converter options
8
- * @returns A promise that resolves to object with `geometry`, compressedGeometry`, `texture` and `sharedResources` appropriate
9
- * for use I3S tiles.
10
- */
11
- export default function convertB3dmToI3sGeometry(
12
- tileContent: {
13
- batchTableJson: {
14
- id: [];
15
- };
16
- cartographicOrigin: Vector3;
17
- cartesianModelMatrix: Matrix4;
18
- gltf: {
19
- scene: {
20
- nodes: [];
21
- };
22
- images: [];
23
- materials: [];
24
- };
25
- },
26
- nodeId: number,
27
- featuresHashArray: any,
28
- attributeStorageInfo: any,
29
- draco: boolean,
30
- generateBoundingVolumes: boolean,
31
- geoidHeightModel: GeoidHeightModel
32
- ): Promise<
33
- {
34
- geometry: ArrayBuffer;
35
- compressedGeometry: ArrayBuffer;
36
- texture: any;
37
- sharedResources: any;
38
- meshMaterial: any;
39
- vertexCount: number;
40
- attributes: any;
41
- featureCount: number;
42
- boundingVolumes: any;
43
- }[]
44
- >;
@@ -1,53 +0,0 @@
1
- /**
2
- * Compress file to gzip file
3
- *
4
- * @param pathFile - the path to the file
5
- * @return the path to the gzip file
6
- */
7
- export function compressFileWithGzip(pathFile: string): Promise<string>;
8
-
9
- /**
10
- * Compress files from map into slpk file
11
- *
12
- * @param fileMap - map with file paths (key: output path, value: input path)
13
- * @param outputFile - output slpk file
14
- * @param level - compression level
15
- */
16
- export function compressFilesWithZip(
17
- fileMap: object,
18
- outputFile: string,
19
- level: number
20
- ): Promise<void>;
21
-
22
- /**
23
- * Compress files using external tool 'zip'
24
- *
25
- * @param inputFolder - folder to archive
26
- * @param outputFile - output slpk file
27
- * @param level - compression level
28
- */
29
- export function compressWithChildProcess(
30
- inputFolder: string,
31
- outputFile: string,
32
- level: number,
33
- sevenZipExe: string
34
- ): Promise<void>;
35
-
36
- /**
37
- * Generate hash file from zip archive
38
- * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/slpk_hashtable.cmn.md
39
- *
40
- * @param inputZipFile
41
- * @param outputFile
42
- */
43
- export function generateHash128FromZip(inputZipFile, outputFile): Promise<void>;
44
-
45
- /**
46
- * Add file to zip archive
47
- *
48
- * @param inputFile
49
- * @param fileName
50
- * @param zipFile
51
- * @param sevenZipExe
52
- */
53
- export function addFileToZip(inputFile, fileName, zipFile, sevenZipExe);
@@ -1,43 +0,0 @@
1
- /**
2
- * Write a file with data and name fileName to path
3
- *
4
- * @param path - output path
5
- * @param data - file content
6
- * @param fileName - name of output file (default: index.json)
7
- */
8
- export function writeFile(path: string, data: string | Uint8Array | ArrayBuffer, fileName?: string);
9
-
10
- /**
11
- * Write a file with data and name fileName to path - specific one for further packaging into slpk
12
- *
13
- * @param path - output path
14
- * @param data - file content
15
- * @param fileName - name of output file (default: index.json)
16
- * @param compress - if need to compress file with gzip (default: true)
17
- */
18
- export function writeFileForSlpk(
19
- path: string,
20
- data: string | Uint8Array | ArrayBuffer,
21
- fileName?: string,
22
- compress?: boolean
23
- );
24
-
25
- /**
26
- * Remove dir with path
27
- *
28
- * @param path
29
- */
30
- export function removeDir(path: string): Promise<void>;
31
-
32
- /**
33
- * Remove file with path
34
- *
35
- * @param path
36
- */
37
- export function removeFile(path: string): Promise<void>;
38
-
39
- /**
40
- * Generates absolute file path
41
- * @param filePath
42
- */
43
- export function getAbsoluteFilePath(filePath: string): string;
@@ -1,32 +0,0 @@
1
- /**
2
- * Convert LOD metric from "Screen Space Error" to "Screen Threshold"
3
- *
4
- * @param tile - 3d-tiles tile Object
5
- * @param coordinates - node converted coordinates
6
- * @returns An array of LOD metrics in format compatible with i3s 3DNodeIndexDocument.lodSelection
7
- * @example
8
- * [
9
- {
10
- "metricType": "maxScreenThresholdSQ",
11
- "maxError": 870638.071285568
12
- },
13
- {
14
- "metricType": "maxScreenThreshold",
15
- "maxError": 1052.8679031638949
16
- }
17
- ]
18
- */
19
- export function convertGeometricErrorToScreenThreshold(
20
- tile: Object,
21
- coordinates: {
22
- mbs?: number[];
23
- }
24
- ): Array<{metricType: string; maxError: number}>;
25
-
26
- /**
27
- * Convert LOD metric from "Screen Threshold" to "Screen Space Error"
28
- * @param node - i3s node data
29
- * @returns lod metric in 3d-tiles format
30
- * @todo implement this function
31
- */
32
- export function convertScreenThresholdToGeometricError(node: Object): number;
@@ -1,44 +0,0 @@
1
- import {Vector3, Matrix4} from '@math.gl/core';
2
- import {GeoidHeightModel} from '../../lib/geoid-height-model';
3
- /**
4
- * Convert binary data from b3dm file to i3s resources
5
- *
6
- * @param tileContent - 3d tile content
7
- * @param options - converter options
8
- * @returns A promise that resolves to object with `geometry`, compressedGeometry`, `texture` and `sharedResources` appropriate
9
- * for use I3S tiles.
10
- */
11
- export default function convertB3dmToI3sGeometry(
12
- tileContent: {
13
- batchTableJson: {
14
- id: [];
15
- };
16
- cartographicOrigin: Vector3;
17
- cartesianModelMatrix: Matrix4;
18
- gltf: {
19
- scene: {
20
- nodes: [];
21
- };
22
- images: [];
23
- materials: [];
24
- };
25
- },
26
- nodeId: number,
27
- featuresHashArray: any,
28
- attributeStorageInfo: any,
29
- draco: boolean,
30
- generateBoundingVolumes: boolean,
31
- geoidHeightModel: GeoidHeightModel
32
- ): Promise<
33
- {
34
- geometry: ArrayBuffer;
35
- compressedGeometry: ArrayBuffer;
36
- texture: any;
37
- sharedResources: any;
38
- meshMaterial: any;
39
- vertexCount: number;
40
- attributes: any;
41
- featureCount: number;
42
- boundingVolumes: any;
43
- }[]
44
- >;