@loaders.gl/tile-converter 3.1.0-alpha.4 → 3.1.0-beta.5

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 (109) hide show
  1. package/bin/converter.js +1 -1
  2. package/dist/bundle.js +86025 -0
  3. package/dist/converter.min.js +292 -0
  4. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +189 -421
  5. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  6. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +214 -296
  7. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  8. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +4 -8
  9. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  10. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +40 -0
  11. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  12. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +7 -17
  13. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  14. package/dist/es5/bundle.js +1 -1
  15. package/dist/es5/bundle.js.map +1 -1
  16. package/dist/es5/deps-installer/deps-installer.js +17 -65
  17. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  18. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +16 -16
  19. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  20. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +9 -33
  21. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  22. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +93 -103
  23. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  24. package/dist/es5/i3s-converter/helpers/geometry-converter.js +348 -511
  25. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  26. package/dist/es5/i3s-converter/helpers/node-debug.js +30 -26
  27. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/node-pages.js +102 -203
  29. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  30. package/dist/es5/i3s-converter/i3s-converter.js +701 -1501
  31. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  32. package/dist/es5/i3s-converter/json-templates/layers.js +15 -25
  33. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
  34. package/dist/es5/i3s-converter/json-templates/metadata.js +2 -2
  35. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
  36. package/dist/es5/i3s-converter/json-templates/node.js +12 -21
  37. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
  38. package/dist/es5/i3s-converter/json-templates/scene-server.js +3 -5
  39. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
  40. package/dist/es5/i3s-converter/json-templates/shared-resources.js +15 -55
  41. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
  42. package/dist/es5/i3s-converter/json-templates/store.js +4 -6
  43. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
  44. package/dist/es5/i3s-server/app.js +6 -6
  45. package/dist/es5/i3s-server/app.js.map +1 -1
  46. package/dist/es5/i3s-server/controllers/index-controller.js +20 -60
  47. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  48. package/dist/es5/i3s-server/routes/index.js +14 -41
  49. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  50. package/dist/es5/index.js +4 -4
  51. package/dist/es5/lib/geoid-height-model.js +100 -114
  52. package/dist/es5/lib/geoid-height-model.js.map +1 -1
  53. package/dist/es5/lib/pgm-parser.js +68 -122
  54. package/dist/es5/lib/pgm-parser.js.map +1 -1
  55. package/dist/es5/lib/utils/compress-util.js +123 -345
  56. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  57. package/dist/es5/lib/utils/file-utils.js +20 -98
  58. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  59. package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
  60. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  61. package/dist/es5/lib/utils/statistic-utills.js +41 -152
  62. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  63. package/dist/es5/pgm-loader.js +3 -5
  64. package/dist/es5/pgm-loader.js.map +1 -1
  65. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +19 -13
  66. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  67. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +19 -8
  68. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  69. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +33 -0
  70. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  71. package/dist/esm/i3s-converter/helpers/geometry-converter.js +29 -31
  72. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  73. package/dist/esm/i3s-converter/helpers/node-debug.js +2 -2
  74. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
  75. package/dist/esm/i3s-converter/helpers/node-pages.js +2 -2
  76. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  77. package/dist/esm/i3s-converter/i3s-converter.js +50 -31
  78. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  79. package/dist/esm/i3s-converter/json-templates/metadata.js +1 -1
  80. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
  81. package/dist/esm/i3s-converter/json-templates/scene-server.js +1 -1
  82. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
  83. package/dist/esm/i3s-converter/json-templates/shared-resources.js +2 -2
  84. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
  85. package/dist/esm/i3s-converter/json-templates/store.js +2 -2
  86. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
  87. package/dist/esm/i3s-server/controllers/index-controller.js +2 -2
  88. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
  89. package/dist/esm/lib/utils/compress-util.js +13 -13
  90. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  91. package/dist/esm/lib/utils/file-utils.js +1 -1
  92. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  93. package/dist/esm/lib/utils/statistic-utills.js +5 -5
  94. package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
  95. package/dist/esm/pgm-loader.js +1 -1
  96. package/dist/esm/pgm-loader.js.map +1 -1
  97. package/package.json +22 -19
  98. package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -2
  99. package/src/3d-tiles-converter/helpers/b3dm-converter.js +35 -7
  100. package/src/3d-tiles-converter/helpers/texture-atlas.ts +55 -0
  101. package/src/i3s-converter/helpers/geometry-converter.js +21 -22
  102. package/src/i3s-converter/i3s-converter.ts +32 -7
  103. package/src/i3s-converter/json-templates/metadata.js +1 -1
  104. package/src/i3s-converter/json-templates/scene-server.js +1 -1
  105. package/src/i3s-converter/json-templates/store.js +2 -2
  106. package/src/i3s-server/controllers/index-controller.js +1 -1
  107. package/dist/dist.min.js +0 -94
  108. package/dist/dist.min.js.map +0 -1
  109. package/dist/scripts/converter.js +0 -274
@@ -9,17 +9,17 @@ import { MD5Hash } from '@loaders.gl/crypto';
9
9
  import crypt from 'crypt';
10
10
  import { getAbsoluteFilePath } from './file-utils';
11
11
  export function compressFileWithGzip(pathFile) {
12
- const compressedPathFile = `${pathFile}.gz`;
12
+ const compressedPathFile = "".concat(pathFile, ".gz");
13
13
  const gzip = createGzip();
14
14
  const input = createReadStream(pathFile);
15
15
  const output = createWriteStream(compressedPathFile);
16
16
  return new Promise((resolve, reject) => {
17
17
  input.on('end', () => {
18
- console.log(`${compressedPathFile} compressed and saved.`);
18
+ console.log("".concat(compressedPathFile, " compressed and saved."));
19
19
  resolve(compressedPathFile);
20
20
  });
21
21
  input.on('error', error => {
22
- console.log(`${compressedPathFile}: compression error!`);
22
+ console.log("".concat(compressedPathFile, ": compression error!"));
23
23
  reject(error);
24
24
  });
25
25
  input.pipe(gzip).pipe(output);
@@ -38,8 +38,8 @@ export async function compressFilesWithZip(fileMap, outputFile, level = 0) {
38
38
  });
39
39
  return new Promise(async (resolve, reject) => {
40
40
  output.on('close', function () {
41
- console.log(`${outputFile} saved.`);
42
- console.log(`${archive.pointer()} total bytes`);
41
+ console.log("".concat(outputFile, " saved."));
42
+ console.log("".concat(archive.pointer(), " total bytes"));
43
43
  resolve(null);
44
44
  });
45
45
  output.on('end', function () {
@@ -73,7 +73,7 @@ export async function compressWithChildProcess() {
73
73
 
74
74
  async function compressWithChildProcessUnix(inputFolder, outputFile, level = 0, inputFiles = '.') {
75
75
  const fullOutputFile = getAbsoluteFilePath(outputFile);
76
- const args = [`-${level}`, '-r', fullOutputFile, inputFiles];
76
+ const args = ["-".concat(level), '-r', fullOutputFile, inputFiles];
77
77
  const childProcess = new ChildProcessProxy();
78
78
  await childProcess.start({
79
79
  command: 'zip',
@@ -87,17 +87,17 @@ async function compressWithChildProcessUnix(inputFolder, outputFile, level = 0,
87
87
 
88
88
  async function compressWithChildProcessWindows(inputFolder, outputFile, level = 0, inputFiles = join('.', '*'), sevenZipExe) {
89
89
  if (inputFiles[0] === '@') {
90
- inputFiles = `*${inputFiles.substr(1)}`;
90
+ inputFiles = "*".concat(inputFiles.substr(1));
91
91
  }
92
92
 
93
93
  const fullOutputFile = getAbsoluteFilePath(outputFile);
94
- const args = ['a', '-tzip', `-mx=${level}`, fullOutputFile, inputFiles];
94
+ const args = ['a', '-tzip', "-mx=".concat(level), fullOutputFile, inputFiles];
95
95
  const childProcess = new ChildProcessProxy();
96
96
  await childProcess.start({
97
97
  command: sevenZipExe,
98
98
  arguments: args,
99
99
  spawn: {
100
- cwd: `${inputFolder}`
100
+ cwd: "".concat(inputFolder)
101
101
  },
102
102
  wait: 0
103
103
  });
@@ -131,7 +131,7 @@ export async function generateHash128FromZip(inputZipFile, outputFile) {
131
131
  const output = createWriteStream(outputFile);
132
132
  return new Promise((resolve, reject) => {
133
133
  output.on('close', function () {
134
- console.log(`${outputFile} generated and saved`);
134
+ console.log("".concat(outputFile, " generated and saved"));
135
135
  resolve(null);
136
136
  });
137
137
  output.on('error', function (err) {
@@ -160,15 +160,15 @@ function _longToByteArray(long) {
160
160
 
161
161
  export async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {
162
162
  await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);
163
- console.log(`${fileName} added to ${zipFile}.`);
163
+ console.log("".concat(fileName, " added to ").concat(zipFile, "."));
164
164
  }
165
165
 
166
166
  function appendFileToArchive(archive, subFileName, subFileData) {
167
167
  return new Promise(resolve => {
168
168
  const fileStream = createReadStream(subFileData);
169
- console.log(`Compression start: ${subFileName}`);
169
+ console.log("Compression start: ".concat(subFileName));
170
170
  fileStream.on('close', () => {
171
- console.log(`Compression finish: ${subFileName}`);
171
+ console.log("Compression finish: ".concat(subFileName));
172
172
  resolve(null);
173
173
  });
174
174
  archive.append(fileStream, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/compress-util.js"],"names":["createGzip","join","promises","fs","createReadStream","createWriteStream","archiver","removeFile","ChildProcessProxy","JSZip","MD5Hash","crypt","getAbsoluteFilePath","compressFileWithGzip","pathFile","compressedPathFile","gzip","input","output","Promise","resolve","reject","on","console","log","error","pipe","compressFilesWithZip","fileMap","outputFile","level","e","archive","zlib","pointer","err","subFileName","subFileData","appendFileToArchive","finalize","compressWithChildProcess","process","platform","compressWithChildProcessWindows","arguments","compressWithChildProcessUnix","inputFolder","inputFiles","fullOutputFile","args","childProcess","start","command","spawn","cwd","wait","sevenZipExe","substr","generateHash128FromZip","inputZipFile","readFile","zip","loadAsync","hashTable","zipFiles","files","relativePath","zipEntry","_data","content","compressedContent","dir","hash","Buffer","from","toLowerCase","push","key","atob","value","byteOffset","sort","prev","next","item","_longToByteArray","write","hexToBytes","concat","close","long","buffer","ArrayBuffer","longNum","Float64Array","Array","Uint8Array","reverse","addFileToZip","fileName","zipFile","fileStream","append","name"],"mappings":"AAAA,SAAQA,UAAR,QAAyB,MAAzB;AACA,SAAQC,IAAR,QAAmB,MAAnB;AACA,SAAQC,QAAQ,IAAIC,EAApB,EAAwBC,gBAAxB,EAA0CC,iBAA1C,QAAkE,IAAlE;AACA,OAAOC,QAAP,MAAqB,UAArB;AACA,SAAQC,UAAR,QAAyB,cAAzB;AACA,SAAQC,iBAAR,QAAgC,0BAAhC;AACA,OAAOC,KAAP,MAAkB,OAAlB;AACA,SAAQC,OAAR,QAAsB,oBAAtB;AACA,OAAOC,KAAP,MAAkB,OAAlB;AACA,SAAQC,mBAAR,QAAkC,cAAlC;AAEA,OAAO,SAASC,oBAAT,CAA8BC,QAA9B,EAAwC;AAC7C,QAAMC,kBAAkB,GAAI,GAAED,QAAS,KAAvC;AACA,QAAME,IAAI,GAAGhB,UAAU,EAAvB;AACA,QAAMiB,KAAK,GAAGb,gBAAgB,CAACU,QAAD,CAA9B;AACA,QAAMI,MAAM,GAAGb,iBAAiB,CAACU,kBAAD,CAAhC;AAEA,SAAO,IAAII,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtCJ,IAAAA,KAAK,CAACK,EAAN,CAAS,KAAT,EAAgB,MAAM;AACpBC,MAAAA,OAAO,CAACC,GAAR,CAAa,GAAET,kBAAmB,wBAAlC;AACAK,MAAAA,OAAO,CAACL,kBAAD,CAAP;AACD,KAHD;AAIAE,IAAAA,KAAK,CAACK,EAAN,CAAS,OAAT,EAAmBG,KAAD,IAAW;AAC3BF,MAAAA,OAAO,CAACC,GAAR,CAAa,GAAET,kBAAmB,sBAAlC;AACAM,MAAAA,MAAM,CAACI,KAAD,CAAN;AACD,KAHD;AAIAR,IAAAA,KAAK,CAACS,IAAN,CAAWV,IAAX,EAAiBU,IAAjB,CAAsBR,MAAtB;AACD,GAVM,CAAP;AAWD;AAED,OAAO,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B,EAAgC;AAC9B,QAAMC,MAAM,GAAG,IAAIC,WAAJ,CAAgB,CAAhB,CAAf;AACA,QAAMC,OAAO,GAAG,IAAIC,YAAJ,CAAiBH,MAAjB,CAAhB;AACAE,EAAAA,OAAO,CAAC,CAAD,CAAP,GAAaH,IAAb;AACA,SAAOK,KAAK,CAACrB,IAAN,CAAW,IAAIsB,UAAJ,CAAeL,MAAf,CAAX,EAAmCM,OAAnC,EAAP;AACD;;AAED,OAAO,eAAeC,YAAf,CAA4BpD,WAA5B,EAAyCqD,QAAzC,EAAmDC,OAAnD,EAA4D5C,WAA5D,EAAyE;AAC9E,QAAMhB,wBAAwB,CAACM,WAAD,EAAcsD,OAAd,EAAuB,CAAvB,EAA0BD,QAA1B,EAAoC3C,WAApC,CAA9B;AACAjC,EAAAA,OAAO,CAACC,GAAR,CAAa,GAAE2E,QAAS,aAAYC,OAAQ,GAA5C;AACD;;AAED,SAAS9D,mBAAT,CAA6BN,OAA7B,EAAsCI,WAAtC,EAAmDC,WAAnD,EAAgE;AAC9D,SAAO,IAAIlB,OAAJ,CAAaC,OAAD,IAAa;AAC9B,UAAMiF,UAAU,GAAGjG,gBAAgB,CAACiC,WAAD,CAAnC;AACAd,IAAAA,OAAO,CAACC,GAAR,CAAa,sBAAqBY,WAAY,EAA9C;AACAiE,IAAAA,UAAU,CAAC/E,EAAX,CAAc,OAAd,EAAuB,MAAM;AAC3BC,MAAAA,OAAO,CAACC,GAAR,CAAa,uBAAsBY,WAAY,EAA/C;AACAhB,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD,KAHD;AAIAY,IAAAA,OAAO,CAACsE,MAAR,CAAeD,UAAf,EAA2B;AAACE,MAAAA,IAAI,EAAEnE;AAAP,KAA3B;AACD,GARM,CAAP;AASD","sourcesContent":["import {createGzip} from 'zlib';\nimport {join} from 'path';\nimport {promises as fs, createReadStream, createWriteStream} from 'fs';\nimport archiver from 'archiver';\nimport {removeFile} from './file-utils';\nimport {ChildProcessProxy} from '@loaders.gl/worker-utils';\nimport JSZip from 'jszip';\nimport {MD5Hash} from '@loaders.gl/crypto';\nimport crypt from 'crypt';\nimport {getAbsoluteFilePath} from './file-utils';\n\nexport function compressFileWithGzip(pathFile) {\n const compressedPathFile = `${pathFile}.gz`;\n const gzip = createGzip();\n const input = createReadStream(pathFile);\n const output = createWriteStream(compressedPathFile);\n\n return new Promise((resolve, reject) => {\n input.on('end', () => {\n console.log(`${compressedPathFile} compressed and saved.`); // eslint-disable-line no-undef,no-console\n resolve(compressedPathFile);\n });\n input.on('error', (error) => {\n console.log(`${compressedPathFile}: compression error!`); // eslint-disable-line no-undef,no-console\n reject(error);\n });\n input.pipe(gzip).pipe(output);\n });\n}\n\nexport async function compressFilesWithZip(fileMap, outputFile, level = 0) {\n // Before creating a new file, we need to delete the old file\n try {\n await removeFile(outputFile);\n } catch (e) {\n // Do nothing if old file doesn't exist\n }\n\n const output = createWriteStream(outputFile);\n const archive = archiver('zip', {\n zlib: {level} // Sets the compression level.\n });\n\n return new Promise(async (resolve, reject) => {\n // listen for all archive data to be writte\n // 'close' event is fired only when a file descriptor is involved\n output.on('close', function () {\n console.log(`${outputFile} saved.`); // eslint-disable-line no-undef,no-console\n console.log(`${archive.pointer()} total bytes`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // This event is fired when the data source is drained no matter what was the data source.\n // It is not part of this library but rather from the NodeJS Stream API.\n // @see: https://nodejs.org/api/stream.html#stream_event_end\n output.on('end', function () {\n console.log('Data has been drained'); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // good practice to catch warnings (ie stat failures and other non-blocking errors)\n archive.on('warning', function (err) {\n console.log(err); // eslint-disable-line no-undef,no-console\n reject(err);\n });\n\n // good practice to catch this error explicitly\n archive.on('error', function (err) {\n reject(err);\n });\n\n // pipe archive data to the file\n archive.pipe(output);\n\n for (const subFileName in fileMap) {\n const subFileData = fileMap[subFileName];\n await appendFileToArchive(archive, subFileName, subFileData);\n }\n\n // finalize the archive (ie we are done appending files but streams have to finish yet)\n archive.finalize();\n });\n}\n\nexport async function compressWithChildProcess() {\n // eslint-disable-next-line no-undef\n if (process.platform === 'win32') {\n await compressWithChildProcessWindows(...arguments);\n } else {\n await compressWithChildProcessUnix(...arguments);\n }\n}\n\nasync function compressWithChildProcessUnix(inputFolder, outputFile, level = 0, inputFiles = '.') {\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = [`-${level}`, '-r', fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: 'zip',\n arguments: args,\n spawn: {\n cwd: inputFolder\n },\n wait: 0\n });\n}\n\nasync function compressWithChildProcessWindows(\n inputFolder,\n outputFile,\n level = 0,\n inputFiles = join('.', '*'),\n sevenZipExe\n) {\n // Workaround for @listfile issue. In 7z.exe @-leading files are handled as listfiles\n // https://sevenzip.osdn.jp/chm/cmdline/syntax.htm\n if (inputFiles[0] === '@') {\n inputFiles = `*${inputFiles.substr(1)}`;\n }\n\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = ['a', '-tzip', `-mx=${level}`, fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: sevenZipExe,\n arguments: args,\n spawn: {\n cwd: `${inputFolder}`\n },\n wait: 0\n });\n}\n\nexport async function generateHash128FromZip(inputZipFile, outputFile) {\n const input = await fs.readFile(inputZipFile);\n const zip = await JSZip.loadAsync(input);\n const hashTable = [];\n const zipFiles = zip.files;\n for (const relativePath in zipFiles) {\n const zipEntry = zipFiles[relativePath];\n // Had to use a workaround because the correct string is getting the wrong data\n // const content = await zipEntry.async('nodebuffer');\n // _data isn't described in the interface, so lint thought it was wrong\n const _data = '_data';\n const content = zipEntry[_data].compressedContent;\n if (zipEntry.dir) continue; // eslint-disable-line no-continue\n // eslint-disable-next-line no-undef\n const hash = await new MD5Hash().hash(Buffer.from(relativePath.toLowerCase()));\n // eslint-disable-next-line no-undef\n hashTable.push({key: atob(hash), value: content.byteOffset});\n }\n\n hashTable.sort((prev, next) => {\n if (prev.key === next.key) {\n return prev.value < next.value ? -1 : 1;\n }\n return prev.key < next.key ? -1 : 1;\n });\n\n const output = createWriteStream(outputFile);\n return new Promise((resolve, reject) => {\n output.on('close', function () {\n console.log(`${outputFile} generated and saved`); // eslint-disable-line\n resolve(null);\n });\n output.on('error', function (err) {\n console.log(err); // eslint-disable-line\n reject(err);\n });\n for (const key in hashTable) {\n const item = hashTable[key];\n const value = _longToByteArray(item.value);\n // TODO: perhaps you need to wait for the 'drain' event if the write returns 'false'\n // eslint-disable-next-line no-undef\n output.write(Buffer.from(crypt.hexToBytes(item.key).concat(value)));\n }\n output.close();\n });\n}\n\nfunction _longToByteArray(long) {\n const buffer = new ArrayBuffer(8); // JS numbers are 8 bytes long, or 64 bits\n const longNum = new Float64Array(buffer); // so equivalent to Float64\n longNum[0] = long;\n return Array.from(new Uint8Array(buffer)).reverse(); // reverse to get little endian\n}\n\nexport async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {\n await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);\n console.log(`${fileName} added to ${zipFile}.`); // eslint-disable-line\n}\n\nfunction appendFileToArchive(archive, subFileName, subFileData) {\n return new Promise((resolve) => {\n const fileStream = createReadStream(subFileData);\n console.log(`Compression start: ${subFileName}`); // eslint-disable-line no-undef,no-console\n fileStream.on('close', () => {\n console.log(`Compression finish: ${subFileName}`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n archive.append(fileStream, {name: subFileName});\n });\n}\n"],"file":"compress-util.js"}
1
+ {"version":3,"sources":["../../../../src/lib/utils/compress-util.js"],"names":["createGzip","join","promises","fs","createReadStream","createWriteStream","archiver","removeFile","ChildProcessProxy","JSZip","MD5Hash","crypt","getAbsoluteFilePath","compressFileWithGzip","pathFile","compressedPathFile","gzip","input","output","Promise","resolve","reject","on","console","log","error","pipe","compressFilesWithZip","fileMap","outputFile","level","e","archive","zlib","pointer","err","subFileName","subFileData","appendFileToArchive","finalize","compressWithChildProcess","process","platform","compressWithChildProcessWindows","arguments","compressWithChildProcessUnix","inputFolder","inputFiles","fullOutputFile","args","childProcess","start","command","spawn","cwd","wait","sevenZipExe","substr","generateHash128FromZip","inputZipFile","readFile","zip","loadAsync","hashTable","zipFiles","files","relativePath","zipEntry","_data","content","compressedContent","dir","hash","Buffer","from","toLowerCase","push","key","atob","value","byteOffset","sort","prev","next","item","_longToByteArray","write","hexToBytes","concat","close","long","buffer","ArrayBuffer","longNum","Float64Array","Array","Uint8Array","reverse","addFileToZip","fileName","zipFile","fileStream","append","name"],"mappings":"AAAA,SAAQA,UAAR,QAAyB,MAAzB;AACA,SAAQC,IAAR,QAAmB,MAAnB;AACA,SAAQC,QAAQ,IAAIC,EAApB,EAAwBC,gBAAxB,EAA0CC,iBAA1C,QAAkE,IAAlE;AACA,OAAOC,QAAP,MAAqB,UAArB;AACA,SAAQC,UAAR,QAAyB,cAAzB;AACA,SAAQC,iBAAR,QAAgC,0BAAhC;AACA,OAAOC,KAAP,MAAkB,OAAlB;AACA,SAAQC,OAAR,QAAsB,oBAAtB;AACA,OAAOC,KAAP,MAAkB,OAAlB;AACA,SAAQC,mBAAR,QAAkC,cAAlC;AAEA,OAAO,SAASC,oBAAT,CAA8BC,QAA9B,EAAwC;AAC7C,QAAMC,kBAAkB,aAAMD,QAAN,QAAxB;AACA,QAAME,IAAI,GAAGhB,UAAU,EAAvB;AACA,QAAMiB,KAAK,GAAGb,gBAAgB,CAACU,QAAD,CAA9B;AACA,QAAMI,MAAM,GAAGb,iBAAiB,CAACU,kBAAD,CAAhC;AAEA,SAAO,IAAII,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtCJ,IAAAA,KAAK,CAACK,EAAN,CAAS,KAAT,EAAgB,MAAM;AACpBC,MAAAA,OAAO,CAACC,GAAR,WAAeT,kBAAf;AACAK,MAAAA,OAAO,CAACL,kBAAD,CAAP;AACD,KAHD;AAIAE,IAAAA,KAAK,CAACK,EAAN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createGzip} from 'zlib';\nimport {join} from 'path';\nimport {promises as fs, createReadStream, createWriteStream} from 'fs';\nimport archiver from 'archiver';\nimport {removeFile} from './file-utils';\nimport {ChildProcessProxy} from '@loaders.gl/worker-utils';\nimport JSZip from 'jszip';\nimport {MD5Hash} from '@loaders.gl/crypto';\nimport crypt from 'crypt';\nimport {getAbsoluteFilePath} from './file-utils';\n\nexport function compressFileWithGzip(pathFile) {\n const compressedPathFile = `${pathFile}.gz`;\n const gzip = createGzip();\n const input = createReadStream(pathFile);\n const output = createWriteStream(compressedPathFile);\n\n return new Promise((resolve, reject) => {\n input.on('end', () => {\n console.log(`${compressedPathFile} compressed and saved.`); // eslint-disable-line no-undef,no-console\n resolve(compressedPathFile);\n });\n input.on('error', (error) => {\n console.log(`${compressedPathFile}: compression error!`); // eslint-disable-line no-undef,no-console\n reject(error);\n });\n input.pipe(gzip).pipe(output);\n });\n}\n\nexport async function compressFilesWithZip(fileMap, outputFile, level = 0) {\n // Before creating a new file, we need to delete the old file\n try {\n await removeFile(outputFile);\n } catch (e) {\n // Do nothing if old file doesn't exist\n }\n\n const output = createWriteStream(outputFile);\n const archive = archiver('zip', {\n zlib: {level} // Sets the compression level.\n });\n\n return new Promise(async (resolve, reject) => {\n // listen for all archive data to be writte\n // 'close' event is fired only when a file descriptor is involved\n output.on('close', function () {\n console.log(`${outputFile} saved.`); // eslint-disable-line no-undef,no-console\n console.log(`${archive.pointer()} total bytes`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // This event is fired when the data source is drained no matter what was the data source.\n // It is not part of this library but rather from the NodeJS Stream API.\n // @see: https://nodejs.org/api/stream.html#stream_event_end\n output.on('end', function () {\n console.log('Data has been drained'); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // good practice to catch warnings (ie stat failures and other non-blocking errors)\n archive.on('warning', function (err) {\n console.log(err); // eslint-disable-line no-undef,no-console\n reject(err);\n });\n\n // good practice to catch this error explicitly\n archive.on('error', function (err) {\n reject(err);\n });\n\n // pipe archive data to the file\n archive.pipe(output);\n\n for (const subFileName in fileMap) {\n const subFileData = fileMap[subFileName];\n await appendFileToArchive(archive, subFileName, subFileData);\n }\n\n // finalize the archive (ie we are done appending files but streams have to finish yet)\n archive.finalize();\n });\n}\n\nexport async function compressWithChildProcess() {\n // eslint-disable-next-line no-undef\n if (process.platform === 'win32') {\n await compressWithChildProcessWindows(...arguments);\n } else {\n await compressWithChildProcessUnix(...arguments);\n }\n}\n\nasync function compressWithChildProcessUnix(inputFolder, outputFile, level = 0, inputFiles = '.') {\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = [`-${level}`, '-r', fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: 'zip',\n arguments: args,\n spawn: {\n cwd: inputFolder\n },\n wait: 0\n });\n}\n\nasync function compressWithChildProcessWindows(\n inputFolder,\n outputFile,\n level = 0,\n inputFiles = join('.', '*'),\n sevenZipExe\n) {\n // Workaround for @listfile issue. In 7z.exe @-leading files are handled as listfiles\n // https://sevenzip.osdn.jp/chm/cmdline/syntax.htm\n if (inputFiles[0] === '@') {\n inputFiles = `*${inputFiles.substr(1)}`;\n }\n\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = ['a', '-tzip', `-mx=${level}`, fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: sevenZipExe,\n arguments: args,\n spawn: {\n cwd: `${inputFolder}`\n },\n wait: 0\n });\n}\n\nexport async function generateHash128FromZip(inputZipFile, outputFile) {\n const input = await fs.readFile(inputZipFile);\n const zip = await JSZip.loadAsync(input);\n const hashTable = [];\n const zipFiles = zip.files;\n for (const relativePath in zipFiles) {\n const zipEntry = zipFiles[relativePath];\n // Had to use a workaround because the correct string is getting the wrong data\n // const content = await zipEntry.async('nodebuffer');\n // _data isn't described in the interface, so lint thought it was wrong\n const _data = '_data';\n const content = zipEntry[_data].compressedContent;\n if (zipEntry.dir) continue; // eslint-disable-line no-continue\n // eslint-disable-next-line no-undef\n const hash = await new MD5Hash().hash(Buffer.from(relativePath.toLowerCase()));\n // eslint-disable-next-line no-undef\n hashTable.push({key: atob(hash), value: content.byteOffset});\n }\n\n hashTable.sort((prev, next) => {\n if (prev.key === next.key) {\n return prev.value < next.value ? -1 : 1;\n }\n return prev.key < next.key ? -1 : 1;\n });\n\n const output = createWriteStream(outputFile);\n return new Promise((resolve, reject) => {\n output.on('close', function () {\n console.log(`${outputFile} generated and saved`); // eslint-disable-line\n resolve(null);\n });\n output.on('error', function (err) {\n console.log(err); // eslint-disable-line\n reject(err);\n });\n for (const key in hashTable) {\n const item = hashTable[key];\n const value = _longToByteArray(item.value);\n // TODO: perhaps you need to wait for the 'drain' event if the write returns 'false'\n // eslint-disable-next-line no-undef\n output.write(Buffer.from(crypt.hexToBytes(item.key).concat(value)));\n }\n output.close();\n });\n}\n\nfunction _longToByteArray(long) {\n const buffer = new ArrayBuffer(8); // JS numbers are 8 bytes long, or 64 bits\n const longNum = new Float64Array(buffer); // so equivalent to Float64\n longNum[0] = long;\n return Array.from(new Uint8Array(buffer)).reverse(); // reverse to get little endian\n}\n\nexport async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {\n await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);\n console.log(`${fileName} added to ${zipFile}.`); // eslint-disable-line\n}\n\nfunction appendFileToArchive(archive, subFileName, subFileData) {\n return new Promise((resolve) => {\n const fileStream = createReadStream(subFileData);\n console.log(`Compression start: ${subFileName}`); // eslint-disable-line no-undef,no-console\n fileStream.on('close', () => {\n console.log(`Compression finish: ${subFileName}`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n archive.append(fileStream, {name: subFileName});\n });\n}\n"],"file":"compress-util.js"}
@@ -13,7 +13,7 @@ export async function writeFile(path, data, fileName = 'index.json') {
13
13
  throw err;
14
14
  }
15
15
 
16
- console.log(`${pathFile} saved.`);
16
+ console.log("".concat(pathFile, " saved."));
17
17
  return pathFile;
18
18
  }
19
19
  export async function writeFileForSlpk(path, data, fileName = 'index.json', compress = true) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/file-utils.js"],"names":["promises","fs","isAbsolute","join","compressFileWithGzip","writeFile","path","data","fileName","mkdir","recursive","pathFile","err","console","log","writeFileForSlpk","compress","pathGzFile","removeFile","removeDir","rmdir","unlink","getAbsoluteFilePath","filePath","process","cwd"],"mappings":"AAAA,SAAQA,QAAQ,IAAIC,EAApB,QAA6B,IAA7B;AACA,SAAQC,UAAR,EAAoBC,IAApB,QAA+B,MAA/B;AACA,SAAQC,oBAAR,QAAmC,iBAAnC;AAEA,OAAO,eAAeC,SAAf,CAAyBC,IAAzB,EAA+BC,IAA/B,EAAqCC,QAAQ,GAAG,YAAhD,EAA8D;AACnE,QAAMP,EAAE,CAACQ,KAAH,CAASH,IAAT,EAAe;AAACI,IAAAA,SAAS,EAAE;AAAZ,GAAf,CAAN;AACA,QAAMC,QAAQ,GAAGR,IAAI,CAACG,IAAD,EAAOE,QAAP,CAArB;;AACA,MAAI;AACF,UAAMP,EAAE,CAACI,SAAH,CAAaM,QAAb,EAAuBJ,IAAvB,CAAN;AACD,GAFD,CAEE,OAAOK,GAAP,EAAY;AACZ,UAAMA,GAAN;AACD;;AACDC,EAAAA,OAAO,CAACC,GAAR,CAAa,GAAEH,QAAS,SAAxB;AACA,SAAOA,QAAP;AACD;AAED,OAAO,eAAeI,gBAAf,CAAgCT,IAAhC,EAAsCC,IAAtC,EAA4CC,QAAQ,GAAG,YAAvD,EAAqEQ,QAAQ,GAAG,IAAhF,EAAsF;AAC3F,QAAML,QAAQ,GAAG,MAAMN,SAAS,CAACC,IAAD,EAAOC,IAAP,EAAaC,QAAb,CAAhC;;AACA,MAAIQ,QAAJ,EAAc;AACZ,UAAMC,UAAU,GAAG,MAAMb,oBAAoB,CAACO,QAAD,CAA7C;AAEA,UAAMO,UAAU,CAACP,QAAD,CAAhB;AACA,WAAOM,UAAP;AACD;;AACD,SAAON,QAAP;AACD;AAED,OAAO,SAASQ,SAAT,CAAmBb,IAAnB,EAAyB;AAC9B,SAAOL,EAAE,CAACmB,KAAH,CAASd,IAAT,EAAe;AAACI,IAAAA,SAAS,EAAE;AAAZ,GAAf,CAAP;AACD;AAED,OAAO,SAASQ,UAAT,CAAoBZ,IAApB,EAA0B;AAC/B,SAAOL,EAAE,CAACoB,MAAH,CAAUf,IAAV,CAAP;AACD;AAED,OAAO,SAASgB,mBAAT,CAA6BC,QAA7B,EAAuC;AAC5C,SAAOrB,UAAU,CAACqB,QAAD,CAAV,GAAuBA,QAAvB,GAAkCpB,IAAI,CAACqB,OAAO,CAACC,GAAR,EAAD,EAAgBF,QAAhB,CAA7C;AACD","sourcesContent":["import {promises as fs} from 'fs';\nimport {isAbsolute, join} from 'path';\nimport {compressFileWithGzip} from './compress-util';\n\nexport async function writeFile(path, data, fileName = 'index.json') {\n await fs.mkdir(path, {recursive: true});\n const pathFile = join(path, fileName);\n try {\n await fs.writeFile(pathFile, data);\n } catch (err) {\n throw err;\n }\n console.log(`${pathFile} saved.`); // eslint-disable-line\n return pathFile;\n}\n\nexport async function writeFileForSlpk(path, data, fileName = 'index.json', compress = true) {\n const pathFile = await writeFile(path, data, fileName);\n if (compress) {\n const pathGzFile = await compressFileWithGzip(pathFile);\n // After compression, we don't need an uncompressed file\n await removeFile(pathFile);\n return pathGzFile;\n }\n return pathFile;\n}\n\nexport function removeDir(path) {\n return fs.rmdir(path, {recursive: true});\n}\n\nexport function removeFile(path) {\n return fs.unlink(path);\n}\n\nexport function getAbsoluteFilePath(filePath) {\n return isAbsolute(filePath) ? filePath : join(process.cwd(), filePath); // eslint-disable-line no-undef\n}\n"],"file":"file-utils.js"}
1
+ {"version":3,"sources":["../../../../src/lib/utils/file-utils.js"],"names":["promises","fs","isAbsolute","join","compressFileWithGzip","writeFile","path","data","fileName","mkdir","recursive","pathFile","err","console","log","writeFileForSlpk","compress","pathGzFile","removeFile","removeDir","rmdir","unlink","getAb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Uf,IAAV,CAAP;AACD;AAED,OAAO,SAASgB,mBAAT,CAA6BC,QAA7B,EAAuC;AAC5C,SAAOrB,UAAU,CAACqB,QAAD,CAAV,GAAuBA,QAAvB,GAAkCpB,IAAI,CAACqB,OAAO,CAACC,GAAR,EAAD,EAAgBF,QAAhB,CAA7C;AACD","sourcesContent":["import {promises as fs} from 'fs';\nimport {isAbsolute, join} from 'path';\nimport {compressFileWithGzip} from './compress-util';\n\nexport async function writeFile(path, data, fileName = 'index.json') {\n await fs.mkdir(path, {recursive: true});\n const pathFile = join(path, fileName);\n try {\n await fs.writeFile(pathFile, data);\n } catch (err) {\n throw err;\n }\n console.log(`${pathFile} saved.`); // eslint-disable-line\n return pathFile;\n}\n\nexport async function writeFileForSlpk(path, data, fileName = 'index.json', compress = true) {\n const pathFile = await writeFile(path, data, fileName);\n if (compress) {\n const pathGzFile = await compressFileWithGzip(pathFile);\n // After compression, we don't need an uncompressed file\n await removeFile(pathFile);\n return pathGzFile;\n }\n return pathFile;\n}\n\nexport function removeDir(path) {\n return fs.rmdir(path, {recursive: true});\n}\n\nexport function removeFile(path) {\n return fs.unlink(path);\n}\n\nexport function getAbsoluteFilePath(filePath) {\n return isAbsolute(filePath) ? filePath : join(process.cwd(), filePath); // eslint-disable-line no-undef\n}\n"],"file":"file-utils.js"}
@@ -13,19 +13,19 @@ export function timeConverter(time) {
13
13
  let result = '';
14
14
 
15
15
  if (hours) {
16
- result += `${hours}h `;
16
+ result += "".concat(hours, "h ");
17
17
  }
18
18
 
19
19
  if (minutes) {
20
- result += `${minutes}m `;
20
+ result += "".concat(minutes, "m ");
21
21
  }
22
22
 
23
23
  if (seconds) {
24
- result += `${seconds}s`;
24
+ result += "".concat(seconds, "s");
25
25
  }
26
26
 
27
27
  if (!result) {
28
- result += `${milliseconds}ms`;
28
+ result += "".concat(milliseconds, "ms");
29
29
  }
30
30
 
31
31
  return result;
@@ -40,7 +40,7 @@ export async function calculateFilesSize(params) {
40
40
 
41
41
  try {
42
42
  if (slpk) {
43
- const slpkPath = join(fullOutputPath, `${tilesetName}.slpk`);
43
+ const slpkPath = join(fullOutputPath, "".concat(tilesetName, ".slpk"));
44
44
  const stat = await fs.stat(slpkPath);
45
45
  return stat.size;
46
46
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/statistic-utills.js"],"names":["join","promises","fs","getAbsoluteFilePath","timeConverter","time","nanoSecondsInMillisecond","timeInSeconds","hours","Math","floor","minutes","seconds","milliseconds","result","calculateFilesSize","params","slpk","outputPath","tilesetName","fullOutputPath","slpkPath","stat","size","directoryPath","totalSize","getTotalFilesSize","error","console","log","dirPath","totalFileSize","files","readdir","file","fileStat","isDirectory"],"mappings":"AAAA,SAAQA,IAAR,QAAmB,MAAnB;AACA,SAAQC,QAAQ,IAAIC,EAApB,QAA6B,IAA7B;AACA,SAAQC,mBAAR,QAAkC,cAAlC;AAEA,OAAO,SAASC,aAAT,CAAuBC,IAAvB,EAA6B;AAClC,QAAMC,wBAAwB,GAAG,GAAjC;AACA,MAAIC,aAAa,GAAGF,IAAI,CAAC,CAAD,CAAxB;AACA,QAAMG,KAAK,GAAGC,IAAI,CAACC,KAAL,CAAWH,aAAa,GAAG,IAA3B,CAAd;AACAA,EAAAA,aAAa,GAAGA,aAAa,GAAGC,KAAK,GAAG,IAAxC;AACA,QAAMG,OAAO,GAAGF,IAAI,CAACC,KAAL,CAAWH,aAAa,GAAG,EAA3B,CAAhB;AACAA,EAAAA,aAAa,GAAGA,aAAa,GAAGI,OAAO,GAAG,EAA1C;AACA,QAAMC,OAAO,GAAGH,IAAI,CAACC,KAAL,CAAWH,aAAX,CAAhB;AACA,QAAMM,YAAY,GAAGR,IAAI,CAAC,CAAD,CAAJ,GAAUC,wBAA/B;AACA,MAAIQ,MAAM,GAAG,EAAb;;AAEA,MAAIN,KAAJ,EAAW;AACTM,IAAAA,MAAM,IAAK,GAAEN,KAAM,IAAnB;AACD;;AAED,MAAIG,OAAJ,EAAa;AACXG,IAA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QAAQ,CAACC,WAAT,EAAJ,EAA4B;AAC1BL,MAAAA,aAAa,IAAI,MAAML,iBAAiB,CAAC1B,IAAI,CAAC8B,OAAD,EAAUI,IAAV,CAAL,CAAxC;AACD,KAFD,MAEO;AACLH,MAAAA,aAAa,IAAII,QAAQ,CAACZ,IAA1B;AACD;AACF;;AACD,SAAOQ,aAAP;AACD","sourcesContent":["import {join} from 'path';\nimport {promises as fs} from 'fs';\nimport {getAbsoluteFilePath} from './file-utils';\n\nexport function timeConverter(time) {\n const nanoSecondsInMillisecond = 1e6;\n let timeInSeconds = time[0];\n const hours = Math.floor(timeInSeconds / 3600);\n timeInSeconds = timeInSeconds - hours * 3600;\n const minutes = Math.floor(timeInSeconds / 60);\n timeInSeconds = timeInSeconds - minutes * 60;\n const seconds = Math.floor(timeInSeconds);\n const milliseconds = time[1] / nanoSecondsInMillisecond;\n let result = '';\n\n if (hours) {\n result += `${hours}h `;\n }\n\n if (minutes) {\n result += `${minutes}m `;\n }\n\n if (seconds) {\n result += `${seconds}s`;\n }\n\n if (!result) {\n result += `${milliseconds}ms`;\n }\n\n return result;\n}\n\nexport async function calculateFilesSize(params) {\n const {slpk, outputPath, tilesetName} = params;\n const fullOutputPath = getAbsoluteFilePath(outputPath);\n\n try {\n if (slpk) {\n const slpkPath = join(fullOutputPath, `${tilesetName}.slpk`);\n const stat = await fs.stat(slpkPath);\n return stat.size;\n }\n\n const directoryPath = join(fullOutputPath, tilesetName);\n const totalSize = await getTotalFilesSize(directoryPath);\n return totalSize;\n } catch (error) {\n console.log('Calculate file sizes error: ', error); // eslint-disable-line\n return null;\n }\n}\n\nasync function getTotalFilesSize(dirPath) {\n let totalFileSize = 0;\n\n const files = await fs.readdir(dirPath);\n\n for (const file of files) {\n const fileStat = await fs.stat(join(dirPath, file));\n if (fileStat.isDirectory()) {\n totalFileSize += await getTotalFilesSize(join(dirPath, file));\n } else {\n totalFileSize += fileStat.size;\n }\n }\n return totalFileSize;\n}\n"],"file":"statistic-utills.js"}
1
+ {"version":3,"sources":["../../../../src/lib/utils/statistic-utills.js"],"names":["join","promises","fs","getAbsoluteFilePath","timeConverter","time","nanoSecondsInMillisecond","timeInSeconds","hours","Math","floor","minutes","seconds","milliseconds","result","calculateFilesSize","params","slpk","outputPath","tilesetName","fullOutputPath","slpkPath","stat","size","directoryPath","totalSize","getTotalFilesSize","error","console","log","dirPath","totalFileSize","files","readdir","file","fileStat","isDirectory"],"mappings":"AAAA,SAAQA,IAAR,QAAmB,MAAnB;AACA,SAAQC,QAAQ,IAAIC,EAApB,QAA6B,IAA7B;AACA,SAAQC,mBAAR,QAAkC,cAAlC;AAEA,OAAO,SAASC,aAAT,CAAuBC,IAAvB,EAA6B;AAClC,QAAMC,wBAAwB,GAAG,GAAjC;AACA,MAAIC,aAAa,GAAGF,IAAI,CAAC,CAAD,CAAxB;AACA,QAAMG,KAAK,GAAGC,IAAI,CAACC,KAAL,CAAWH,aAAa,GAAG,IAA3B,CAAd;AACAA,EAAAA,aAAa,GAAGA,aAAa,GAAGC,KAAK,GAAG,IAAxC;AACA,QAAMG,OAAO,GAAGF,IAAI,CAACC,KAAL,CAAWH,aAAa,GAAG,EAA3B,CAAhB;AACAA,EAAAA,aAAa,GAAGA,aAAa,GAAGI,OAAO,GAAG,EAA1C;AACA,QAAMC,OAAO,GAAGH,IAAI,CAACC,KAAL,CAAWH,aAAX,CAAhB;AACA,QAAMM,YAAY,GAAGR,IAAI,CAAC,CAAD,CAAJ,GAAUC,wBAA/B;AACA,MAAIQ,MAAM,GAAG,EAAb;;AAEA,MAAIN,KAAJ,EAAW;AACTM,IAAAA,MAAM,cAAON,KAAP,OAAN;AACD;;AAED,MAAIG,OAAJ,EAAa;AACXG,IAAAA,MAAM,cAAOH,OAAP,OAAN;AACD;;AAED,MAAIC,OAAJ,EAAa;AACXE,IAAAA,MAAM,cAAOF,OAAP,MAAN;AACD;;AAED,MAAI,CAACE,MAAL,EAAa;AACXA,IAAAA,MAAM,cAAOD,YAAP,OAAN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;;AACD,SAAOQ,aAAP;AACD","sourcesContent":["import {join} from 'path';\nimport {promises as fs} from 'fs';\nimport {getAbsoluteFilePath} from './file-utils';\n\nexport function timeConverter(time) {\n const nanoSecondsInMillisecond = 1e6;\n let timeInSeconds = time[0];\n const hours = Math.floor(timeInSeconds / 3600);\n timeInSeconds = timeInSeconds - hours * 3600;\n const minutes = Math.floor(timeInSeconds / 60);\n timeInSeconds = timeInSeconds - minutes * 60;\n const seconds = Math.floor(timeInSeconds);\n const milliseconds = time[1] / nanoSecondsInMillisecond;\n let result = '';\n\n if (hours) {\n result += `${hours}h `;\n }\n\n if (minutes) {\n result += `${minutes}m `;\n }\n\n if (seconds) {\n result += `${seconds}s`;\n }\n\n if (!result) {\n result += `${milliseconds}ms`;\n }\n\n return result;\n}\n\nexport async function calculateFilesSize(params) {\n const {slpk, outputPath, tilesetName} = params;\n const fullOutputPath = getAbsoluteFilePath(outputPath);\n\n try {\n if (slpk) {\n const slpkPath = join(fullOutputPath, `${tilesetName}.slpk`);\n const stat = await fs.stat(slpkPath);\n return stat.size;\n }\n\n const directoryPath = join(fullOutputPath, tilesetName);\n const totalSize = await getTotalFilesSize(directoryPath);\n return totalSize;\n } catch (error) {\n console.log('Calculate file sizes error: ', error); // eslint-disable-line\n return null;\n }\n}\n\nasync function getTotalFilesSize(dirPath) {\n let totalFileSize = 0;\n\n const files = await fs.readdir(dirPath);\n\n for (const file of files) {\n const fileStat = await fs.stat(join(dirPath, file));\n if (fileStat.isDirectory()) {\n totalFileSize += await getTotalFilesSize(join(dirPath, file));\n } else {\n totalFileSize += fileStat.size;\n }\n }\n return totalFileSize;\n}\n"],"file":"statistic-utills.js"}
@@ -1,4 +1,4 @@
1
- const VERSION = typeof "3.1.0-alpha.4" !== 'undefined' ? "3.1.0-alpha.4" : 'latest';
1
+ const VERSION = typeof "3.1.0-beta.5" !== 'undefined' ? "3.1.0-beta.5" : 'latest';
2
2
  import { parsePgm } from './lib/pgm-parser';
3
3
  export const PGMLoader = {
4
4
  name: 'PGM - Netpbm grayscale image format',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/pgm-loader.ts"],"names":["VERSION","parsePgm","PGMLoader","name","id","module","version","mimeTypes","parse","arrayBuffer","options","Uint8Array","extensions","cubic"],"mappings":"AAIA,MAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAEA,SAAQC,QAAR,QAAuB,kBAAvB;AAKA,OAAO,MAAMC,SAA2B,GAAG;AACzCC,EAAAA,IAAI,EAAE,qCADmC;AAEzCC,EAAAA,EAAE,EAAE,KAFqC;AAGzCC,EAAAA,MAAM,EAAE,gBAHiC;AAIzCC,EAAAA,OAAO,EAAEN,OAJgC;AAKzCO,EAAAA,SAAS,EAAE,CAAC,0BAAD,CAL8B;AAMzCC,EAAAA,KAAK,EAAE,CAACC,WAAD,EAAcC,OAAd,KAA0BT,QAAQ,CAAC,IAAIU,UAAJ,CAAeF,WAAf,CAAD,EAA8BC,OAA9B,CANA;AAOzCE,EAAAA,UAAU,EAAE,CAAC,KAAD,CAP6B;AAQzCF,EAAAA,OAAO,EAAE;AAEPG,IAAAA,KAAK,EAAE;AAFA;AARgC,CAApC","sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nimport {parsePgm} from './lib/pgm-parser';\n\n/**\n * Loader for PGM - Netpbm grayscale image format\n */\nexport const PGMLoader: LoaderWithParser = {\n name: 'PGM - Netpbm grayscale image format',\n id: 'pgm',\n module: 'tile-converter',\n version: VERSION,\n mimeTypes: ['image/x-portable-graymap'],\n parse: (arrayBuffer, options) => parsePgm(new Uint8Array(arrayBuffer), options),\n extensions: ['pgm'],\n options: {\n // TODO - use pgm namespace\n cubic: false\n }\n};\n"],"file":"pgm-loader.js"}
1
+ {"version":3,"sources":["../../src/pgm-loader.ts"],"names":["VERSION","parsePgm","PGMLoader","name","id","module","version","mimeTypes","parse","arrayBuffer","options","Uint8Array","extensions","cubic"],"mappings":"AAIA,MAAMA,OAAO,GAAG,0BAAuB,WAAvB,oBAAmD,QAAnE;AAEA,SAAQC,QAAR,QAAuB,kBAAvB;AAKA,OAAO,MAAMC,SAA2B,GAAG;AACzCC,EAAAA,IAAI,EAAE,qCADmC;AAEzCC,EAAAA,EAAE,EAAE,KAFqC;AAGzCC,EAAAA,MAAM,EAAE,gBAHiC;AAIzCC,EAAAA,OAAO,EAAEN,OAJgC;AAKzCO,EAAAA,SAAS,EAAE,CAAC,0BAAD,CAL8B;AAMzCC,EAAAA,KAAK,EAAE,CAACC,WAAD,EAAcC,OAAd,KAA0BT,QAAQ,CAAC,IAAIU,UAAJ,CAAeF,WAAf,CAAD,EAA8BC,OAA9B,CANA;AAOzCE,EAAAA,UAAU,EAAE,CAAC,KAAD,CAP6B;AAQzCF,EAAAA,OAAO,EAAE;AAEPG,IAAAA,KAAK,EAAE;AAFA;AARgC,CAApC","sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nimport {parsePgm} from './lib/pgm-parser';\n\n/**\n * Loader for PGM - Netpbm grayscale image format\n */\nexport const PGMLoader: LoaderWithParser = {\n name: 'PGM - Netpbm grayscale image format',\n id: 'pgm',\n module: 'tile-converter',\n version: VERSION,\n mimeTypes: ['image/x-portable-graymap'],\n parse: (arrayBuffer, options) => parsePgm(new Uint8Array(arrayBuffer), options),\n extensions: ['pgm'],\n options: {\n // TODO - use pgm namespace\n cubic: false\n }\n};\n"],"file":"pgm-loader.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/tile-converter",
3
- "version": "3.1.0-alpha.4",
3
+ "version": "3.1.0-beta.5",
4
4
  "description": "Converter",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -15,7 +15,7 @@
15
15
  "3dTiles",
16
16
  "i3s"
17
17
  ],
18
- "types": "src/index.ts",
18
+ "types": "dist/index.d.ts",
19
19
  "main": "dist/es5/index.js",
20
20
  "module": "dist/esm/index.js",
21
21
  "sideEffects": false,
@@ -33,24 +33,24 @@
33
33
  "fs": false
34
34
  },
35
35
  "scripts": {
36
- "pre-build": "npm run build-bin && npm run build-bundle",
37
- "build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js",
38
- "build-bin": "BABEL_ENV=es5 babel scripts --config-file ../../babel.config.js --out-dir dist/scripts",
39
- "build-converter-bundle": "webpack --config ./converter-webpack/bundle.js"
36
+ "pre-build": "npm run build-bundle",
37
+ "post-build": "npm run build-converter-bundle",
38
+ "build-bundle": "esbuild ./src/index.ts --bundle --outfile=dist/bundle.js --platform=node",
39
+ "build-converter-bundle": "webpack --display errors-only --config ./converter-webpack/bundle.js",
40
+ "build-bin": "BABEL_ENV=es5 babel scripts --config-file ../../babel.config.js --out-dir dist/scripts"
40
41
  },
41
42
  "dependencies": {
42
- "@loaders.gl/3d-tiles": "3.1.0-alpha.4",
43
- "@loaders.gl/core": "3.1.0-alpha.4",
44
- "@loaders.gl/crypto": "3.1.0-alpha.4",
45
- "@loaders.gl/draco": "3.1.0-alpha.4",
46
- "@loaders.gl/gltf": "3.1.0-alpha.4",
47
- "@loaders.gl/i3s": "3.1.0-alpha.4",
48
- "@loaders.gl/images": "3.1.0-alpha.4",
49
- "@loaders.gl/loader-utils": "3.1.0-alpha.4",
50
- "@loaders.gl/polyfills": "3.1.0-alpha.4",
51
- "@loaders.gl/tiles": "3.1.0-alpha.4",
52
- "@loaders.gl/worker-utils": "3.1.0-alpha.4",
53
- "@loaders.gl/zip": "3.1.0-alpha.4",
43
+ "@loaders.gl/3d-tiles": "3.1.0-beta.5",
44
+ "@loaders.gl/crypto": "3.1.0-beta.5",
45
+ "@loaders.gl/draco": "3.1.0-beta.5",
46
+ "@loaders.gl/gltf": "3.1.0-beta.5",
47
+ "@loaders.gl/i3s": "3.1.0-beta.5",
48
+ "@loaders.gl/images": "3.1.0-beta.5",
49
+ "@loaders.gl/loader-utils": "3.1.0-beta.5",
50
+ "@loaders.gl/polyfills": "3.1.0-beta.5",
51
+ "@loaders.gl/tiles": "3.1.0-beta.5",
52
+ "@loaders.gl/worker-utils": "3.1.0-beta.5",
53
+ "@loaders.gl/zip": "3.1.0-beta.5",
54
54
  "@luma.gl/engine": "^8.5.4",
55
55
  "@math.gl/core": "^3.5.1",
56
56
  "@math.gl/culling": "^3.5.1",
@@ -66,5 +66,8 @@
66
66
  "morgan": "~1.9.1",
67
67
  "uuid": "^8.1.0"
68
68
  },
69
- "gitHead": "e309784af37ef9f3640c7733c7851124c72e1fa3"
69
+ "peerDependencies": {
70
+ "@loaders.gl/core": "3.1.0-beta.1"
71
+ },
72
+ "gitHead": "5d66468457cc878d2dbff3d7807d737ceb181c9a"
70
73
  }
@@ -5,7 +5,7 @@ import {join} from 'path';
5
5
  import process from 'process';
6
6
  import transform from 'json-map-transform';
7
7
  import {load} from '@loaders.gl/core';
8
- import {I3SLoader, I3SAttributeLoader} from '@loaders.gl/i3s';
8
+ import {I3SLoader, I3SAttributeLoader, COORDINATE_SYSTEM} from '@loaders.gl/i3s';
9
9
  import {Tileset3D, Tile3D} from '@loaders.gl/tiles';
10
10
 
11
11
  import {PGMLoader} from '../pgm-loader';
@@ -67,7 +67,9 @@ 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
- this.sourceTileset = new Tileset3D(sourceTilesetJson, {});
70
+ this.sourceTileset = new Tileset3D(sourceTilesetJson, {
71
+ loadOptions: {i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS}}
72
+ });
71
73
 
72
74
  if (!this.sourceTileset.root.header.obb) {
73
75
  this.sourceTileset.root.header.obb = createObbFromMbs(this.sourceTileset.root.header.mbs);
@@ -3,8 +3,11 @@ import {GLTFScenegraph, GLTFWriter} from '@loaders.gl/gltf';
3
3
  import {Tile3DWriter} from '@loaders.gl/3d-tiles';
4
4
  import {ImageWriter} from '@loaders.gl/images';
5
5
  import {Matrix4, Vector3} from '@math.gl/core';
6
+ import {Ellipsoid} from '@math.gl/geospatial';
7
+ import {convertTextureAtlas} from './texture-atlas';
6
8
 
7
9
  const Z_UP_TO_Y_UP_MATRIX = new Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
10
+ const scratchVector = new Vector3();
8
11
 
9
12
  export default class B3dmConverter {
10
13
  async convert(i3sTile, attributes = null) {
@@ -23,7 +26,14 @@ export default class B3dmConverter {
23
26
  }
24
27
 
25
28
  async buildGltf(i3sTile) {
26
- const {material, attributes, indices: originalIndices, cartesianOrigin} = i3sTile.content;
29
+ const {
30
+ material,
31
+ attributes,
32
+ indices: originalIndices,
33
+ cartesianOrigin,
34
+ cartographicOrigin,
35
+ modelMatrix
36
+ } = i3sTile.content;
27
37
  const gltfBuilder = new GLTFScenegraph();
28
38
 
29
39
  const textureIndex = await this._addI3sTextureToGltf(i3sTile, gltfBuilder);
@@ -32,7 +42,20 @@ export default class B3dmConverter {
32
42
 
33
43
  const positions = attributes.positions;
34
44
  const positionsValue = positions.value;
35
- attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin);
45
+
46
+ if (attributes.uvRegions && attributes.texCoords) {
47
+ attributes.texCoords.value = convertTextureAtlas(
48
+ attributes.texCoords.value,
49
+ attributes.uvRegions.value
50
+ );
51
+ }
52
+
53
+ attributes.positions.value = this._normalizePositions(
54
+ positionsValue,
55
+ cartesianOrigin,
56
+ cartographicOrigin,
57
+ modelMatrix
58
+ );
36
59
  if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
37
60
  delete attributes.normals;
38
61
  }
@@ -88,15 +111,20 @@ export default class B3dmConverter {
88
111
  * Generate a positions array which is correct for 3DTiles/GLTF format
89
112
  * @param {Float64Array} positionsValue - the input geometry positions array
90
113
  * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system
114
+ * @param {number[]} cartographicOrigin - the tile center in the cartographic coordinate system
115
+ * @param {number[]} modelMatrix - the model matrix of geometry
91
116
  * @returns {Float32Array} - the output geometry positions array
92
117
  */
93
- _normalizePositions(positionsValue, cartesianOrigin) {
118
+ _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {
94
119
  const newPositionsValue = new Float32Array(positionsValue.length);
95
120
  for (let index = 0; index < positionsValue.length; index += 3) {
96
121
  const vertex = positionsValue.subarray(index, index + 3);
97
- const originVector = new Vector3(cartesianOrigin);
98
- let vertexVector = new Vector3(Array.from(vertex));
99
- vertexVector = vertexVector.subtract(originVector);
122
+ const cartesianOriginVector = new Vector3(cartesianOrigin);
123
+ let vertexVector = new Vector3(Array.from(vertex))
124
+ .transform(modelMatrix)
125
+ .add(cartographicOrigin);
126
+ Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);
127
+ vertexVector = scratchVector.subtract(cartesianOriginVector);
100
128
  newPositionsValue.set(vertexVector, index);
101
129
  }
102
130
  return newPositionsValue;
@@ -267,7 +295,7 @@ export default class B3dmConverter {
267
295
  return 0;
268
296
  }
269
297
  const firstKey = Object.keys(attributes)[0];
270
- return attributes[firstKey].length;
298
+ return firstKey ? attributes[firstKey].length : 0;
271
299
  }
272
300
 
273
301
  /* Checks that normals buffer is correct
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Apply uvRegions to texture coordinates.
3
+ * Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md
4
+ * Shader formula vec2 uv = fract(texCoords) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;
5
+ * @param texCoords
6
+ * @param uvRegions
7
+ */
8
+ export function convertTextureAtlas(texCoords: Float32Array, uvRegions: Uint16Array): Float32Array {
9
+ const convertedTexCoords = new Float32Array(texCoords.length);
10
+ const normalisedRegions = normalizeRegions(uvRegions);
11
+
12
+ for (let index = 0; index < texCoords.length; index += 2) {
13
+ const uv = texCoords.subarray(index, index + 2);
14
+ const regions = normalisedRegions.slice(index * 2, index * 2 + 4);
15
+ // fract(texCoords)
16
+ const fractatedUV = fract(uv);
17
+ // (uvRegions.zw - uvRegions.xy)
18
+ const subtracted = [regions[2] - regions[0], regions[3] - regions[1]];
19
+ // fract(texCoords) * (uvRegions.zw - uvRegions.xy)
20
+ const multiplicationResult = [fractatedUV[0] * subtracted[0], fractatedUV[1] * subtracted[1]];
21
+ // fract(texCoords) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;
22
+ const convertedUV = [
23
+ multiplicationResult[0] + regions[0],
24
+ multiplicationResult[1] + regions[1]
25
+ ];
26
+
27
+ convertedTexCoords[index] = convertedUV[0];
28
+ convertedTexCoords[index + 1] = convertedUV[1];
29
+ }
30
+
31
+ return convertedTexCoords;
32
+ }
33
+
34
+ /**
35
+ * Do fractation of UV array.
36
+ * @param uv
37
+ */
38
+ function fract(uv: number[2]): number[2] {
39
+ return [uv[0] - Math.floor(uv[0]), uv[1] - Math.floor(uv[1])];
40
+ }
41
+
42
+ /**
43
+ * Normalize uvRegions by dividing by the maximum Uint16 value
44
+ * @param regions
45
+ */
46
+ function normalizeRegions(regions: Uint16Array): number[4] {
47
+ const MAX_UINT_16_VALUE = 65535;
48
+ const normalizedRegions = [];
49
+
50
+ for (let index = 0; index < regions.length; index++) {
51
+ normalizedRegions[index] = regions[index] / MAX_UINT_16_VALUE;
52
+ }
53
+
54
+ return normalizedRegions;
55
+ }
@@ -40,8 +40,12 @@ export default async function convertB3dmToI3sGeometry(
40
40
 
41
41
  const result = [];
42
42
  let nodesCounter = nodeId;
43
- for (let i = 0; i < (tileContent.gltf.materials.length || 1); i++) {
44
- const sourceMaterial = tileContent.gltf.materials[i] || {id: 'default'};
43
+ let {materials = []} = tileContent.gltf;
44
+ if (!materials.length === 0) {
45
+ materials.push({id: 'default'});
46
+ }
47
+ for (let i = 0; i < materials.length; i++) {
48
+ const sourceMaterial = materials[i];
45
49
  if (!convertedAttributesMap.has(sourceMaterial.id)) {
46
50
  continue; // eslint-disable-line no-continue
47
51
  }
@@ -62,6 +66,9 @@ export default async function convertB3dmToI3sGeometry(
62
66
  nodesCounter++;
63
67
  }
64
68
 
69
+ if (!result.length) {
70
+ return null;
71
+ }
65
72
  return result;
66
73
  }
67
74
 
@@ -158,7 +165,7 @@ function convertAttributes(tileContent) {
158
165
  });
159
166
  }
160
167
 
161
- const nodes = tileContent.gltf.scene.nodes;
168
+ const nodes = (tileContent.gltf.scene || tileContent.gltf.scenes?.[0] || tileContent.gltf).nodes;
162
169
  convertNodes(nodes, tileContent, attributesMap);
163
170
 
164
171
  for (const attrKey of attributesMap.keys()) {
@@ -167,19 +174,6 @@ function convertAttributes(tileContent) {
167
174
  attributesMap.delete(attrKey);
168
175
  continue; // eslint-disable-line no-continue
169
176
  }
170
- const vertexCount = attributes.positions.length / VALUES_PER_VERTEX;
171
- if (!attributes.colors.length) {
172
- attributes.colors = new Uint8Array(vertexCount * VALUES_PER_COLOR_ELEMENT);
173
- for (let index = 0; index < attributes.colors.length; index += 4) {
174
- attributes.colors.set([255, 255, 255, 255], index);
175
- }
176
- }
177
- if (!attributes.texCoords.length) {
178
- attributes.texCoords = new Float32Array(vertexCount * VALUES_PER_TEX_COORD);
179
- for (let index = 0; index < attributes.texCoords.length; index += 2) {
180
- attributes.texCoords.set([1, 1], index);
181
- }
182
- }
183
177
  attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));
184
178
  }
185
179
 
@@ -366,10 +360,13 @@ function transformVertexNormals(vertexVector, calleeArgs) {
366
360
  * @returns {Float32Array}
367
361
  */
368
362
  function flattenTexCoords(texCoords, indices) {
363
+ const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
369
364
  if (!texCoords) {
370
- return new Float32Array(0);
365
+ // We need dummy UV0s because it is required in 1.6
366
+ // https://github.com/Esri/i3s-spec/blob/master/docs/1.6/vertexAttribute.cmn.md
367
+ newTexCoords.fill(1);
368
+ return newTexCoords;
371
369
  }
372
- const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
373
370
  for (let i = 0; i < indices.length; i++) {
374
371
  const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
375
372
  const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
@@ -386,12 +383,14 @@ function flattenTexCoords(texCoords, indices) {
386
383
  * @returns {Uint8Array}
387
384
  */
388
385
  function flattenColors(colorsAttribute, indices) {
386
+ const components = colorsAttribute?.components || VALUES_PER_COLOR_ELEMENT;
387
+ const newColors = new Uint8Array(indices.length * components);
389
388
  if (!colorsAttribute) {
390
- return new Uint8Array(0);
389
+ // Vertex color multiplies by material color so it must be normalized 1 by default
390
+ newColors.fill(255);
391
+ return newColors;
391
392
  }
392
- const components = colorsAttribute.components;
393
393
  const colors = colorsAttribute.value;
394
- const newColors = new Uint8Array(indices.length * components);
395
394
  for (let i = 0; i < indices.length; i++) {
396
395
  const colorIndex = indices[i] * components;
397
396
  const color = colors.subarray(colorIndex, colorIndex + components);
@@ -445,7 +444,7 @@ function getBatchIdsByAttributeName(attributes) {
445
444
 
446
445
  function convertMaterials(tileContent) {
447
446
  const result = [];
448
- const sourceMaterials = tileContent.gltf.materials;
447
+ const sourceMaterials = tileContent.gltf.materials || [];
449
448
  for (const sourceMaterial of sourceMaterials) {
450
449
  result.push(convertMaterial(sourceMaterial));
451
450
  }