@loaders.gl/tile-converter 3.1.0-alpha.3 → 3.1.0-beta.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 (198) hide show
  1. package/bin/converter.js +1 -1
  2. package/dist/bundle.js +85947 -4
  3. package/dist/converter.min.js +292 -0
  4. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +267 -0
  5. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
  6. package/dist/{3d-tiles-converter → es5/3d-tiles-converter}/helpers/b3dm-converter.d.ts +0 -0
  7. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +269 -0
  8. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
  9. package/dist/{3d-tiles-converter → es5/3d-tiles-converter}/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -0
  10. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +22 -0
  11. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
  12. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +40 -0
  13. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  14. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +48 -0
  15. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -0
  16. package/dist/es5/bundle.js +7 -0
  17. package/dist/es5/bundle.js.map +1 -0
  18. package/dist/{deps-installer → es5/deps-installer}/deps-installer.d.ts +0 -0
  19. package/dist/es5/deps-installer/deps-installer.js +39 -0
  20. package/dist/es5/deps-installer/deps-installer.js.map +1 -0
  21. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +65 -0
  22. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -0
  23. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +30 -0
  24. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
  25. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +208 -0
  26. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -0
  27. package/dist/{i3s-converter → es5/i3s-converter}/helpers/geometry-converter.d.ts +0 -0
  28. package/dist/es5/i3s-converter/helpers/geometry-converter.js +700 -0
  29. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -0
  30. package/dist/es5/i3s-converter/helpers/node-debug.js +103 -0
  31. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -0
  32. package/dist/{i3s-converter → es5/i3s-converter}/helpers/node-pages.d.ts +0 -0
  33. package/dist/es5/i3s-converter/helpers/node-pages.js +150 -0
  34. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -0
  35. package/dist/es5/i3s-converter/i3s-converter.js +915 -0
  36. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -0
  37. package/dist/es5/i3s-converter/json-templates/layers.js +203 -0
  38. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -0
  39. package/dist/es5/i3s-converter/json-templates/metadata.js +29 -0
  40. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -0
  41. package/dist/es5/i3s-converter/json-templates/node.js +91 -0
  42. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -0
  43. package/dist/es5/i3s-converter/json-templates/scene-server.js +35 -0
  44. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -0
  45. package/dist/es5/i3s-converter/json-templates/shared-resources.js +141 -0
  46. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -0
  47. package/dist/es5/i3s-converter/json-templates/store.js +105 -0
  48. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -0
  49. package/dist/es5/i3s-server/app.js +23 -0
  50. package/dist/es5/i3s-server/app.js.map +1 -0
  51. package/dist/{i3s-server → es5/i3s-server}/bin/www +0 -0
  52. package/dist/{i3s-server → es5/i3s-server}/certs/cert.pem +0 -0
  53. package/dist/{i3s-server → es5/i3s-server}/certs/key.pem +0 -0
  54. package/dist/es5/i3s-server/controllers/index-controller.js +33 -0
  55. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -0
  56. package/dist/es5/i3s-server/routes/index.js +22 -0
  57. package/dist/es5/i3s-server/routes/index.js.map +1 -0
  58. package/dist/es5/index.js +40 -0
  59. package/dist/es5/index.js.map +1 -0
  60. package/dist/{lib → es5/lib}/geoid-height-model.d.ts +0 -0
  61. package/dist/es5/lib/geoid-height-model.js +149 -0
  62. package/dist/es5/lib/geoid-height-model.js.map +1 -0
  63. package/dist/{lib → es5/lib}/pgm-parser.d.ts +0 -0
  64. package/dist/es5/lib/pgm-parser.js +192 -0
  65. package/dist/es5/lib/pgm-parser.js.map +1 -0
  66. package/dist/es5/lib/utils/compress-util.js +202 -0
  67. package/dist/es5/lib/utils/compress-util.js.map +1 -0
  68. package/dist/{lib → es5/lib}/utils/compress-utils.d.ts +0 -0
  69. package/dist/{lib → es5/lib}/utils/file-utils.d.ts +0 -0
  70. package/dist/es5/lib/utils/file-utils.js +59 -0
  71. package/dist/es5/lib/utils/file-utils.js.map +1 -0
  72. package/dist/{lib → es5/lib}/utils/lod-conversion-utils.d.ts +0 -0
  73. package/dist/es5/lib/utils/lod-conversion-utils.js +52 -0
  74. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -0
  75. package/dist/{lib → es5/lib}/utils/statistic-utills.d.ts +0 -0
  76. package/dist/es5/lib/utils/statistic-utills.js +85 -0
  77. package/dist/es5/lib/utils/statistic-utills.js.map +1 -0
  78. package/dist/es5/pgm-loader.js +24 -0
  79. package/dist/es5/pgm-loader.js.map +1 -0
  80. package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/3d-tiles-converter.js +19 -13
  81. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
  82. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.d.ts +23 -0
  83. package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/helpers/b3dm-converter.js +19 -8
  84. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
  85. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +16 -0
  86. package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/helpers/i3s-obb-to-3d-tiles-obb.js +0 -0
  87. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
  88. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +33 -0
  89. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  90. package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/json-templates/tileset.js +0 -0
  91. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -0
  92. package/dist/esm/bundle.js +5 -0
  93. package/dist/esm/bundle.js.map +1 -0
  94. package/dist/esm/deps-installer/deps-installer.d.ts +10 -0
  95. package/dist/{deps-installer → esm/deps-installer}/deps-installer.js +0 -0
  96. package/dist/esm/deps-installer/deps-installer.js.map +1 -0
  97. package/dist/{i3s-converter → esm/i3s-converter}/helpers/coordinate-converter.js +0 -0
  98. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -0
  99. package/dist/{i3s-converter → esm/i3s-converter}/helpers/create-scene-server-path.js +0 -0
  100. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
  101. package/dist/{i3s-converter → esm/i3s-converter}/helpers/geometry-attributes.js +0 -0
  102. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -0
  103. package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +40 -0
  104. package/dist/{i3s-converter → esm/i3s-converter}/helpers/geometry-converter.js +29 -31
  105. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -0
  106. package/dist/{i3s-converter → esm/i3s-converter}/helpers/node-debug.js +2 -2
  107. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -0
  108. package/dist/esm/i3s-converter/helpers/node-pages.d.ts +144 -0
  109. package/dist/{i3s-converter → esm/i3s-converter}/helpers/node-pages.js +2 -2
  110. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -0
  111. package/dist/{i3s-converter → esm/i3s-converter}/i3s-converter.js +50 -31
  112. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -0
  113. package/dist/{i3s-converter → esm/i3s-converter}/json-templates/layers.js +0 -0
  114. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -0
  115. package/dist/{i3s-converter → esm/i3s-converter}/json-templates/metadata.js +1 -1
  116. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -0
  117. package/dist/{i3s-converter → esm/i3s-converter}/json-templates/node.js +0 -0
  118. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -0
  119. package/dist/{i3s-converter → esm/i3s-converter}/json-templates/scene-server.js +1 -1
  120. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -0
  121. package/dist/{i3s-converter → esm/i3s-converter}/json-templates/shared-resources.js +2 -2
  122. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -0
  123. package/dist/{i3s-converter → esm/i3s-converter}/json-templates/store.js +2 -2
  124. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -0
  125. package/dist/{i3s-server → esm/i3s-server}/app.js +0 -0
  126. package/dist/esm/i3s-server/app.js.map +1 -0
  127. package/dist/esm/i3s-server/bin/www +102 -0
  128. package/dist/esm/i3s-server/certs/cert.pem +19 -0
  129. package/dist/esm/i3s-server/certs/key.pem +27 -0
  130. package/dist/{i3s-server → esm/i3s-server}/controllers/index-controller.js +2 -2
  131. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -0
  132. package/dist/{i3s-server → esm/i3s-server}/routes/index.js +0 -0
  133. package/dist/esm/i3s-server/routes/index.js.map +1 -0
  134. package/dist/{index.js → esm/index.js} +0 -0
  135. package/dist/esm/index.js.map +1 -0
  136. package/dist/esm/lib/geoid-height-model.d.ts +41 -0
  137. package/dist/{lib → esm/lib}/geoid-height-model.js +0 -0
  138. package/dist/esm/lib/geoid-height-model.js.map +1 -0
  139. package/dist/esm/lib/pgm-parser.d.ts +14 -0
  140. package/dist/{lib → esm/lib}/pgm-parser.js +0 -0
  141. package/dist/esm/lib/pgm-parser.js.map +1 -0
  142. package/dist/{lib → esm/lib}/utils/compress-util.js +13 -13
  143. package/dist/esm/lib/utils/compress-util.js.map +1 -0
  144. package/dist/esm/lib/utils/compress-utils.d.ts +53 -0
  145. package/dist/esm/lib/utils/file-utils.d.ts +43 -0
  146. package/dist/{lib → esm/lib}/utils/file-utils.js +1 -1
  147. package/dist/esm/lib/utils/file-utils.js.map +1 -0
  148. package/dist/esm/lib/utils/lod-conversion-utils.d.ts +32 -0
  149. package/dist/{lib → esm/lib}/utils/lod-conversion-utils.js +0 -0
  150. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -0
  151. package/dist/esm/lib/utils/statistic-utills.d.ts +25 -0
  152. package/dist/{lib → esm/lib}/utils/statistic-utills.js +5 -5
  153. package/dist/esm/lib/utils/statistic-utills.js.map +1 -0
  154. package/dist/{pgm-loader.js → esm/pgm-loader.js} +1 -1
  155. package/dist/esm/pgm-loader.js.map +1 -0
  156. package/package.json +24 -21
  157. package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -2
  158. package/src/3d-tiles-converter/helpers/b3dm-converter.js +35 -7
  159. package/src/3d-tiles-converter/helpers/texture-atlas.ts +55 -0
  160. package/src/i3s-converter/helpers/geometry-converter.js +21 -22
  161. package/src/i3s-converter/i3s-converter.ts +32 -7
  162. package/src/i3s-converter/json-templates/metadata.js +1 -1
  163. package/src/i3s-converter/json-templates/scene-server.js +1 -1
  164. package/src/i3s-converter/json-templates/store.js +2 -2
  165. package/src/i3s-server/controllers/index-controller.js +1 -1
  166. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
  167. package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
  168. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
  169. package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
  170. package/dist/bundle.js.map +0 -1
  171. package/dist/deps-installer/deps-installer.js.map +0 -1
  172. package/dist/dist.min.js +0 -94
  173. package/dist/dist.min.js.map +0 -1
  174. package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
  175. package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
  176. package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
  177. package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
  178. package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
  179. package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
  180. package/dist/i3s-converter/i3s-converter.js.map +0 -1
  181. package/dist/i3s-converter/json-templates/layers.js.map +0 -1
  182. package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
  183. package/dist/i3s-converter/json-templates/node.js.map +0 -1
  184. package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
  185. package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
  186. package/dist/i3s-converter/json-templates/store.js.map +0 -1
  187. package/dist/i3s-server/app.js.map +0 -1
  188. package/dist/i3s-server/controllers/index-controller.js.map +0 -1
  189. package/dist/i3s-server/routes/index.js.map +0 -1
  190. package/dist/index.js.map +0 -1
  191. package/dist/lib/geoid-height-model.js.map +0 -1
  192. package/dist/lib/pgm-parser.js.map +0 -1
  193. package/dist/lib/utils/compress-util.js.map +0 -1
  194. package/dist/lib/utils/file-utils.js.map +0 -1
  195. package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
  196. package/dist/lib/utils/statistic-utills.js.map +0 -1
  197. package/dist/pgm-loader.js.map +0 -1
  198. package/dist/scripts/converter.js +0 -274
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Do milliseconds time conversion to readable time string.
3
+ * @param tile - 3d-tiles tile Object
4
+ * @param coordinates - node converted coordinates
5
+ * @returns String which characterizes conversion time period
6
+ */
7
+ export function timeConverter(time: [number, number]): String;
8
+
9
+ /**
10
+ * Calculate files sizes after conversion.
11
+ * @param params - Object with params of conversion.
12
+ * @returns Promise with generated files size in bytes.
13
+ */
14
+ export function calculateFilesSize(params: {
15
+ slpk: boolean;
16
+ outputPath: string;
17
+ tilesetName: string;
18
+ }): Number;
19
+
20
+ /**
21
+ * Reqursivelly calculate files sizes in directory.
22
+ * @param dirPath - Directory path.
23
+ * @returns Promise with files size in directory.
24
+ */
25
+ export function getTotalFilesSize(dirPath: string): Number;
@@ -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
  }
@@ -0,0 +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,I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,MAAMpB,EAAE,CAACoB,IAAH,CAAQD,QAAR,CAAnB;AACA,aAAOC,IAAI,CAACC,IAAZ;AACD;;AAED,UAAMC,aAAa,GAAGxB,IAAI,CAACoB,cAAD,EAAiBD,WAAjB,CAA1B;AACA,UAAMM,SAAS,GAAG,MAAMC,iBAAiB,CAACF,aAAD,CAAzC;AACA,WAAOC,SAAP;AACD,GAVD,CAUE,OAAOE,KAAP,EAAc;AACdC,IAAAA,OAAO,CAACC,GAAR,CAAY,8BAAZ,EAA4CF,KAA5C;AACA,WAAO,IAAP;AACD;AACF;;AAED,eAAeD,iBAAf,CAAiCI,OAAjC,EAA0C;AACxC,MAAIC,aAAa,GAAG,CAApB;AAEA,QAAMC,KAAK,GAAG,MAAM9B,EAAE,CAAC+B,OAAH,CAAWH,OAAX,CAApB;;AAEA,OAAK,MAAMI,IAAX,IAAmBF,KAAnB,EAA0B;AACxB,UAAMG,QAAQ,GAAG,MAAMjC,EAAE,CAACoB,IAAH,CAAQtB,IAAI,CAAC8B,OAAD,EAAUI,IAAV,CAAZ,CAAvB;;AACA,QAAIC,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,4 +1,4 @@
1
- const VERSION = typeof "3.1.0-alpha.3" !== 'undefined' ? "3.1.0-alpha.3" : 'latest';
1
+ const VERSION = typeof "3.1.0-beta.2" !== 'undefined' ? "3.1.0-beta.2" : 'latest';
2
2
  import { parsePgm } from './lib/pgm-parser';
3
3
  export const PGMLoader = {
4
4
  name: 'PGM - Netpbm grayscale image format',
@@ -0,0 +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,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.3",
3
+ "version": "3.1.0-beta.2",
4
4
  "description": "Converter",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -15,9 +15,9 @@
15
15
  "3dTiles",
16
16
  "i3s"
17
17
  ],
18
- "types": "src/index.ts",
19
- "main": "dist/index.js",
20
- "module": "dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "main": "dist/es5/index.js",
20
+ "module": "dist/esm/index.js",
21
21
  "sideEffects": false,
22
22
  "bin": {
23
23
  "tile-converter": "./bin/converter.js",
@@ -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.3",
43
- "@loaders.gl/core": "3.1.0-alpha.3",
44
- "@loaders.gl/crypto": "3.1.0-alpha.3",
45
- "@loaders.gl/draco": "3.1.0-alpha.3",
46
- "@loaders.gl/gltf": "3.1.0-alpha.3",
47
- "@loaders.gl/i3s": "3.1.0-alpha.3",
48
- "@loaders.gl/images": "3.1.0-alpha.3",
49
- "@loaders.gl/loader-utils": "3.1.0-alpha.3",
50
- "@loaders.gl/polyfills": "3.1.0-alpha.3",
51
- "@loaders.gl/tiles": "3.1.0-alpha.3",
52
- "@loaders.gl/worker-utils": "3.1.0-alpha.3",
53
- "@loaders.gl/zip": "3.1.0-alpha.3",
43
+ "@loaders.gl/3d-tiles": "3.1.0-beta.2",
44
+ "@loaders.gl/crypto": "3.1.0-beta.2",
45
+ "@loaders.gl/draco": "3.1.0-beta.2",
46
+ "@loaders.gl/gltf": "3.1.0-beta.2",
47
+ "@loaders.gl/i3s": "3.1.0-beta.2",
48
+ "@loaders.gl/images": "3.1.0-beta.2",
49
+ "@loaders.gl/loader-utils": "3.1.0-beta.2",
50
+ "@loaders.gl/polyfills": "3.1.0-beta.2",
51
+ "@loaders.gl/tiles": "3.1.0-beta.2",
52
+ "@loaders.gl/worker-utils": "3.1.0-beta.2",
53
+ "@loaders.gl/zip": "3.1.0-beta.2",
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": "68e1c443d1b63aa2515436a7411ed0a029b42c15"
69
+ "peerDependencies": {
70
+ "@loaders.gl/core": "3.1.0-beta.1"
71
+ },
72
+ "gitHead": "90f487e7b3f15c554d57c92497d3a12d71676818"
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
  }
@@ -19,9 +19,9 @@ import type {
19
19
  Field,
20
20
  PopupInfo
21
21
  } from '@loaders.gl/i3s';
22
- import {load} from '@loaders.gl/core';
22
+ import {load, encode} from '@loaders.gl/core';
23
23
  import {Tileset3D} from '@loaders.gl/tiles';
24
- import {CesiumIonLoader} from '@loaders.gl/3d-tiles';
24
+ import {CesiumIonLoader, Tiles3DLoader} from '@loaders.gl/3d-tiles';
25
25
  import {join} from 'path';
26
26
  import {v4 as uuidv4} from 'uuid';
27
27
  import process from 'process';
@@ -51,6 +51,8 @@ import {SHARED_RESOURCES_TEMPLATE} from './json-templates/shared-resources';
51
51
  import {validateNodeBoundingVolumes} from './helpers/node-debug';
52
52
  import {GeoidHeightModel} from '../lib/geoid-height-model';
53
53
  import TileHeader from '@loaders.gl/tiles/src/tileset/tile-3d';
54
+ import {KTX2BasisUniversalTextureWriter} from '@loaders.gl/textures';
55
+ import {LoaderWithParser} from '@loaders.gl/loader-utils';
54
56
 
55
57
  const ION_DEFAULT_TOKEN =
56
58
  process.env.IonToken || // eslint-disable-line
@@ -63,6 +65,7 @@ const SHORT_INT_TYPE = 'Int32';
63
65
  const DOUBLE_TYPE = 'double';
64
66
  const OBJECT_ID_TYPE = 'OBJECTID';
65
67
  const REFRESH_TOKEN_TIMEOUT = 1800; // 30 minutes in seconds
68
+ const CESIUM_DATASET_PREFIX = 'https://';
66
69
  // const FS_FILE_TOO_LARGE = 'ERR_FS_FILE_TOO_LARGE';
67
70
 
68
71
  /**
@@ -88,6 +91,7 @@ export default class I3SConverter {
88
91
  refreshTokenTime: [number, number];
89
92
  sourceTileset: Tileset3D | null;
90
93
  geoidHeightModel: GeoidHeightModel | null;
94
+ Loader: LoaderWithParser = Tiles3DLoader;
91
95
 
92
96
  constructor() {
93
97
  this.nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE);
@@ -148,6 +152,7 @@ export default class I3SConverter {
148
152
  } = options;
149
153
  this.options = {maxDepth, slpk, sevenZipExe, egmFilePath, draco, token, inputUrl};
150
154
  this.validate = validate;
155
+ this.Loader = inputUrl.indexOf(CESIUM_DATASET_PREFIX) !== -1 ? CesiumIonLoader : Tiles3DLoader;
151
156
 
152
157
  console.log('Loading egm file...'); // eslint-disable-line
153
158
  this.geoidHeightModel = await load(egmFilePath, PGMLoader);
@@ -163,7 +168,7 @@ export default class I3SConverter {
163
168
  tilesetOptions.loadOptions.fetch = {headers: preloadOptions.headers};
164
169
  }
165
170
  Object.assign(tilesetOptions, preloadOptions);
166
- const sourceTilesetJson = await load(inputUrl, CesiumIonLoader, tilesetOptions.loadOptions);
171
+ const sourceTilesetJson = await load(inputUrl, this.Loader, tilesetOptions.loadOptions);
167
172
  // console.log(tilesetJson); // eslint-disable-line
168
173
  this.sourceTileset = new Tileset3D(sourceTilesetJson, tilesetOptions);
169
174
 
@@ -636,14 +641,14 @@ export default class I3SConverter {
636
641
  parentId: number,
637
642
  resources: I3SGeometry
638
643
  ): NodeInPage {
639
- const {meshMaterial, texture, vertexCount, featureCount} = resources;
644
+ const {meshMaterial, texture, vertexCount, featureCount, geometry} = resources;
640
645
  const nodeInPage = {
641
646
  lodThreshold: maxScreenThresholdSQ.maxError,
642
647
  obb: boundingVolumes.obb,
643
648
  children: [],
644
649
  mesh: null
645
650
  };
646
- if (sourceTile.content && sourceTile.content.type === 'b3dm') {
651
+ if (geometry && sourceTile.content && sourceTile.content.type === 'b3dm') {
647
652
  nodeInPage.mesh = {
648
653
  geometry: {
649
654
  definition: texture ? 0 : 1
@@ -717,7 +722,7 @@ export default class I3SConverter {
717
722
  node.sharedResource = {href: './shared'};
718
723
 
719
724
  if (texture) {
720
- node.textureData = [{href: './textures/0'}];
725
+ node.textureData = [{href: './textures/0'}, {href: './textures/1'}];
721
726
  }
722
727
 
723
728
  if (
@@ -852,24 +857,41 @@ export default class I3SConverter {
852
857
  {
853
858
  name: '0',
854
859
  format
860
+ },
861
+ {
862
+ name: '1',
863
+ format: 'ktx2'
855
864
  }
856
865
  ]
857
866
  });
858
867
  }
859
868
 
860
869
  const textureData = texture.bufferView.data;
870
+ const ktx2TextureData = await encode(texture.image, KTX2BasisUniversalTextureWriter);
871
+
861
872
  if (this.options.slpk) {
862
873
  const slpkTexturePath = join(childPath, 'textures');
863
874
  const compress = false;
875
+
864
876
  this.fileMap[`${slpkChildPath}/textures/0.${format}`] = await writeFileForSlpk(
865
877
  slpkTexturePath,
866
878
  textureData,
867
879
  `0.${format}`,
868
880
  compress
869
881
  );
882
+
883
+ this.fileMap[`${slpkChildPath}/textures/1.ktx2`] = await writeFileForSlpk(
884
+ slpkTexturePath,
885
+ ktx2TextureData,
886
+ `1.ktx2`,
887
+ compress
888
+ );
870
889
  } else {
871
890
  const texturePath = join(childPath, 'textures/0/');
872
891
  await writeFile(texturePath, textureData, `index.${format}`);
892
+
893
+ const ktx2TexturePath = join(childPath, 'textures/1/');
894
+ await writeFile(ktx2TexturePath, ktx2TextureData, `index.ktx2`);
873
895
  }
874
896
  }
875
897
  }
@@ -1159,10 +1181,13 @@ export default class I3SConverter {
1159
1181
  * Fetch preload options for ION tileset
1160
1182
  */
1161
1183
  private async _fetchPreloadOptions(): Promise<any> {
1184
+ if (!this.Loader.preload) {
1185
+ return {};
1186
+ }
1162
1187
  const options = {
1163
1188
  'cesium-ion': {accessToken: this.options.token || ION_DEFAULT_TOKEN}
1164
1189
  };
1165
- const preloadOptions = await CesiumIonLoader.preload(this.options.inputUrl, options);
1190
+ const preloadOptions = await this.Loader.preload(this.options.inputUrl, options);
1166
1191
  this.refreshTokenTime = process.hrtime();
1167
1192
  return {...options, ...preloadOptions};
1168
1193
  }
@@ -13,7 +13,7 @@ export const METADATA = {
13
13
  },
14
14
  I3SVersion: {
15
15
  path: 'I3SVersion',
16
- default: '1.7'
16
+ default: '1.8'
17
17
  },
18
18
  nodeCount: {
19
19
  path: 'nodeCount'
@@ -14,7 +14,7 @@ export const SCENE_SERVER_TEMPLATE = {
14
14
  },
15
15
  serviceVersion: {
16
16
  path: 'serviceVersion',
17
- default: '1.7'
17
+ default: '1.8'
18
18
  },
19
19
  supportedBindings: {
20
20
  path: 'supportedBindings',
@@ -9,7 +9,7 @@ export const STORE = {
9
9
  },
10
10
  version: {
11
11
  path: 'version',
12
- default: '1.7'
12
+ default: '1.8'
13
13
  },
14
14
  resourcePattern: {
15
15
  path: 'resourcePattern',
@@ -40,7 +40,7 @@ export const STORE = {
40
40
  },
41
41
  textureEncoding: {
42
42
  path: 'textureEncoding',
43
- default: ['image/jpeg']
43
+ default: ['image/jpeg', 'image/ktx2']
44
44
  },
45
45
  lodType: {
46
46
  path: 'lodType',
@@ -7,7 +7,7 @@ const I3S_LAYER_PATH = process.env.I3sLayerPath || ''; // eslint-disable-line no
7
7
  const FULL_LAYER_PATH = path.join(process.cwd(), I3S_LAYER_PATH); // eslint-disable-line no-undef
8
8
 
9
9
  async function getFileNameByUrl(url) {
10
- const extensions = ['json', 'bin', 'jpg', 'jpeg', 'png', 'bin.dds'];
10
+ const extensions = ['json', 'bin', 'jpg', 'jpeg', 'png', 'bin.dds', 'ktx2'];
11
11
  for (const ext of extensions) {
12
12
  const fileName = `${FULL_LAYER_PATH}${url}/index.${ext}`;
13
13
  try {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/3d-tiles-converter/3d-tiles-converter.ts"],"names":["join","process","transform","load","I3SLoader","I3SAttributeLoader","Tileset3D","Tile3D","PGMLoader","i3sObbTo3dTilesObb","convertScreenThresholdToGeometricError","writeFile","removeDir","calculateFilesSize","timeConverter","TILESET","tilesetTemplate","B3dmConverter","createObbFromMbs","I3S","Tiles3DConverter","constructor","options","tilesetPath","vertexCounter","conversionStartTime","geoidHeightModel","sourceTileset","attributeStorageInfo","convert","inputUrl","outputPath","tilesetName","maxDepth","egmFilePath","hrtime","console","log","sourceTilesetJson","root","header","obb","mbs","e","rootTile","boundingVolume","box","geometricError","children","_addChildren","tileset","JSON","stringify","_finishConversion","slpk","parentSourceNode","parentNode","level","childNodeInfo","sourceChild","_loadChildNode","push","contentUrl","_loadTile","content","vertexCount","attributes","_loadChildAttributes","child","b3dm","uri","id","Uint8Array","unloadContent","nodePages","nodePagesTile","formTileFromNodePages","loader","nodeUrl","_relativeUrlToFullUrl","url","href","i3s","loadOptions","isTileHeader","loadContent","baseUrl","relativeUrl","resultArray","split","relativeUrlArray","folder","slice","promises","attributeUrls","index","length","attribute","attributeName","name","attributeType","_getAttributeType","attributesList","Promise","all","_replaceNestedArrays","Object","assign","attributeValues","valueType","objectIds","attributeObject","key","Array","from","params","filesSize","diff","conversionTime"],"mappings":";AAGA,SAAQA,IAAR,QAAmB,MAAnB;AACA,OAAOC,OAAP,MAAoB,SAApB;AACA,OAAOC,SAAP,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jCA,QAAAA,eAAe,CAACC,GAAD,CAAf,GAAuBC,KAAK,CAACC,IAAN,CAAWH,eAAe,CAACC,GAAD,CAA1B,CAAvB;AACD;AACF;AACF;;AAM8B,QAAjB3D,iBAAiB,CAAC8D,MAAD,EAIb;AAChB,UAAMC,SAAS,GAAG,MAAMvG,kBAAkB,CAACsG,MAAD,CAA1C;AACA,UAAME,IAAI,GAAGpH,OAAO,CAACkC,MAAR,CAAe,KAAKV,mBAApB,CAAb;AACA,UAAM6F,cAAc,GAAGxG,aAAa,CAACuG,IAAD,CAApC;AAEAjF,IAAAA,OAAO,CAACC,GAAR,CAAa,kDAAb;AACAD,IAAAA,OAAO,CAACC,GAAR,CAAa,wBAAuBlB,GAAI,EAAxC;AACAiB,IAAAA,OAAO,CAACC,GAAR,CAAa,0BAAyBiF,cAAe,EAArD;AACAlF,IAAAA,OAAO,CAACC,GAAR,CAAa,gBAAb,EAA8B,KAAKb,aAAnC;AACAY,IAAAA,OAAO,CAACC,GAAR,CAAa,gBAAb,EAA8B+E,SAA9B,EAAyC,QAAzC;AACAhF,IAAAA,OAAO,CAACC,GAAR,CAAa,kDAAb;AACD;;AApQmC","sourcesContent":["import type {AttributeStorageInfo, FeatureAttribute, NodeReference} from '@loaders.gl/i3s';\nimport type {Node3D} from '@loaders.gl/3d-tiles';\n\nimport {join} from 'path';\nimport process from 'process';\nimport transform from 'json-map-transform';\nimport {load} from '@loaders.gl/core';\nimport {I3SLoader, I3SAttributeLoader} from '@loaders.gl/i3s';\nimport {Tileset3D, Tile3D} from '@loaders.gl/tiles';\n\nimport {PGMLoader} from '../pgm-loader';\nimport {i3sObbTo3dTilesObb} from './helpers/i3s-obb-to-3d-tiles-obb';\nimport {convertScreenThresholdToGeometricError} from '../lib/utils/lod-conversion-utils';\nimport {writeFile, removeDir} from '../lib/utils/file-utils';\nimport {calculateFilesSize, timeConverter} from '../lib/utils/statistic-utills';\nimport {TILESET as tilesetTemplate} from './json-templates/tileset';\nimport B3dmConverter from './helpers/b3dm-converter';\nimport {createObbFromMbs} from '../i3s-converter/helpers/coordinate-converter';\nimport {GeoidHeightModel} from '../lib/geoid-height-model';\n\nconst I3S = 'I3S';\n\n/**\n * Converter from i3s to 3d-tiles\n */\nexport default class Tiles3DConverter {\n options: any;\n tilesetPath: string;\n vertexCounter: number;\n conversionStartTime: [number, number];\n geoidHeightModel: GeoidHeightModel;\n sourceTileset: Tileset3D;\n attributeStorageInfo: AttributeStorageInfo;\n\n constructor() {\n this.options = {};\n this.tilesetPath = '';\n this.vertexCounter = 0;\n this.conversionStartTime = [0, 0];\n this.geoidHeightModel = null;\n this.sourceTileset = null;\n this.attributeStorageInfo = null;\n }\n\n /**\n * Convert i3s format data to 3dTiles\n * @param options\n * @param options.inputUrl the url to read the tileset from\n * @param options.outputPath the output filename\n * @param options.tilesetName the output name of the tileset\n * @param options.egmFilePath location of *.pgm file to convert heights from ellipsoidal to gravity-related format\n * @param options.maxDepth The max tree depth of conversion\n */\n private async convert(options: {\n inputUrl: string;\n outputPath: string;\n tilesetName: string;\n maxDepth: number;\n egmFilePath: string;\n }): Promise<any> {\n const {inputUrl, outputPath, tilesetName, maxDepth, egmFilePath} = options;\n this.conversionStartTime = process.hrtime();\n this.options = {maxDepth};\n\n console.log('Loading egm file...'); // eslint-disable-line\n this.geoidHeightModel = await load(egmFilePath, PGMLoader);\n console.log('Loading egm file completed!'); // eslint-disable-line\n\n const sourceTilesetJson = await load(inputUrl, I3SLoader, {});\n this.sourceTileset = new Tileset3D(sourceTilesetJson, {});\n\n if (!this.sourceTileset.root.header.obb) {\n this.sourceTileset.root.header.obb = createObbFromMbs(this.sourceTileset.root.header.mbs);\n }\n\n this.tilesetPath = join(`${outputPath}`, `${tilesetName}`);\n this.attributeStorageInfo = sourceTilesetJson.attributeStorageInfo;\n // Removing the tilesetPath needed to exclude erroneous files after conversion\n try {\n await removeDir(this.tilesetPath);\n } catch (e) {\n // do nothing\n }\n\n const rootTile: Node3D = {\n boundingVolume: {\n box: i3sObbTo3dTilesObb(this.sourceTileset.root.header.obb, this.geoidHeightModel)\n },\n geometricError: convertScreenThresholdToGeometricError(this.sourceTileset.root),\n children: []\n };\n\n await this._addChildren(this.sourceTileset.root, rootTile, 1);\n\n const tileset = transform({root: rootTile}, tilesetTemplate);\n await writeFile(this.tilesetPath, JSON.stringify(tileset), 'tileset.json');\n\n this._finishConversion({slpk: false, outputPath, tilesetName});\n }\n\n /**\n * The recursive function of traversal of a nodes tree\n * @param parentSourceNode the parent node tile object (@loaders.gl/tiles/Tile3D)\n * @param parentNode object in resulting tileset\n * @param level a current level of a tree depth\n */\n private async _addChildren(\n parentSourceNode: Tile3D,\n parentNode: Node3D,\n level: number\n ): Promise<void> {\n if (this.options.maxDepth && level > this.options.maxDepth) {\n return;\n }\n for (const childNodeInfo of parentSourceNode.header.children || []) {\n const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);\n parentSourceNode.children.push(sourceChild);\n if (sourceChild.contentUrl) {\n await this.sourceTileset._loadTile(sourceChild);\n this.vertexCounter += sourceChild.content.vertexCount;\n\n let attributes = null;\n if (this.attributeStorageInfo) {\n attributes = await this._loadChildAttributes(sourceChild, this.attributeStorageInfo);\n }\n\n if (!sourceChild.header.obb) {\n sourceChild.header.obb = createObbFromMbs(sourceChild.header.mbs);\n }\n\n const boundingVolume = {\n box: i3sObbTo3dTilesObb(sourceChild.header.obb, this.geoidHeightModel)\n };\n const child: Node3D = {\n boundingVolume,\n geometricError: convertScreenThresholdToGeometricError(sourceChild),\n children: []\n };\n\n const b3dm = await new B3dmConverter().convert(sourceChild, attributes);\n child.content = {\n uri: `${sourceChild.id}.b3dm`,\n boundingVolume\n };\n await writeFile(this.tilesetPath, new Uint8Array(b3dm), `${sourceChild.id}.b3dm`);\n parentNode.children.push(child);\n\n sourceChild.unloadContent();\n await this._addChildren(sourceChild, child, level + 1);\n } else {\n await this._addChildren(sourceChild, parentNode, level + 1);\n }\n }\n }\n\n /**\n * Load a child node having information from the node header\n * @param parentNode a parent node tile object (@loaders.gl/tiles/Tile3D)\n * @param childNodeInfo child information from 3DNodeIndexDocument\n * (https://github.com/Esri/i3s-spec/blob/master/docs/1.7/nodeReference.cmn.md)\n */\n private async _loadChildNode(parentNode: Tile3D, childNodeInfo: NodeReference): Promise<Tile3D> {\n let header;\n if (this.sourceTileset.tileset.nodePages) {\n console.log(`Node conversion: ${childNodeInfo.id}`); // eslint-disable-line no-console,no-undef\n header = await this.sourceTileset.tileset.nodePagesTile.formTileFromNodePages(\n childNodeInfo.id\n );\n } else {\n const {loader} = this.sourceTileset;\n const nodeUrl = this._relativeUrlToFullUrl(parentNode.url, childNodeInfo.href);\n // load metadata\n const options = {\n i3s: {\n ...this.sourceTileset.loadOptions,\n isTileHeader: true,\n loadContent: false\n }\n };\n\n console.log(`Node conversion: ${nodeUrl}`); // eslint-disable-line no-console,no-undef\n header = await load(nodeUrl, loader, options);\n }\n return new Tile3D(this.sourceTileset, header, parentNode);\n }\n\n /**\n * Make an url of a resource from its relative url having the base url\n * @param baseUrl the base url. A resulting url will be related from this url\n * @param relativeUrl a realtive url of a resource\n */\n private _relativeUrlToFullUrl(baseUrl: string, relativeUrl: string): string {\n let resultArray = baseUrl.split('/');\n const relativeUrlArray = relativeUrl.split('/');\n for (const folder of relativeUrlArray) {\n switch (folder) {\n case '.':\n continue; // eslint-disable-line no-continue\n case '..':\n resultArray = resultArray.slice(0, -1);\n break;\n default:\n resultArray.push(folder);\n }\n }\n return resultArray.join('/');\n }\n\n /**\n * Do loading all attributes related to particular node.\n * @param sourceChild\n * @param attributeStorageInfo\n * @returns Promise of attributes object.\n */\n private async _loadChildAttributes(\n sourceChild: Tile3D,\n attributeStorageInfo: AttributeStorageInfo\n ): Promise<FeatureAttribute> {\n const promises = [];\n const {attributeUrls} = sourceChild.header;\n\n for (let index = 0; index < attributeUrls.length; index++) {\n const inputUrl = attributeUrls[index];\n const attribute = attributeStorageInfo[index];\n const options = {\n attributeName: attribute.name,\n attributeType: this._getAttributeType(attribute)\n };\n\n promises.push(load(inputUrl, I3SAttributeLoader, options));\n }\n const attributesList = await Promise.all(promises);\n this._replaceNestedArrays(attributesList);\n return Object.assign({}, ...attributesList);\n }\n\n /**\n * Returns attribute type for loading attributes\n * @param attribute\n * Workaround for I3S v1.6. There is no attribute.attributeValues.valueType field in attribute.\n * There is an 'Oid32' type if attribute has objectIds property.\n * Doc: https://github.com/Esri/i3s-spec/blob/master/docs/1.6/attributeStorageInfo.cmn.md\n */\n private _getAttributeType(attribute: AttributeStorageInfo): string {\n if (attribute.attributeValues) {\n return attribute.attributeValues.valueType;\n } else if (attribute.objectIds) {\n return 'Oid32';\n }\n return '';\n }\n\n /**\n * Make simple arrays from attribute typed arrays.\n * @param attributesList\n */\n private _replaceNestedArrays(attributesList: FeatureAttribute[]): void {\n for (let index = 0; index < attributesList.length; index++) {\n const attributeObject = attributesList[index];\n\n for (const key in attributeObject) {\n attributeObject[key] = Array.from(attributeObject[key]);\n }\n }\n }\n\n /**\n * Print statistics in the end of conversion\n * @param params - output files data\n */\n private async _finishConversion(params: {\n slpk: boolean;\n outputPath: string;\n tilesetName: string;\n }): Promise<void> {\n const filesSize = await calculateFilesSize(params);\n const diff = process.hrtime(this.conversionStartTime);\n const conversionTime = timeConverter(diff);\n\n console.log(`------------------------------------------------`); // eslint-disable-line\n console.log(`Finish conversion of ${I3S}`); // eslint-disable-line\n console.log(`Total conversion time: ${conversionTime}`); // eslint-disable-line\n console.log(`Vertex count: `, this.vertexCounter); // eslint-disable-line\n console.log(`File(s) size: `, filesSize, ' bytes'); // eslint-disable-line\n console.log(`------------------------------------------------`); // eslint-disable-line\n }\n}\n"],"file":"3d-tiles-converter.js"}