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

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 (468) hide show
  1. package/bin/converter.js +1 -1
  2. package/dist/3d-tiles-attributes-worker.d.ts +28 -0
  3. package/dist/3d-tiles-attributes-worker.d.ts.map +1 -0
  4. package/dist/3d-tiles-attributes-worker.js +3 -0
  5. package/dist/3d-tiles-attributes-worker.js.map +7 -0
  6. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +90 -0
  7. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -0
  8. package/dist/3d-tiles-converter/3d-tiles-converter.js +275 -226
  9. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +71 -18
  10. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -0
  11. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +256 -236
  12. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +4 -7
  13. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts.map +1 -0
  14. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +22 -9
  15. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +9 -0
  16. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -0
  17. package/dist/3d-tiles-converter/helpers/texture-atlas.js +47 -28
  18. package/dist/3d-tiles-converter/json-templates/tileset.d.ts +15 -0
  19. package/dist/3d-tiles-converter/json-templates/tileset.d.ts.map +1 -0
  20. package/dist/3d-tiles-converter/json-templates/tileset.js +42 -36
  21. package/dist/bundle.d.ts +2 -0
  22. package/dist/bundle.d.ts.map +1 -0
  23. package/dist/bundle.js +2 -2
  24. package/dist/constants.d.ts +2 -0
  25. package/dist/constants.d.ts.map +1 -0
  26. package/dist/constants.js +4 -0
  27. package/dist/converter-cli.d.ts +2 -0
  28. package/dist/converter-cli.d.ts.map +1 -0
  29. package/dist/converter-cli.js +280 -0
  30. package/dist/converter.min.js +185 -190
  31. package/dist/deps-installer/deps-installer.d.ts +11 -3
  32. package/dist/deps-installer/deps-installer.d.ts.map +1 -0
  33. package/dist/deps-installer/deps-installer.js +61 -23
  34. package/dist/dist.min.js +64143 -0
  35. package/dist/es5/3d-tiles-attributes-worker.js +25 -0
  36. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -0
  37. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +467 -0
  38. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
  39. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +293 -0
  40. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
  41. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +18 -0
  42. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
  43. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +33 -0
  44. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  45. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +61 -0
  46. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -0
  47. package/dist/es5/bundle.js +6 -0
  48. package/dist/es5/bundle.js.map +1 -0
  49. package/dist/es5/constants.js +9 -0
  50. package/dist/es5/constants.js.map +1 -0
  51. package/dist/es5/converter-cli.js +289 -0
  52. package/dist/es5/converter-cli.js.map +1 -0
  53. package/dist/es5/deps-installer/deps-installer.js +124 -0
  54. package/dist/es5/deps-installer/deps-installer.js.map +1 -0
  55. package/dist/es5/i3s-attributes-worker.js +25 -0
  56. package/dist/es5/i3s-attributes-worker.js.map +1 -0
  57. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +116 -0
  58. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  59. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +89 -0
  60. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -0
  61. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +41 -0
  62. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
  63. package/dist/es5/i3s-converter/helpers/feature-attributes.js +174 -0
  64. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -0
  65. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +213 -0
  66. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -0
  67. package/dist/es5/i3s-converter/helpers/geometry-converter.js +1192 -0
  68. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -0
  69. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +113 -0
  70. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  71. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js +82 -0
  72. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js.map +1 -0
  73. package/dist/es5/i3s-converter/helpers/node-debug.js +76 -0
  74. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -0
  75. package/dist/es5/i3s-converter/helpers/node-index-document.js +521 -0
  76. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -0
  77. package/dist/es5/i3s-converter/helpers/node-pages.js +519 -0
  78. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -0
  79. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +111 -0
  80. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -0
  81. package/dist/es5/i3s-converter/helpers/tileset-traversal.js +82 -0
  82. package/dist/es5/i3s-converter/helpers/tileset-traversal.js.map +1 -0
  83. package/dist/es5/i3s-converter/i3s-converter.js +1541 -0
  84. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -0
  85. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js +107 -0
  86. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
  87. package/dist/es5/i3s-converter/json-templates/layers.js +163 -0
  88. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -0
  89. package/dist/es5/i3s-converter/json-templates/metadata.js +31 -0
  90. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -0
  91. package/dist/es5/i3s-converter/json-templates/node.js +99 -0
  92. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -0
  93. package/dist/es5/i3s-converter/json-templates/scene-server.js +39 -0
  94. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -0
  95. package/dist/es5/i3s-converter/json-templates/shared-resources.js +173 -0
  96. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -0
  97. package/dist/es5/i3s-converter/json-templates/store.js +107 -0
  98. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -0
  99. package/dist/es5/i3s-converter/types.js +18 -0
  100. package/dist/es5/i3s-converter/types.js.map +1 -0
  101. package/dist/es5/i3s-server/README.md +19 -0
  102. package/dist/es5/i3s-server/app.js +27 -0
  103. package/dist/es5/i3s-server/app.js.map +1 -0
  104. package/dist/es5/i3s-server/controllers/index-controller.js +55 -0
  105. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -0
  106. package/dist/es5/i3s-server/controllers/slpk-controller.js +84 -0
  107. package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -0
  108. package/dist/es5/i3s-server/routes/index.js +37 -0
  109. package/dist/es5/i3s-server/routes/index.js.map +1 -0
  110. package/dist/es5/i3s-server/routes/slpk-router.js +71 -0
  111. package/dist/es5/i3s-server/routes/slpk-router.js.map +1 -0
  112. package/dist/es5/i3s-server/utils/create-scene-server.js +17 -0
  113. package/dist/es5/i3s-server/utils/create-scene-server.js.map +1 -0
  114. package/dist/es5/index.js +21 -0
  115. package/dist/es5/index.js.map +1 -0
  116. package/dist/es5/lib/utils/compress-util.js +346 -0
  117. package/dist/es5/lib/utils/compress-util.js.map +1 -0
  118. package/dist/es5/lib/utils/file-utils.js +208 -0
  119. package/dist/es5/lib/utils/file-utils.js.map +1 -0
  120. package/dist/es5/lib/utils/geometry-utils.js +15 -0
  121. package/dist/es5/lib/utils/geometry-utils.js.map +1 -0
  122. package/dist/es5/lib/utils/lod-conversion-utils.js +44 -0
  123. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -0
  124. package/dist/es5/lib/utils/queue.js +47 -0
  125. package/dist/es5/lib/utils/queue.js.map +1 -0
  126. package/dist/es5/lib/utils/statistic-utills.d.ts +25 -0
  127. package/dist/es5/lib/utils/statistic-utills.js +147 -0
  128. package/dist/es5/lib/utils/statistic-utills.js.map +1 -0
  129. package/dist/es5/lib/utils/write-queue.js +214 -0
  130. package/dist/es5/lib/utils/write-queue.js.map +1 -0
  131. package/dist/es5/pgm-loader.js +41 -0
  132. package/dist/es5/pgm-loader.js.map +1 -0
  133. package/dist/es5/workers/3d-tiles-attributes-worker.js +28 -0
  134. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -0
  135. package/dist/es5/workers/i3s-attributes-worker.js +30 -0
  136. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -0
  137. package/dist/esm/3d-tiles-attributes-worker.js +16 -0
  138. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -0
  139. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +245 -0
  140. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
  141. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +218 -0
  142. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
  143. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +10 -0
  144. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
  145. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +27 -0
  146. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  147. package/dist/esm/3d-tiles-converter/json-templates/tileset.js +37 -0
  148. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -0
  149. package/dist/esm/bundle.js +4 -0
  150. package/dist/esm/bundle.js.map +1 -0
  151. package/dist/esm/constants.js +2 -0
  152. package/dist/esm/constants.js.map +1 -0
  153. package/dist/esm/converter-cli.js +232 -0
  154. package/dist/esm/converter-cli.js.map +1 -0
  155. package/dist/esm/deps-installer/deps-installer.js +45 -0
  156. package/dist/esm/deps-installer/deps-installer.js.map +1 -0
  157. package/dist/esm/i3s-attributes-worker.js +16 -0
  158. package/dist/esm/i3s-attributes-worker.js.map +1 -0
  159. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +105 -0
  160. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  161. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +79 -0
  162. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -0
  163. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +16 -0
  164. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
  165. package/dist/esm/i3s-converter/helpers/feature-attributes.js +147 -0
  166. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -0
  167. package/{src → dist/esm}/i3s-converter/helpers/geometry-attributes.js +80 -106
  168. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -0
  169. package/dist/esm/i3s-converter/helpers/geometry-converter.js +906 -0
  170. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -0
  171. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +110 -0
  172. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  173. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js +35 -0
  174. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js.map +1 -0
  175. package/{src → dist/esm}/i3s-converter/helpers/node-debug.js +20 -41
  176. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -0
  177. package/dist/esm/i3s-converter/helpers/node-index-document.js +201 -0
  178. package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -0
  179. package/dist/esm/i3s-converter/helpers/node-pages.js +206 -0
  180. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -0
  181. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +48 -0
  182. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -0
  183. package/dist/esm/i3s-converter/helpers/tileset-traversal.js +14 -0
  184. package/dist/esm/i3s-converter/helpers/tileset-traversal.js.map +1 -0
  185. package/dist/esm/i3s-converter/i3s-converter.js +778 -0
  186. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -0
  187. package/dist/esm/i3s-converter/json-templates/geometry-definitions.js +89 -0
  188. package/dist/esm/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
  189. package/dist/esm/i3s-converter/json-templates/layers.js +133 -0
  190. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -0
  191. package/dist/esm/i3s-converter/json-templates/metadata.js +22 -0
  192. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -0
  193. package/dist/esm/i3s-converter/json-templates/node.js +80 -0
  194. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -0
  195. package/dist/esm/i3s-converter/json-templates/scene-server.js +28 -0
  196. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -0
  197. package/dist/esm/i3s-converter/json-templates/shared-resources.js +123 -0
  198. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -0
  199. package/dist/esm/i3s-converter/json-templates/store.js +98 -0
  200. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -0
  201. package/dist/esm/i3s-converter/types.js +11 -0
  202. package/dist/esm/i3s-converter/types.js.map +1 -0
  203. package/dist/esm/i3s-server/README.md +19 -0
  204. package/dist/esm/i3s-server/app.js +26 -0
  205. package/dist/esm/i3s-server/app.js.map +1 -0
  206. package/dist/esm/i3s-server/bin/www +102 -0
  207. package/dist/esm/i3s-server/certs/cert.pem +19 -0
  208. package/dist/esm/i3s-server/certs/key.pem +27 -0
  209. package/dist/esm/i3s-server/controllers/index-controller.js +24 -0
  210. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -0
  211. package/dist/esm/i3s-server/controllers/slpk-controller.js +36 -0
  212. package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -0
  213. package/dist/esm/i3s-server/routes/index.js +16 -0
  214. package/dist/esm/i3s-server/routes/index.js.map +1 -0
  215. package/dist/esm/i3s-server/routes/slpk-router.js +33 -0
  216. package/dist/esm/i3s-server/routes/slpk-router.js.map +1 -0
  217. package/dist/esm/i3s-server/utils/create-scene-server.js +16 -0
  218. package/dist/esm/i3s-server/utils/create-scene-server.js.map +1 -0
  219. package/dist/esm/index.js +3 -0
  220. package/dist/esm/index.js.map +1 -0
  221. package/dist/esm/lib/utils/compress-util.js +168 -0
  222. package/dist/esm/lib/utils/compress-util.js.map +1 -0
  223. package/dist/esm/lib/utils/file-utils.js +87 -0
  224. package/dist/esm/lib/utils/file-utils.js.map +1 -0
  225. package/dist/esm/lib/utils/geometry-utils.js +8 -0
  226. package/dist/esm/lib/utils/geometry-utils.js.map +1 -0
  227. package/dist/esm/lib/utils/lod-conversion-utils.js +37 -0
  228. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -0
  229. package/dist/esm/lib/utils/queue.js +15 -0
  230. package/dist/esm/lib/utils/queue.js.map +1 -0
  231. package/dist/esm/lib/utils/statistic-utills.d.ts +25 -0
  232. package/dist/esm/lib/utils/statistic-utills.js +62 -0
  233. package/dist/esm/lib/utils/statistic-utills.js.map +1 -0
  234. package/dist/esm/lib/utils/write-queue.js +85 -0
  235. package/dist/esm/lib/utils/write-queue.js.map +1 -0
  236. package/dist/esm/pgm-loader.js +15 -0
  237. package/dist/esm/pgm-loader.js.map +1 -0
  238. package/dist/esm/workers/3d-tiles-attributes-worker.js +8 -0
  239. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -0
  240. package/dist/esm/workers/i3s-attributes-worker.js +7 -0
  241. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -0
  242. package/dist/i3s-attributes-worker.d.ts +45 -0
  243. package/dist/i3s-attributes-worker.d.ts.map +1 -0
  244. package/dist/i3s-attributes-worker.js +9 -0
  245. package/dist/i3s-attributes-worker.js.map +7 -0
  246. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +13 -0
  247. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -0
  248. package/dist/i3s-converter/helpers/batch-ids-extensions.js +138 -0
  249. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +40 -0
  250. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -0
  251. package/dist/i3s-converter/helpers/coordinate-converter.js +119 -42
  252. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +9 -0
  253. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -0
  254. package/dist/i3s-converter/helpers/create-scene-server-path.js +27 -15
  255. package/dist/i3s-converter/helpers/feature-attributes.d.ts +56 -0
  256. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -0
  257. package/dist/i3s-converter/helpers/feature-attributes.js +216 -0
  258. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +8 -0
  259. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -0
  260. package/dist/i3s-converter/helpers/geometry-attributes.js +188 -185
  261. package/dist/i3s-converter/helpers/geometry-converter.d.ts +41 -35
  262. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -0
  263. package/dist/i3s-converter/helpers/geometry-converter.js +1179 -650
  264. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +28 -0
  265. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -0
  266. package/dist/i3s-converter/helpers/gltf-attributes.js +128 -0
  267. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts +18 -0
  268. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts.map +1 -0
  269. package/dist/i3s-converter/helpers/load-3d-tiles.js +53 -0
  270. package/dist/i3s-converter/helpers/node-debug.d.ts +8 -0
  271. package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -0
  272. package/dist/i3s-converter/helpers/node-debug.js +106 -74
  273. package/dist/i3s-converter/helpers/node-index-document.d.ts +103 -0
  274. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -0
  275. package/dist/i3s-converter/helpers/node-index-document.js +268 -0
  276. package/dist/i3s-converter/helpers/node-pages.d.ts +125 -113
  277. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -0
  278. package/dist/i3s-converter/helpers/node-pages.js +313 -133
  279. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +23 -0
  280. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -0
  281. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +76 -0
  282. package/dist/i3s-converter/helpers/tileset-traversal.d.ts +25 -0
  283. package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -0
  284. package/dist/i3s-converter/helpers/tileset-traversal.js +29 -0
  285. package/dist/i3s-converter/i3s-converter.d.ts +267 -0
  286. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -0
  287. package/dist/i3s-converter/i3s-converter.js +891 -867
  288. package/dist/i3s-converter/json-templates/geometry-definitions.d.ts +7 -0
  289. package/dist/i3s-converter/json-templates/geometry-definitions.d.ts.map +1 -0
  290. package/dist/i3s-converter/json-templates/geometry-definitions.js +87 -0
  291. package/dist/i3s-converter/json-templates/layers.d.ts +70 -0
  292. package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -0
  293. package/dist/i3s-converter/json-templates/layers.js +138 -190
  294. package/dist/i3s-converter/json-templates/metadata.d.ts +22 -0
  295. package/dist/i3s-converter/json-templates/metadata.d.ts.map +1 -0
  296. package/dist/i3s-converter/json-templates/metadata.js +25 -22
  297. package/dist/i3s-converter/json-templates/node.d.ts +61 -0
  298. package/dist/i3s-converter/json-templates/node.d.ts.map +1 -0
  299. package/dist/i3s-converter/json-templates/node.js +88 -79
  300. package/dist/i3s-converter/json-templates/scene-server.d.ts +28 -0
  301. package/dist/i3s-converter/json-templates/scene-server.d.ts.map +1 -0
  302. package/dist/i3s-converter/json-templates/scene-server.js +31 -28
  303. package/dist/i3s-converter/json-templates/shared-resources.d.ts +14 -0
  304. package/dist/i3s-converter/json-templates/shared-resources.d.ts.map +1 -0
  305. package/dist/i3s-converter/json-templates/shared-resources.js +124 -125
  306. package/dist/i3s-converter/json-templates/store.d.ts +95 -0
  307. package/dist/i3s-converter/json-templates/store.d.ts.map +1 -0
  308. package/dist/i3s-converter/json-templates/store.js +100 -95
  309. package/dist/i3s-converter/types.d.ts +163 -0
  310. package/dist/i3s-converter/types.d.ts.map +1 -0
  311. package/dist/i3s-converter/types.js +17 -0
  312. package/dist/i3s-server/app.d.ts +3 -0
  313. package/dist/i3s-server/app.d.ts.map +1 -0
  314. package/dist/i3s-server/app.js +11 -10
  315. package/dist/i3s-server/controllers/index-controller.d.ts +2 -0
  316. package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -0
  317. package/dist/i3s-server/controllers/index-controller.js +16 -24
  318. package/dist/i3s-server/controllers/slpk-controller.d.ts +3 -0
  319. package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -0
  320. package/dist/i3s-server/controllers/slpk-controller.js +32 -0
  321. package/dist/i3s-server/routes/index.d.ts +3 -0
  322. package/dist/i3s-server/routes/index.d.ts.map +1 -0
  323. package/dist/i3s-server/routes/index.js +11 -15
  324. package/dist/i3s-server/routes/slpk-router.d.ts +3 -0
  325. package/dist/i3s-server/routes/slpk-router.d.ts.map +1 -0
  326. package/dist/i3s-server/routes/slpk-router.js +33 -0
  327. package/dist/i3s-server/utils/create-scene-server.d.ts +11 -0
  328. package/dist/i3s-server/utils/create-scene-server.d.ts.map +1 -0
  329. package/dist/i3s-server/utils/create-scene-server.js +14 -0
  330. package/dist/index.d.ts +3 -0
  331. package/dist/index.d.ts.map +1 -0
  332. package/dist/index.js +10 -5
  333. package/dist/lib/utils/compress-util.d.ts +45 -0
  334. package/dist/lib/utils/compress-util.d.ts.map +1 -0
  335. package/dist/lib/utils/compress-util.js +238 -160
  336. package/dist/lib/utils/file-utils.d.ts +22 -14
  337. package/dist/lib/utils/file-utils.d.ts.map +1 -0
  338. package/dist/lib/utils/file-utils.js +134 -36
  339. package/dist/lib/utils/geometry-utils.d.ts +9 -0
  340. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  341. package/dist/lib/utils/geometry-utils.js +18 -0
  342. package/dist/lib/utils/lod-conversion-utils.d.ts +23 -13
  343. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -0
  344. package/dist/lib/utils/lod-conversion-utils.js +72 -39
  345. package/dist/lib/utils/queue.d.ts +7 -0
  346. package/dist/lib/utils/queue.d.ts.map +1 -0
  347. package/dist/lib/utils/queue.js +18 -0
  348. package/dist/lib/utils/statistic-utills.d.ts +3 -25
  349. package/dist/lib/utils/statistic-utills.d.ts.map +1 -0
  350. package/dist/lib/utils/statistic-utills.js +58 -67
  351. package/dist/lib/utils/write-queue.d.ts +39 -0
  352. package/dist/lib/utils/write-queue.d.ts.map +1 -0
  353. package/dist/lib/utils/write-queue.js +80 -0
  354. package/dist/pgm-loader.d.ts +6 -0
  355. package/dist/pgm-loader.d.ts.map +1 -0
  356. package/dist/pgm-loader.js +23 -14
  357. package/dist/workers/3d-tiles-attributes-worker.d.ts +2 -0
  358. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +1 -0
  359. package/dist/workers/3d-tiles-attributes-worker.js +9 -0
  360. package/dist/workers/i3s-attributes-worker.d.ts +2 -0
  361. package/dist/workers/i3s-attributes-worker.d.ts.map +1 -0
  362. package/dist/workers/i3s-attributes-worker.js +5 -0
  363. package/package.json +34 -24
  364. package/src/3d-tiles-attributes-worker.ts +43 -0
  365. package/src/3d-tiles-converter/3d-tiles-converter.ts +131 -63
  366. package/src/3d-tiles-converter/helpers/{b3dm-converter.js → b3dm-converter.ts} +72 -53
  367. package/src/3d-tiles-converter/helpers/{i3s-obb-to-3d-tiles-obb.js → i3s-obb-to-3d-tiles-obb.ts} +16 -1
  368. package/src/3d-tiles-converter/helpers/texture-atlas.ts +4 -4
  369. package/src/3d-tiles-converter/json-templates/{tileset.js → tileset.ts} +9 -9
  370. package/src/constants.ts +2 -0
  371. package/src/converter-cli.ts +370 -0
  372. package/src/deps-installer/deps-installer.ts +72 -0
  373. package/src/i3s-attributes-worker.ts +59 -0
  374. package/src/i3s-converter/helpers/batch-ids-extensions.ts +202 -0
  375. package/src/i3s-converter/helpers/coordinate-converter.ts +94 -33
  376. package/src/i3s-converter/helpers/create-scene-server-path.ts +29 -0
  377. package/src/i3s-converter/helpers/feature-attributes.ts +247 -0
  378. package/src/i3s-converter/helpers/geometry-attributes.ts +267 -0
  379. package/src/i3s-converter/helpers/geometry-converter.ts +1667 -0
  380. package/src/i3s-converter/helpers/gltf-attributes.ts +163 -0
  381. package/src/i3s-converter/helpers/load-3d-tiles.ts +68 -0
  382. package/src/i3s-converter/helpers/node-debug.ts +146 -0
  383. package/src/i3s-converter/helpers/node-index-document.ts +335 -0
  384. package/src/i3s-converter/helpers/node-pages.ts +344 -0
  385. package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +81 -0
  386. package/src/i3s-converter/helpers/tileset-traversal.ts +51 -0
  387. package/src/i3s-converter/i3s-converter.ts +650 -669
  388. package/src/i3s-converter/json-templates/geometry-definitions.ts +83 -0
  389. package/src/i3s-converter/json-templates/layers.ts +137 -0
  390. package/src/i3s-converter/json-templates/{metadata.js → metadata.ts} +2 -2
  391. package/src/i3s-converter/json-templates/{node.js → node.ts} +12 -12
  392. package/src/i3s-converter/json-templates/{scene-server.js → scene-server.ts} +2 -2
  393. package/src/i3s-converter/json-templates/{shared-resources.js → shared-resources.ts} +17 -17
  394. package/src/i3s-converter/types.ts +185 -0
  395. package/src/i3s-server/README.md +19 -0
  396. package/src/i3s-server/app.js +8 -1
  397. package/src/i3s-server/controllers/slpk-controller.js +38 -0
  398. package/src/i3s-server/routes/slpk-router.js +33 -0
  399. package/src/i3s-server/utils/create-scene-server.js +15 -0
  400. package/src/index.ts +0 -4
  401. package/src/lib/utils/{compress-util.js → compress-util.ts} +105 -18
  402. package/src/lib/utils/file-utils.ts +140 -0
  403. package/src/lib/utils/geometry-utils.ts +14 -0
  404. package/src/lib/utils/{lod-conversion-utils.js → lod-conversion-utils.ts} +31 -5
  405. package/src/lib/utils/queue.ts +17 -0
  406. package/src/lib/utils/write-queue.ts +110 -0
  407. package/src/pgm-loader.ts +3 -3
  408. package/src/workers/3d-tiles-attributes-worker.ts +6 -0
  409. package/src/workers/i3s-attributes-worker.ts +7 -0
  410. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
  411. package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
  412. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
  413. package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
  414. package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
  415. package/dist/bundle.js.map +0 -1
  416. package/dist/deps-installer/deps-installer.js.map +0 -1
  417. package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
  418. package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
  419. package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
  420. package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
  421. package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
  422. package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
  423. package/dist/i3s-converter/i3s-converter.js.map +0 -1
  424. package/dist/i3s-converter/json-templates/layers.js.map +0 -1
  425. package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
  426. package/dist/i3s-converter/json-templates/node.js.map +0 -1
  427. package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
  428. package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
  429. package/dist/i3s-converter/json-templates/store.js.map +0 -1
  430. package/dist/i3s-server/app.js.map +0 -1
  431. package/dist/i3s-server/controllers/index-controller.js.map +0 -1
  432. package/dist/i3s-server/routes/index.js.map +0 -1
  433. package/dist/index.js.map +0 -1
  434. package/dist/lib/geoid-height-model.d.ts +0 -41
  435. package/dist/lib/geoid-height-model.js +0 -140
  436. package/dist/lib/geoid-height-model.js.map +0 -1
  437. package/dist/lib/pgm-parser.d.ts +0 -14
  438. package/dist/lib/pgm-parser.js +0 -183
  439. package/dist/lib/pgm-parser.js.map +0 -1
  440. package/dist/lib/utils/compress-util.js.map +0 -1
  441. package/dist/lib/utils/compress-utils.d.ts +0 -53
  442. package/dist/lib/utils/file-utils.js.map +0 -1
  443. package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
  444. package/dist/lib/utils/statistic-utills.js.map +0 -1
  445. package/dist/pgm-loader.js.map +0 -1
  446. package/src/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  447. package/src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  448. package/src/deps-installer/deps-installer.d.ts +0 -10
  449. package/src/deps-installer/deps-installer.js +0 -22
  450. package/src/i3s-converter/helpers/create-scene-server-path.js +0 -25
  451. package/src/i3s-converter/helpers/geometry-converter.d.ts +0 -40
  452. package/src/i3s-converter/helpers/geometry-converter.js +0 -915
  453. package/src/i3s-converter/helpers/node-pages.d.ts +0 -144
  454. package/src/i3s-converter/helpers/node-pages.js +0 -208
  455. package/src/i3s-converter/json-templates/layers.js +0 -199
  456. package/src/lib/geoid-height-model.d.ts +0 -41
  457. package/src/lib/geoid-height-model.js +0 -239
  458. package/src/lib/pgm-parser.d.ts +0 -14
  459. package/src/lib/pgm-parser.js +0 -179
  460. package/src/lib/utils/compress-utils.d.ts +0 -53
  461. package/src/lib/utils/file-utils.d.ts +0 -43
  462. package/src/lib/utils/file-utils.js +0 -38
  463. package/src/lib/utils/lod-conversion-utils.d.ts +0 -32
  464. /package/dist/{i3s-server → es5/i3s-server}/bin/www +0 -0
  465. /package/dist/{i3s-server → es5/i3s-server}/certs/cert.pem +0 -0
  466. /package/dist/{i3s-server → es5/i3s-server}/certs/key.pem +0 -0
  467. /package/src/i3s-converter/json-templates/{store.js → store.ts} +0 -0
  468. /package/src/lib/utils/{statistic-utills.js → statistic-utills.ts} +0 -0
@@ -0,0 +1,906 @@
1
+ import { Vector3, Matrix4, Vector4 } from '@math.gl/core';
2
+ import { Ellipsoid } from '@math.gl/geospatial';
3
+ import { DracoWriterWorker } from '@loaders.gl/draco';
4
+ import { assert, encode } from '@loaders.gl/core';
5
+ import { concatenateArrayBuffers, concatenateTypedArrays } from '@loaders.gl/loader-utils';
6
+ import md5 from 'md5';
7
+ import { v4 as uuidv4 } from 'uuid';
8
+ import { generateAttributes } from './geometry-attributes';
9
+ import { createBoundingVolumesFromGeometry } from './coordinate-converter';
10
+ import { prepareDataForAttributesConversion } from './gltf-attributes';
11
+ import { handleBatchIdsExtensions } from './batch-ids-extensions';
12
+ import { checkPropertiesLength, flattenPropertyTableByFeatureIds } from './feature-attributes';
13
+ import { GL } from '@loaders.gl/math';
14
+ import { generateSyntheticIndices } from '../../lib/utils/geometry-utils';
15
+ const DEFAULT_ROUGHNESS_FACTOR = 1;
16
+ const DEFAULT_METALLIC_FACTOR = 1;
17
+ const VALUES_PER_VERTEX = 3;
18
+ const VALUES_PER_TEX_COORD = 2;
19
+ const VALUES_PER_COLOR_ELEMENT = 4;
20
+ const STRING_TYPE = 'string';
21
+ const SHORT_INT_TYPE = 'Int32';
22
+ const DOUBLE_TYPE = 'Float64';
23
+ const OBJECT_ID_TYPE = 'Oid32';
24
+ const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
25
+ const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
26
+ const EXT_MESH_FEATURES = 'EXT_mesh_features';
27
+ let scratchVector = new Vector3();
28
+ export default async function convertB3dmToI3sGeometry(tileContent, tileTransform, tileBoundingVolume, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel, workerSource) {
29
+ var _tileContent$gltf;
30
+ const useCartesianPositions = generateBoundingVolumes;
31
+ const materialAndTextureList = await convertMaterials((_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : _tileContent$gltf.materials, shouldMergeMaterials);
32
+ const dataForAttributesConversion = prepareDataForAttributesConversion(tileContent, tileTransform, tileBoundingVolume);
33
+ const convertedAttributesMap = await convertAttributes(dataForAttributesConversion, materialAndTextureList, useCartesianPositions);
34
+ if (generateBoundingVolumes) {
35
+ _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
36
+ }
37
+ const result = [];
38
+ for (const materialAndTexture of materialAndTextureList) {
39
+ const originarMaterialId = materialAndTexture.mergedMaterials[0].originalMaterialId;
40
+ if (!convertedAttributesMap.has(originarMaterialId)) {
41
+ continue;
42
+ }
43
+ const convertedAttributes = convertedAttributesMap.get(originarMaterialId);
44
+ if (!convertedAttributes) {
45
+ continue;
46
+ }
47
+ const {
48
+ material,
49
+ texture
50
+ } = materialAndTexture;
51
+ const nodeId = await addNodeToNodePage();
52
+ result.push(await _makeNodeResources({
53
+ convertedAttributes,
54
+ material,
55
+ texture,
56
+ tileContent,
57
+ nodeId,
58
+ featuresHashArray,
59
+ propertyTable,
60
+ attributeStorageInfo,
61
+ draco,
62
+ workerSource
63
+ }));
64
+ }
65
+ if (!result.length) {
66
+ return null;
67
+ }
68
+ return result;
69
+ }
70
+ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {
71
+ for (const attributes of convertedAttributesMap.values()) {
72
+ const boundingVolumes = createBoundingVolumesFromGeometry(attributes.positions, geoidHeightModel);
73
+ attributes.boundingVolumes = boundingVolumes;
74
+ const cartographicOrigin = boundingVolumes.obb.center;
75
+ for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {
76
+ const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);
77
+ Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
78
+ scratchVector[2] = scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);
79
+ scratchVector = scratchVector.subtract(cartographicOrigin);
80
+ attributes.positions.set(scratchVector, index);
81
+ }
82
+ }
83
+ }
84
+ async function _makeNodeResources(_ref) {
85
+ var _tileContent$gltf2;
86
+ let {
87
+ convertedAttributes,
88
+ material,
89
+ texture,
90
+ tileContent,
91
+ nodeId,
92
+ featuresHashArray,
93
+ propertyTable,
94
+ attributeStorageInfo,
95
+ draco,
96
+ workerSource
97
+ } = _ref;
98
+ const boundingVolumes = convertedAttributes.boundingVolumes;
99
+ const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
100
+ const {
101
+ faceRange,
102
+ featureIds,
103
+ positions,
104
+ normals,
105
+ colors,
106
+ uvRegions,
107
+ texCoords,
108
+ featureCount
109
+ } = generateAttributes(convertedAttributes);
110
+ if (tileContent.batchTableJson) {
111
+ makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
112
+ }
113
+ const header = new Uint32Array(2);
114
+ const typedFeatureIds = generateBigUint64Array(featureIds);
115
+ header.set([vertexCount, featureCount], 0);
116
+ const fileBuffer = new Uint8Array(concatenateArrayBuffers(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, uvRegions, typedFeatureIds.buffer, faceRange.buffer));
117
+ const compressedGeometry = draco ? generateCompressedGeometry(vertexCount, convertedAttributes, {
118
+ positions,
119
+ normals,
120
+ texCoords: texture ? texCoords : new Float32Array(0),
121
+ colors,
122
+ uvRegions,
123
+ featureIds,
124
+ faceRange
125
+ }, workerSource.draco) : null;
126
+ let attributes = [];
127
+ if (attributeStorageInfo && propertyTable) {
128
+ attributes = convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo);
129
+ }
130
+ return {
131
+ nodeId,
132
+ geometry: fileBuffer,
133
+ compressedGeometry,
134
+ texture,
135
+ hasUvRegions: Boolean(uvRegions.length),
136
+ sharedResources: getSharedResources(((_tileContent$gltf2 = tileContent.gltf) === null || _tileContent$gltf2 === void 0 ? void 0 : _tileContent$gltf2.materials) || [], nodeId),
137
+ meshMaterial: material,
138
+ vertexCount,
139
+ attributes,
140
+ featureCount,
141
+ boundingVolumes
142
+ };
143
+ }
144
+ export async function convertAttributes(attributesData, materialAndTextureList, useCartesianPositions) {
145
+ const {
146
+ nodes,
147
+ images,
148
+ cartographicOrigin,
149
+ cartesianModelMatrix
150
+ } = attributesData;
151
+ const attributesMap = new Map();
152
+ for (const materialAndTexture of materialAndTextureList) {
153
+ const attributes = {
154
+ positions: new Float32Array(0),
155
+ normals: new Float32Array(0),
156
+ texCoords: new Float32Array(0),
157
+ colors: new Uint8Array(0),
158
+ uvRegions: new Uint16Array(0),
159
+ featureIndicesGroups: [],
160
+ featureIndices: [],
161
+ boundingVolumes: null,
162
+ mergedMaterials: materialAndTexture.mergedMaterials
163
+ };
164
+ for (const mergedMaterial of materialAndTexture.mergedMaterials) {
165
+ attributesMap.set(mergedMaterial.originalMaterialId, attributes);
166
+ }
167
+ }
168
+ convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
169
+ for (const attrKey of attributesMap.keys()) {
170
+ const attributes = attributesMap.get(attrKey);
171
+ if (!attributes) {
172
+ continue;
173
+ }
174
+ if (attributes.positions.length === 0) {
175
+ attributesMap.delete(attrKey);
176
+ continue;
177
+ }
178
+ if (attributes.featureIndicesGroups) {
179
+ attributes.featureIndices = attributes.featureIndicesGroups.reduce((acc, value) => acc.concat(value));
180
+ delete attributes.featureIndicesGroups;
181
+ }
182
+ }
183
+ return attributesMap;
184
+ }
185
+ function convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
186
+ let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
187
+ if (nodes) {
188
+ for (const node of nodes) {
189
+ convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
190
+ }
191
+ }
192
+ }
193
+ function getCompositeTransformationMatrix(node, matrix) {
194
+ let transformationMatrix = matrix;
195
+ const {
196
+ matrix: nodeMatrix,
197
+ rotation,
198
+ scale,
199
+ translation
200
+ } = node;
201
+ if (nodeMatrix) {
202
+ transformationMatrix = matrix.multiplyRight(nodeMatrix);
203
+ }
204
+ if (translation) {
205
+ transformationMatrix = transformationMatrix.translate(translation);
206
+ }
207
+ if (rotation) {
208
+ transformationMatrix = transformationMatrix.rotateXYZ(rotation);
209
+ }
210
+ if (scale) {
211
+ transformationMatrix = transformationMatrix.scale(scale);
212
+ }
213
+ return transformationMatrix;
214
+ }
215
+ function convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
216
+ let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
217
+ const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
218
+ const mesh = node.mesh;
219
+ if (mesh) {
220
+ convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
221
+ }
222
+ convertNodes(node.children || [], images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
223
+ }
224
+ function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap) {
225
+ let useCartesianPositions = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
226
+ let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
227
+ for (const primitive of mesh.primitives) {
228
+ let outputAttributes = null;
229
+ let materialUvRegion;
230
+ if (primitive.material) {
231
+ var _outputAttributes, _outputAttributes$mer;
232
+ outputAttributes = attributesMap.get(primitive.material.id);
233
+ materialUvRegion = (_outputAttributes = outputAttributes) === null || _outputAttributes === void 0 ? void 0 : (_outputAttributes$mer = _outputAttributes.mergedMaterials.find(_ref2 => {
234
+ var _primitive$material;
235
+ let {
236
+ originalMaterialId
237
+ } = _ref2;
238
+ return originalMaterialId === ((_primitive$material = primitive.material) === null || _primitive$material === void 0 ? void 0 : _primitive$material.id);
239
+ })) === null || _outputAttributes$mer === void 0 ? void 0 : _outputAttributes$mer.uvRegion;
240
+ } else if (attributesMap.has('default')) {
241
+ outputAttributes = attributesMap.get('default');
242
+ }
243
+ assert(outputAttributes !== null, 'Primitive - material mapping failed');
244
+ assert(primitive.mode === undefined || primitive.mode === GL.TRIANGLES || primitive.mode === GL.TRIANGLE_STRIP, "Primitive - unsupported mode ".concat(primitive.mode));
245
+ const attributes = primitive.attributes;
246
+ if (!outputAttributes) {
247
+ continue;
248
+ }
249
+ const indices = normalizeIndices(primitive);
250
+ outputAttributes.positions = concatenateTypedArrays(outputAttributes.positions, transformVertexArray({
251
+ vertices: attributes.POSITION.value,
252
+ cartographicOrigin,
253
+ cartesianModelMatrix,
254
+ nodeMatrix: matrix,
255
+ indices,
256
+ attributeSpecificTransformation: transformVertexPositions,
257
+ useCartesianPositions
258
+ }));
259
+ outputAttributes.normals = concatenateTypedArrays(outputAttributes.normals, transformVertexArray({
260
+ vertices: attributes.NORMAL && attributes.NORMAL.value,
261
+ cartographicOrigin,
262
+ cartesianModelMatrix,
263
+ nodeMatrix: matrix,
264
+ indices,
265
+ attributeSpecificTransformation: transformVertexNormals,
266
+ useCartesianPositions: false
267
+ }));
268
+ outputAttributes.texCoords = concatenateTypedArrays(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, indices));
269
+ outputAttributes.colors = concatenateTypedArrays(outputAttributes.colors, flattenColors(attributes.COLOR_0, indices));
270
+ if (materialUvRegion) {
271
+ outputAttributes.uvRegions = concatenateTypedArrays(outputAttributes.uvRegions, createUvRegion(materialUvRegion, indices));
272
+ }
273
+ outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
274
+ outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images), indices));
275
+ }
276
+ }
277
+ function normalizeIndices(primitive) {
278
+ var _primitive$indices;
279
+ let indices = (_primitive$indices = primitive.indices) === null || _primitive$indices === void 0 ? void 0 : _primitive$indices.value;
280
+ if (!indices) {
281
+ const positions = primitive.attributes.POSITION.value;
282
+ return generateSyntheticIndices(positions.length / VALUES_PER_VERTEX);
283
+ }
284
+ if (indices && primitive.mode === GL.TRIANGLE_STRIP) {
285
+ const TypedArrayConstructor = indices.constructor;
286
+ const newIndices = new TypedArrayConstructor((indices.length - 2) * 3);
287
+ let triangleIndex = 0;
288
+ let currentTriangle = indices.slice(0, 3);
289
+ newIndices.set(currentTriangle, 0);
290
+ for (let i = 1; i + 2 < indices.length; i++) {
291
+ triangleIndex += 3;
292
+ currentTriangle = indices.slice(i, i + 3);
293
+ if (i % 2 === 0) {
294
+ newIndices.set(currentTriangle, triangleIndex);
295
+ } else {
296
+ newIndices.set(currentTriangle.reverse(), triangleIndex);
297
+ }
298
+ }
299
+ indices = newIndices;
300
+ }
301
+ return indices;
302
+ }
303
+ function transformVertexArray(args) {
304
+ const {
305
+ vertices,
306
+ indices,
307
+ attributeSpecificTransformation
308
+ } = args;
309
+ const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
310
+ if (!vertices) {
311
+ return newVertices;
312
+ }
313
+ for (let i = 0; i < indices.length; i++) {
314
+ const coordIndex = indices[i] * VALUES_PER_VERTEX;
315
+ const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
316
+ let vertexVector = new Vector3(Array.from(vertex));
317
+ vertexVector = attributeSpecificTransformation(vertexVector, args);
318
+ newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;
319
+ newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;
320
+ newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;
321
+ }
322
+ return newVertices;
323
+ }
324
+ function transformVertexPositions(vertexVector, calleeArgs) {
325
+ const {
326
+ cartesianModelMatrix,
327
+ cartographicOrigin,
328
+ nodeMatrix,
329
+ useCartesianPositions
330
+ } = calleeArgs;
331
+ if (nodeMatrix) {
332
+ vertexVector = vertexVector.transform(nodeMatrix);
333
+ }
334
+ vertexVector = vertexVector.transform(cartesianModelMatrix);
335
+ if (useCartesianPositions) {
336
+ return vertexVector;
337
+ }
338
+ Ellipsoid.WGS84.cartesianToCartographic([vertexVector[0], vertexVector[1], vertexVector[2]], vertexVector);
339
+ vertexVector = vertexVector.subtract(cartographicOrigin);
340
+ return vertexVector;
341
+ }
342
+ function transformVertexNormals(vertexVector, calleeArgs) {
343
+ const {
344
+ cartesianModelMatrix,
345
+ nodeMatrix
346
+ } = calleeArgs;
347
+ if (nodeMatrix) {
348
+ vertexVector = vertexVector.transformAsVector(nodeMatrix);
349
+ }
350
+ vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);
351
+ return vertexVector;
352
+ }
353
+ function flattenTexCoords(texCoords, indices) {
354
+ const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
355
+ if (!texCoords) {
356
+ newTexCoords.fill(1);
357
+ return newTexCoords;
358
+ }
359
+ for (let i = 0; i < indices.length; i++) {
360
+ const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
361
+ const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
362
+ newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];
363
+ newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];
364
+ }
365
+ return newTexCoords;
366
+ }
367
+ function flattenColors(colorsAttribute, indices) {
368
+ const components = (colorsAttribute === null || colorsAttribute === void 0 ? void 0 : colorsAttribute.components) || VALUES_PER_COLOR_ELEMENT;
369
+ const newColors = new Uint8Array(indices.length * components);
370
+ if (!colorsAttribute) {
371
+ newColors.fill(255);
372
+ return newColors;
373
+ }
374
+ const colors = colorsAttribute.value;
375
+ for (let i = 0; i < indices.length; i++) {
376
+ const colorIndex = indices[i] * components;
377
+ const color = colors.subarray(colorIndex, colorIndex + components);
378
+ const colorUint8 = new Uint8Array(components);
379
+ for (let j = 0; j < color.length; j++) {
380
+ colorUint8[j] = color[j] * 255;
381
+ }
382
+ newColors.set(colorUint8, i * components);
383
+ }
384
+ return newColors;
385
+ }
386
+ function createUvRegion(materialUvRegion, indices) {
387
+ const result = new Uint16Array(indices.length * 4);
388
+ for (let i = 0; i < result.length; i += 4) {
389
+ result.set(materialUvRegion, i);
390
+ }
391
+ return result;
392
+ }
393
+ function flattenBatchIds(batchedIds, indices) {
394
+ if (!batchedIds.length || !indices.length) {
395
+ return [];
396
+ }
397
+ const newBatchIds = [];
398
+ for (let i = 0; i < indices.length; i++) {
399
+ const coordIndex = indices[i];
400
+ newBatchIds.push(batchedIds[coordIndex]);
401
+ }
402
+ return newBatchIds;
403
+ }
404
+ function getBatchIds(attributes, primitive, images) {
405
+ const batchIds = handleBatchIdsExtensions(attributes, primitive, images);
406
+ if (batchIds.length) {
407
+ return batchIds;
408
+ }
409
+ for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
410
+ const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
411
+ if (attributes[possibleBatchIdAttributeName] && attributes[possibleBatchIdAttributeName].value) {
412
+ return attributes[possibleBatchIdAttributeName].value;
413
+ }
414
+ }
415
+ return [];
416
+ }
417
+ async function convertMaterials() {
418
+ let sourceMaterials = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
419
+ let shouldMergeMaterials = arguments.length > 1 ? arguments[1] : undefined;
420
+ let materials = [];
421
+ for (const sourceMaterial of sourceMaterials) {
422
+ materials.push(convertMaterial(sourceMaterial));
423
+ }
424
+ if (shouldMergeMaterials) {
425
+ materials = await mergeAllMaterials(materials);
426
+ }
427
+ return materials;
428
+ }
429
+ async function mergeAllMaterials(materials) {
430
+ const result = [];
431
+ while (materials.length > 0) {
432
+ let newMaterial = materials.splice(0, 1)[0];
433
+ const mergedIndices = [];
434
+ for (let i = 0; i < materials.length; i++) {
435
+ const material = materials[i];
436
+ if (newMaterial.texture && material.texture || !newMaterial.texture && !material.texture) {
437
+ newMaterial = await mergeMaterials(newMaterial, material);
438
+ mergedIndices.push(i);
439
+ }
440
+ }
441
+ if (newMaterial.texture && mergedIndices.length) {
442
+ var _newMaterial$mergedMa, _newMaterial$mergedMa2;
443
+ const newWidth = (_newMaterial$mergedMa = newMaterial.mergedMaterials) === null || _newMaterial$mergedMa === void 0 ? void 0 : _newMaterial$mergedMa.reduce((accum, _ref3) => {
444
+ let {
445
+ textureSize
446
+ } = _ref3;
447
+ return accum + ((textureSize === null || textureSize === void 0 ? void 0 : textureSize.width) || 0);
448
+ }, 0);
449
+ const newHeight = (_newMaterial$mergedMa2 = newMaterial.mergedMaterials) === null || _newMaterial$mergedMa2 === void 0 ? void 0 : _newMaterial$mergedMa2.reduce((accum, _ref4) => {
450
+ let {
451
+ textureSize
452
+ } = _ref4;
453
+ return Math.max(accum, (textureSize === null || textureSize === void 0 ? void 0 : textureSize.height) || 0);
454
+ }, 0);
455
+ let currentX = -1;
456
+ for (const aTextureMetadata of newMaterial.mergedMaterials) {
457
+ if (aTextureMetadata.textureSize) {
458
+ const newX = currentX + 1 + aTextureMetadata.textureSize.width / newWidth * 2 ** (Uint16Array.BYTES_PER_ELEMENT * 8) - 1;
459
+ aTextureMetadata.uvRegion = new Uint16Array([currentX + 1, 0, newX, aTextureMetadata.textureSize.height / newHeight * 2 ** (Uint16Array.BYTES_PER_ELEMENT * 8) - 1]);
460
+ currentX = newX;
461
+ }
462
+ }
463
+ newMaterial.texture.image.width = newWidth;
464
+ newMaterial.texture.image.height = newHeight;
465
+ }
466
+ for (const index of mergedIndices.reverse()) {
467
+ materials.splice(index, 1);
468
+ }
469
+ result.push(newMaterial);
470
+ }
471
+ if (!result.length) {
472
+ result.push({
473
+ material: getDefaultMaterial(),
474
+ mergedMaterials: [{
475
+ originalMaterialId: 'default'
476
+ }]
477
+ });
478
+ }
479
+ return result;
480
+ }
481
+ async function mergeMaterials(material1, material2) {
482
+ var _material1$texture, _material2$texture;
483
+ if ((_material1$texture = material1.texture) !== null && _material1$texture !== void 0 && _material1$texture.bufferView && (_material2$texture = material2.texture) !== null && _material2$texture !== void 0 && _material2$texture.bufferView && material1.mergedMaterials && material2.mergedMaterials) {
484
+ const buffer1 = Buffer.from(material1.texture.bufferView.data);
485
+ const buffer2 = Buffer.from(material2.texture.bufferView.data);
486
+ try {
487
+ const {
488
+ joinImages
489
+ } = await import('join-images');
490
+ const sharpData = await joinImages([buffer1, buffer2], {
491
+ direction: 'horizontal'
492
+ });
493
+ material1.texture.bufferView.data = await sharpData.toFormat(material1.texture.mimeType === 'image/png' ? 'png' : 'jpeg').toBuffer();
494
+ } catch (error) {
495
+ console.log('Join images into a texture atlas has failed. Consider usage `--split-nodes` option. (See documentation https://loaders.gl/modules/tile-converter/docs/cli-reference/tile-converter)');
496
+ throw error;
497
+ }
498
+ material1.material.pbrMetallicRoughness.baseColorTexture.textureSetDefinitionId = 1;
499
+ }
500
+ material1.mergedMaterials = material1.mergedMaterials.concat(material2.mergedMaterials);
501
+ return material1;
502
+ }
503
+ function convertMaterial(sourceMaterial) {
504
+ var _sourceMaterial$emiss, _sourceMaterial$pbrMe, _sourceMaterial$pbrMe2, _sourceMaterial$pbrMe3;
505
+ const material = {
506
+ doubleSided: sourceMaterial.doubleSided,
507
+ emissiveFactor: (_sourceMaterial$emiss = sourceMaterial.emissiveFactor) === null || _sourceMaterial$emiss === void 0 ? void 0 : _sourceMaterial$emiss.map(c => Math.round(c * 255)),
508
+ alphaMode: convertAlphaMode(sourceMaterial.alphaMode),
509
+ pbrMetallicRoughness: {
510
+ roughnessFactor: (sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe === void 0 ? void 0 : _sourceMaterial$pbrMe.roughnessFactor) || DEFAULT_ROUGHNESS_FACTOR,
511
+ metallicFactor: (sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe2 = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe2 === void 0 ? void 0 : _sourceMaterial$pbrMe2.metallicFactor) || DEFAULT_METALLIC_FACTOR
512
+ }
513
+ };
514
+ let texture;
515
+ if (sourceMaterial !== null && sourceMaterial !== void 0 && (_sourceMaterial$pbrMe3 = sourceMaterial.pbrMetallicRoughness) !== null && _sourceMaterial$pbrMe3 !== void 0 && _sourceMaterial$pbrMe3.baseColorTexture) {
516
+ texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
517
+ material.pbrMetallicRoughness.baseColorTexture = {
518
+ textureSetDefinitionId: 0
519
+ };
520
+ } else if (sourceMaterial.emissiveTexture) {
521
+ texture = sourceMaterial.emissiveTexture.texture.source;
522
+ material.pbrMetallicRoughness.baseColorTexture = {
523
+ textureSetDefinitionId: 0
524
+ };
525
+ }
526
+ sourceMaterial.id = Number.isFinite(sourceMaterial.id) ? sourceMaterial.id : uuidv4();
527
+ let mergedMaterials = [{
528
+ originalMaterialId: sourceMaterial.id
529
+ }];
530
+ if (!texture) {
531
+ var _sourceMaterial$pbrMe4;
532
+ const baseColorFactor = sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe4 = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe4 === void 0 ? void 0 : _sourceMaterial$pbrMe4.baseColorFactor;
533
+ material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(c => Math.round(c * 255)) || undefined;
534
+ } else {
535
+ mergedMaterials[0].textureSize = {
536
+ width: texture.image.width,
537
+ height: texture.image.height
538
+ };
539
+ }
540
+ return {
541
+ material,
542
+ texture,
543
+ mergedMaterials
544
+ };
545
+ }
546
+ function convertAlphaMode(gltfAlphaMode) {
547
+ switch (gltfAlphaMode) {
548
+ case 'OPAQUE':
549
+ return 'opaque';
550
+ case 'MASK':
551
+ return 'mask';
552
+ case 'BLEND':
553
+ return 'blend';
554
+ default:
555
+ return 'opaque';
556
+ }
557
+ }
558
+ function getDefaultMaterial() {
559
+ return {
560
+ alphaMode: 'opaque',
561
+ pbrMetallicRoughness: {
562
+ metallicFactor: 1,
563
+ roughnessFactor: 1
564
+ }
565
+ };
566
+ }
567
+ function getSharedResources(gltfMaterials, nodeId) {
568
+ const i3sResources = {};
569
+ if (!gltfMaterials || !gltfMaterials.length) {
570
+ return i3sResources;
571
+ }
572
+ i3sResources.materialDefinitionInfos = [];
573
+ for (const gltfMaterial of gltfMaterials) {
574
+ const {
575
+ materialDefinitionInfo,
576
+ textureDefinitionInfo
577
+ } = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId);
578
+ i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
579
+ if (textureDefinitionInfo) {
580
+ i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
581
+ i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
582
+ }
583
+ }
584
+ return i3sResources;
585
+ }
586
+ function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
587
+ var _gltfMaterial$pbrMeta;
588
+ const texture = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : (_gltfMaterial$pbrMeta = gltfMaterial.pbrMetallicRoughness) === null || _gltfMaterial$pbrMeta === void 0 ? void 0 : _gltfMaterial$pbrMeta.baseColorTexture) || gltfMaterial.emissiveTexture;
589
+ let textureDefinitionInfo = null;
590
+ if (texture) {
591
+ textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
592
+ }
593
+ const {
594
+ baseColorFactor,
595
+ metallicFactor
596
+ } = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : gltfMaterial.pbrMetallicRoughness) || {};
597
+ let colorFactor = baseColorFactor;
598
+ if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
599
+ colorFactor = gltfMaterial.emissiveFactor;
600
+ colorFactor[3] = colorFactor[3] || 1;
601
+ }
602
+ return {
603
+ materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor || [1, 1, 1, 1], metallicFactor),
604
+ textureDefinitionInfo
605
+ };
606
+ }
607
+ function extractSharedResourcesMaterialInfo(baseColorFactor) {
608
+ let metallicFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
609
+ const matDielectricColorComponent = 0.04 / 255;
610
+ const black = new Vector4(0, 0, 0, 1);
611
+ const unitVector = new Vector4(1, 1, 1, 1);
612
+ const dielectricSpecular = new Vector4(matDielectricColorComponent, matDielectricColorComponent, matDielectricColorComponent, 0);
613
+ const baseColorVector = new Vector4(baseColorFactor);
614
+ const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);
615
+ const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);
616
+ dielectricSpecular[3] = 1;
617
+ const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
618
+ return {
619
+ params: {
620
+ diffuse: diffuse.toArray(),
621
+ specular: specular.toArray(),
622
+ renderMode: 'solid'
623
+ }
624
+ };
625
+ }
626
+ function extractSharedResourcesTextureInfo(texture, nodeId) {
627
+ var _texture$source, _texture$source2, _texture$source3, _texture$source4;
628
+ return {
629
+ encoding: texture !== null && texture !== void 0 && (_texture$source = texture.source) !== null && _texture$source !== void 0 && _texture$source.mimeType ? [texture.source.mimeType] : undefined,
630
+ images: [{
631
+ id: generateImageId(texture, nodeId),
632
+ size: (_texture$source2 = texture.source) === null || _texture$source2 === void 0 ? void 0 : _texture$source2.image.width,
633
+ length: (_texture$source3 = texture.source) !== null && _texture$source3 !== void 0 && _texture$source3.image.data.length ? [(_texture$source4 = texture.source) === null || _texture$source4 === void 0 ? void 0 : _texture$source4.image.data.length] : undefined
634
+ }]
635
+ };
636
+ }
637
+ function generateImageId(texture, nodeId) {
638
+ var _texture$source5;
639
+ const {
640
+ width,
641
+ height
642
+ } = ((_texture$source5 = texture.source) === null || _texture$source5 === void 0 ? void 0 : _texture$source5.image) || {};
643
+ if (!width || !height) {
644
+ return '';
645
+ }
646
+ const levelCountOfTexture = 1;
647
+ const indexOfLevel = 0;
648
+ const indexOfTextureInStore = nodeId + 1;
649
+ const zerosCount = 32 - indexOfTextureInStore.toString(2).length;
650
+ const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));
651
+ const shiftedLevelCountOfTexture = levelCountOfTexture << 28;
652
+ const shiftedIndexOfLevel = indexOfLevel << 24;
653
+ const shiftedWidth = width - 1 << 12;
654
+ const shiftedHeight = height - 1 << 0;
655
+ const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;
656
+ const imageId = BigInt("0b".concat(leftHalf.toString(2)).concat(rightHalf));
657
+ return imageId.toString();
658
+ }
659
+ function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {
660
+ const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);
661
+ replaceIndicesByUnique(featureIndices, replaceMap);
662
+ replaceIndicesByUnique(featureIds, replaceMap);
663
+ }
664
+ function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
665
+ const featureMap = {};
666
+ for (let index = 0; index < featureIds.length; index++) {
667
+ const oldFeatureId = featureIds[index];
668
+ const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
669
+ featureMap[oldFeatureId.toString()] = uniqueFeatureId;
670
+ }
671
+ return featureMap;
672
+ }
673
+ function generateStringFromBatchTableByIndex(batchTable, index) {
674
+ let str = '';
675
+ for (const key in batchTable) {
676
+ str += batchTable[key][index];
677
+ }
678
+ return str;
679
+ }
680
+ function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
681
+ const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
682
+ const hash = md5(batchTableStr);
683
+ if (featuresHashArray.includes(hash)) {
684
+ return featuresHashArray.indexOf(hash);
685
+ }
686
+ return featuresHashArray.push(hash) - 1;
687
+ }
688
+ function replaceIndicesByUnique(indicesArray, featureMap) {
689
+ for (let index = 0; index < indicesArray.length; index++) {
690
+ indicesArray[index] = featureMap[indicesArray[index]];
691
+ }
692
+ }
693
+ function convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo) {
694
+ const attributeBuffers = [];
695
+ const needFlattenPropertyTable = checkPropertiesLength(featureIds, propertyTable);
696
+ const properties = needFlattenPropertyTable ? flattenPropertyTableByFeatureIds(featureIds, propertyTable) : propertyTable;
697
+ const propertyTableWithObjectIds = {
698
+ OBJECTID: featureIds,
699
+ ...properties
700
+ };
701
+ for (const propertyName in propertyTableWithObjectIds) {
702
+ const type = getAttributeType(propertyName, attributeStorageInfo);
703
+ const value = propertyTableWithObjectIds[propertyName];
704
+ const attributeBuffer = generateAttributeBuffer(type, value);
705
+ attributeBuffers.push(attributeBuffer);
706
+ }
707
+ return attributeBuffers;
708
+ }
709
+ function generateAttributeBuffer(type, value) {
710
+ let attributeBuffer;
711
+ switch (type) {
712
+ case OBJECT_ID_TYPE:
713
+ case SHORT_INT_TYPE:
714
+ attributeBuffer = generateShortIntegerAttributeBuffer(value);
715
+ break;
716
+ case DOUBLE_TYPE:
717
+ attributeBuffer = generateDoubleAttributeBuffer(value);
718
+ break;
719
+ case STRING_TYPE:
720
+ attributeBuffer = generateStringAttributeBuffer(value);
721
+ break;
722
+ default:
723
+ attributeBuffer = generateStringAttributeBuffer(value);
724
+ }
725
+ return attributeBuffer;
726
+ }
727
+ function getAttributeType(key, attributeStorageInfo) {
728
+ const attribute = attributeStorageInfo.find(attr => attr.name === key);
729
+ return attribute.attributeValues.valueType;
730
+ }
731
+ function generateShortIntegerAttributeBuffer(featureIds) {
732
+ const count = new Uint32Array([featureIds.length]);
733
+ const valuesArray = new Uint32Array(featureIds);
734
+ return concatenateArrayBuffers(count.buffer, valuesArray.buffer);
735
+ }
736
+ function generateDoubleAttributeBuffer(featureIds) {
737
+ const count = new Uint32Array([featureIds.length]);
738
+ const padding = new Uint8Array(4);
739
+ const valuesArray = new Float64Array(featureIds);
740
+ return concatenateArrayBuffers(count.buffer, padding.buffer, valuesArray.buffer);
741
+ }
742
+ function generateStringAttributeBuffer(batchAttributes) {
743
+ const stringCountArray = new Uint32Array([batchAttributes.length]);
744
+ let totalNumberOfBytes = 0;
745
+ const stringSizesArray = new Uint32Array(batchAttributes.length);
746
+ const stringBufferArray = [];
747
+ for (let index = 0; index < batchAttributes.length; index++) {
748
+ const currentString = "".concat(String(batchAttributes[index]), "\0");
749
+ const currentStringBuffer = Buffer.from(currentString);
750
+ const currentStringSize = currentStringBuffer.length;
751
+ totalNumberOfBytes += currentStringSize;
752
+ stringSizesArray[index] = currentStringSize;
753
+ stringBufferArray.push(currentStringBuffer);
754
+ }
755
+ const totalBytes = new Uint32Array([totalNumberOfBytes]);
756
+ return concatenateArrayBuffers(stringCountArray.buffer, totalBytes.buffer, stringSizesArray.buffer, ...stringBufferArray);
757
+ }
758
+ function generateBigUint64Array(featureIds) {
759
+ const typedFeatureIds = new BigUint64Array(featureIds.length);
760
+ for (let index = 0; index < featureIds.length; index++) {
761
+ typedFeatureIds[index] = BigInt(featureIds[index]);
762
+ }
763
+ return typedFeatureIds;
764
+ }
765
+ async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes, dracoWorkerSoure) {
766
+ const {
767
+ positions,
768
+ normals,
769
+ texCoords,
770
+ colors,
771
+ uvRegions,
772
+ featureIds,
773
+ faceRange
774
+ } = attributes;
775
+ const indices = new Uint32Array(vertexCount);
776
+ for (let index = 0; index < indices.length; index++) {
777
+ indices.set([index], index);
778
+ }
779
+ const featureIndices = new Uint32Array(convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount);
780
+ const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
781
+ const compressedAttributes = {
782
+ positions,
783
+ normals,
784
+ colors,
785
+ 'feature-index': featureIndex
786
+ };
787
+ if (texCoords.length) {
788
+ compressedAttributes.texCoords = texCoords;
789
+ }
790
+ const attributesMetadata = {
791
+ 'feature-index': {
792
+ 'i3s-attribute-type': 'feature-index',
793
+ 'i3s-feature-ids': new Int32Array(featureIds)
794
+ }
795
+ };
796
+ if (uvRegions.length) {
797
+ compressedAttributes['uv-region'] = uvRegions;
798
+ attributesMetadata['uv-region'] = {
799
+ 'i3s-attribute-type': 'uv-region'
800
+ };
801
+ }
802
+ return encode({
803
+ attributes: compressedAttributes,
804
+ indices
805
+ }, DracoWriterWorker, {
806
+ ...DracoWriterWorker.options,
807
+ source: dracoWorkerSoure,
808
+ reuseWorkers: true,
809
+ _nodeWorkers: true,
810
+ draco: {
811
+ method: 'MESH_SEQUENTIAL_ENCODING',
812
+ attributesMetadata
813
+ }
814
+ });
815
+ }
816
+ function generateFeatureIndexAttribute(featureIndex, faceRange) {
817
+ const orderedFeatureIndices = new Uint32Array(featureIndex.length);
818
+ let fillIndex = 0;
819
+ let startIndex = 0;
820
+ for (let index = 1; index < faceRange.length; index += 2) {
821
+ const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
822
+ orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);
823
+ fillIndex++;
824
+ startIndex = endIndex + 1;
825
+ }
826
+ return orderedFeatureIndices;
827
+ }
828
+ export function getPropertyTable(tileContent) {
829
+ if (!tileContent) {
830
+ return null;
831
+ }
832
+ const batchTableJson = tileContent === null || tileContent === void 0 ? void 0 : tileContent.batchTableJson;
833
+ if (batchTableJson) {
834
+ return batchTableJson;
835
+ }
836
+ const {
837
+ extensionName,
838
+ extension
839
+ } = getPropertyTableExtension(tileContent);
840
+ switch (extensionName) {
841
+ case EXT_MESH_FEATURES:
842
+ {
843
+ console.warn('The I3S converter does not yet support the EXT_mesh_features extension');
844
+ return null;
845
+ }
846
+ case EXT_FEATURE_METADATA:
847
+ {
848
+ return getPropertyTableFromExtFeatureMetadata(extension);
849
+ }
850
+ default:
851
+ return null;
852
+ }
853
+ }
854
+ function getPropertyTableExtension(tileContent) {
855
+ var _tileContent$gltf3, _tileContent$gltf5, _tileContent$gltf5$ex;
856
+ const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];
857
+ const extensionsUsed = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf3 = tileContent.gltf) === null || _tileContent$gltf3 === void 0 ? void 0 : _tileContent$gltf3.extensionsUsed;
858
+ if (!extensionsUsed) {
859
+ return {
860
+ extensionName: null,
861
+ extension: null
862
+ };
863
+ }
864
+ let extensionName = '';
865
+ for (const extensionItem of (tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf4 = tileContent.gltf) === null || _tileContent$gltf4 === void 0 ? void 0 : _tileContent$gltf4.extensionsUsed) || []) {
866
+ var _tileContent$gltf4;
867
+ if (extensionsWithPropertyTables.includes(extensionItem)) {
868
+ extensionName = extensionItem;
869
+ break;
870
+ }
871
+ }
872
+ const extension = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf5 = tileContent.gltf) === null || _tileContent$gltf5 === void 0 ? void 0 : (_tileContent$gltf5$ex = _tileContent$gltf5.extensions) === null || _tileContent$gltf5$ex === void 0 ? void 0 : _tileContent$gltf5$ex[extensionName];
873
+ return {
874
+ extensionName,
875
+ extension
876
+ };
877
+ }
878
+ function getPropertyTableFromExtFeatureMetadata(extension) {
879
+ if (extension !== null && extension !== void 0 && extension.featureTables) {
880
+ var _Object$keys;
881
+ const firstFeatureTableName = (_Object$keys = Object.keys(extension.featureTables)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
882
+ if (firstFeatureTableName) {
883
+ const featureTable = extension === null || extension === void 0 ? void 0 : extension.featureTables[firstFeatureTableName];
884
+ const propertyTable = {};
885
+ for (const propertyName in featureTable.properties) {
886
+ propertyTable[propertyName] = featureTable.properties[propertyName].data;
887
+ }
888
+ return propertyTable;
889
+ }
890
+ }
891
+ if (extension !== null && extension !== void 0 && extension.featureTextures) {
892
+ var _Object$keys2;
893
+ const firstTextureName = (_Object$keys2 = Object.keys(extension.featureTextures)) === null || _Object$keys2 === void 0 ? void 0 : _Object$keys2[0];
894
+ if (firstTextureName) {
895
+ const featureTable = extension === null || extension === void 0 ? void 0 : extension.featureTextures[firstTextureName];
896
+ const propertyTable = {};
897
+ for (const propertyName in featureTable.properties) {
898
+ propertyTable[propertyName] = featureTable.properties[propertyName].data;
899
+ }
900
+ return propertyTable;
901
+ }
902
+ }
903
+ console.warn("The I3S converter couldn't handle EXT_feature_metadata extension: There is neither featureTables, no featureTextures in the extension.");
904
+ return null;
905
+ }
906
+ //# sourceMappingURL=geometry-converter.js.map