@loaders.gl/tile-converter 4.0.0-alpha.4 → 4.0.0-alpha.6

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