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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/bin/i3s-server.js +4 -0
  2. package/bin/slpk-extractor.js +4 -0
  3. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +5 -5
  4. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  5. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +10 -5
  6. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  7. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts +10 -0
  8. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -0
  9. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +2 -1
  10. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -1
  11. package/dist/converter.min.js +172 -103
  12. package/dist/deps-installer/deps-installer.d.ts +3 -2
  13. package/dist/deps-installer/deps-installer.d.ts.map +1 -1
  14. package/dist/dist.min.js +32715 -32567
  15. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +97 -117
  16. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  17. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +24 -22
  18. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  19. package/dist/es5/3d-tiles-converter/helpers/load-i3s.js +63 -0
  20. package/dist/es5/3d-tiles-converter/helpers/load-i3s.js.map +1 -0
  21. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  22. package/dist/es5/converter-cli.js +25 -65
  23. package/dist/es5/converter-cli.js.map +1 -1
  24. package/dist/es5/deps-installer/deps-installer.js +113 -39
  25. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  26. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +45 -15
  27. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  29. package/dist/es5/i3s-converter/helpers/feature-attributes.js +8 -18
  30. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
  31. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +83 -43
  32. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  33. package/dist/es5/i3s-converter/helpers/geometry-converter.js +100 -102
  34. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  35. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  36. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js +70 -4
  37. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js.map +1 -1
  38. package/dist/es5/i3s-converter/helpers/node-index-document.js +3 -2
  39. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
  40. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +47 -12
  41. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
  42. package/dist/es5/i3s-converter/i3s-converter.js +187 -174
  43. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  44. package/dist/es5/i3s-converter/types.js +11 -11
  45. package/dist/es5/i3s-converter/types.js.map +1 -1
  46. package/dist/es5/i3s-server/README.md +46 -2
  47. package/dist/es5/i3s-server/app.js +23 -15
  48. package/dist/es5/i3s-server/app.js.map +1 -1
  49. package/dist/es5/i3s-server/bin/www.js +33 -0
  50. package/dist/es5/i3s-server/bin/www.js.map +1 -0
  51. package/dist/es5/i3s-server/controllers/index-controller.js +23 -22
  52. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  53. package/dist/es5/i3s-server/controllers/slpk-controller.js +35 -38
  54. package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -1
  55. package/dist/es5/i3s-server/routes/index.js +2 -2
  56. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  57. package/dist/es5/i3s-server/routes/slpk-router.js +14 -13
  58. package/dist/es5/i3s-server/routes/slpk-router.js.map +1 -1
  59. package/dist/es5/i3s-server/utils/create-scene-server.js +7 -4
  60. package/dist/es5/i3s-server/utils/create-scene-server.js.map +1 -1
  61. package/dist/es5/i3s-server/utils/server-utils.js +49 -0
  62. package/dist/es5/i3s-server/utils/server-utils.js.map +1 -0
  63. package/dist/es5/lib/utils/cli-utils.js +57 -0
  64. package/dist/es5/lib/utils/cli-utils.js.map +1 -0
  65. package/dist/es5/lib/utils/compress-util.js +1 -1
  66. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  67. package/dist/es5/lib/utils/lod-conversion-utils.js +10 -4
  68. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  69. package/dist/es5/pgm-loader.js +11 -3
  70. package/dist/es5/pgm-loader.js.map +1 -1
  71. package/dist/es5/slpk-extractor/slpk-extractor.js +171 -0
  72. package/dist/es5/slpk-extractor/slpk-extractor.js.map +1 -0
  73. package/dist/es5/slpk-extractor-cli.js +117 -0
  74. package/dist/es5/slpk-extractor-cli.js.map +1 -0
  75. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +51 -58
  76. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  77. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +12 -11
  78. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  79. package/dist/esm/3d-tiles-converter/helpers/load-i3s.js +32 -0
  80. package/dist/esm/3d-tiles-converter/helpers/load-i3s.js.map +1 -0
  81. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  82. package/dist/esm/converter-cli.js +8 -48
  83. package/dist/esm/converter-cli.js.map +1 -1
  84. package/dist/esm/deps-installer/deps-installer.js +38 -12
  85. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  86. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +28 -11
  87. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  88. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  89. package/dist/esm/i3s-converter/helpers/feature-attributes.js +10 -8
  90. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
  91. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +77 -34
  92. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  93. package/dist/esm/i3s-converter/helpers/geometry-converter.js +60 -61
  94. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  95. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  96. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js +33 -4
  97. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js.map +1 -1
  98. package/dist/esm/i3s-converter/helpers/node-index-document.js +2 -1
  99. package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -1
  100. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +37 -12
  101. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
  102. package/dist/esm/i3s-converter/i3s-converter.js +101 -73
  103. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  104. package/dist/esm/i3s-converter/types.js +9 -9
  105. package/dist/esm/i3s-converter/types.js.map +1 -1
  106. package/dist/esm/i3s-server/README.md +46 -2
  107. package/dist/esm/i3s-server/app.js +13 -11
  108. package/dist/esm/i3s-server/app.js.map +1 -1
  109. package/dist/esm/i3s-server/bin/i3s-server.min.js +516 -0
  110. package/dist/esm/i3s-server/bin/www.js +30 -0
  111. package/dist/esm/i3s-server/bin/www.js.map +1 -0
  112. package/dist/esm/i3s-server/controllers/index-controller.js +4 -7
  113. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
  114. package/dist/esm/i3s-server/controllers/slpk-controller.js +9 -26
  115. package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -1
  116. package/dist/esm/i3s-server/routes/index.js +1 -1
  117. package/dist/esm/i3s-server/routes/index.js.map +1 -1
  118. package/dist/esm/i3s-server/routes/slpk-router.js +5 -11
  119. package/dist/esm/i3s-server/routes/slpk-router.js.map +1 -1
  120. package/dist/esm/i3s-server/utils/create-scene-server.js +2 -5
  121. package/dist/esm/i3s-server/utils/create-scene-server.js.map +1 -1
  122. package/dist/esm/i3s-server/utils/server-utils.js +40 -0
  123. package/dist/esm/i3s-server/utils/server-utils.js.map +1 -0
  124. package/dist/esm/lib/utils/cli-utils.js +47 -0
  125. package/dist/esm/lib/utils/cli-utils.js.map +1 -0
  126. package/dist/esm/lib/utils/compress-util.js +1 -1
  127. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  128. package/dist/esm/lib/utils/lod-conversion-utils.js +6 -4
  129. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  130. package/dist/esm/pgm-loader.js +7 -4
  131. package/dist/esm/pgm-loader.js.map +1 -1
  132. package/dist/esm/slpk-extractor/slpk-extractor.js +63 -0
  133. package/dist/esm/slpk-extractor/slpk-extractor.js.map +1 -0
  134. package/dist/esm/slpk-extractor-cli.js +74 -0
  135. package/dist/esm/slpk-extractor-cli.js.map +1 -0
  136. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +15 -2
  137. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  138. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +1 -2
  139. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
  140. package/dist/i3s-converter/helpers/feature-attributes.d.ts +8 -8
  141. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
  142. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  143. package/dist/i3s-converter/helpers/geometry-converter.d.ts +9 -9
  144. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  145. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +3 -3
  146. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  147. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts +15 -0
  148. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts.map +1 -1
  149. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  150. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +4 -5
  151. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
  152. package/dist/i3s-converter/i3s-converter.d.ts +3 -2
  153. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  154. package/dist/i3s-converter/types.d.ts +48 -7
  155. package/dist/i3s-converter/types.d.ts.map +1 -1
  156. package/dist/i3s-server/app.d.ts +1 -2
  157. package/dist/i3s-server/app.d.ts.map +1 -1
  158. package/dist/i3s-server/bin/www.d.ts +3 -0
  159. package/dist/i3s-server/bin/www.d.ts.map +1 -0
  160. package/dist/i3s-server/controllers/index-controller.d.ts +6 -1
  161. package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -1
  162. package/dist/i3s-server/controllers/slpk-controller.d.ts +13 -2
  163. package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -1
  164. package/dist/i3s-server/routes/index.d.ts +1 -2
  165. package/dist/i3s-server/routes/index.d.ts.map +1 -1
  166. package/dist/i3s-server/routes/slpk-router.d.ts +2 -2
  167. package/dist/i3s-server/routes/slpk-router.d.ts.map +1 -1
  168. package/dist/i3s-server/utils/create-scene-server.d.ts +11 -5
  169. package/dist/i3s-server/utils/create-scene-server.d.ts.map +1 -1
  170. package/dist/i3s-server/utils/server-utils.d.ts +24 -0
  171. package/dist/i3s-server/utils/server-utils.d.ts.map +1 -0
  172. package/dist/lib/utils/cli-utils.d.ts +34 -0
  173. package/dist/lib/utils/cli-utils.d.ts.map +1 -0
  174. package/dist/lib/utils/lod-conversion-utils.d.ts +2 -2
  175. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -1
  176. package/dist/pgm-loader.d.ts +9 -2
  177. package/dist/pgm-loader.d.ts.map +1 -1
  178. package/dist/slpk-extractor/slpk-extractor.d.ts +23 -0
  179. package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -0
  180. package/dist/slpk-extractor-cli.d.ts +17 -0
  181. package/dist/slpk-extractor-cli.d.ts.map +1 -0
  182. package/dist/slpk-extractor.min.js +189 -0
  183. package/package.json +27 -21
  184. package/src/3d-tiles-converter/3d-tiles-converter.ts +65 -69
  185. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +23 -19
  186. package/src/3d-tiles-converter/helpers/load-i3s.ts +52 -0
  187. package/src/3d-tiles-converter/helpers/texture-atlas.ts +6 -2
  188. package/src/converter-cli.ts +16 -74
  189. package/src/deps-installer/deps-installer.ts +56 -11
  190. package/src/i3s-converter/helpers/batch-ids-extensions.ts +77 -32
  191. package/src/i3s-converter/helpers/coordinate-converter.ts +1 -2
  192. package/src/i3s-converter/helpers/feature-attributes.ts +23 -18
  193. package/src/i3s-converter/helpers/geometry-attributes.ts +81 -44
  194. package/src/i3s-converter/helpers/geometry-converter.ts +149 -126
  195. package/src/i3s-converter/helpers/gltf-attributes.ts +9 -10
  196. package/src/i3s-converter/helpers/load-3d-tiles.ts +61 -5
  197. package/src/i3s-converter/helpers/node-index-document.ts +5 -1
  198. package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +70 -21
  199. package/src/i3s-converter/i3s-converter.ts +145 -73
  200. package/src/i3s-converter/types.ts +49 -7
  201. package/src/i3s-server/README.md +46 -2
  202. package/src/i3s-server/{app.js → app.ts} +11 -9
  203. package/src/i3s-server/bin/www.ts +38 -0
  204. package/src/i3s-server/controllers/{index-controller.js → index-controller.ts} +10 -9
  205. package/src/i3s-server/controllers/slpk-controller.ts +32 -0
  206. package/src/i3s-server/routes/{index.js → index.ts} +2 -1
  207. package/src/i3s-server/routes/{slpk-router.js → slpk-router.ts} +5 -10
  208. package/src/i3s-server/utils/create-scene-server.ts +20 -0
  209. package/src/i3s-server/utils/server-utils.ts +70 -0
  210. package/src/lib/utils/cli-utils.ts +78 -0
  211. package/src/lib/utils/compress-util.ts +1 -1
  212. package/src/lib/utils/lod-conversion-utils.ts +10 -6
  213. package/src/pgm-loader.ts +15 -7
  214. package/src/slpk-extractor/slpk-extractor.ts +101 -0
  215. package/src/slpk-extractor-cli.ts +128 -0
  216. package/dist/3d-tiles-attributes-worker.d.ts +0 -28
  217. package/dist/3d-tiles-attributes-worker.d.ts.map +0 -1
  218. package/dist/3d-tiles-attributes-worker.js +0 -3
  219. package/dist/3d-tiles-attributes-worker.js.map +0 -7
  220. package/dist/3d-tiles-converter/3d-tiles-converter.js +0 -288
  221. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +0 -269
  222. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -23
  223. package/dist/3d-tiles-converter/helpers/texture-atlas.js +0 -52
  224. package/dist/3d-tiles-converter/json-templates/tileset.js +0 -43
  225. package/dist/bundle.js +0 -5
  226. package/dist/constants.js +0 -4
  227. package/dist/converter-cli.js +0 -280
  228. package/dist/deps-installer/deps-installer.js +0 -63
  229. package/dist/es5/3d-tiles-attributes-worker.js +0 -25
  230. package/dist/es5/3d-tiles-attributes-worker.js.map +0 -1
  231. package/dist/es5/i3s-attributes-worker.js +0 -25
  232. package/dist/es5/i3s-attributes-worker.js.map +0 -1
  233. package/dist/es5/i3s-server/bin/www +0 -102
  234. package/dist/es5/workers/3d-tiles-attributes-worker.js +0 -28
  235. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +0 -1
  236. package/dist/es5/workers/i3s-attributes-worker.js +0 -30
  237. package/dist/es5/workers/i3s-attributes-worker.js.map +0 -1
  238. package/dist/esm/3d-tiles-attributes-worker.js +0 -16
  239. package/dist/esm/3d-tiles-attributes-worker.js.map +0 -1
  240. package/dist/esm/i3s-attributes-worker.js +0 -16
  241. package/dist/esm/i3s-attributes-worker.js.map +0 -1
  242. package/dist/esm/i3s-server/bin/www +0 -102
  243. package/dist/esm/workers/3d-tiles-attributes-worker.js +0 -8
  244. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +0 -1
  245. package/dist/esm/workers/i3s-attributes-worker.js +0 -7
  246. package/dist/esm/workers/i3s-attributes-worker.js.map +0 -1
  247. package/dist/i3s-attributes-worker.d.ts +0 -45
  248. package/dist/i3s-attributes-worker.d.ts.map +0 -1
  249. package/dist/i3s-attributes-worker.js +0 -9
  250. package/dist/i3s-attributes-worker.js.map +0 -7
  251. package/dist/i3s-converter/helpers/batch-ids-extensions.js +0 -138
  252. package/dist/i3s-converter/helpers/coordinate-converter.js +0 -123
  253. package/dist/i3s-converter/helpers/create-scene-server-path.js +0 -28
  254. package/dist/i3s-converter/helpers/feature-attributes.js +0 -216
  255. package/dist/i3s-converter/helpers/geometry-attributes.js +0 -202
  256. package/dist/i3s-converter/helpers/geometry-converter.js +0 -1225
  257. package/dist/i3s-converter/helpers/gltf-attributes.js +0 -128
  258. package/dist/i3s-converter/helpers/load-3d-tiles.js +0 -53
  259. package/dist/i3s-converter/helpers/node-debug.js +0 -120
  260. package/dist/i3s-converter/helpers/node-index-document.js +0 -268
  261. package/dist/i3s-converter/helpers/node-pages.js +0 -316
  262. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +0 -76
  263. package/dist/i3s-converter/helpers/tileset-traversal.js +0 -29
  264. package/dist/i3s-converter/i3s-converter.js +0 -911
  265. package/dist/i3s-converter/json-templates/geometry-definitions.js +0 -87
  266. package/dist/i3s-converter/json-templates/layers.js +0 -139
  267. package/dist/i3s-converter/json-templates/metadata.js +0 -25
  268. package/dist/i3s-converter/json-templates/node.js +0 -89
  269. package/dist/i3s-converter/json-templates/scene-server.js +0 -31
  270. package/dist/i3s-converter/json-templates/shared-resources.js +0 -129
  271. package/dist/i3s-converter/json-templates/store.js +0 -103
  272. package/dist/i3s-converter/types.js +0 -17
  273. package/dist/i3s-server/app.js +0 -22
  274. package/dist/i3s-server/controllers/index-controller.js +0 -23
  275. package/dist/i3s-server/controllers/slpk-controller.js +0 -32
  276. package/dist/i3s-server/routes/index.js +0 -16
  277. package/dist/i3s-server/routes/slpk-router.js +0 -33
  278. package/dist/i3s-server/utils/create-scene-server.js +0 -14
  279. package/dist/index.js +0 -10
  280. package/dist/lib/utils/compress-util.js +0 -257
  281. package/dist/lib/utils/file-utils.js +0 -139
  282. package/dist/lib/utils/geometry-utils.js +0 -18
  283. package/dist/lib/utils/lod-conversion-utils.js +0 -76
  284. package/dist/lib/utils/queue.js +0 -18
  285. package/dist/lib/utils/statistic-utills.js +0 -64
  286. package/dist/lib/utils/write-queue.js +0 -80
  287. package/dist/pgm-loader.js +0 -24
  288. package/dist/workers/3d-tiles-attributes-worker.d.ts +0 -2
  289. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +0 -1
  290. package/dist/workers/3d-tiles-attributes-worker.js +0 -9
  291. package/dist/workers/i3s-attributes-worker.d.ts +0 -2
  292. package/dist/workers/i3s-attributes-worker.d.ts.map +0 -1
  293. package/dist/workers/i3s-attributes-worker.js +0 -5
  294. package/src/3d-tiles-attributes-worker.ts +0 -43
  295. package/src/i3s-attributes-worker.ts +0 -59
  296. package/src/i3s-server/bin/www +0 -102
  297. package/src/i3s-server/controllers/slpk-controller.js +0 -38
  298. package/src/i3s-server/utils/create-scene-server.js +0 -15
  299. package/src/workers/3d-tiles-attributes-worker.ts +0 -6
  300. package/src/workers/i3s-attributes-worker.ts +0 -7
@@ -1,911 +0,0 @@
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
67
- const HARDCODED_NODES_PER_PAGE = 64;
68
- const _3D_TILES = '3DTILES';
69
- const _3D_OBJECT_LAYER_TYPE = '3DObject';
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 }
233
- });
234
- const tilePreprocessData = await (0, preprocess_3d_tiles_1.analyzeTileContent)(sourceTile, 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: []
264
- });
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() {
326
- if (this.options.slpk) {
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
- });
336
- }
337
- }
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
- }
372
- }
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
- }
421
- }
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
- }
623
- }
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
- }
649
- }
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
- }
696
- }
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
- }
720
- }
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
- }
747
- }
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
- }
763
- }
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
- }
818
- }
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
- }
870
- }
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
909
- }
910
- }
911
- exports.default = I3SConverter;