@loaders.gl/tile-converter 4.0.0-alpha.1 → 4.0.0-alpha.11

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 (502) hide show
  1. package/bin/converter.js +1 -1
  2. package/bin/slpk-extractor.js +4 -0
  3. package/dist/3d-tiles-attributes-worker.d.ts +28 -0
  4. package/dist/3d-tiles-attributes-worker.d.ts.map +1 -0
  5. package/dist/3d-tiles-attributes-worker.js +3 -0
  6. package/dist/3d-tiles-attributes-worker.js.map +7 -0
  7. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +90 -0
  8. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -0
  9. package/dist/3d-tiles-converter/3d-tiles-converter.js +275 -226
  10. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +71 -18
  11. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -0
  12. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +256 -236
  13. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +4 -7
  14. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts.map +1 -0
  15. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +22 -9
  16. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +9 -0
  17. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -0
  18. package/dist/3d-tiles-converter/helpers/texture-atlas.js +47 -28
  19. package/dist/3d-tiles-converter/json-templates/tileset.d.ts +15 -0
  20. package/dist/3d-tiles-converter/json-templates/tileset.d.ts.map +1 -0
  21. package/dist/3d-tiles-converter/json-templates/tileset.js +42 -36
  22. package/dist/bundle.d.ts +2 -0
  23. package/dist/bundle.d.ts.map +1 -0
  24. package/dist/bundle.js +2 -2
  25. package/dist/constants.d.ts +2 -0
  26. package/dist/constants.d.ts.map +1 -0
  27. package/dist/constants.js +4 -0
  28. package/dist/converter-cli.d.ts +2 -0
  29. package/dist/converter-cli.d.ts.map +1 -0
  30. package/dist/converter-cli.js +214 -0
  31. package/dist/converter.min.js +185 -190
  32. package/dist/deps-installer/deps-installer.d.ts +11 -3
  33. package/dist/deps-installer/deps-installer.d.ts.map +1 -0
  34. package/dist/deps-installer/deps-installer.js +61 -23
  35. package/dist/dist.min.js +64143 -0
  36. package/dist/es5/3d-tiles-attributes-worker.js +25 -0
  37. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -0
  38. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +467 -0
  39. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
  40. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +293 -0
  41. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
  42. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +18 -0
  43. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
  44. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +33 -0
  45. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  46. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +61 -0
  47. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -0
  48. package/dist/es5/bundle.js +6 -0
  49. package/dist/es5/bundle.js.map +1 -0
  50. package/dist/es5/constants.js +9 -0
  51. package/dist/es5/constants.js.map +1 -0
  52. package/dist/es5/converter-cli.js +244 -0
  53. package/dist/es5/converter-cli.js.map +1 -0
  54. package/dist/es5/deps-installer/deps-installer.js +124 -0
  55. package/dist/es5/deps-installer/deps-installer.js.map +1 -0
  56. package/dist/es5/i3s-attributes-worker.js +25 -0
  57. package/dist/es5/i3s-attributes-worker.js.map +1 -0
  58. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +116 -0
  59. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  60. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +89 -0
  61. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -0
  62. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +41 -0
  63. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
  64. package/dist/es5/i3s-converter/helpers/feature-attributes.js +174 -0
  65. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -0
  66. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +213 -0
  67. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -0
  68. package/dist/es5/i3s-converter/helpers/geometry-converter.js +1192 -0
  69. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -0
  70. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +113 -0
  71. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  72. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js +82 -0
  73. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js.map +1 -0
  74. package/dist/es5/i3s-converter/helpers/node-debug.js +76 -0
  75. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -0
  76. package/dist/es5/i3s-converter/helpers/node-index-document.js +521 -0
  77. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -0
  78. package/dist/es5/i3s-converter/helpers/node-pages.js +519 -0
  79. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -0
  80. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +111 -0
  81. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -0
  82. package/dist/es5/i3s-converter/helpers/tileset-traversal.js +82 -0
  83. package/dist/es5/i3s-converter/helpers/tileset-traversal.js.map +1 -0
  84. package/dist/es5/i3s-converter/i3s-converter.js +1541 -0
  85. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -0
  86. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js +107 -0
  87. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
  88. package/dist/es5/i3s-converter/json-templates/layers.js +163 -0
  89. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -0
  90. package/dist/es5/i3s-converter/json-templates/metadata.js +31 -0
  91. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -0
  92. package/dist/es5/i3s-converter/json-templates/node.js +99 -0
  93. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -0
  94. package/dist/es5/i3s-converter/json-templates/scene-server.js +39 -0
  95. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -0
  96. package/dist/es5/i3s-converter/json-templates/shared-resources.js +173 -0
  97. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -0
  98. package/dist/es5/i3s-converter/json-templates/store.js +107 -0
  99. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -0
  100. package/dist/es5/i3s-converter/types.js +18 -0
  101. package/dist/es5/i3s-converter/types.js.map +1 -0
  102. package/dist/es5/i3s-server/README.md +19 -0
  103. package/dist/es5/i3s-server/app.js +27 -0
  104. package/dist/es5/i3s-server/app.js.map +1 -0
  105. package/dist/es5/i3s-server/controllers/index-controller.js +55 -0
  106. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -0
  107. package/dist/es5/i3s-server/controllers/slpk-controller.js +84 -0
  108. package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -0
  109. package/dist/es5/i3s-server/routes/index.js +37 -0
  110. package/dist/es5/i3s-server/routes/index.js.map +1 -0
  111. package/dist/es5/i3s-server/routes/slpk-router.js +71 -0
  112. package/dist/es5/i3s-server/routes/slpk-router.js.map +1 -0
  113. package/dist/es5/i3s-server/utils/create-scene-server.js +17 -0
  114. package/dist/es5/i3s-server/utils/create-scene-server.js.map +1 -0
  115. package/dist/es5/index.js +21 -0
  116. package/dist/es5/index.js.map +1 -0
  117. package/dist/es5/lib/utils/cli-utils.js +57 -0
  118. package/dist/es5/lib/utils/cli-utils.js.map +1 -0
  119. package/dist/es5/lib/utils/compress-util.js +346 -0
  120. package/dist/es5/lib/utils/compress-util.js.map +1 -0
  121. package/dist/es5/lib/utils/file-utils.js +208 -0
  122. package/dist/es5/lib/utils/file-utils.js.map +1 -0
  123. package/dist/es5/lib/utils/geometry-utils.js +15 -0
  124. package/dist/es5/lib/utils/geometry-utils.js.map +1 -0
  125. package/dist/es5/lib/utils/lod-conversion-utils.js +44 -0
  126. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -0
  127. package/dist/es5/lib/utils/queue.js +47 -0
  128. package/dist/es5/lib/utils/queue.js.map +1 -0
  129. package/dist/es5/lib/utils/statistic-utills.d.ts +25 -0
  130. package/dist/es5/lib/utils/statistic-utills.js +147 -0
  131. package/dist/es5/lib/utils/statistic-utills.js.map +1 -0
  132. package/dist/es5/lib/utils/write-queue.js +214 -0
  133. package/dist/es5/lib/utils/write-queue.js.map +1 -0
  134. package/dist/es5/pgm-loader.js +41 -0
  135. package/dist/es5/pgm-loader.js.map +1 -0
  136. package/dist/es5/slpk-extractor/helpers/file-handle-provider.js +181 -0
  137. package/dist/es5/slpk-extractor/helpers/file-handle-provider.js.map +1 -0
  138. package/dist/es5/slpk-extractor/slpk-extractor.js +172 -0
  139. package/dist/es5/slpk-extractor/slpk-extractor.js.map +1 -0
  140. package/dist/es5/slpk-extractor-cli.js +117 -0
  141. package/dist/es5/slpk-extractor-cli.js.map +1 -0
  142. package/dist/es5/workers/3d-tiles-attributes-worker.js +28 -0
  143. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -0
  144. package/dist/es5/workers/i3s-attributes-worker.js +30 -0
  145. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -0
  146. package/dist/esm/3d-tiles-attributes-worker.js +16 -0
  147. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -0
  148. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +245 -0
  149. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
  150. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +218 -0
  151. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
  152. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +10 -0
  153. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
  154. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +27 -0
  155. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  156. package/dist/esm/3d-tiles-converter/json-templates/tileset.js +37 -0
  157. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -0
  158. package/dist/esm/bundle.js +4 -0
  159. package/dist/esm/bundle.js.map +1 -0
  160. package/dist/esm/constants.js +2 -0
  161. package/dist/esm/constants.js.map +1 -0
  162. package/dist/esm/converter-cli.js +187 -0
  163. package/dist/esm/converter-cli.js.map +1 -0
  164. package/dist/esm/deps-installer/deps-installer.js +45 -0
  165. package/dist/esm/deps-installer/deps-installer.js.map +1 -0
  166. package/dist/esm/i3s-attributes-worker.js +16 -0
  167. package/dist/esm/i3s-attributes-worker.js.map +1 -0
  168. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +105 -0
  169. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  170. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +79 -0
  171. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -0
  172. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +16 -0
  173. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
  174. package/dist/esm/i3s-converter/helpers/feature-attributes.js +147 -0
  175. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -0
  176. package/{src → dist/esm}/i3s-converter/helpers/geometry-attributes.js +80 -106
  177. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -0
  178. package/dist/esm/i3s-converter/helpers/geometry-converter.js +906 -0
  179. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -0
  180. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +110 -0
  181. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  182. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js +35 -0
  183. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js.map +1 -0
  184. package/{src → dist/esm}/i3s-converter/helpers/node-debug.js +20 -41
  185. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -0
  186. package/dist/esm/i3s-converter/helpers/node-index-document.js +201 -0
  187. package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -0
  188. package/dist/esm/i3s-converter/helpers/node-pages.js +206 -0
  189. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -0
  190. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +48 -0
  191. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -0
  192. package/dist/esm/i3s-converter/helpers/tileset-traversal.js +14 -0
  193. package/dist/esm/i3s-converter/helpers/tileset-traversal.js.map +1 -0
  194. package/dist/esm/i3s-converter/i3s-converter.js +778 -0
  195. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -0
  196. package/dist/esm/i3s-converter/json-templates/geometry-definitions.js +89 -0
  197. package/dist/esm/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
  198. package/dist/esm/i3s-converter/json-templates/layers.js +133 -0
  199. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -0
  200. package/dist/esm/i3s-converter/json-templates/metadata.js +22 -0
  201. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -0
  202. package/dist/esm/i3s-converter/json-templates/node.js +80 -0
  203. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -0
  204. package/dist/esm/i3s-converter/json-templates/scene-server.js +28 -0
  205. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -0
  206. package/dist/esm/i3s-converter/json-templates/shared-resources.js +123 -0
  207. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -0
  208. package/dist/esm/i3s-converter/json-templates/store.js +98 -0
  209. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -0
  210. package/dist/esm/i3s-converter/types.js +11 -0
  211. package/dist/esm/i3s-converter/types.js.map +1 -0
  212. package/dist/esm/i3s-server/README.md +19 -0
  213. package/dist/esm/i3s-server/app.js +26 -0
  214. package/dist/esm/i3s-server/app.js.map +1 -0
  215. package/dist/esm/i3s-server/bin/www +102 -0
  216. package/dist/esm/i3s-server/certs/cert.pem +19 -0
  217. package/dist/esm/i3s-server/certs/key.pem +27 -0
  218. package/dist/esm/i3s-server/controllers/index-controller.js +24 -0
  219. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -0
  220. package/dist/esm/i3s-server/controllers/slpk-controller.js +36 -0
  221. package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -0
  222. package/dist/esm/i3s-server/routes/index.js +16 -0
  223. package/dist/esm/i3s-server/routes/index.js.map +1 -0
  224. package/dist/esm/i3s-server/routes/slpk-router.js +33 -0
  225. package/dist/esm/i3s-server/routes/slpk-router.js.map +1 -0
  226. package/dist/esm/i3s-server/utils/create-scene-server.js +16 -0
  227. package/dist/esm/i3s-server/utils/create-scene-server.js.map +1 -0
  228. package/dist/esm/index.js +3 -0
  229. package/dist/esm/index.js.map +1 -0
  230. package/dist/esm/lib/utils/cli-utils.js +47 -0
  231. package/dist/esm/lib/utils/cli-utils.js.map +1 -0
  232. package/dist/esm/lib/utils/compress-util.js +168 -0
  233. package/dist/esm/lib/utils/compress-util.js.map +1 -0
  234. package/dist/esm/lib/utils/file-utils.js +87 -0
  235. package/dist/esm/lib/utils/file-utils.js.map +1 -0
  236. package/dist/esm/lib/utils/geometry-utils.js +8 -0
  237. package/dist/esm/lib/utils/geometry-utils.js.map +1 -0
  238. package/dist/esm/lib/utils/lod-conversion-utils.js +37 -0
  239. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -0
  240. package/dist/esm/lib/utils/queue.js +15 -0
  241. package/dist/esm/lib/utils/queue.js.map +1 -0
  242. package/dist/esm/lib/utils/statistic-utills.d.ts +25 -0
  243. package/dist/esm/lib/utils/statistic-utills.js +62 -0
  244. package/dist/esm/lib/utils/statistic-utills.js.map +1 -0
  245. package/dist/esm/lib/utils/write-queue.js +85 -0
  246. package/dist/esm/lib/utils/write-queue.js.map +1 -0
  247. package/dist/esm/pgm-loader.js +15 -0
  248. package/dist/esm/pgm-loader.js.map +1 -0
  249. package/dist/esm/slpk-extractor/helpers/file-handle-provider.js +43 -0
  250. package/dist/esm/slpk-extractor/helpers/file-handle-provider.js.map +1 -0
  251. package/dist/esm/slpk-extractor/slpk-extractor.js +63 -0
  252. package/dist/esm/slpk-extractor/slpk-extractor.js.map +1 -0
  253. package/dist/esm/slpk-extractor-cli.js +74 -0
  254. package/dist/esm/slpk-extractor-cli.js.map +1 -0
  255. package/dist/esm/workers/3d-tiles-attributes-worker.js +8 -0
  256. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -0
  257. package/dist/esm/workers/i3s-attributes-worker.js +7 -0
  258. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -0
  259. package/dist/i3s-attributes-worker.d.ts +45 -0
  260. package/dist/i3s-attributes-worker.d.ts.map +1 -0
  261. package/dist/i3s-attributes-worker.js +9 -0
  262. package/dist/i3s-attributes-worker.js.map +7 -0
  263. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +13 -0
  264. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -0
  265. package/dist/i3s-converter/helpers/batch-ids-extensions.js +138 -0
  266. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +39 -0
  267. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -0
  268. package/dist/i3s-converter/helpers/coordinate-converter.js +118 -42
  269. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +9 -0
  270. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -0
  271. package/dist/i3s-converter/helpers/create-scene-server-path.js +27 -15
  272. package/dist/i3s-converter/helpers/feature-attributes.d.ts +56 -0
  273. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -0
  274. package/dist/i3s-converter/helpers/feature-attributes.js +216 -0
  275. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +8 -0
  276. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -0
  277. package/dist/i3s-converter/helpers/geometry-attributes.js +188 -185
  278. package/dist/i3s-converter/helpers/geometry-converter.d.ts +41 -35
  279. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -0
  280. package/dist/i3s-converter/helpers/geometry-converter.js +1179 -650
  281. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +28 -0
  282. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -0
  283. package/dist/i3s-converter/helpers/gltf-attributes.js +129 -0
  284. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts +18 -0
  285. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts.map +1 -0
  286. package/dist/i3s-converter/helpers/load-3d-tiles.js +53 -0
  287. package/dist/i3s-converter/helpers/node-debug.d.ts +8 -0
  288. package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -0
  289. package/dist/i3s-converter/helpers/node-debug.js +106 -74
  290. package/dist/i3s-converter/helpers/node-index-document.d.ts +103 -0
  291. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -0
  292. package/dist/i3s-converter/helpers/node-index-document.js +268 -0
  293. package/dist/i3s-converter/helpers/node-pages.d.ts +125 -113
  294. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -0
  295. package/dist/i3s-converter/helpers/node-pages.js +313 -133
  296. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +22 -0
  297. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -0
  298. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +75 -0
  299. package/dist/i3s-converter/helpers/tileset-traversal.d.ts +25 -0
  300. package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -0
  301. package/dist/i3s-converter/helpers/tileset-traversal.js +29 -0
  302. package/dist/i3s-converter/i3s-converter.d.ts +267 -0
  303. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -0
  304. package/dist/i3s-converter/i3s-converter.js +891 -867
  305. package/dist/i3s-converter/json-templates/geometry-definitions.d.ts +7 -0
  306. package/dist/i3s-converter/json-templates/geometry-definitions.d.ts.map +1 -0
  307. package/dist/i3s-converter/json-templates/geometry-definitions.js +87 -0
  308. package/dist/i3s-converter/json-templates/layers.d.ts +70 -0
  309. package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -0
  310. package/dist/i3s-converter/json-templates/layers.js +138 -190
  311. package/dist/i3s-converter/json-templates/metadata.d.ts +22 -0
  312. package/dist/i3s-converter/json-templates/metadata.d.ts.map +1 -0
  313. package/dist/i3s-converter/json-templates/metadata.js +25 -22
  314. package/dist/i3s-converter/json-templates/node.d.ts +61 -0
  315. package/dist/i3s-converter/json-templates/node.d.ts.map +1 -0
  316. package/dist/i3s-converter/json-templates/node.js +88 -79
  317. package/dist/i3s-converter/json-templates/scene-server.d.ts +28 -0
  318. package/dist/i3s-converter/json-templates/scene-server.d.ts.map +1 -0
  319. package/dist/i3s-converter/json-templates/scene-server.js +31 -28
  320. package/dist/i3s-converter/json-templates/shared-resources.d.ts +14 -0
  321. package/dist/i3s-converter/json-templates/shared-resources.d.ts.map +1 -0
  322. package/dist/i3s-converter/json-templates/shared-resources.js +124 -125
  323. package/dist/i3s-converter/json-templates/store.d.ts +95 -0
  324. package/dist/i3s-converter/json-templates/store.d.ts.map +1 -0
  325. package/dist/i3s-converter/json-templates/store.js +100 -95
  326. package/dist/i3s-converter/types.d.ts +163 -0
  327. package/dist/i3s-converter/types.d.ts.map +1 -0
  328. package/dist/i3s-converter/types.js +17 -0
  329. package/dist/i3s-server/app.d.ts +3 -0
  330. package/dist/i3s-server/app.d.ts.map +1 -0
  331. package/dist/i3s-server/app.js +11 -10
  332. package/dist/i3s-server/controllers/index-controller.d.ts +2 -0
  333. package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -0
  334. package/dist/i3s-server/controllers/index-controller.js +16 -24
  335. package/dist/i3s-server/controllers/slpk-controller.d.ts +3 -0
  336. package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -0
  337. package/dist/i3s-server/controllers/slpk-controller.js +32 -0
  338. package/dist/i3s-server/routes/index.d.ts +3 -0
  339. package/dist/i3s-server/routes/index.d.ts.map +1 -0
  340. package/dist/i3s-server/routes/index.js +11 -15
  341. package/dist/i3s-server/routes/slpk-router.d.ts +3 -0
  342. package/dist/i3s-server/routes/slpk-router.d.ts.map +1 -0
  343. package/dist/i3s-server/routes/slpk-router.js +33 -0
  344. package/dist/i3s-server/utils/create-scene-server.d.ts +11 -0
  345. package/dist/i3s-server/utils/create-scene-server.d.ts.map +1 -0
  346. package/dist/i3s-server/utils/create-scene-server.js +14 -0
  347. package/dist/index.d.ts +3 -0
  348. package/dist/index.d.ts.map +1 -0
  349. package/dist/index.js +10 -5
  350. package/dist/lib/utils/cli-utils.d.ts +34 -0
  351. package/dist/lib/utils/cli-utils.d.ts.map +1 -0
  352. package/dist/lib/utils/cli-utils.js +82 -0
  353. package/dist/lib/utils/compress-util.d.ts +45 -0
  354. package/dist/lib/utils/compress-util.d.ts.map +1 -0
  355. package/dist/lib/utils/compress-util.js +238 -160
  356. package/dist/lib/utils/file-utils.d.ts +22 -14
  357. package/dist/lib/utils/file-utils.d.ts.map +1 -0
  358. package/dist/lib/utils/file-utils.js +134 -36
  359. package/dist/lib/utils/geometry-utils.d.ts +9 -0
  360. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  361. package/dist/lib/utils/geometry-utils.js +18 -0
  362. package/dist/lib/utils/lod-conversion-utils.d.ts +23 -13
  363. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -0
  364. package/dist/lib/utils/lod-conversion-utils.js +72 -39
  365. package/dist/lib/utils/queue.d.ts +7 -0
  366. package/dist/lib/utils/queue.d.ts.map +1 -0
  367. package/dist/lib/utils/queue.js +18 -0
  368. package/dist/lib/utils/statistic-utills.d.ts +3 -25
  369. package/dist/lib/utils/statistic-utills.d.ts.map +1 -0
  370. package/dist/lib/utils/statistic-utills.js +58 -67
  371. package/dist/lib/utils/write-queue.d.ts +39 -0
  372. package/dist/lib/utils/write-queue.d.ts.map +1 -0
  373. package/dist/lib/utils/write-queue.js +80 -0
  374. package/dist/pgm-loader.d.ts +6 -0
  375. package/dist/pgm-loader.d.ts.map +1 -0
  376. package/dist/pgm-loader.js +23 -14
  377. package/dist/slpk-extractor/helpers/file-handle-provider.d.ts +48 -0
  378. package/dist/slpk-extractor/helpers/file-handle-provider.d.ts.map +1 -0
  379. package/dist/slpk-extractor/helpers/file-handle-provider.js +71 -0
  380. package/dist/slpk-extractor/slpk-extractor.d.ts +23 -0
  381. package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -0
  382. package/dist/slpk-extractor/slpk-extractor.js +78 -0
  383. package/dist/slpk-extractor-cli.d.ts +17 -0
  384. package/dist/slpk-extractor-cli.d.ts.map +1 -0
  385. package/dist/slpk-extractor-cli.js +102 -0
  386. package/dist/slpk-extractor.min.js +189 -0
  387. package/dist/workers/3d-tiles-attributes-worker.d.ts +2 -0
  388. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +1 -0
  389. package/dist/workers/3d-tiles-attributes-worker.js +9 -0
  390. package/dist/workers/i3s-attributes-worker.d.ts +2 -0
  391. package/dist/workers/i3s-attributes-worker.d.ts.map +1 -0
  392. package/dist/workers/i3s-attributes-worker.js +5 -0
  393. package/package.json +36 -24
  394. package/src/3d-tiles-attributes-worker.ts +43 -0
  395. package/src/3d-tiles-converter/3d-tiles-converter.ts +131 -63
  396. package/src/3d-tiles-converter/helpers/{b3dm-converter.js → b3dm-converter.ts} +72 -53
  397. package/src/3d-tiles-converter/helpers/{i3s-obb-to-3d-tiles-obb.js → i3s-obb-to-3d-tiles-obb.ts} +16 -1
  398. package/src/3d-tiles-converter/helpers/texture-atlas.ts +4 -4
  399. package/src/3d-tiles-converter/json-templates/{tileset.js → tileset.ts} +9 -9
  400. package/src/constants.ts +2 -0
  401. package/src/converter-cli.ts +305 -0
  402. package/src/deps-installer/deps-installer.ts +72 -0
  403. package/src/i3s-attributes-worker.ts +59 -0
  404. package/src/i3s-converter/helpers/batch-ids-extensions.ts +202 -0
  405. package/src/i3s-converter/helpers/coordinate-converter.ts +94 -34
  406. package/src/i3s-converter/helpers/create-scene-server-path.ts +29 -0
  407. package/src/i3s-converter/helpers/feature-attributes.ts +247 -0
  408. package/src/i3s-converter/helpers/geometry-attributes.ts +267 -0
  409. package/src/i3s-converter/helpers/geometry-converter.ts +1667 -0
  410. package/src/i3s-converter/helpers/gltf-attributes.ts +162 -0
  411. package/src/i3s-converter/helpers/load-3d-tiles.ts +68 -0
  412. package/src/i3s-converter/helpers/node-debug.ts +146 -0
  413. package/src/i3s-converter/helpers/node-index-document.ts +335 -0
  414. package/src/i3s-converter/helpers/node-pages.ts +344 -0
  415. package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +79 -0
  416. package/src/i3s-converter/helpers/tileset-traversal.ts +51 -0
  417. package/src/i3s-converter/i3s-converter.ts +650 -669
  418. package/src/i3s-converter/json-templates/geometry-definitions.ts +83 -0
  419. package/src/i3s-converter/json-templates/layers.ts +137 -0
  420. package/src/i3s-converter/json-templates/{metadata.js → metadata.ts} +2 -2
  421. package/src/i3s-converter/json-templates/{node.js → node.ts} +12 -12
  422. package/src/i3s-converter/json-templates/{scene-server.js → scene-server.ts} +2 -2
  423. package/src/i3s-converter/json-templates/{shared-resources.js → shared-resources.ts} +17 -17
  424. package/src/i3s-converter/types.ts +185 -0
  425. package/src/i3s-server/README.md +19 -0
  426. package/src/i3s-server/app.js +8 -1
  427. package/src/i3s-server/controllers/slpk-controller.js +38 -0
  428. package/src/i3s-server/routes/slpk-router.js +33 -0
  429. package/src/i3s-server/utils/create-scene-server.js +15 -0
  430. package/src/index.ts +0 -4
  431. package/src/lib/utils/cli-utils.ts +78 -0
  432. package/src/lib/utils/{compress-util.js → compress-util.ts} +105 -18
  433. package/src/lib/utils/file-utils.ts +140 -0
  434. package/src/lib/utils/geometry-utils.ts +14 -0
  435. package/src/lib/utils/{lod-conversion-utils.js → lod-conversion-utils.ts} +31 -5
  436. package/src/lib/utils/queue.ts +17 -0
  437. package/src/lib/utils/write-queue.ts +110 -0
  438. package/src/pgm-loader.ts +3 -3
  439. package/src/slpk-extractor/helpers/file-handle-provider.ts +91 -0
  440. package/src/slpk-extractor/slpk-extractor.ts +102 -0
  441. package/src/slpk-extractor-cli.ts +128 -0
  442. package/src/workers/3d-tiles-attributes-worker.ts +6 -0
  443. package/src/workers/i3s-attributes-worker.ts +7 -0
  444. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
  445. package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
  446. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
  447. package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
  448. package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
  449. package/dist/bundle.js.map +0 -1
  450. package/dist/deps-installer/deps-installer.js.map +0 -1
  451. package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
  452. package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
  453. package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
  454. package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
  455. package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
  456. package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
  457. package/dist/i3s-converter/i3s-converter.js.map +0 -1
  458. package/dist/i3s-converter/json-templates/layers.js.map +0 -1
  459. package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
  460. package/dist/i3s-converter/json-templates/node.js.map +0 -1
  461. package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
  462. package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
  463. package/dist/i3s-converter/json-templates/store.js.map +0 -1
  464. package/dist/i3s-server/app.js.map +0 -1
  465. package/dist/i3s-server/controllers/index-controller.js.map +0 -1
  466. package/dist/i3s-server/routes/index.js.map +0 -1
  467. package/dist/index.js.map +0 -1
  468. package/dist/lib/geoid-height-model.d.ts +0 -41
  469. package/dist/lib/geoid-height-model.js +0 -140
  470. package/dist/lib/geoid-height-model.js.map +0 -1
  471. package/dist/lib/pgm-parser.d.ts +0 -14
  472. package/dist/lib/pgm-parser.js +0 -183
  473. package/dist/lib/pgm-parser.js.map +0 -1
  474. package/dist/lib/utils/compress-util.js.map +0 -1
  475. package/dist/lib/utils/compress-utils.d.ts +0 -53
  476. package/dist/lib/utils/file-utils.js.map +0 -1
  477. package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
  478. package/dist/lib/utils/statistic-utills.js.map +0 -1
  479. package/dist/pgm-loader.js.map +0 -1
  480. package/src/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  481. package/src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  482. package/src/deps-installer/deps-installer.d.ts +0 -10
  483. package/src/deps-installer/deps-installer.js +0 -22
  484. package/src/i3s-converter/helpers/create-scene-server-path.js +0 -25
  485. package/src/i3s-converter/helpers/geometry-converter.d.ts +0 -40
  486. package/src/i3s-converter/helpers/geometry-converter.js +0 -915
  487. package/src/i3s-converter/helpers/node-pages.d.ts +0 -144
  488. package/src/i3s-converter/helpers/node-pages.js +0 -208
  489. package/src/i3s-converter/json-templates/layers.js +0 -199
  490. package/src/lib/geoid-height-model.d.ts +0 -41
  491. package/src/lib/geoid-height-model.js +0 -239
  492. package/src/lib/pgm-parser.d.ts +0 -14
  493. package/src/lib/pgm-parser.js +0 -179
  494. package/src/lib/utils/compress-utils.d.ts +0 -53
  495. package/src/lib/utils/file-utils.d.ts +0 -43
  496. package/src/lib/utils/file-utils.js +0 -38
  497. package/src/lib/utils/lod-conversion-utils.d.ts +0 -32
  498. /package/dist/{i3s-server → es5/i3s-server}/bin/www +0 -0
  499. /package/dist/{i3s-server → es5/i3s-server}/certs/cert.pem +0 -0
  500. /package/dist/{i3s-server → es5/i3s-server}/certs/key.pem +0 -0
  501. /package/src/i3s-converter/json-templates/{store.js → store.ts} +0 -0
  502. /package/src/lib/utils/{statistic-utills.js → statistic-utills.ts} +0 -0
@@ -1,887 +1,911 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { load, encode } from '@loaders.gl/core';
3
- import { Tileset3D } from '@loaders.gl/tiles';
4
- import { CesiumIonLoader } from '@loaders.gl/3d-tiles';
5
- import { join } from 'path';
6
- import { v4 as uuidv4 } from 'uuid';
7
- import process from 'process';
8
- import transform from 'json-map-transform';
9
- import md5 from 'md5';
10
- import NodePages from './helpers/node-pages';
11
- import { writeFile, removeDir, writeFileForSlpk } from '../lib/utils/file-utils';
12
- import { compressWithChildProcess } from '../lib/utils/compress-util';
13
- import { calculateFilesSize, timeConverter } from '../lib/utils/statistic-utills';
14
- import convertB3dmToI3sGeometry from './helpers/geometry-converter';
15
- import { createBoundingVolumes, convertCommonToI3SExtentCoordinate } from './helpers/coordinate-converter';
16
- import { createSceneServerPath } from './helpers/create-scene-server-path';
17
- import { convertGeometricErrorToScreenThreshold } from '../lib/utils/lod-conversion-utils';
18
- import { PGMLoader } from '../pgm-loader';
19
- import { LAYERS as layersTemplate } from './json-templates/layers';
20
- import { NODE as nodeTemplate } from './json-templates/node';
21
- import { SHARED_RESOURCES_TEMPLATE } from './json-templates/shared-resources';
22
- import { validateNodeBoundingVolumes } from './helpers/node-debug';
23
- import { KTX2BasisUniversalTextureWriter } from '@loaders.gl/textures';
24
- const ION_DEFAULT_TOKEN = process.env.IonToken || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJlYWMxMzcyYy0zZjJkLTQwODctODNlNi01MDRkZmMzMjIxOWIiLCJpZCI6OTYyMCwic2NvcGVzIjpbImFzbCIsImFzciIsImdjIl0sImlhdCI6MTU2Mjg2NjI3M30.1FNiClUyk00YH_nWfSGpiQAjR5V2OvREDq1PJ5QMjWQ';
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ const core_1 = require("@loaders.gl/core");
31
+ const _3d_tiles_1 = require("@loaders.gl/3d-tiles");
32
+ const path_1 = require("path");
33
+ const uuid_1 = require("uuid");
34
+ const process_1 = __importDefault(require("process"));
35
+ const json_map_transform_1 = __importDefault(require("json-map-transform"));
36
+ const md5_1 = __importDefault(require("md5"));
37
+ const node_pages_1 = __importDefault(require("./helpers/node-pages"));
38
+ const file_utils_1 = require("../lib/utils/file-utils");
39
+ const compress_util_1 = require("../lib/utils/compress-util");
40
+ const statistic_utills_1 = require("../lib/utils/statistic-utills");
41
+ const geometry_converter_1 = __importStar(require("./helpers/geometry-converter"));
42
+ const coordinate_converter_1 = require("./helpers/coordinate-converter");
43
+ const create_scene_server_path_1 = require("./helpers/create-scene-server-path");
44
+ const lod_conversion_utils_1 = require("../lib/utils/lod-conversion-utils");
45
+ const pgm_loader_1 = require("../pgm-loader");
46
+ const layers_1 = require("./json-templates/layers");
47
+ const geometry_definitions_1 = require("./json-templates/geometry-definitions");
48
+ const shared_resources_1 = require("./json-templates/shared-resources");
49
+ const node_debug_1 = require("./helpers/node-debug");
50
+ const textures_1 = require("@loaders.gl/textures");
51
+ const images_1 = require("@loaders.gl/images");
52
+ const types_1 = require("./types");
53
+ const worker_utils_1 = require("@loaders.gl/worker-utils");
54
+ const draco_1 = require("@loaders.gl/draco");
55
+ const write_queue_1 = __importDefault(require("../lib/utils/write-queue"));
56
+ const i3s_attributes_worker_1 = require("../i3s-attributes-worker");
57
+ const constants_1 = require("../constants");
58
+ const feature_attributes_1 = require("./helpers/feature-attributes");
59
+ const node_index_document_1 = require("./helpers/node-index-document");
60
+ const load_3d_tiles_1 = require("./helpers/load-3d-tiles");
61
+ const core_2 = require("@math.gl/core");
62
+ const tiles_1 = require("@loaders.gl/tiles");
63
+ const tileset_traversal_1 = require("./helpers/tileset-traversal");
64
+ const preprocess_3d_tiles_1 = require("./helpers/preprocess-3d-tiles");
65
+ const ION_DEFAULT_TOKEN = process_1.default.env?.IonToken || // eslint-disable-line
66
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJlYWMxMzcyYy0zZjJkLTQwODctODNlNi01MDRkZmMzMjIxOWIiLCJpZCI6OTYyMCwic2NvcGVzIjpbImFzbCIsImFzciIsImdjIl0sImlhdCI6MTU2Mjg2NjI3M30.1FNiClUyk00YH_nWfSGpiQAjR5V2OvREDq1PJ5QMjWQ'; // eslint-disable-line
25
67
  const HARDCODED_NODES_PER_PAGE = 64;
26
68
  const _3D_TILES = '3DTILES';
27
69
  const _3D_OBJECT_LAYER_TYPE = '3DObject';
28
- const STRING_TYPE = 'string';
29
- const SHORT_INT_TYPE = 'Int32';
30
- const DOUBLE_TYPE = 'double';
31
- const OBJECT_ID_TYPE = 'OBJECTID';
32
- const REFRESH_TOKEN_TIMEOUT = 1800;
33
- export default class I3SConverter {
34
- constructor() {
35
- _defineProperty(this, "nodePages", void 0);
36
-
37
- _defineProperty(this, "fileMap", void 0);
38
-
39
- _defineProperty(this, "options", void 0);
40
-
41
- _defineProperty(this, "layers0Path", void 0);
42
-
43
- _defineProperty(this, "materialMap", void 0);
44
-
45
- _defineProperty(this, "materialDefinitions", void 0);
46
-
47
- _defineProperty(this, "vertexCounter", void 0);
48
-
49
- _defineProperty(this, "layers0", void 0);
50
-
51
- _defineProperty(this, "featuresHashArray", void 0);
52
-
53
- _defineProperty(this, "refinementCounter", void 0);
54
-
55
- _defineProperty(this, "validate", void 0);
56
-
57
- _defineProperty(this, "boundingVolumeWarnings", void 0);
58
-
59
- _defineProperty(this, "conversionStartTime", void 0);
60
-
61
- _defineProperty(this, "refreshTokenTime", void 0);
62
-
63
- _defineProperty(this, "sourceTileset", void 0);
64
-
65
- _defineProperty(this, "geoidHeightModel", void 0);
66
-
67
- this.nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE);
68
- this.fileMap = {};
69
- this.options = {};
70
- this.layers0Path = '';
71
- this.materialMap = new Map();
72
- this.materialDefinitions = [];
73
- this.vertexCounter = 0;
74
- this.layers0 = null;
75
- this.featuresHashArray = [];
76
- this.refinementCounter = {
77
- tilesCount: 0,
78
- tilesWithAddRefineCount: 0
79
- };
80
- this.validate = false;
81
- this.boundingVolumeWarnings = null;
82
- }
83
-
84
- async convert(options) {
85
- this.conversionStartTime = process.hrtime();
86
- const {
87
- tilesetName,
88
- slpk,
89
- egmFilePath,
90
- inputUrl,
91
- validate,
92
- outputPath,
93
- draco,
94
- sevenZipExe,
95
- maxDepth,
96
- token
97
- } = options;
98
- this.options = {
99
- maxDepth,
100
- slpk,
101
- sevenZipExe,
102
- egmFilePath,
103
- draco,
104
- token,
105
- inputUrl
106
- };
107
- this.validate = validate;
108
- console.log('Loading egm file...');
109
- this.geoidHeightModel = await load(egmFilePath, PGMLoader);
110
- console.log('Loading egm file completed!');
111
-
112
- if (slpk) {
113
- this.nodePages.useWriteFunction(writeFileForSlpk);
114
- }
115
-
116
- const preloadOptions = await this._fetchPreloadOptions();
117
- const tilesetOptions = {
118
- loadOptions: {}
119
- };
120
-
121
- if (preloadOptions.headers) {
122
- tilesetOptions.loadOptions.fetch = {
123
- headers: preloadOptions.headers
124
- };
125
- }
126
-
127
- Object.assign(tilesetOptions, preloadOptions);
128
- const sourceTilesetJson = await load(inputUrl, CesiumIonLoader, tilesetOptions.loadOptions);
129
- this.sourceTileset = new Tileset3D(sourceTilesetJson, tilesetOptions);
130
- await this._createAndSaveTileset(outputPath, tilesetName);
131
- await this._finishConversion({
132
- slpk,
133
- outputPath,
134
- tilesetName
135
- });
136
- return sourceTilesetJson;
137
- }
138
-
139
- async _createAndSaveTileset(outputPath, tilesetName) {
140
- const tilesetPath = join("".concat(outputPath), "".concat(tilesetName));
141
-
142
- try {
143
- await removeDir(tilesetPath);
144
- } catch (e) {}
145
-
146
- this.layers0Path = join(tilesetPath, 'SceneServer', 'layers', '0');
147
-
148
- this._formLayers0(tilesetName);
149
-
150
- this.materialDefinitions = [];
151
- this.materialMap = new Map();
152
- const sourceRootTile = this.sourceTileset.root;
153
- const boundingVolumes = createBoundingVolumes(sourceRootTile, this.geoidHeightModel);
154
- const parentId = this.nodePages.push({
155
- lodThreshold: 0,
156
- obb: boundingVolumes.obb,
157
- children: []
158
- });
159
- const isCreateSlpk = this.options.slpk;
160
-
161
- const root0 = this._formRootNodeIndexDocument(boundingVolumes);
162
-
163
- await this._convertNodesTree(root0, sourceRootTile, parentId, boundingVolumes);
164
- this.layers0.materialDefinitions = this.materialDefinitions;
165
- await this._writeLayers0();
166
- createSceneServerPath(tilesetName, this.layers0, tilesetPath);
167
- await this._writeNodeIndexDocument(root0, 'root', join(this.layers0Path, 'nodes', 'root'));
168
- await this.nodePages.save(this.layers0Path, this.fileMap, isCreateSlpk);
169
- await this._createSlpk(tilesetPath);
170
- }
171
-
172
- _formLayers0(tilesetName) {
173
- const extent = convertCommonToI3SExtentCoordinate(this.sourceTileset);
174
- const layers0data = {
175
- version: "{".concat(uuidv4().toUpperCase(), "}"),
176
- id: 0,
177
- name: tilesetName,
178
- href: './layers/0',
179
- store: {
180
- id: "{".concat(uuidv4().toUpperCase(), "}"),
181
- extent
182
- },
183
- nodePages: {
184
- nodesPerPage: HARDCODED_NODES_PER_PAGE
185
- },
186
- compressGeometry: this.options.draco
187
- };
188
- this.layers0 = transform(layers0data, layersTemplate);
189
- }
190
-
191
- _formRootNodeIndexDocument(boundingVolumes) {
192
- const root0data = {
193
- version: "{".concat(uuidv4().toUpperCase(), "}"),
194
- id: 'root',
195
- level: 0,
196
- lodSelection: [{
197
- metricType: 'maxScreenThresholdSQ',
198
- maxError: 0
199
- }, {
200
- metricType: 'maxScreenThreshold',
201
- maxError: 0
202
- }],
203
- ...boundingVolumes,
204
- children: []
205
- };
206
- return transform(root0data, nodeTemplate);
207
- }
208
-
209
- async _convertNodesTree(root0, sourceRootTile, parentId, boundingVolumes) {
210
- await this.sourceTileset._loadTile(sourceRootTile);
211
-
212
- if (sourceRootTile.content && sourceRootTile.content.type === 'b3dm') {
213
- root0.children.push({
214
- id: '1',
215
- href: './1',
216
- ...boundingVolumes
217
- });
218
- const [child] = await this._createNode(root0, sourceRootTile, parentId, 0);
219
- const childPath = join(this.layers0Path, 'nodes', child.path);
220
-
221
- if (this.options.slpk) {
222
- this.fileMap['nodes/1/3dNodeIndexDocument.json.gz'] = await writeFileForSlpk(childPath, JSON.stringify(child), '3dNodeIndexDocument.json');
223
- } else {
224
- await writeFile(childPath, JSON.stringify(child));
225
- }
226
- } else {
227
- await this._addChildrenWithNeighborsAndWriteFile({
228
- parentNode: root0,
229
- sourceTiles: sourceRootTile.children,
230
- parentId,
231
- level: 1
232
- });
233
- }
234
-
235
- await sourceRootTile.unloadContent();
236
- }
237
-
238
- async _writeLayers0() {
239
- if (this.options.slpk) {
240
- this.fileMap['3dSceneLayer.json.gz'] = await writeFileForSlpk(this.layers0Path, JSON.stringify(this.layers0), '3dSceneLayer.json');
241
- } else {
242
- await writeFile(this.layers0Path, JSON.stringify(this.layers0));
243
- }
244
- }
245
-
246
- async _writeNodeIndexDocument(root0, nodePath, rootPath) {
247
- if (this.options.slpk) {
248
- this.fileMap["nodes/".concat(nodePath, "/3dNodeIndexDocument.json.gz")] = await writeFileForSlpk(rootPath, JSON.stringify(root0), '3dNodeIndexDocument.json');
249
- } else {
250
- await writeFile(rootPath, JSON.stringify(root0));
251
- }
252
- }
253
-
254
- async _createSlpk(tilesetPath) {
255
- if (this.options.slpk) {
256
- const slpkTilesetPath = join(tilesetPath, 'SceneServer', 'layers', '0');
257
- const slpkFileName = "".concat(tilesetPath, ".slpk");
258
- await compressWithChildProcess(slpkTilesetPath, slpkFileName, 0, '.', this.options.sevenZipExe);
259
-
260
- try {
261
- await removeDir(tilesetPath);
262
- } catch (e) {}
263
- }
264
- }
265
-
266
- async _addChildrenWithNeighborsAndWriteFile(data) {
267
- const childNodes = [];
268
- await this._addChildren({ ...data,
269
- childNodes
270
- });
271
- await this._addNeighborsAndWriteFile(data.parentNode, childNodes);
272
- }
273
-
274
- async _addChildren(data) {
275
- const {
276
- childNodes,
277
- sourceTiles,
278
- parentNode,
279
- parentId,
280
- level
281
- } = data;
282
-
283
- if (this.options.maxDepth && level > this.options.maxDepth) {
284
- return;
285
- }
286
-
287
- for (const sourceTile of sourceTiles) {
288
- if (sourceTile.type === 'json') {
289
- await this.sourceTileset._loadTile(sourceTile);
290
- await this._addChildren({
291
- parentNode,
292
- sourceTiles: sourceTile.children,
293
- childNodes,
294
- parentId,
295
- level: level + 1
70
+ const REFRESH_TOKEN_TIMEOUT = 1800; // 30 minutes in seconds
71
+ const CESIUM_DATASET_PREFIX = 'https://';
72
+ // const FS_FILE_TOO_LARGE = 'ERR_FS_FILE_TOO_LARGE';
73
+ /**
74
+ * Converter from 3d-tiles tileset to i3s layer
75
+ */
76
+ class I3SConverter {
77
+ constructor() {
78
+ this.boundingVolumeWarnings = [];
79
+ this.conversionStartTime = [0, 0];
80
+ this.refreshTokenTime = [0, 0];
81
+ this.sourceTileset = null;
82
+ this.loadOptions = {
83
+ _nodeWorkers: true,
84
+ reuseWorkers: true,
85
+ basis: {
86
+ format: 'rgba32',
87
+ // We need to load local fs workers because nodejs can't load workers from the Internet
88
+ workerUrl: './modules/textures/dist/basis-worker-node.js'
89
+ },
90
+ // We need to load local fs workers because nodejs can't load workers from the Internet
91
+ draco: { workerUrl: './modules/draco/dist/draco-worker-node.js' },
92
+ fetch: {}
93
+ };
94
+ this.geoidHeightModel = null;
95
+ this.Loader = _3d_tiles_1.Tiles3DLoader;
96
+ this.workerSource = {};
97
+ this.writeQueue = new write_queue_1.default();
98
+ this.compressList = null;
99
+ this.preprocessData = {
100
+ meshTopologyTypes: new Set()
101
+ };
102
+ this.nodePages = new node_pages_1.default(file_utils_1.writeFile, HARDCODED_NODES_PER_PAGE, this);
103
+ this.options = {};
104
+ this.layers0Path = '';
105
+ this.materialMap = new Map();
106
+ this.materialDefinitions = [];
107
+ this.geometryMap = new Map();
108
+ this.geometryConfigs = [];
109
+ this.vertexCounter = 0;
110
+ this.layers0 = null;
111
+ this.featuresHashArray = [];
112
+ this.refinementCounter = {
113
+ tilesCount: 0,
114
+ tilesWithAddRefineCount: 0
115
+ };
116
+ this.validate = false;
117
+ this.generateTextures = false;
118
+ this.generateBoundingVolumes = false;
119
+ this.layersHasTexture = false;
120
+ this.compressList = null;
121
+ }
122
+ /**
123
+ * Convert a 3d tileset
124
+ * @param options
125
+ * @param options.inputUrl the url to read the tileset from
126
+ * @param options.outputPath the output filename
127
+ * @param options.tilesetName the output name of the tileset
128
+ * @param options.maxDepth The max tree depth of conversion
129
+ * @param options.slpk Generate slpk (Scene Layer Packages) output file
130
+ * @param options.sevenZipExe Location of 7z.exe archiver to create slpk on Windows
131
+ * @param options.egmFilePath location of *.pgm file to convert heights from ellipsoidal to gravity-related format
132
+ * @param options.token Token for Cesium ION tilesets authentication
133
+ * @param options.draco Generate I3S 1.7 draco compressed geometries
134
+ * @param options.validate -enable validation
135
+ * @param options.generateTextures - generate alternative type of textures (to have non-compressed jpeg/png and compressed ktx2)
136
+ * @param options.generateBoundingVolumes - generate bounding volumes from vertices coordinates instead of source tiles bounding volumes
137
+ * @param options.instantNodeWriting - Keep created 3DNodeIndexDocument files on disk instead of memory. This option reduce memory usage but decelerates conversion speed
138
+ */
139
+ async convert(options) {
140
+ if (core_1.isBrowser) {
141
+ console.log(constants_1.BROWSER_ERROR_MESSAGE);
142
+ return constants_1.BROWSER_ERROR_MESSAGE;
143
+ }
144
+ this.conversionStartTime = process_1.default.hrtime();
145
+ const { tilesetName, slpk, egmFilePath, inputUrl, validate, outputPath, draco = true, sevenZipExe, maxDepth, token, generateTextures, generateBoundingVolumes, instantNodeWriting = false, mergeMaterials = true } = options;
146
+ this.options = {
147
+ maxDepth,
148
+ slpk,
149
+ sevenZipExe,
150
+ egmFilePath,
151
+ draco,
152
+ token,
153
+ inputUrl,
154
+ instantNodeWriting,
155
+ mergeMaterials
156
+ };
157
+ this.compressList = (this.options.instantNodeWriting && []) || null;
158
+ this.validate = Boolean(validate);
159
+ this.Loader = inputUrl.indexOf(CESIUM_DATASET_PREFIX) !== -1 ? _3d_tiles_1.CesiumIonLoader : _3d_tiles_1.Tiles3DLoader;
160
+ this.generateTextures = Boolean(generateTextures);
161
+ this.generateBoundingVolumes = Boolean(generateBoundingVolumes);
162
+ this.writeQueue = new write_queue_1.default();
163
+ this.writeQueue.startListening();
164
+ console.log('Loading egm file...'); // eslint-disable-line
165
+ this.geoidHeightModel = await (0, core_1.load)(egmFilePath, pgm_loader_1.PGMLoader);
166
+ console.log('Loading egm file completed!'); // eslint-disable-line
167
+ if (slpk) {
168
+ this.nodePages.useWriteFunction(file_utils_1.writeFileForSlpk);
169
+ }
170
+ await this.loadWorkers();
171
+ try {
172
+ const preloadOptions = await this._fetchPreloadOptions();
173
+ if (preloadOptions.headers) {
174
+ this.loadOptions.fetch = { headers: preloadOptions.headers };
175
+ }
176
+ this.sourceTileset = await (0, core_1.load)(inputUrl, this.Loader, this.loadOptions);
177
+ const preprocessResult = await this.preprocessConversion();
178
+ if (preprocessResult) {
179
+ await this._createAndSaveTileset(outputPath, tilesetName);
180
+ await this._finishConversion({ slpk: Boolean(slpk), outputPath, tilesetName });
181
+ }
182
+ }
183
+ catch (error) {
184
+ throw error;
185
+ }
186
+ finally {
187
+ await this.writeQueue.finalize();
188
+ // Clean up worker pools
189
+ const workerFarm = worker_utils_1.WorkerFarm.getWorkerFarm({});
190
+ workerFarm.destroy();
191
+ }
192
+ return 'success';
193
+ }
194
+ /**
195
+ * Preprocess stage of the tile converter. Traverse all the tiles tree and
196
+ * check a tile content to be sure that the data is supported
197
+ * @returns true - the conversion is possible, false - the tileset's content is not supported
198
+ */
199
+ async preprocessConversion() {
200
+ console.log(`Analyze source tileset`);
201
+ const sourceRootTile = this.sourceTileset.root;
202
+ await (0, tileset_traversal_1.traverseDatasetWith)(sourceRootTile, null, this.analyzeTile.bind(this), undefined, this.options.maxDepth);
203
+ const { meshTopologyTypes } = this.preprocessData;
204
+ console.log(`------------------------------------------------`);
205
+ console.log(`Preprocess results:`);
206
+ console.log(`glTF mesh topology types: ${Array.from(meshTopologyTypes).join(', ')}`);
207
+ console.log(`------------------------------------------------`);
208
+ if (!meshTopologyTypes.has(types_1.GltfPrimitiveModeString.TRIANGLES) &&
209
+ !meshTopologyTypes.has(types_1.GltfPrimitiveModeString.TRIANGLE_STRIP)) {
210
+ console.log('The tileset is of unsupported mesh topology types. The conversion will be interrupted.');
211
+ console.log(`------------------------------------------------`);
212
+ return false;
213
+ }
214
+ return true;
215
+ }
216
+ /**
217
+ * Analyze a tile content. The callback for preprocess stage.
218
+ * @param sourceTile - 3DTiles tile JSON metadata
219
+ * @param traversalProps - mandatory argument but it is not used for the preprocess stage
220
+ * @returns - nothing
221
+ */
222
+ async analyzeTile(sourceTile, traversalProps) {
223
+ if (sourceTile.type === 'json') {
224
+ await (0, load_3d_tiles_1.loadNestedTileset)(this.sourceTileset, sourceTile, this.loadOptions);
225
+ return null;
226
+ }
227
+ if (sourceTile.id) {
228
+ console.log(`[analyze]: ${sourceTile.id}`); // eslint-disable-line
229
+ }
230
+ const tileContent = await (0, load_3d_tiles_1.loadTile3DContent)(this.sourceTileset, sourceTile, {
231
+ ...this.loadOptions,
232
+ '3d-tiles': { ...this.loadOptions['3d-tiles'], loadGLTF: false }
296
233
  });
297
- await sourceTile.unloadContent();
298
- } else {
299
- const boundingVolumes = createBoundingVolumes(sourceTile, this.geoidHeightModel);
300
- const children = await this._createNode(parentNode, sourceTile, parentId, level);
301
-
302
- for (const child of children) {
303
- parentNode.children.push({
304
- id: child.id,
305
- href: "../".concat(child.path),
306
- ...boundingVolumes
307
- });
308
- childNodes.push(child);
309
- }
310
- }
311
-
312
- if (sourceTile.id) {
313
- console.log(sourceTile.id);
314
- }
315
- }
316
- }
317
-
318
- async _addNeighborsAndWriteFile(parentNode, childNodes) {
319
- for (const node of childNodes) {
320
- const childPath = join(this.layers0Path, 'nodes', node.path);
321
- const nodePath = node.path;
322
- delete node.path;
323
-
324
- if (parentNode.children.length < 1000) {
325
- for (const neighbor of parentNode.children) {
326
- if (node.id === neighbor.id) {
327
- continue;
328
- }
329
-
330
- node.neighbors.push({ ...neighbor
331
- });
332
- }
333
- } else {
334
- console.warn("Node ".concat(node.id, ": neighbors attribute is omited because of large number of neigbors"));
335
- delete node.neighbors;
336
- }
337
-
338
- await this._writeNodeIndexDocument(node, nodePath, childPath);
339
- node.neighbors = [];
340
- }
341
- }
342
-
343
- async _createNode(parentTile, sourceTile, parentId, level) {
344
- var _sourceTile$content;
345
-
346
- if (this.validate) {
347
- this._checkAddRefinementTypeForTile(sourceTile);
348
- }
349
-
350
- await this._updateTilesetOptions();
351
- await this.sourceTileset._loadTile(sourceTile);
352
- const boundingVolumes = createBoundingVolumes(sourceTile, this.geoidHeightModel);
353
- const lodSelection = convertGeometricErrorToScreenThreshold(sourceTile, boundingVolumes);
354
- const maxScreenThresholdSQ = lodSelection.find(val => val.metricType === 'maxScreenThresholdSQ') || {
355
- maxError: 0
356
- };
357
- const batchTable = sourceTile === null || sourceTile === void 0 ? void 0 : (_sourceTile$content = sourceTile.content) === null || _sourceTile$content === void 0 ? void 0 : _sourceTile$content.batchTableJson;
358
-
359
- if (batchTable) {
360
- this._convertAttributeStorageInfo(sourceTile.content);
361
- }
362
-
363
- const resourcesData = await this._convertResources(sourceTile);
364
- const nodes = [];
365
- const emptyResources = {
366
- geometry: null,
367
- compressedGeometry: null,
368
- texture: null,
369
- sharedResources: null,
370
- meshMaterial: null,
371
- vertexCount: null,
372
- attributes: null,
373
- featureCount: null
374
- };
375
-
376
- for (const resources of resourcesData || [emptyResources]) {
377
- const nodeInPage = this._createNodeInNodePages(maxScreenThresholdSQ, boundingVolumes, sourceTile, parentId, resources);
378
-
379
- const node = this._createNodeIndexDocument(parentTile, boundingVolumes, lodSelection, nodeInPage, resources);
380
-
381
- if (nodeInPage.mesh) {
382
- await this._writeResources(resources, node.path);
383
- }
384
-
385
- if (this.validate) {
386
- this.boundingVolumeWarnings = validateNodeBoundingVolumes(node);
387
-
388
- if (this.boundingVolumeWarnings && this.boundingVolumeWarnings.length) {
389
- console.warn('Bounding Volume Warnings: ', ...this.boundingVolumeWarnings);
390
- }
391
- }
392
-
393
- nodes.push(node);
394
- }
395
-
396
- sourceTile.unloadContent();
397
- const firstNode = nodes[0];
398
- await this._addChildrenWithNeighborsAndWriteFile({
399
- parentNode: firstNode,
400
- sourceTiles: sourceTile.children,
401
- parentId: firstNode.id,
402
- level: level + 1
403
- });
404
- return nodes;
405
- }
406
-
407
- _convertAttributeStorageInfo(sourceTileContent) {
408
- const batchTable = sourceTileContent && sourceTileContent.batchTableJson;
409
-
410
- if (batchTable && !this.layers0.attributeStorageInfo.length) {
411
- this._convertBatchTableInfoToNodeAttributes(batchTable);
412
- }
413
- }
414
-
415
- async _convertResources(sourceTile) {
416
- if (!sourceTile.content || sourceTile.content.type !== 'b3dm') {
417
- return null;
418
- }
419
-
420
- const resourcesData = await convertB3dmToI3sGeometry(sourceTile.content, Number(this.nodePages.nodesCounter), this.featuresHashArray, this.layers0.attributeStorageInfo, this.options.draco);
421
- return resourcesData;
422
- }
423
-
424
- _createNodeInNodePages(maxScreenThresholdSQ, boundingVolumes, sourceTile, parentId, resources) {
425
- const {
426
- meshMaterial,
427
- texture,
428
- vertexCount,
429
- featureCount,
430
- geometry
431
- } = resources;
432
- const nodeInPage = {
433
- lodThreshold: maxScreenThresholdSQ.maxError,
434
- obb: boundingVolumes.obb,
435
- children: [],
436
- mesh: null
437
- };
438
-
439
- if (geometry && sourceTile.content && sourceTile.content.type === 'b3dm') {
440
- nodeInPage.mesh = {
441
- geometry: {
442
- definition: texture ? 0 : 1
443
- },
444
- attribute: {}
445
- };
446
- }
447
-
448
- const nodeId = this.nodePages.push(nodeInPage, parentId);
449
-
450
- if (meshMaterial) {
451
- this.nodePages.updateMaterialByNodeId(nodeId, this._findOrCreateMaterial(meshMaterial));
452
- }
453
-
454
- if (texture) {
455
- const texelCountHint = texture.image.height * texture.image.width;
456
- this.nodePages.updateTexelCountHintByNodeId(nodeId, texelCountHint);
457
- }
458
-
459
- if (vertexCount) {
460
- this.vertexCounter += vertexCount;
461
- this.nodePages.updateVertexCountByNodeId(nodeId, vertexCount);
462
- }
463
-
464
- this.nodePages.updateNodeAttributeByNodeId(nodeId);
465
-
466
- if (featureCount) {
467
- this.nodePages.updateFeatureCountByNodeId(nodeId, featureCount);
468
- }
469
-
470
- return nodeInPage;
471
- }
472
-
473
- _createNodeIndexDocument(parentNode, boundingVolumes, lodSelection, nodeInPage, resources) {
474
- const {
475
- texture,
476
- attributes
477
- } = resources;
478
- const nodeId = nodeInPage.index;
479
- const nodeData = {
480
- version: parentNode.version,
481
- id: nodeId.toString(),
482
- path: nodeId.toString(),
483
- level: parentNode.level + 1,
484
- ...boundingVolumes,
485
- lodSelection,
486
- parentNode: {
487
- id: parentNode.id,
488
- href: "../".concat(parentNode.id),
489
- mbs: parentNode.mbs,
490
- obb: parentNode.obb
491
- },
492
- children: [],
493
- neighbors: []
494
- };
495
- const node = transform(nodeData, nodeTemplate);
496
-
497
- if (nodeInPage.mesh) {
498
- node.geometryData = [{
499
- href: './geometries/0'
500
- }];
501
- node.sharedResource = {
502
- href: './shared'
503
- };
504
-
505
- if (texture) {
506
- node.textureData = [{
507
- href: './textures/0'
508
- }, {
509
- href: './textures/1'
510
- }];
511
- }
512
-
513
- if (attributes && attributes.length && this.layers0.attributeStorageInfo && this.layers0.attributeStorageInfo.length) {
514
- node.attributeData = [];
515
-
516
- for (let index = 0; index < attributes.length; index++) {
517
- const folderName = this.layers0.attributeStorageInfo[index].key;
518
- node.attributeData.push({
519
- href: "./attributes/".concat(folderName, "/0")
520
- });
521
- }
522
- }
523
- }
524
-
525
- return node;
526
- }
527
-
528
- async _writeResources(resources, nodePath) {
529
- const {
530
- geometry: geometryBuffer,
531
- compressedGeometry,
532
- texture,
533
- sharedResources,
534
- attributes
535
- } = resources;
536
- const childPath = join(this.layers0Path, 'nodes', nodePath);
537
- const slpkChildPath = join('nodes', nodePath);
538
- await this._writeGeometries(geometryBuffer, compressedGeometry, childPath, slpkChildPath);
539
- await this._writeShared(sharedResources, childPath, slpkChildPath, nodePath);
540
- await this._writeTexture(texture, childPath, slpkChildPath);
541
- await this._writeAttributes(attributes, childPath, slpkChildPath);
542
- }
543
-
544
- async _writeGeometries(geometryBuffer, compressedGeometry, childPath, slpkChildPath) {
545
- if (this.options.slpk) {
546
- const slpkGeometryPath = join(childPath, 'geometries');
547
- this.fileMap["".concat(slpkChildPath, "/geometries/0.bin.gz")] = await writeFileForSlpk(slpkGeometryPath, geometryBuffer, '0.bin');
548
- } else {
549
- const geometryPath = join(childPath, 'geometries/0/');
550
- await writeFile(geometryPath, geometryBuffer, 'index.bin');
551
- }
552
-
553
- if (this.options.draco) {
554
- if (this.options.slpk) {
555
- const slpkCompressedGeometryPath = join(childPath, 'geometries');
556
- this.fileMap["".concat(slpkChildPath, "/geometries/1.bin.gz")] = await writeFileForSlpk(slpkCompressedGeometryPath, compressedGeometry, '1.bin');
557
- } else {
558
- const compressedGeometryPath = join(childPath, 'geometries/1/');
559
- await writeFile(compressedGeometryPath, compressedGeometry, 'index.bin');
560
- }
561
- }
562
- }
563
-
564
- async _writeShared(sharedResources, childPath, slpkChildPath, nodePath) {
565
- sharedResources.nodePath = nodePath;
566
- const sharedData = transform(sharedResources, SHARED_RESOURCES_TEMPLATE);
567
- const sharedDataStr = JSON.stringify(sharedData);
568
-
569
- if (this.options.slpk) {
570
- const slpkSharedPath = join(childPath, 'shared');
571
- this.fileMap["".concat(slpkChildPath, "/shared/sharedResource.json.gz")] = await writeFileForSlpk(slpkSharedPath, sharedDataStr, 'sharedResource.json');
572
- } else {
573
- const sharedPath = join(childPath, 'shared/');
574
- await writeFile(sharedPath, sharedDataStr);
575
- }
576
- }
577
-
578
- async _writeTexture(texture, childPath, slpkChildPath) {
579
- if (texture) {
580
- const format = this._getFormatByMimeType(texture.mimeType);
581
-
582
- if (!this.layers0.textureSetDefinitions.length) {
583
- this.layers0.textureSetDefinitions.push({
584
- formats: [{
585
- name: '0',
586
- format
587
- }, {
588
- name: '1',
589
- format: 'ktx2'
590
- }]
234
+ const tilePreprocessData = await (0, preprocess_3d_tiles_1.analyzeTileContent)(tileContent);
235
+ (0, preprocess_3d_tiles_1.mergePreprocessData)(this.preprocessData, tilePreprocessData);
236
+ return null;
237
+ }
238
+ /**
239
+ * Convert and save the layer and embedded tiles
240
+ * @param outputPath - path to save output data
241
+ * @param tilesetName - new tileset path
242
+ */
243
+ async _createAndSaveTileset(outputPath, tilesetName) {
244
+ const tilesetPath = (0, path_1.join)(`${outputPath}`, `${tilesetName}`);
245
+ // Removing the tilesetPath needed to exclude erroneous files after conversion
246
+ try {
247
+ await (0, file_utils_1.removeDir)(tilesetPath);
248
+ }
249
+ catch (e) {
250
+ // do nothing
251
+ }
252
+ this.layers0Path = (0, path_1.join)(tilesetPath, 'SceneServer', 'layers', '0');
253
+ this.materialDefinitions = [];
254
+ this.materialMap = new Map();
255
+ const sourceRootTile = this.sourceTileset.root;
256
+ const sourceBoundingVolume = (0, tiles_1.createBoundingVolume)(sourceRootTile.boundingVolume, new core_2.Matrix4(sourceRootTile.transform), null);
257
+ this._formLayers0(tilesetName, sourceBoundingVolume, this.sourceTileset?.root?.boundingVolume?.region);
258
+ const boundingVolumes = (0, coordinate_converter_1.createBoundingVolumes)(sourceBoundingVolume, this.geoidHeightModel);
259
+ await this.nodePages.push({
260
+ index: 0,
261
+ lodThreshold: 0,
262
+ obb: boundingVolumes.obb,
263
+ children: []
591
264
  });
592
- }
593
-
594
- const textureData = texture.bufferView.data;
595
- const ktx2TextureData = await encode(texture.image, KTX2BasisUniversalTextureWriter);
596
-
597
- if (this.options.slpk) {
598
- const slpkTexturePath = join(childPath, 'textures');
599
- const compress = false;
600
- this.fileMap["".concat(slpkChildPath, "/textures/0.").concat(format)] = await writeFileForSlpk(slpkTexturePath, textureData, "0.".concat(format), compress);
601
- this.fileMap["".concat(slpkChildPath, "/textures/1.ktx2")] = await writeFileForSlpk(slpkTexturePath, ktx2TextureData, "1.ktx2", compress);
602
- } else {
603
- const texturePath = join(childPath, 'textures/0/');
604
- await writeFile(texturePath, textureData, "index.".concat(format));
605
- const ktx2TexturePath = join(childPath, 'textures/1/');
606
- await writeFile(ktx2TexturePath, ktx2TextureData, "index.ktx2");
607
- }
608
- }
609
- }
610
-
611
- async _writeAttributes(attributes, childPath, slpkChildPath) {
612
- if (attributes.length && this.layers0.attributeStorageInfo && this.layers0.attributeStorageInfo.length) {
613
- for (let index = 0; index < attributes.length; index++) {
614
- const folderName = this.layers0.attributeStorageInfo[index].key;
615
- const fileBuffer = new Uint8Array(attributes[index]);
616
-
265
+ const rootNode = await node_index_document_1.NodeIndexDocument.createRootNode(boundingVolumes, this);
266
+ await (0, tileset_traversal_1.traverseDatasetWith)(sourceRootTile, {
267
+ transform: new core_2.Matrix4(sourceRootTile.transform),
268
+ parentNodes: [rootNode]
269
+ }, this.convertTile.bind(this), this.finalizeTile.bind(this), this.options.maxDepth);
270
+ this.layers0.materialDefinitions = this.materialDefinitions;
271
+ // @ts-ignore
272
+ this.layers0.geometryDefinitions = (0, json_map_transform_1.default)(this.geometryConfigs.map((config) => ({
273
+ geometryConfig: { ...config, draco: this.options.draco }
274
+ })), (0, geometry_definitions_1.GEOMETRY_DEFINITION)());
275
+ if (this.layersHasTexture === false) {
276
+ this.layers0.store.defaultGeometrySchema.ordering =
277
+ this.layers0.store.defaultGeometrySchema.ordering.filter((attribute) => attribute !== 'uv0');
278
+ }
279
+ await this._writeLayers0();
280
+ (0, create_scene_server_path_1.createSceneServerPath)(tilesetName, this.layers0, tilesetPath);
281
+ for (const filePath of this.compressList || []) {
282
+ await (0, compress_util_1.compressFileWithGzip)(filePath);
283
+ await (0, file_utils_1.removeFile)(filePath);
284
+ }
285
+ await this.nodePages.save();
286
+ await this.writeQueue.finalize();
287
+ await this._createSlpk(tilesetPath);
288
+ }
289
+ /**
290
+ * Form object of 3DSceneLayer https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DSceneLayer.cmn.md
291
+ * @param tilesetName - Name of layer
292
+ * @param sourceBoundingVolume - initialized bounding volume of the source root tile
293
+ * @param boundingVolumeRegion - region bounding volume of the source root tile
294
+ */
295
+ _formLayers0(tilesetName, sourceBoundingVolume, boundingVolumeRegion) {
296
+ if (!this.sourceTileset?.root) {
297
+ return;
298
+ }
299
+ const fullExtent = (0, coordinate_converter_1.convertBoundingVolumeToI3SFullExtent)(sourceBoundingVolume);
300
+ if (boundingVolumeRegion) {
301
+ fullExtent.zmin = boundingVolumeRegion[4];
302
+ fullExtent.zmax = boundingVolumeRegion[5];
303
+ }
304
+ const extent = [fullExtent.xmin, fullExtent.ymin, fullExtent.xmax, fullExtent.ymax];
305
+ const layers0data = {
306
+ version: `{${(0, uuid_1.v4)().toUpperCase()}}`,
307
+ id: 0,
308
+ name: tilesetName,
309
+ href: './layers/0',
310
+ store: {
311
+ id: `{${(0, uuid_1.v4)().toUpperCase()}}`,
312
+ extent
313
+ },
314
+ nodePages: {
315
+ nodesPerPage: HARDCODED_NODES_PER_PAGE
316
+ },
317
+ compressGeometry: this.options.draco,
318
+ fullExtent
319
+ };
320
+ this.layers0 = (0, json_map_transform_1.default)(layers0data, (0, layers_1.LAYERS)());
321
+ }
322
+ /**
323
+ * Write 3DSceneLayer https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DSceneLayer.cmn.md in file
324
+ */
325
+ async _writeLayers0() {
617
326
  if (this.options.slpk) {
618
- const slpkAttributesPath = join(childPath, 'attributes', folderName);
619
- this.fileMap["".concat(slpkChildPath, "/attributes/").concat(folderName, ".bin.gz")] = await writeFileForSlpk(slpkAttributesPath, fileBuffer, '0.bin');
620
- } else {
621
- const attributesPath = join(childPath, "attributes/".concat(folderName, "/0"));
622
- await writeFile(attributesPath, fileBuffer, 'index.bin');
327
+ await this.writeQueue.enqueue({
328
+ archiveKey: '3dSceneLayer.json.gz',
329
+ writePromise: () => (0, file_utils_1.writeFileForSlpk)(this.layers0Path, JSON.stringify(this.layers0), '3dSceneLayer.json')
330
+ });
331
+ }
332
+ else {
333
+ await this.writeQueue.enqueue({
334
+ writePromise: () => (0, file_utils_1.writeFile)(this.layers0Path, JSON.stringify(this.layers0))
335
+ });
623
336
  }
624
- }
625
337
  }
626
- }
627
-
628
- _getFormatByMimeType(mimeType) {
629
- switch (mimeType) {
630
- case 'image/jpeg':
631
- return 'jpg';
632
-
633
- case 'image/png':
634
- return 'png';
635
-
636
- default:
637
- return 'jpg';
338
+ /**
339
+ * Pack files into *.slpk archive
340
+ * @param tilesetPath - Path to save file
341
+ */
342
+ async _createSlpk(tilesetPath) {
343
+ if (this.options.slpk) {
344
+ const slpkTilesetPath = (0, path_1.join)(tilesetPath, 'SceneServer', 'layers', '0');
345
+ const slpkFileName = `${tilesetPath}.slpk`;
346
+ await (0, compress_util_1.compressWithChildProcess)(slpkTilesetPath, slpkFileName, 0, '.', this.options.sevenZipExe);
347
+ // TODO: `addFileToZip` corrupts archive so it can't be validated with windows i3s_converter.exe
348
+ // const fileHash128Path = `${tilesetPath}/@specialIndexFileHASH128@`;
349
+ // try {
350
+ // await generateHash128FromZip(slpkFileName, fileHash128Path);
351
+ // await addFileToZip(
352
+ // tilesetPath,
353
+ // '@specialIndexFileHASH128@',
354
+ // slpkFileName,
355
+ // this.options.sevenZipExe
356
+ // );
357
+ // } catch (error) {
358
+ // if (error.code === FS_FILE_TOO_LARGE) {
359
+ // console.warn(`${slpkFileName} file is too big to generate a hash`); // eslint-disable-line
360
+ // } else {
361
+ // console.error(error); // eslint-disable-line
362
+ // }
363
+ // }
364
+ // All converted files are contained in slpk now they can be deleted
365
+ try {
366
+ await (0, file_utils_1.removeDir)(tilesetPath);
367
+ }
368
+ catch (e) {
369
+ // do nothing
370
+ }
371
+ }
638
372
  }
639
- }
640
-
641
- _findOrCreateMaterial(material) {
642
- const hash = md5(JSON.stringify(material));
643
-
644
- if (this.materialMap.has(hash)) {
645
- return this.materialMap.get(hash);
373
+ /**
374
+ * Convert the specific 3DTiles tile to I3S nodes.
375
+ * This is callback function for the traversal generic function
376
+ * @param sourceTile - current 3DTiles tile JSON metadata
377
+ * @param traversalProps - traversal properties calculated recursively
378
+ * @returns - traversal properties for the child tiles
379
+ */
380
+ async convertTile(sourceTile, traversalProps) {
381
+ if (sourceTile.type === 'json' || sourceTile.type === 'empty') {
382
+ if (sourceTile.type === 'json') {
383
+ if (sourceTile.id) {
384
+ console.log(`[load]: ${sourceTile.id}`); // eslint-disable-line
385
+ }
386
+ await (0, load_3d_tiles_1.loadNestedTileset)(this.sourceTileset, sourceTile, this.loadOptions);
387
+ }
388
+ return traversalProps;
389
+ }
390
+ if (sourceTile.id) {
391
+ console.log(`[convert]: ${sourceTile.id}`); // eslint-disable-line
392
+ }
393
+ const { parentNodes, transform } = traversalProps;
394
+ let transformationMatrix = transform.clone();
395
+ if (sourceTile.transform) {
396
+ transformationMatrix = transformationMatrix.multiplyRight(sourceTile.transform);
397
+ }
398
+ const parentNode = parentNodes[0];
399
+ const childNodes = await this._createNode(parentNode, sourceTile, transformationMatrix);
400
+ await parentNode.addChildren(childNodes);
401
+ const newTraversalProps = {
402
+ transform: transformationMatrix,
403
+ parentNodes: childNodes
404
+ };
405
+ return newTraversalProps;
406
+ }
407
+ /**
408
+ * Do final action with nodes after the current node and all child nodes been converted.
409
+ * @param conversionResults - array of conversion results of the current node
410
+ * @param currentTraversalProps - traversal properties of the current node
411
+ */
412
+ async finalizeTile(conversionResults, currentTraversalProps) {
413
+ for (const result of conversionResults) {
414
+ for (const node of result.parentNodes) {
415
+ await node.addNeighbors();
416
+ }
417
+ }
418
+ for (const node of currentTraversalProps.parentNodes) {
419
+ await node.save();
420
+ }
646
421
  }
647
-
648
- const newMaterialId = this.materialDefinitions.push(material) - 1;
649
- this.materialMap.set(hash, newMaterialId);
650
- return newMaterialId;
651
- }
652
-
653
- _createdStorageAttribute(attributeIndex, key, attributeType) {
654
- const storageAttribute = {
655
- key: "f_".concat(attributeIndex),
656
- name: key,
657
- ordering: ['attributeValues'],
658
- header: [{
659
- property: 'count',
660
- valueType: 'UInt32'
661
- }],
662
- attributeValues: {
663
- valueType: 'Int32',
664
- valuesPerElement: 1
665
- }
666
- };
667
-
668
- switch (attributeType) {
669
- case OBJECT_ID_TYPE:
670
- this._setupIdAttribute(storageAttribute);
671
-
672
- break;
673
-
674
- case STRING_TYPE:
675
- this._setupStringAttribute(storageAttribute);
676
-
677
- break;
678
-
679
- case DOUBLE_TYPE:
680
- this._setupDoubleAttribute(storageAttribute);
681
-
682
- break;
683
-
684
- case SHORT_INT_TYPE:
685
- break;
686
-
687
- default:
688
- this._setupStringAttribute(storageAttribute);
689
-
422
+ /**
423
+ * Convert tile to one or more I3S nodes
424
+ * @param parentNode - 3DNodeIndexDocument of parent node
425
+ * @param sourceTile - source 3DTile data
426
+ * @param transformationMatrix - transformation matrix of the current tile, calculated recursively multiplying
427
+ * transform of all parent tiles and transform of the current tile
428
+ * @param level - tree level
429
+ */
430
+ async _createNode(parentNode, sourceTile, transformationMatrix) {
431
+ this._checkAddRefinementTypeForTile(sourceTile);
432
+ await this._updateTilesetOptions();
433
+ const tileContent = await (0, load_3d_tiles_1.loadTile3DContent)(this.sourceTileset, sourceTile, this.loadOptions);
434
+ const sourceBoundingVolume = (0, tiles_1.createBoundingVolume)(sourceTile.boundingVolume, transformationMatrix, null);
435
+ let boundingVolumes = (0, coordinate_converter_1.createBoundingVolumes)(sourceBoundingVolume, this.geoidHeightModel);
436
+ const propertyTable = (0, geometry_converter_1.getPropertyTable)(tileContent);
437
+ if (propertyTable && !this.layers0?.attributeStorageInfo?.length) {
438
+ this._convertPropertyTableToNodeAttributes(propertyTable);
439
+ }
440
+ const resourcesData = await this._convertResources(sourceTile, transformationMatrix, sourceBoundingVolume, tileContent, parentNode.inPageId, propertyTable);
441
+ const nodes = [];
442
+ const nodeIds = [];
443
+ const nodesInPage = [];
444
+ const emptyResources = {
445
+ geometry: null,
446
+ compressedGeometry: null,
447
+ texture: null,
448
+ hasUvRegions: false,
449
+ sharedResources: null,
450
+ meshMaterial: null,
451
+ vertexCount: null,
452
+ attributes: null,
453
+ featureCount: null,
454
+ boundingVolumes: null
455
+ };
456
+ for (const resources of resourcesData || [emptyResources]) {
457
+ this.layersHasTexture = this.layersHasTexture || Boolean(resources.texture);
458
+ if (this.generateBoundingVolumes && resources.boundingVolumes) {
459
+ boundingVolumes = resources.boundingVolumes;
460
+ }
461
+ const lodSelection = (0, lod_conversion_utils_1.convertGeometricErrorToScreenThreshold)(sourceTile, boundingVolumes);
462
+ const maxScreenThresholdSQ = lodSelection.find((val) => val.metricType === 'maxScreenThresholdSQ') || { maxError: 0 };
463
+ const nodeInPage = await this._updateNodeInNodePages(maxScreenThresholdSQ, boundingVolumes, sourceTile, parentNode.inPageId, resources);
464
+ const nodeData = await node_index_document_1.NodeIndexDocument.createNodeIndexDocument(parentNode, boundingVolumes, lodSelection, nodeInPage, resources);
465
+ const node = await new node_index_document_1.NodeIndexDocument(nodeInPage.index, this).addData(nodeData);
466
+ nodes.push(node);
467
+ if (nodeInPage.mesh) {
468
+ await this._writeResources(resources, node.id);
469
+ }
470
+ if (this.validate) {
471
+ this.boundingVolumeWarnings = (0, node_debug_1.validateNodeBoundingVolumes)(nodeData);
472
+ if (this.boundingVolumeWarnings && this.boundingVolumeWarnings.length) {
473
+ console.warn('Bounding Volume Warnings: ', ...this.boundingVolumeWarnings); //eslint-disable-line
474
+ }
475
+ }
476
+ nodeIds.push(nodeInPage.index);
477
+ nodesInPage.push(nodeInPage);
478
+ }
479
+ return nodes;
480
+ }
481
+ /**
482
+ * Convert tile to one or more I3S nodes
483
+ * @param sourceTile - source tile (3DTile)
484
+ * @param transformationMatrix - transformation matrix of the current tile, calculated recursively multiplying
485
+ * transform of all parent tiles and transform of the current tile
486
+ * @param boundingVolume - initialized bounding volume of the source tile
487
+ * @param tileContent - content of the source tile
488
+ * @param parentId - id of parent node in node pages
489
+ * @param propertyTable - batch table from b3dm / feature properties from EXT_FEATURE_METADATA
490
+ * @returns - converted node resources
491
+ */
492
+ async _convertResources(sourceTile, transformationMatrix, boundingVolume, tileContent, parentId, propertyTable) {
493
+ if (!this.isContentSupported(sourceTile) || !tileContent) {
494
+ return null;
495
+ }
496
+ const draftObb = {
497
+ center: [],
498
+ halfSize: [],
499
+ quaternion: []
500
+ };
501
+ const resourcesData = await (0, geometry_converter_1.default)(tileContent, transformationMatrix, boundingVolume, async () => (await this.nodePages.push({ index: 0, obb: draftObb }, parentId)).index, propertyTable, this.featuresHashArray, this.layers0?.attributeStorageInfo, this.options.draco, this.generateBoundingVolumes, this.options.mergeMaterials, this.geoidHeightModel, this.workerSource);
502
+ return resourcesData;
503
+ }
504
+ /**
505
+ * Update node object (https://github.com/Esri/i3s-spec/blob/master/docs/1.7/node.cmn.md)
506
+ * in node pages (https://github.com/Esri/i3s-spec/blob/master/docs/1.7/nodePage.cmn.md)
507
+ * @param maxScreenThresholdSQ - Level of Details (LOD) metric
508
+ * @param boundingVolumes - Bounding volumes
509
+ * @param sourceTile - source tile (3DTile)
510
+ * @param parentId - id of parent node in node pages
511
+ * @param resources - the node resources data
512
+ * @param resources.meshMaterial - PBR-like material object
513
+ * @param resources.texture - texture image
514
+ * @param resources.vertexCount - number of vertices in geometry
515
+ * @param resources.featureCount - number of features
516
+ * @param resources.geometry - Uint8Array with geometry attributes
517
+ * @return the node object in node pages
518
+ */
519
+ async _updateNodeInNodePages(maxScreenThresholdSQ, boundingVolumes, sourceTile, parentId, resources) {
520
+ const { meshMaterial, texture, vertexCount, featureCount, geometry, hasUvRegions } = resources;
521
+ const nodeInPage = {
522
+ index: 0,
523
+ lodThreshold: maxScreenThresholdSQ.maxError,
524
+ obb: boundingVolumes.obb,
525
+ children: []
526
+ };
527
+ if (geometry && this.isContentSupported(sourceTile)) {
528
+ nodeInPage.mesh = {
529
+ geometry: {
530
+ definition: this.findOrCreateGeometryDefinition(Boolean(texture), hasUvRegions),
531
+ resource: 0
532
+ },
533
+ attribute: {
534
+ resource: 0
535
+ },
536
+ material: {
537
+ definition: 0
538
+ }
539
+ };
540
+ }
541
+ let nodeId = resources.nodeId;
542
+ let node;
543
+ if (!nodeId) {
544
+ node = await this.nodePages.push(nodeInPage, parentId);
545
+ }
546
+ else {
547
+ node = await this.nodePages.getNodeById(nodeId);
548
+ }
549
+ node_pages_1.default.updateAll(node, nodeInPage);
550
+ if (meshMaterial) {
551
+ node_pages_1.default.updateMaterialByNodeId(node, this._findOrCreateMaterial(meshMaterial));
552
+ }
553
+ if (texture) {
554
+ const texelCountHint = texture.image.height * texture.image.width;
555
+ node_pages_1.default.updateTexelCountHintByNodeId(node, texelCountHint);
556
+ }
557
+ if (vertexCount) {
558
+ this.vertexCounter += vertexCount;
559
+ node_pages_1.default.updateVertexCountByNodeId(node, vertexCount);
560
+ }
561
+ node_pages_1.default.updateNodeAttributeByNodeId(node);
562
+ if (featureCount) {
563
+ node_pages_1.default.updateFeatureCountByNodeId(node, featureCount);
564
+ }
565
+ this.nodePages.saveNode(node);
566
+ return node;
567
+ }
568
+ /**
569
+ * Write node resources in files
570
+ * @param resources - source tile (3DTile)
571
+ * @param resources.geometry - Uint8Array with geometry attributes
572
+ * @param resources.compressedGeometry - Uint8Array with compressed (draco) geometry
573
+ * @param resources.texture - texture image
574
+ * @param resources.sharedResources - shared resource data object
575
+ * @param resources.attributes - feature attributes
576
+ * @return {Promise<void>}
577
+ */
578
+ async _writeResources(resources, nodePath) {
579
+ const { geometry: geometryBuffer, compressedGeometry, texture, sharedResources, attributes } = resources;
580
+ const childPath = (0, path_1.join)(this.layers0Path, 'nodes', nodePath);
581
+ const slpkChildPath = (0, path_1.join)('nodes', nodePath);
582
+ await this._writeGeometries(geometryBuffer, compressedGeometry, childPath, slpkChildPath);
583
+ await this._writeShared(sharedResources, childPath, slpkChildPath, nodePath);
584
+ await this._writeTexture(texture, childPath, slpkChildPath);
585
+ await this._writeAttributes(attributes, childPath, slpkChildPath);
586
+ }
587
+ /**
588
+ * Write non-compressed and compressed geometries in files
589
+ * @param geometryBuffer - Uint8Array with geometry attributes
590
+ * @param compressedGeometry - Uint8Array with compressed (draco) geometry
591
+ * @param childPath - a child path to write resources
592
+ * @param slpkChildPath - resource path inside *slpk file
593
+ */
594
+ async _writeGeometries(geometryBuffer, compressedGeometry, childPath, slpkChildPath) {
595
+ if (this.options.slpk) {
596
+ const slpkGeometryPath = (0, path_1.join)(childPath, 'geometries');
597
+ await this.writeQueue.enqueue({
598
+ archiveKey: `${slpkChildPath}/geometries/0.bin.gz`,
599
+ writePromise: () => (0, file_utils_1.writeFileForSlpk)(slpkGeometryPath, geometryBuffer, '0.bin')
600
+ });
601
+ }
602
+ else {
603
+ const geometryPath = (0, path_1.join)(childPath, 'geometries/0/');
604
+ await this.writeQueue.enqueue({
605
+ writePromise: () => (0, file_utils_1.writeFile)(geometryPath, geometryBuffer, 'index.bin')
606
+ });
607
+ }
608
+ if (this.options.draco) {
609
+ if (this.options.slpk) {
610
+ const slpkCompressedGeometryPath = (0, path_1.join)(childPath, 'geometries');
611
+ await this.writeQueue.enqueue({
612
+ archiveKey: `${slpkChildPath}/geometries/1.bin.gz`,
613
+ writePromise: () => (0, file_utils_1.writeFileForSlpk)(slpkCompressedGeometryPath, compressedGeometry, '1.bin')
614
+ });
615
+ }
616
+ else {
617
+ const compressedGeometryPath = (0, path_1.join)(childPath, 'geometries/1/');
618
+ await this.writeQueue.enqueue({
619
+ writePromise: () => (0, file_utils_1.writeFile)(compressedGeometryPath, compressedGeometry, 'index.bin')
620
+ });
621
+ }
622
+ }
690
623
  }
691
-
692
- return storageAttribute;
693
- }
694
-
695
- getAttributeType(key, attribute) {
696
- if (key === OBJECT_ID_TYPE) {
697
- return OBJECT_ID_TYPE;
624
+ /**
625
+ * Write shared resources in a file
626
+ * @param sharedResources - shared resource data object
627
+ * @param childPath - a child path to write resources
628
+ * @param slpkChildPath - resource path inside *slpk file
629
+ * @param nodePath - a node path
630
+ */
631
+ async _writeShared(sharedResources, childPath, slpkChildPath, nodePath) {
632
+ if (!sharedResources) {
633
+ return;
634
+ }
635
+ sharedResources.nodePath = nodePath;
636
+ const sharedData = (0, json_map_transform_1.default)(sharedResources, (0, shared_resources_1.SHARED_RESOURCES)());
637
+ const sharedDataStr = JSON.stringify(sharedData);
638
+ if (this.options.slpk) {
639
+ const slpkSharedPath = (0, path_1.join)(childPath, 'shared');
640
+ await this.writeQueue.enqueue({
641
+ archiveKey: `${slpkChildPath}/shared/sharedResource.json.gz`,
642
+ writePromise: () => (0, file_utils_1.writeFileForSlpk)(slpkSharedPath, sharedDataStr, 'sharedResource.json')
643
+ });
644
+ }
645
+ else {
646
+ const sharedPath = (0, path_1.join)(childPath, 'shared/');
647
+ await this.writeQueue.enqueue({ writePromise: () => (0, file_utils_1.writeFile)(sharedPath, sharedDataStr) });
648
+ }
698
649
  }
699
-
700
- if (typeof attribute === STRING_TYPE) {
701
- return STRING_TYPE;
702
- } else if (typeof attribute === 'number') {
703
- return Number.isInteger(attribute) ? SHORT_INT_TYPE : DOUBLE_TYPE;
650
+ /**
651
+ * Generates textures based on texture mime type and fill in textureSetDefinitions data.
652
+ * @param texture - the texture image
653
+ * @param childPath - a child path to write resources
654
+ * @param slpkChildPath - the resource path inside *slpk file
655
+ */
656
+ async _writeTexture(texture, childPath, slpkChildPath) {
657
+ if (texture) {
658
+ const format = this._getFormatByMimeType(texture?.mimeType);
659
+ const formats = [];
660
+ const textureData = texture.bufferView.data;
661
+ switch (format) {
662
+ case 'jpg':
663
+ case 'png': {
664
+ formats.push({ name: '0', format });
665
+ await this.writeTextureFile(textureData, '0', format, childPath, slpkChildPath);
666
+ if (this.generateTextures) {
667
+ formats.push({ name: '1', format: 'ktx2' });
668
+ // For Node.js texture.image.data is type of Buffer
669
+ const copyArrayBuffer = texture.image.data.subarray();
670
+ const arrayToEncode = new Uint8Array(copyArrayBuffer);
671
+ const ktx2TextureData = (0, core_1.encode)({ ...texture.image, data: arrayToEncode }, textures_1.KTX2BasisWriterWorker, {
672
+ ...textures_1.KTX2BasisWriterWorker.options,
673
+ source: this.workerSource.ktx2,
674
+ reuseWorkers: true,
675
+ _nodeWorkers: true
676
+ });
677
+ await this.writeTextureFile(ktx2TextureData, '1', 'ktx2', childPath, slpkChildPath);
678
+ }
679
+ break;
680
+ }
681
+ case 'ktx2': {
682
+ formats.push({ name: '1', format });
683
+ await this.writeTextureFile(textureData, '1', format, childPath, slpkChildPath);
684
+ if (this.generateTextures) {
685
+ formats.push({ name: '0', format: 'jpg' });
686
+ const decodedFromKTX2TextureData = (0, core_1.encode)(texture.image.data[0], images_1.ImageWriter);
687
+ await this.writeTextureFile(decodedFromKTX2TextureData, '0', 'jpg', childPath, slpkChildPath);
688
+ }
689
+ }
690
+ }
691
+ if (!this.layers0.textureSetDefinitions.length) {
692
+ this.layers0.textureSetDefinitions.push({ formats });
693
+ this.layers0.textureSetDefinitions.push({ formats, atlas: true });
694
+ }
695
+ }
704
696
  }
705
-
706
- return STRING_TYPE;
707
- }
708
-
709
- _setupStringAttribute(storageAttribute) {
710
- storageAttribute.ordering.unshift('attributeByteCounts');
711
- storageAttribute.header.push({
712
- property: 'attributeValuesByteCount',
713
- valueType: 'UInt32'
714
- });
715
- storageAttribute.attributeValues = {
716
- valueType: 'String',
717
- encoding: 'UTF-8',
718
- valuesPerElement: 1
719
- };
720
- storageAttribute.attributeByteCounts = {
721
- valueType: 'UInt32',
722
- valuesPerElement: 1
723
- };
724
- }
725
-
726
- _setupIdAttribute(storageAttribute) {
727
- storageAttribute.attributeValues = {
728
- valueType: 'Oid32',
729
- valuesPerElement: 1
730
- };
731
- }
732
-
733
- _setupDoubleAttribute(storageAttribute) {
734
- storageAttribute.attributeValues = {
735
- valueType: 'Float64',
736
- valuesPerElement: 1
737
- };
738
- }
739
-
740
- _createFieldAttribute(key, fieldAttributeType) {
741
- return {
742
- name: key,
743
- type: fieldAttributeType,
744
- alias: key
745
- };
746
- }
747
-
748
- _convertBatchTableInfoToNodeAttributes(batchTable) {
749
- let attributeIndex = 0;
750
- const batchTableWithObjectId = {
751
- OBJECTID: [0],
752
- ...batchTable
753
- };
754
-
755
- for (const key in batchTableWithObjectId) {
756
- const firstAttribute = batchTableWithObjectId[key][0];
757
- const attributeType = this.getAttributeType(key, firstAttribute);
758
-
759
- const storageAttribute = this._createdStorageAttribute(attributeIndex, key, attributeType);
760
-
761
- const fieldAttributeType = this._getFieldAttributeType(attributeType);
762
-
763
- const fieldAttribute = this._createFieldAttribute(key, fieldAttributeType);
764
-
765
- const popupInfo = this._createPopupInfo(batchTableWithObjectId);
766
-
767
- this.layers0.attributeStorageInfo.push(storageAttribute);
768
- this.layers0.fields.push(fieldAttribute);
769
- this.layers0.popupInfo = popupInfo;
770
- this.layers0.layerType = _3D_OBJECT_LAYER_TYPE;
771
- attributeIndex += 1;
697
+ /**
698
+ * Write the texture image in a file
699
+ * @param textureData
700
+ * @param name
701
+ * @param format
702
+ * @param childPath
703
+ * @param slpkChildPath
704
+ */
705
+ async writeTextureFile(textureData, name, format, childPath, slpkChildPath) {
706
+ if (this.options.slpk) {
707
+ const slpkTexturePath = (0, path_1.join)(childPath, 'textures');
708
+ const compress = false;
709
+ await this.writeQueue.enqueue({
710
+ archiveKey: `${slpkChildPath}/textures/${name}.${format}`,
711
+ writePromise: () => (0, file_utils_1.writeFileForSlpk)(slpkTexturePath, textureData, `${name}.${format}`, compress)
712
+ });
713
+ }
714
+ else {
715
+ const texturePath = (0, path_1.join)(childPath, `textures/${name}/`);
716
+ await this.writeQueue.enqueue({
717
+ writePromise: () => (0, file_utils_1.writeFile)(texturePath, textureData, `index.${format}`)
718
+ });
719
+ }
772
720
  }
773
- }
774
-
775
- _getFieldAttributeType(attributeType) {
776
- switch (attributeType) {
777
- case OBJECT_ID_TYPE:
778
- return 'esriFieldTypeOID';
779
-
780
- case STRING_TYPE:
781
- return 'esriFieldTypeString';
782
-
783
- case SHORT_INT_TYPE:
784
- return 'esriFieldTypeInteger';
785
-
786
- case DOUBLE_TYPE:
787
- return 'esriFieldTypeDouble';
788
-
789
- default:
790
- return 'esriFieldTypeString';
721
+ /**
722
+ * Write feature attributes in files
723
+ * @param attributes - feature attributes
724
+ * @param childPath - a child path to write resources
725
+ * @param slpkChildPath - the resource path inside *slpk file
726
+ */
727
+ async _writeAttributes(attributes = [], childPath, slpkChildPath) {
728
+ if (attributes?.length && this.layers0?.attributeStorageInfo?.length) {
729
+ for (let index = 0; index < attributes.length; index++) {
730
+ const folderName = this.layers0.attributeStorageInfo[index].key;
731
+ const fileBuffer = new Uint8Array(attributes[index]);
732
+ if (this.options.slpk) {
733
+ const slpkAttributesPath = (0, path_1.join)(childPath, 'attributes', folderName);
734
+ await this.writeQueue.enqueue({
735
+ archiveKey: `${slpkChildPath}/attributes/${folderName}.bin.gz`,
736
+ writePromise: () => (0, file_utils_1.writeFileForSlpk)(slpkAttributesPath, fileBuffer, '0.bin')
737
+ });
738
+ }
739
+ else {
740
+ const attributesPath = (0, path_1.join)(childPath, `attributes/${folderName}/0`);
741
+ await this.writeQueue.enqueue({
742
+ writePromise: () => (0, file_utils_1.writeFile)(attributesPath, fileBuffer, 'index.bin')
743
+ });
744
+ }
745
+ }
746
+ }
791
747
  }
792
- }
793
-
794
- _createPopupInfo(batchTable) {
795
- const title = '{OBJECTID}';
796
- const mediaInfos = [];
797
- const fieldInfos = [];
798
- const popupElements = [];
799
- const expressionInfos = [];
800
-
801
- for (const key in batchTable) {
802
- fieldInfos.push({
803
- fieldName: key,
804
- visible: true,
805
- isEditable: false,
806
- label: key
807
- });
748
+ /**
749
+ * Return file format by its MIME type
750
+ * @param mimeType - feature attributes
751
+ */
752
+ _getFormatByMimeType(mimeType) {
753
+ switch (mimeType) {
754
+ case 'image/jpeg':
755
+ return 'jpg';
756
+ case 'image/png':
757
+ return 'png';
758
+ case 'image/ktx2':
759
+ return 'ktx2';
760
+ default:
761
+ return 'jpg';
762
+ }
808
763
  }
809
-
810
- popupElements.push({
811
- fieldInfos,
812
- type: 'fields'
813
- });
814
- return {
815
- title,
816
- mediaInfos,
817
- popupElements,
818
- fieldInfos,
819
- expressionInfos
820
- };
821
- }
822
-
823
- async _finishConversion(params) {
824
- const {
825
- tilesCount,
826
- tilesWithAddRefineCount
827
- } = this.refinementCounter;
828
- const addRefinementPercentage = tilesWithAddRefineCount ? tilesWithAddRefineCount / tilesCount * 100 : 0;
829
- const filesSize = await calculateFilesSize(params);
830
- const diff = process.hrtime(this.conversionStartTime);
831
- const conversionTime = timeConverter(diff);
832
- console.log("------------------------------------------------");
833
- console.log("Finishing conversion of ".concat(_3D_TILES));
834
- console.log("Total conversion time: ".concat(conversionTime));
835
- console.log("Vertex count: ", this.vertexCounter);
836
- console.log("File(s) size: ", filesSize, ' bytes');
837
- console.log("Percentage of tiles with \"ADD\" refinement type:", addRefinementPercentage, '%');
838
- console.log("------------------------------------------------");
839
- }
840
-
841
- async _fetchPreloadOptions() {
842
- const options = {
843
- 'cesium-ion': {
844
- accessToken: this.options.token || ION_DEFAULT_TOKEN
845
- }
846
- };
847
- const preloadOptions = await CesiumIonLoader.preload(this.options.inputUrl, options);
848
- this.refreshTokenTime = process.hrtime();
849
- return { ...options,
850
- ...preloadOptions
851
- };
852
- }
853
-
854
- async _updateTilesetOptions() {
855
- const diff = process.hrtime(this.refreshTokenTime);
856
-
857
- if (diff[0] < REFRESH_TOKEN_TIMEOUT) {
858
- return;
764
+ /**
765
+ * Find or create material in materialDefinitions array
766
+ * @param material - end-to-end index of the node
767
+ * @return material id
768
+ */
769
+ _findOrCreateMaterial(material) {
770
+ const hash = (0, md5_1.default)(JSON.stringify(material));
771
+ if (this.materialMap.has(hash)) {
772
+ return this.materialMap.get(hash) || 0;
773
+ }
774
+ const newMaterialId = this.materialDefinitions.push(material) - 1;
775
+ this.materialMap.set(hash, newMaterialId);
776
+ return newMaterialId;
777
+ }
778
+ /**
779
+ * Get unique geometry configuration index
780
+ * In the end of conversion configurations will be transformed to geometryDefinitions array
781
+ * @param hasTexture
782
+ * @param hasUvRegions
783
+ * @returns
784
+ */
785
+ findOrCreateGeometryDefinition(hasTexture, hasUvRegions) {
786
+ const geometryConfig = { hasTexture, hasUvRegions };
787
+ const hash = (0, md5_1.default)(JSON.stringify(geometryConfig));
788
+ if (this.geometryMap.has(hash)) {
789
+ return this.geometryMap.get(hash) || 0;
790
+ }
791
+ const newGeometryId = this.geometryConfigs.push(geometryConfig) - 1;
792
+ this.geometryMap.set(hash, newGeometryId);
793
+ return newGeometryId;
794
+ }
795
+ /**
796
+ * Do conversion of 3DTiles property table to I3s node attributes.
797
+ * @param propertyTable - Table with layer meta data.
798
+ */
799
+ _convertPropertyTableToNodeAttributes(propertyTable) {
800
+ let attributeIndex = 0;
801
+ const propertyTableWithObjectId = {
802
+ OBJECTID: [0],
803
+ ...propertyTable
804
+ };
805
+ for (const key in propertyTableWithObjectId) {
806
+ const firstAttribute = propertyTableWithObjectId[key][0];
807
+ const attributeType = (0, feature_attributes_1.getAttributeType)(key, firstAttribute);
808
+ const storageAttribute = (0, feature_attributes_1.createdStorageAttribute)(attributeIndex, key, attributeType);
809
+ const fieldAttributeType = (0, feature_attributes_1.getFieldAttributeType)(attributeType);
810
+ const fieldAttribute = (0, feature_attributes_1.createFieldAttribute)(key, fieldAttributeType);
811
+ const popupInfo = (0, feature_attributes_1.createPopupInfo)(propertyTableWithObjectId);
812
+ this.layers0.attributeStorageInfo.push(storageAttribute);
813
+ this.layers0.fields.push(fieldAttribute);
814
+ this.layers0.popupInfo = popupInfo;
815
+ this.layers0.layerType = _3D_OBJECT_LAYER_TYPE;
816
+ attributeIndex += 1;
817
+ }
859
818
  }
860
-
861
- this.refreshTokenTime = process.hrtime();
862
- const preloadOptions = await this._fetchPreloadOptions();
863
- this.sourceTileset.options = { ...this.sourceTileset.options,
864
- ...preloadOptions
865
- };
866
-
867
- if (preloadOptions.headers) {
868
- this.sourceTileset.loadOptions.fetch = { ...this.sourceTileset.loadOptions.fetch,
869
- headers: preloadOptions.headers
870
- };
871
- console.log('Authorization Bearer token has been updated');
819
+ /**
820
+ * Print statistics in the end of conversion
821
+ * @param params - output files data
822
+ */
823
+ async _finishConversion(params) {
824
+ const { tilesCount, tilesWithAddRefineCount } = this.refinementCounter;
825
+ const addRefinementPercentage = tilesWithAddRefineCount
826
+ ? (tilesWithAddRefineCount / tilesCount) * 100
827
+ : 0;
828
+ const filesSize = await (0, statistic_utills_1.calculateFilesSize)(params);
829
+ const diff = process_1.default.hrtime(this.conversionStartTime);
830
+ const conversionTime = (0, statistic_utills_1.timeConverter)(diff);
831
+ console.log(`------------------------------------------------`); // eslint-disable-line no-undef, no-console
832
+ console.log(`Finishing conversion of ${_3D_TILES}`); // eslint-disable-line no-undef, no-console
833
+ console.log(`Total conversion time: ${conversionTime}`); // eslint-disable-line no-undef, no-console
834
+ console.log(`Vertex count: `, this.vertexCounter); // eslint-disable-line no-undef, no-console
835
+ console.log(`File(s) size: `, filesSize, ' bytes'); // eslint-disable-line no-undef, no-console
836
+ console.log(`Percentage of tiles with "ADD" refinement type:`, addRefinementPercentage, '%'); // eslint-disable-line no-undef, no-console
837
+ console.log(`------------------------------------------------`); // eslint-disable-line no-undef, no-console
838
+ }
839
+ /**
840
+ * Fetch preload options for ION tileset
841
+ */
842
+ async _fetchPreloadOptions() {
843
+ if (!this.Loader.preload) {
844
+ return {};
845
+ }
846
+ const options = {
847
+ 'cesium-ion': { accessToken: this.options.token || ION_DEFAULT_TOKEN }
848
+ };
849
+ const preloadOptions = await this.Loader.preload(this.options.inputUrl, options);
850
+ this.refreshTokenTime = process_1.default.hrtime();
851
+ return { ...options, ...preloadOptions };
852
+ }
853
+ /**
854
+ * Update options of source tileset
855
+ */
856
+ async _updateTilesetOptions() {
857
+ const diff = process_1.default.hrtime(this.refreshTokenTime);
858
+ if (diff[0] < REFRESH_TOKEN_TIMEOUT) {
859
+ return;
860
+ }
861
+ this.refreshTokenTime = process_1.default.hrtime();
862
+ const preloadOptions = await this._fetchPreloadOptions();
863
+ if (preloadOptions.headers) {
864
+ this.loadOptions.fetch = {
865
+ ...this.loadOptions.fetch,
866
+ headers: preloadOptions.headers
867
+ };
868
+ console.log('Authorization Bearer token has been updated'); // eslint-disable-line no-undef, no-console
869
+ }
872
870
  }
873
- }
874
-
875
- _checkAddRefinementTypeForTile(tile) {
876
- const ADD_TILE_REFINEMENT = 1;
877
-
878
- if (tile.refine === ADD_TILE_REFINEMENT) {
879
- this.refinementCounter.tilesWithAddRefineCount += 1;
880
- console.warn('This tile uses "ADD" type of refinement');
871
+ /** Do calculations of all tiles and tiles with "ADD" type of refinement.
872
+ * @param tile
873
+ */
874
+ _checkAddRefinementTypeForTile(tile) {
875
+ const ADD_TILE_REFINEMENT = 1;
876
+ if (tile.refine === ADD_TILE_REFINEMENT) {
877
+ this.refinementCounter.tilesWithAddRefineCount += 1;
878
+ console.warn('This tile uses "ADD" type of refinement'); // eslint-disable-line
879
+ }
880
+ this.refinementCounter.tilesCount += 1;
881
+ }
882
+ /**
883
+ * Check if the tile's content format is supported by the converter
884
+ * @param sourceTile
885
+ * @returns
886
+ */
887
+ isContentSupported(sourceTile) {
888
+ return ['b3dm', 'glTF', 'scenegraph'].includes(sourceTile.type || '');
889
+ }
890
+ async loadWorkers() {
891
+ console.log(`Loading workers source...`); // eslint-disable-line no-undef, no-console
892
+ if (this.options.draco) {
893
+ const url = (0, worker_utils_1.getWorkerURL)(draco_1.DracoWriterWorker, { ...(0, core_1.getLoaderOptions)() });
894
+ const sourceResponse = await (0, core_1.fetchFile)(url);
895
+ const source = await sourceResponse.text();
896
+ this.workerSource.draco = source;
897
+ }
898
+ if (this.generateTextures) {
899
+ const url = (0, worker_utils_1.getWorkerURL)(textures_1.KTX2BasisWriterWorker, { ...(0, core_1.getLoaderOptions)() });
900
+ const sourceResponse = await (0, core_1.fetchFile)(url);
901
+ const source = await sourceResponse.text();
902
+ this.workerSource.ktx2 = source;
903
+ }
904
+ const i3sAttributesWorkerUrl = (0, worker_utils_1.getWorkerURL)(i3s_attributes_worker_1.I3SAttributesWorker, { ...(0, core_1.getLoaderOptions)() });
905
+ const sourceResponse = await (0, core_1.fetchFile)(i3sAttributesWorkerUrl);
906
+ const source = await sourceResponse.text();
907
+ this.workerSource.I3SAttributes = source;
908
+ console.log(`Loading workers source completed!`); // eslint-disable-line no-undef, no-console
881
909
  }
882
-
883
- this.refinementCounter.tilesCount += 1;
884
- }
885
-
886
910
  }
887
- //# sourceMappingURL=i3s-converter.js.map
911
+ exports.default = I3SConverter;