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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/bin/i3s-server.js +4 -0
  2. package/bin/slpk-extractor.js +4 -0
  3. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +5 -5
  4. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  5. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +10 -5
  6. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  7. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts +10 -0
  8. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -0
  9. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +2 -1
  10. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -1
  11. package/dist/converter.min.js +172 -103
  12. package/dist/deps-installer/deps-installer.d.ts +3 -2
  13. package/dist/deps-installer/deps-installer.d.ts.map +1 -1
  14. package/dist/dist.min.js +32715 -32567
  15. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +97 -117
  16. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  17. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +24 -22
  18. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  19. package/dist/es5/3d-tiles-converter/helpers/load-i3s.js +63 -0
  20. package/dist/es5/3d-tiles-converter/helpers/load-i3s.js.map +1 -0
  21. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  22. package/dist/es5/converter-cli.js +25 -65
  23. package/dist/es5/converter-cli.js.map +1 -1
  24. package/dist/es5/deps-installer/deps-installer.js +113 -39
  25. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  26. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +45 -15
  27. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  29. package/dist/es5/i3s-converter/helpers/feature-attributes.js +8 -18
  30. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
  31. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +83 -43
  32. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  33. package/dist/es5/i3s-converter/helpers/geometry-converter.js +100 -102
  34. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  35. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  36. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js +70 -4
  37. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js.map +1 -1
  38. package/dist/es5/i3s-converter/helpers/node-index-document.js +3 -2
  39. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
  40. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +47 -12
  41. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
  42. package/dist/es5/i3s-converter/i3s-converter.js +187 -174
  43. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  44. package/dist/es5/i3s-converter/types.js +11 -11
  45. package/dist/es5/i3s-converter/types.js.map +1 -1
  46. package/dist/es5/i3s-server/README.md +46 -2
  47. package/dist/es5/i3s-server/app.js +23 -15
  48. package/dist/es5/i3s-server/app.js.map +1 -1
  49. package/dist/es5/i3s-server/bin/www.js +33 -0
  50. package/dist/es5/i3s-server/bin/www.js.map +1 -0
  51. package/dist/es5/i3s-server/controllers/index-controller.js +23 -22
  52. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  53. package/dist/es5/i3s-server/controllers/slpk-controller.js +35 -38
  54. package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -1
  55. package/dist/es5/i3s-server/routes/index.js +2 -2
  56. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  57. package/dist/es5/i3s-server/routes/slpk-router.js +14 -13
  58. package/dist/es5/i3s-server/routes/slpk-router.js.map +1 -1
  59. package/dist/es5/i3s-server/utils/create-scene-server.js +7 -4
  60. package/dist/es5/i3s-server/utils/create-scene-server.js.map +1 -1
  61. package/dist/es5/i3s-server/utils/server-utils.js +49 -0
  62. package/dist/es5/i3s-server/utils/server-utils.js.map +1 -0
  63. package/dist/es5/lib/utils/cli-utils.js +57 -0
  64. package/dist/es5/lib/utils/cli-utils.js.map +1 -0
  65. package/dist/es5/lib/utils/compress-util.js +1 -1
  66. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  67. package/dist/es5/lib/utils/lod-conversion-utils.js +10 -4
  68. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  69. package/dist/es5/pgm-loader.js +11 -3
  70. package/dist/es5/pgm-loader.js.map +1 -1
  71. package/dist/es5/slpk-extractor/slpk-extractor.js +171 -0
  72. package/dist/es5/slpk-extractor/slpk-extractor.js.map +1 -0
  73. package/dist/es5/slpk-extractor-cli.js +117 -0
  74. package/dist/es5/slpk-extractor-cli.js.map +1 -0
  75. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +51 -58
  76. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  77. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +12 -11
  78. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  79. package/dist/esm/3d-tiles-converter/helpers/load-i3s.js +32 -0
  80. package/dist/esm/3d-tiles-converter/helpers/load-i3s.js.map +1 -0
  81. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  82. package/dist/esm/converter-cli.js +8 -48
  83. package/dist/esm/converter-cli.js.map +1 -1
  84. package/dist/esm/deps-installer/deps-installer.js +38 -12
  85. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  86. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +28 -11
  87. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  88. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  89. package/dist/esm/i3s-converter/helpers/feature-attributes.js +10 -8
  90. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
  91. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +77 -34
  92. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  93. package/dist/esm/i3s-converter/helpers/geometry-converter.js +60 -61
  94. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  95. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  96. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js +33 -4
  97. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js.map +1 -1
  98. package/dist/esm/i3s-converter/helpers/node-index-document.js +2 -1
  99. package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -1
  100. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +37 -12
  101. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
  102. package/dist/esm/i3s-converter/i3s-converter.js +101 -73
  103. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  104. package/dist/esm/i3s-converter/types.js +9 -9
  105. package/dist/esm/i3s-converter/types.js.map +1 -1
  106. package/dist/esm/i3s-server/README.md +46 -2
  107. package/dist/esm/i3s-server/app.js +13 -11
  108. package/dist/esm/i3s-server/app.js.map +1 -1
  109. package/dist/esm/i3s-server/bin/i3s-server.min.js +516 -0
  110. package/dist/esm/i3s-server/bin/www.js +30 -0
  111. package/dist/esm/i3s-server/bin/www.js.map +1 -0
  112. package/dist/esm/i3s-server/controllers/index-controller.js +4 -7
  113. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
  114. package/dist/esm/i3s-server/controllers/slpk-controller.js +9 -26
  115. package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -1
  116. package/dist/esm/i3s-server/routes/index.js +1 -1
  117. package/dist/esm/i3s-server/routes/index.js.map +1 -1
  118. package/dist/esm/i3s-server/routes/slpk-router.js +5 -11
  119. package/dist/esm/i3s-server/routes/slpk-router.js.map +1 -1
  120. package/dist/esm/i3s-server/utils/create-scene-server.js +2 -5
  121. package/dist/esm/i3s-server/utils/create-scene-server.js.map +1 -1
  122. package/dist/esm/i3s-server/utils/server-utils.js +40 -0
  123. package/dist/esm/i3s-server/utils/server-utils.js.map +1 -0
  124. package/dist/esm/lib/utils/cli-utils.js +47 -0
  125. package/dist/esm/lib/utils/cli-utils.js.map +1 -0
  126. package/dist/esm/lib/utils/compress-util.js +1 -1
  127. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  128. package/dist/esm/lib/utils/lod-conversion-utils.js +6 -4
  129. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  130. package/dist/esm/pgm-loader.js +7 -4
  131. package/dist/esm/pgm-loader.js.map +1 -1
  132. package/dist/esm/slpk-extractor/slpk-extractor.js +63 -0
  133. package/dist/esm/slpk-extractor/slpk-extractor.js.map +1 -0
  134. package/dist/esm/slpk-extractor-cli.js +74 -0
  135. package/dist/esm/slpk-extractor-cli.js.map +1 -0
  136. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +15 -2
  137. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  138. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +1 -2
  139. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
  140. package/dist/i3s-converter/helpers/feature-attributes.d.ts +8 -8
  141. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
  142. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  143. package/dist/i3s-converter/helpers/geometry-converter.d.ts +9 -9
  144. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  145. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +3 -3
  146. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  147. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts +15 -0
  148. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts.map +1 -1
  149. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  150. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +4 -5
  151. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
  152. package/dist/i3s-converter/i3s-converter.d.ts +3 -2
  153. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  154. package/dist/i3s-converter/types.d.ts +48 -7
  155. package/dist/i3s-converter/types.d.ts.map +1 -1
  156. package/dist/i3s-server/app.d.ts +1 -2
  157. package/dist/i3s-server/app.d.ts.map +1 -1
  158. package/dist/i3s-server/bin/www.d.ts +3 -0
  159. package/dist/i3s-server/bin/www.d.ts.map +1 -0
  160. package/dist/i3s-server/controllers/index-controller.d.ts +6 -1
  161. package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -1
  162. package/dist/i3s-server/controllers/slpk-controller.d.ts +13 -2
  163. package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -1
  164. package/dist/i3s-server/routes/index.d.ts +1 -2
  165. package/dist/i3s-server/routes/index.d.ts.map +1 -1
  166. package/dist/i3s-server/routes/slpk-router.d.ts +2 -2
  167. package/dist/i3s-server/routes/slpk-router.d.ts.map +1 -1
  168. package/dist/i3s-server/utils/create-scene-server.d.ts +11 -5
  169. package/dist/i3s-server/utils/create-scene-server.d.ts.map +1 -1
  170. package/dist/i3s-server/utils/server-utils.d.ts +24 -0
  171. package/dist/i3s-server/utils/server-utils.d.ts.map +1 -0
  172. package/dist/lib/utils/cli-utils.d.ts +34 -0
  173. package/dist/lib/utils/cli-utils.d.ts.map +1 -0
  174. package/dist/lib/utils/lod-conversion-utils.d.ts +2 -2
  175. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -1
  176. package/dist/pgm-loader.d.ts +9 -2
  177. package/dist/pgm-loader.d.ts.map +1 -1
  178. package/dist/slpk-extractor/slpk-extractor.d.ts +23 -0
  179. package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -0
  180. package/dist/slpk-extractor-cli.d.ts +17 -0
  181. package/dist/slpk-extractor-cli.d.ts.map +1 -0
  182. package/dist/slpk-extractor.min.js +189 -0
  183. package/package.json +27 -21
  184. package/src/3d-tiles-converter/3d-tiles-converter.ts +65 -69
  185. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +23 -19
  186. package/src/3d-tiles-converter/helpers/load-i3s.ts +52 -0
  187. package/src/3d-tiles-converter/helpers/texture-atlas.ts +6 -2
  188. package/src/converter-cli.ts +16 -74
  189. package/src/deps-installer/deps-installer.ts +56 -11
  190. package/src/i3s-converter/helpers/batch-ids-extensions.ts +77 -32
  191. package/src/i3s-converter/helpers/coordinate-converter.ts +1 -2
  192. package/src/i3s-converter/helpers/feature-attributes.ts +23 -18
  193. package/src/i3s-converter/helpers/geometry-attributes.ts +81 -44
  194. package/src/i3s-converter/helpers/geometry-converter.ts +149 -126
  195. package/src/i3s-converter/helpers/gltf-attributes.ts +9 -10
  196. package/src/i3s-converter/helpers/load-3d-tiles.ts +61 -5
  197. package/src/i3s-converter/helpers/node-index-document.ts +5 -1
  198. package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +70 -21
  199. package/src/i3s-converter/i3s-converter.ts +145 -73
  200. package/src/i3s-converter/types.ts +49 -7
  201. package/src/i3s-server/README.md +46 -2
  202. package/src/i3s-server/{app.js → app.ts} +11 -9
  203. package/src/i3s-server/bin/www.ts +38 -0
  204. package/src/i3s-server/controllers/{index-controller.js → index-controller.ts} +10 -9
  205. package/src/i3s-server/controllers/slpk-controller.ts +32 -0
  206. package/src/i3s-server/routes/{index.js → index.ts} +2 -1
  207. package/src/i3s-server/routes/{slpk-router.js → slpk-router.ts} +5 -10
  208. package/src/i3s-server/utils/create-scene-server.ts +20 -0
  209. package/src/i3s-server/utils/server-utils.ts +70 -0
  210. package/src/lib/utils/cli-utils.ts +78 -0
  211. package/src/lib/utils/compress-util.ts +1 -1
  212. package/src/lib/utils/lod-conversion-utils.ts +10 -6
  213. package/src/pgm-loader.ts +15 -7
  214. package/src/slpk-extractor/slpk-extractor.ts +101 -0
  215. package/src/slpk-extractor-cli.ts +128 -0
  216. package/dist/3d-tiles-attributes-worker.d.ts +0 -28
  217. package/dist/3d-tiles-attributes-worker.d.ts.map +0 -1
  218. package/dist/3d-tiles-attributes-worker.js +0 -3
  219. package/dist/3d-tiles-attributes-worker.js.map +0 -7
  220. package/dist/3d-tiles-converter/3d-tiles-converter.js +0 -288
  221. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +0 -269
  222. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -23
  223. package/dist/3d-tiles-converter/helpers/texture-atlas.js +0 -52
  224. package/dist/3d-tiles-converter/json-templates/tileset.js +0 -43
  225. package/dist/bundle.js +0 -5
  226. package/dist/constants.js +0 -4
  227. package/dist/converter-cli.js +0 -280
  228. package/dist/deps-installer/deps-installer.js +0 -63
  229. package/dist/es5/3d-tiles-attributes-worker.js +0 -25
  230. package/dist/es5/3d-tiles-attributes-worker.js.map +0 -1
  231. package/dist/es5/i3s-attributes-worker.js +0 -25
  232. package/dist/es5/i3s-attributes-worker.js.map +0 -1
  233. package/dist/es5/i3s-server/bin/www +0 -102
  234. package/dist/es5/workers/3d-tiles-attributes-worker.js +0 -28
  235. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +0 -1
  236. package/dist/es5/workers/i3s-attributes-worker.js +0 -30
  237. package/dist/es5/workers/i3s-attributes-worker.js.map +0 -1
  238. package/dist/esm/3d-tiles-attributes-worker.js +0 -16
  239. package/dist/esm/3d-tiles-attributes-worker.js.map +0 -1
  240. package/dist/esm/i3s-attributes-worker.js +0 -16
  241. package/dist/esm/i3s-attributes-worker.js.map +0 -1
  242. package/dist/esm/i3s-server/bin/www +0 -102
  243. package/dist/esm/workers/3d-tiles-attributes-worker.js +0 -8
  244. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +0 -1
  245. package/dist/esm/workers/i3s-attributes-worker.js +0 -7
  246. package/dist/esm/workers/i3s-attributes-worker.js.map +0 -1
  247. package/dist/i3s-attributes-worker.d.ts +0 -45
  248. package/dist/i3s-attributes-worker.d.ts.map +0 -1
  249. package/dist/i3s-attributes-worker.js +0 -9
  250. package/dist/i3s-attributes-worker.js.map +0 -7
  251. package/dist/i3s-converter/helpers/batch-ids-extensions.js +0 -138
  252. package/dist/i3s-converter/helpers/coordinate-converter.js +0 -123
  253. package/dist/i3s-converter/helpers/create-scene-server-path.js +0 -28
  254. package/dist/i3s-converter/helpers/feature-attributes.js +0 -216
  255. package/dist/i3s-converter/helpers/geometry-attributes.js +0 -202
  256. package/dist/i3s-converter/helpers/geometry-converter.js +0 -1225
  257. package/dist/i3s-converter/helpers/gltf-attributes.js +0 -128
  258. package/dist/i3s-converter/helpers/load-3d-tiles.js +0 -53
  259. package/dist/i3s-converter/helpers/node-debug.js +0 -120
  260. package/dist/i3s-converter/helpers/node-index-document.js +0 -268
  261. package/dist/i3s-converter/helpers/node-pages.js +0 -316
  262. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +0 -76
  263. package/dist/i3s-converter/helpers/tileset-traversal.js +0 -29
  264. package/dist/i3s-converter/i3s-converter.js +0 -911
  265. package/dist/i3s-converter/json-templates/geometry-definitions.js +0 -87
  266. package/dist/i3s-converter/json-templates/layers.js +0 -139
  267. package/dist/i3s-converter/json-templates/metadata.js +0 -25
  268. package/dist/i3s-converter/json-templates/node.js +0 -89
  269. package/dist/i3s-converter/json-templates/scene-server.js +0 -31
  270. package/dist/i3s-converter/json-templates/shared-resources.js +0 -129
  271. package/dist/i3s-converter/json-templates/store.js +0 -103
  272. package/dist/i3s-converter/types.js +0 -17
  273. package/dist/i3s-server/app.js +0 -22
  274. package/dist/i3s-server/controllers/index-controller.js +0 -23
  275. package/dist/i3s-server/controllers/slpk-controller.js +0 -32
  276. package/dist/i3s-server/routes/index.js +0 -16
  277. package/dist/i3s-server/routes/slpk-router.js +0 -33
  278. package/dist/i3s-server/utils/create-scene-server.js +0 -14
  279. package/dist/index.js +0 -10
  280. package/dist/lib/utils/compress-util.js +0 -257
  281. package/dist/lib/utils/file-utils.js +0 -139
  282. package/dist/lib/utils/geometry-utils.js +0 -18
  283. package/dist/lib/utils/lod-conversion-utils.js +0 -76
  284. package/dist/lib/utils/queue.js +0 -18
  285. package/dist/lib/utils/statistic-utills.js +0 -64
  286. package/dist/lib/utils/write-queue.js +0 -80
  287. package/dist/pgm-loader.js +0 -24
  288. package/dist/workers/3d-tiles-attributes-worker.d.ts +0 -2
  289. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +0 -1
  290. package/dist/workers/3d-tiles-attributes-worker.js +0 -9
  291. package/dist/workers/i3s-attributes-worker.d.ts +0 -2
  292. package/dist/workers/i3s-attributes-worker.d.ts.map +0 -1
  293. package/dist/workers/i3s-attributes-worker.js +0 -5
  294. package/src/3d-tiles-attributes-worker.ts +0 -43
  295. package/src/i3s-attributes-worker.ts +0 -59
  296. package/src/i3s-server/bin/www +0 -102
  297. package/src/i3s-server/controllers/slpk-controller.js +0 -38
  298. package/src/i3s-server/utils/create-scene-server.js +0 -15
  299. package/src/workers/3d-tiles-attributes-worker.ts +0 -6
  300. package/src/workers/i3s-attributes-worker.ts +0 -7
@@ -1,1225 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getPropertyTable = exports.convertAttributes = void 0;
30
- const core_1 = require("@math.gl/core");
31
- const geospatial_1 = require("@math.gl/geospatial");
32
- const draco_1 = require("@loaders.gl/draco");
33
- const core_2 = require("@loaders.gl/core");
34
- const loader_utils_1 = require("@loaders.gl/loader-utils");
35
- const md5_1 = __importDefault(require("md5"));
36
- const uuid_1 = require("uuid");
37
- const geometry_attributes_1 = require("./geometry-attributes");
38
- const coordinate_converter_1 = require("./coordinate-converter");
39
- const gltf_attributes_1 = require("./gltf-attributes");
40
- const batch_ids_extensions_1 = require("./batch-ids-extensions");
41
- const feature_attributes_1 = require("./feature-attributes");
42
- const math_1 = require("@loaders.gl/math");
43
- const geometry_utils_1 = require("../../lib/utils/geometry-utils");
44
- // Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/pbrMetallicRoughness.cmn.md
45
- const DEFAULT_ROUGHNESS_FACTOR = 1;
46
- const DEFAULT_METALLIC_FACTOR = 1;
47
- const VALUES_PER_VERTEX = 3;
48
- const VALUES_PER_TEX_COORD = 2;
49
- const VALUES_PER_COLOR_ELEMENT = 4;
50
- const STRING_TYPE = 'string';
51
- const SHORT_INT_TYPE = 'Int32';
52
- const DOUBLE_TYPE = 'Float64';
53
- const OBJECT_ID_TYPE = 'Oid32';
54
- /*
55
- * 'CUSTOM_ATTRIBUTE_2' - Attribute name which includes batch info and used by New York map.
56
- * _BATCHID - Default attribute name which includes batch info.
57
- * BATCHID - Legacy attribute name which includes batch info.
58
- */
59
- const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
60
- const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
61
- const EXT_MESH_FEATURES = 'EXT_mesh_features';
62
- let scratchVector = new core_1.Vector3();
63
- /**
64
- * Convert binary data from b3dm file to i3s resources
65
- *
66
- * @param tileContent - 3d tile content
67
- * @param tileTransform - transformation matrix of the tile, calculated recursively multiplying
68
- * transform of all parent tiles and transform of the current tile
69
- * @param tileBoundingVolume - initialized bounding volume of the source tile
70
- * @param addNodeToNodePage - function to add new node to node pages
71
- * @param propertyTable - batch table (corresponding to feature attributes data)
72
- * @param featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes
73
- * @param attributeStorageInfo - attributes metadata from 3DSceneLayer json
74
- * @param draco - is converter should create draco compressed geometry
75
- * @param generateBoundingVolumes - is converter should create accurate bounding voulmes from geometry attributes
76
- * @param shouldMergeMaterials - Try to merge similar materials to be able to merge meshes into one node
77
- * @param geoidHeightModel - model to convert elevation from elipsoidal to geoid
78
- * @param workerSource - source code of used workers
79
- * @returns Array of node resources to create one or more i3s nodes
80
- */
81
- async function convertB3dmToI3sGeometry(tileContent, tileTransform, tileBoundingVolume, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel, workerSource) {
82
- const useCartesianPositions = generateBoundingVolumes;
83
- const materialAndTextureList = await convertMaterials(tileContent.gltf?.materials, shouldMergeMaterials);
84
- const dataForAttributesConversion = (0, gltf_attributes_1.prepareDataForAttributesConversion)(tileContent, tileTransform, tileBoundingVolume);
85
- const convertedAttributesMap = await convertAttributes(dataForAttributesConversion, materialAndTextureList, useCartesianPositions);
86
- /** Usage of worker here brings more overhead than advantage */
87
- // const convertedAttributesMap: Map<string, ConvertedAttributes> =
88
- // await transformI3SAttributesOnWorker(dataForAttributesConversion, {
89
- // reuseWorkers: true,
90
- // _nodeWorkers: true,
91
- // useCartesianPositions,
92
- // source: workerSource.I3SAttributes
93
- // });
94
- if (generateBoundingVolumes) {
95
- _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
96
- }
97
- const result = [];
98
- for (const materialAndTexture of materialAndTextureList) {
99
- const originarMaterialId = materialAndTexture.mergedMaterials[0].originalMaterialId;
100
- if (!convertedAttributesMap.has(originarMaterialId)) {
101
- continue; // eslint-disable-line no-continue
102
- }
103
- const convertedAttributes = convertedAttributesMap.get(originarMaterialId);
104
- if (!convertedAttributes) {
105
- continue;
106
- }
107
- const { material, texture } = materialAndTexture;
108
- const nodeId = await addNodeToNodePage();
109
- result.push(await _makeNodeResources({
110
- convertedAttributes,
111
- material,
112
- texture,
113
- tileContent,
114
- nodeId,
115
- featuresHashArray,
116
- propertyTable,
117
- attributeStorageInfo,
118
- draco,
119
- workerSource
120
- }));
121
- }
122
- if (!result.length) {
123
- return null;
124
- }
125
- return result;
126
- }
127
- exports.default = convertB3dmToI3sGeometry;
128
- /**
129
- * Create bounding volumes based on positions
130
- * @param convertedAttributesMap - geometry attributes map
131
- * @param geoidHeightModel - geoid height model to convert elevation from elipsoidal to geoid
132
- */
133
- function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {
134
- for (const attributes of convertedAttributesMap.values()) {
135
- const boundingVolumes = (0, coordinate_converter_1.createBoundingVolumesFromGeometry)(attributes.positions, geoidHeightModel);
136
- attributes.boundingVolumes = boundingVolumes;
137
- const cartographicOrigin = boundingVolumes.obb.center;
138
- for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {
139
- const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);
140
- geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
141
- scratchVector[2] =
142
- scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);
143
- scratchVector = scratchVector.subtract(cartographicOrigin);
144
- attributes.positions.set(scratchVector, index);
145
- }
146
- }
147
- }
148
- /**
149
- *
150
- * @param params
151
- * @param params.convertedAttributes - Converted geometry attributes
152
- * @param params.material - I3S PBR-like material definition
153
- * @param params.texture - texture content
154
- * @param params.tileContent - 3DTiles decoded content
155
- * @param params.nodeId - new node ID
156
- * @param params.featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes
157
- * @param params.propertyTable - batch table (corresponding to feature attributes data)
158
- * @param params.attributeStorageInfo - attributes metadata from 3DSceneLayer json
159
- * @param params.draco - is converter should create draco compressed geometry
160
- * @param params.workerSource - source code of used workers
161
- * @returns Array of I3S node resources
162
- */
163
- async function _makeNodeResources({ convertedAttributes, material, texture, tileContent, nodeId, featuresHashArray, propertyTable, attributeStorageInfo, draco, workerSource }) {
164
- const boundingVolumes = convertedAttributes.boundingVolumes;
165
- const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
166
- const { faceRange, featureIds, positions, normals, colors, uvRegions, texCoords, featureCount } = (0, geometry_attributes_1.generateAttributes)(convertedAttributes);
167
- if (tileContent.batchTableJson) {
168
- makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
169
- }
170
- const header = new Uint32Array(2);
171
- const typedFeatureIds = generateBigUint64Array(featureIds);
172
- header.set([vertexCount, featureCount], 0);
173
- const fileBuffer = new Uint8Array((0, loader_utils_1.concatenateArrayBuffers)(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, uvRegions, typedFeatureIds.buffer, faceRange.buffer));
174
- const compressedGeometry = draco
175
- ? generateCompressedGeometry(vertexCount, convertedAttributes, {
176
- positions,
177
- normals,
178
- texCoords: texture ? texCoords : new Float32Array(0),
179
- colors,
180
- uvRegions,
181
- featureIds,
182
- faceRange
183
- }, workerSource.draco)
184
- : null;
185
- let attributes = [];
186
- if (attributeStorageInfo && propertyTable) {
187
- attributes = convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo);
188
- }
189
- return {
190
- nodeId,
191
- geometry: fileBuffer,
192
- compressedGeometry,
193
- texture,
194
- hasUvRegions: Boolean(uvRegions.length),
195
- sharedResources: getSharedResources(tileContent.gltf?.materials || [], nodeId),
196
- meshMaterial: material,
197
- vertexCount,
198
- attributes,
199
- featureCount,
200
- boundingVolumes
201
- };
202
- }
203
- /**
204
- * Convert attributes from the gltf nodes tree to i3s plain geometry
205
- * @param attributesData - geometry attributes from gltf
206
- * @param materialAndTextureList - array of data about materials and textures of the content
207
- * @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.
208
- * Cartesian coordinates will be required for creating bounding voulmest from geometry positions
209
- * @returns map of converted geometry attributes
210
- */
211
- async function convertAttributes(attributesData, materialAndTextureList, useCartesianPositions) {
212
- const { nodes, images, cartographicOrigin, cartesianModelMatrix } = attributesData;
213
- const attributesMap = new Map();
214
- for (const materialAndTexture of materialAndTextureList) {
215
- const attributes = {
216
- positions: new Float32Array(0),
217
- normals: new Float32Array(0),
218
- texCoords: new Float32Array(0),
219
- colors: new Uint8Array(0),
220
- uvRegions: new Uint16Array(0),
221
- featureIndicesGroups: [],
222
- featureIndices: [],
223
- boundingVolumes: null,
224
- mergedMaterials: materialAndTexture.mergedMaterials
225
- };
226
- for (const mergedMaterial of materialAndTexture.mergedMaterials) {
227
- attributesMap.set(mergedMaterial.originalMaterialId, attributes);
228
- }
229
- }
230
- convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
231
- for (const attrKey of attributesMap.keys()) {
232
- const attributes = attributesMap.get(attrKey);
233
- if (!attributes) {
234
- continue;
235
- }
236
- if (attributes.positions.length === 0) {
237
- attributesMap.delete(attrKey);
238
- continue; // eslint-disable-line no-continue
239
- }
240
- if (attributes.featureIndicesGroups) {
241
- attributes.featureIndices = attributes.featureIndicesGroups.reduce((acc, value) => acc.concat(value));
242
- delete attributes.featureIndicesGroups;
243
- }
244
- }
245
- return attributesMap;
246
- }
247
- exports.convertAttributes = convertAttributes;
248
- /**
249
- * Gltf has hierarchical structure of nodes. This function converts nodes starting from those which are in gltf scene object.
250
- * The goal is applying tranformation matrix for all children. Functions "convertNodes" and "convertNode" work together recursively.
251
- * @param nodes - gltf nodes array
252
- * @param images - gltf images array
253
- * @param cartographicOrigin - cartographic origin of bounding volume
254
- * @param cartesianModelMatrix - cartesian model matrix to convert coordinates to cartographic
255
- * @param attributesMap - for recursive concatenation of attributes
256
- * @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.
257
- * Cartesian coordinates will be required for creating bounding voulmest from geometry positions
258
- * @param matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices
259
- * @returns {void}
260
- */
261
- function convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new core_1.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
262
- if (nodes) {
263
- for (const node of nodes) {
264
- convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
265
- }
266
- }
267
- }
268
- /**
269
- * Generate transformation matrix for node
270
- * Aapply all gltf transformations to initial transformation matrix.
271
- * @param node
272
- * @param matrix
273
- */
274
- function getCompositeTransformationMatrix(node, matrix) {
275
- let transformationMatrix = matrix;
276
- const { matrix: nodeMatrix, rotation, scale, translation } = node;
277
- if (nodeMatrix) {
278
- transformationMatrix = matrix.multiplyRight(nodeMatrix);
279
- }
280
- if (translation) {
281
- transformationMatrix = transformationMatrix.translate(translation);
282
- }
283
- if (rotation) {
284
- transformationMatrix = transformationMatrix.rotateXYZ(rotation);
285
- }
286
- if (scale) {
287
- transformationMatrix = transformationMatrix.scale(scale);
288
- }
289
- return transformationMatrix;
290
- }
291
- /**
292
- * Convert all primitives of node and all children nodes
293
- * @param node - gltf node
294
- * @param images - gltf images array
295
- * @param cartographicOrigin - cartographic origin of bounding volume
296
- * @param cartesianModelMatrix - cartesian model matrix to convert coordinates to cartographic
297
- * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of
298
- * attributes
299
- * @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.
300
- * Cartesian coordinates will be required for creating bounding voulmest from geometry positions
301
- * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices
302
- */
303
- function convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new core_1.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
304
- const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
305
- const mesh = node.mesh;
306
- if (mesh) {
307
- convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
308
- }
309
- convertNodes(node.children || [], images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
310
- }
311
- /**
312
- * Convert all primitives of the mesh
313
- * @param mesh - gltf mesh data
314
- * @param images - gltf images array
315
- * @param cartographicOrigin - cartographic origin of bounding volume
316
- * @param cartesianModelMatrix - cartesian model matrix to convert coordinates to cartographic
317
- * @param attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of
318
- * attributes
319
- * @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.
320
- * Cartesian coordinates will be required for creating bounding voulmest from geometry positions
321
- * @param attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of
322
- * attributes
323
-
324
- * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices
325
- */
326
- function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions = false, matrix = new core_1.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
327
- for (const primitive of mesh.primitives) {
328
- let outputAttributes = null;
329
- let materialUvRegion;
330
- if (primitive.material) {
331
- outputAttributes = attributesMap.get(primitive.material.id);
332
- materialUvRegion = outputAttributes?.mergedMaterials.find(({ originalMaterialId }) => originalMaterialId === primitive.material?.id)?.uvRegion;
333
- }
334
- else if (attributesMap.has('default')) {
335
- outputAttributes = attributesMap.get('default');
336
- }
337
- (0, core_2.assert)(outputAttributes !== null, 'Primitive - material mapping failed');
338
- // Per the spec https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#_mesh_primitive_mode
339
- // GL.TRIANGLES is default. So in case `mode` is `undefined`, it is 'TRIANGLES'
340
- (0, core_2.assert)(primitive.mode === undefined ||
341
- primitive.mode === math_1.GL.TRIANGLES ||
342
- primitive.mode === math_1.GL.TRIANGLE_STRIP, `Primitive - unsupported mode ${primitive.mode}`);
343
- const attributes = primitive.attributes;
344
- if (!outputAttributes) {
345
- continue;
346
- }
347
- const indices = normalizeIndices(primitive);
348
- outputAttributes.positions = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.positions, transformVertexArray({
349
- vertices: attributes.POSITION.value,
350
- cartographicOrigin,
351
- cartesianModelMatrix,
352
- nodeMatrix: matrix,
353
- indices,
354
- attributeSpecificTransformation: transformVertexPositions,
355
- useCartesianPositions
356
- }));
357
- outputAttributes.normals = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.normals, transformVertexArray({
358
- vertices: attributes.NORMAL && attributes.NORMAL.value,
359
- cartographicOrigin,
360
- cartesianModelMatrix,
361
- nodeMatrix: matrix,
362
- indices,
363
- attributeSpecificTransformation: transformVertexNormals,
364
- useCartesianPositions: false
365
- }));
366
- outputAttributes.texCoords = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, indices));
367
- outputAttributes.colors = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, indices));
368
- if (materialUvRegion) {
369
- outputAttributes.uvRegions = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.uvRegions, createUvRegion(materialUvRegion, indices));
370
- }
371
- outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
372
- outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images), indices));
373
- }
374
- }
375
- /**
376
- * Converts TRIANGLE-STRIPS to independent TRIANGLES
377
- * @param primitive - the primitive to get the indices from
378
- * @returns indices of vertices of the independent triangles
379
- */
380
- function normalizeIndices(primitive) {
381
- let indices = primitive.indices?.value;
382
- if (!indices) {
383
- const positions = primitive.attributes.POSITION.value;
384
- return (0, geometry_utils_1.generateSyntheticIndices)(positions.length / VALUES_PER_VERTEX);
385
- }
386
- if (indices && primitive.mode === math_1.GL.TRIANGLE_STRIP) {
387
- /*
388
- TRIANGLE_STRIP geometry contains n+2 vertices for n triangles;
389
- TRIANGLE geometry contains n*3 vertices for n triangles.
390
- The conversion from TRIANGLE_STRIP to TRIANGLE implies duplicating adjacent vertices.
391
- */
392
- const TypedArrayConstructor = indices.constructor;
393
- const newIndices = new TypedArrayConstructor((indices.length - 2) * 3);
394
- // Copy the first triangle indices with no modification like [i0, i1, i2, ...] -> [i0, i1, i2, ...]
395
- let triangleIndex = 0;
396
- let currentTriangle = indices.slice(0, 3);
397
- newIndices.set(currentTriangle, 0);
398
- // The rest triangle indices are being taken from strips using the following logic:
399
- // [i1, i2, i3, i4, i5, i6, ...] -> [i3, i2, i1, i2, i3, i4, i5, i4, i3, i4, i5, i6, ...]
400
- for (let i = 1; i + 2 < indices.length; i++) {
401
- triangleIndex += 3;
402
- currentTriangle = indices.slice(i, i + 3);
403
- if (i % 2 === 0) {
404
- newIndices.set(currentTriangle, triangleIndex);
405
- }
406
- else {
407
- // The following "reverce" is necessary to calculate normals correctly
408
- newIndices.set(currentTriangle.reverse(), triangleIndex);
409
- }
410
- }
411
- indices = newIndices;
412
- }
413
- return indices;
414
- }
415
- /**
416
- * Convert vertices attributes (POSITIONS or NORMALS) to i3s compatible format
417
- * @param args
418
- * @param args.vertices - gltf primitive POSITION or NORMAL attribute
419
- * @param args.cartographicOrigin - cartographic origin coordinates
420
- * @param args.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format
421
- * @param args.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices
422
- * @param args.indices - gltf primitive indices
423
- * @param args.attributeSpecificTransformation - function to do attribute - specific transformations
424
- * @param args.useCartesianPositions - use coordinates as it is.
425
- * @returns
426
- */
427
- function transformVertexArray(args) {
428
- const { vertices, indices, attributeSpecificTransformation } = args;
429
- const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
430
- if (!vertices) {
431
- return newVertices;
432
- }
433
- for (let i = 0; i < indices.length; i++) {
434
- const coordIndex = indices[i] * VALUES_PER_VERTEX;
435
- const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
436
- let vertexVector = new core_1.Vector3(Array.from(vertex));
437
- vertexVector = attributeSpecificTransformation(vertexVector, args);
438
- newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;
439
- newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;
440
- newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;
441
- }
442
- return newVertices;
443
- }
444
- /**
445
- * Trasform positions vector with the attribute specific transformations
446
- * @param vertexVector - source positions vector to transform
447
- * @param calleeArgs
448
- * @param calleeArgs.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format
449
- * @param calleeArgs.cartographicOrigin - cartographic origin coordinates
450
- * @param calleeArgs.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices
451
- * @param calleeArgs.useCartesianPositions - use coordinates as it is.
452
- * @returns transformed positions vector
453
- */
454
- function transformVertexPositions(vertexVector, calleeArgs) {
455
- const { cartesianModelMatrix, cartographicOrigin, nodeMatrix, useCartesianPositions } = calleeArgs;
456
- if (nodeMatrix) {
457
- vertexVector = vertexVector.transform(nodeMatrix);
458
- }
459
- vertexVector = vertexVector.transform(cartesianModelMatrix);
460
- if (useCartesianPositions) {
461
- return vertexVector;
462
- }
463
- geospatial_1.Ellipsoid.WGS84.cartesianToCartographic([vertexVector[0], vertexVector[1], vertexVector[2]], vertexVector);
464
- vertexVector = vertexVector.subtract(cartographicOrigin);
465
- return vertexVector;
466
- }
467
- /**
468
- * Trasform normals vector with the attribute specific transformations
469
- * @param vertexVector - source normals vector to transform
470
- * @param calleeArgs
471
- * @param calleeArgs.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format
472
- * @param calleeArgs.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices
473
- * @returns transformed normals vector
474
- */
475
- function transformVertexNormals(vertexVector, calleeArgs) {
476
- const { cartesianModelMatrix, nodeMatrix } = calleeArgs;
477
- if (nodeMatrix) {
478
- vertexVector = vertexVector.transformAsVector(nodeMatrix);
479
- }
480
- vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);
481
- return vertexVector;
482
- }
483
- /**
484
- * Convert uv0 (texture coordinates) from coords based on indices to plain arrays, compatible with i3s
485
- * @param texCoords - gltf primitive TEXCOORD_0 attribute
486
- * @param indices - gltf primitive indices
487
- * @returns flattened texture coordinates
488
- */
489
- function flattenTexCoords(texCoords, indices) {
490
- const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
491
- if (!texCoords) {
492
- // We need dummy UV0s because it is required in 1.6
493
- // https://github.com/Esri/i3s-spec/blob/master/docs/1.6/vertexAttribute.cmn.md
494
- newTexCoords.fill(1);
495
- return newTexCoords;
496
- }
497
- for (let i = 0; i < indices.length; i++) {
498
- const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
499
- const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
500
- newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];
501
- newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];
502
- }
503
- return newTexCoords;
504
- }
505
- /**
506
- * Convert color from COLOR_0 based on indices to plain arrays, compatible with i3s
507
- * @param colorsAttribute - gltf primitive COLOR_0 attribute
508
- * @param indices - gltf primitive indices
509
- * @returns flattened colors attribute
510
- */
511
- function flattenColors(colorsAttribute, indices) {
512
- const components = colorsAttribute?.components || VALUES_PER_COLOR_ELEMENT;
513
- const newColors = new Uint8Array(indices.length * components);
514
- if (!colorsAttribute) {
515
- // Vertex color multiplies by material color so it must be normalized 1 by default
516
- newColors.fill(255);
517
- return newColors;
518
- }
519
- const colors = colorsAttribute.value;
520
- for (let i = 0; i < indices.length; i++) {
521
- const colorIndex = indices[i] * components;
522
- const color = colors.subarray(colorIndex, colorIndex + components);
523
- const colorUint8 = new Uint8Array(components);
524
- for (let j = 0; j < color.length; j++) {
525
- colorUint8[j] = color[j] * 255;
526
- }
527
- newColors.set(colorUint8, i * components);
528
- }
529
- return newColors;
530
- }
531
- /**
532
- * Create per-vertex uv-region array
533
- * @param materialUvRegion - uv-region fragment for a single vertex
534
- * @param indices - geometry indices data
535
- * @returns - uv-region array
536
- */
537
- function createUvRegion(materialUvRegion, indices) {
538
- const result = new Uint16Array(indices.length * 4);
539
- for (let i = 0; i < result.length; i += 4) {
540
- result.set(materialUvRegion, i);
541
- }
542
- return result;
543
- }
544
- /**
545
- * Flatten batchedIds list based on indices to right ordered array, compatible with i3s
546
- * @param batchedIds - gltf primitive
547
- * @param indices - gltf primitive indices
548
- * @returns flattened batch ids
549
- */
550
- function flattenBatchIds(batchedIds, indices) {
551
- if (!batchedIds.length || !indices.length) {
552
- return [];
553
- }
554
- const newBatchIds = [];
555
- for (let i = 0; i < indices.length; i++) {
556
- const coordIndex = indices[i];
557
- newBatchIds.push(batchedIds[coordIndex]);
558
- }
559
- return newBatchIds;
560
- }
561
- /**
562
- * Get batchIds for featureIds creation
563
- * @param attributes - gltf accessors
564
- * @param primitive - gltf primitive data
565
- * @param images - gltf texture images
566
- */
567
- function getBatchIds(attributes, primitive, images) {
568
- const batchIds = (0, batch_ids_extensions_1.handleBatchIdsExtensions)(attributes, primitive, images);
569
- if (batchIds.length) {
570
- return batchIds;
571
- }
572
- for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
573
- const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
574
- if (attributes[possibleBatchIdAttributeName] &&
575
- attributes[possibleBatchIdAttributeName].value) {
576
- return attributes[possibleBatchIdAttributeName].value;
577
- }
578
- }
579
- return [];
580
- }
581
- /**
582
- * Convert GLTF material to I3S material definitions and textures
583
- * @param sourceMaterials Source GLTF materials
584
- * @param shouldMergeMaterials - if true - the converter will try to merge similar materials
585
- * to be able to merge primitives having those materials
586
- * @returns Array of Couples I3SMaterialDefinition + texture content
587
- */
588
- async function convertMaterials(sourceMaterials = [], shouldMergeMaterials) {
589
- let materials = [];
590
- for (const sourceMaterial of sourceMaterials) {
591
- materials.push(convertMaterial(sourceMaterial));
592
- }
593
- if (shouldMergeMaterials) {
594
- materials = await mergeAllMaterials(materials);
595
- }
596
- return materials;
597
- }
598
- /**
599
- * Merge materials when possible
600
- * @param materials materials array
601
- * @returns merged materials array
602
- */
603
- async function mergeAllMaterials(materials) {
604
- const result = [];
605
- while (materials.length > 0) {
606
- let newMaterial = materials.splice(0, 1)[0];
607
- const mergedIndices = [];
608
- for (let i = 0; i < materials.length; i++) {
609
- const material = materials[i];
610
- if ((newMaterial.texture && material.texture) ||
611
- (!newMaterial.texture && !material.texture)) {
612
- newMaterial = await mergeMaterials(newMaterial, material);
613
- mergedIndices.push(i);
614
- }
615
- }
616
- if (newMaterial.texture && mergedIndices.length) {
617
- const newWidth = newMaterial.mergedMaterials?.reduce((accum, { textureSize }) => accum + (textureSize?.width || 0), 0);
618
- const newHeight = newMaterial.mergedMaterials?.reduce((accum, { textureSize }) => Math.max(accum, textureSize?.height || 0), 0);
619
- let currentX = -1;
620
- for (const aTextureMetadata of newMaterial.mergedMaterials) {
621
- if (aTextureMetadata.textureSize) {
622
- const newX = currentX +
623
- 1 +
624
- (aTextureMetadata.textureSize.width / newWidth) *
625
- 2 ** (Uint16Array.BYTES_PER_ELEMENT * 8) -
626
- 1;
627
- aTextureMetadata.uvRegion = new Uint16Array([
628
- currentX + 1,
629
- 0,
630
- newX,
631
- (aTextureMetadata.textureSize.height / newHeight) *
632
- 2 ** (Uint16Array.BYTES_PER_ELEMENT * 8) -
633
- 1
634
- ]);
635
- currentX = newX;
636
- }
637
- }
638
- newMaterial.texture.image.width = newWidth;
639
- newMaterial.texture.image.height = newHeight;
640
- }
641
- for (const index of mergedIndices.reverse()) {
642
- materials.splice(index, 1);
643
- }
644
- result.push(newMaterial);
645
- }
646
- if (!result.length) {
647
- result.push({
648
- material: getDefaultMaterial(),
649
- mergedMaterials: [{ originalMaterialId: 'default' }]
650
- });
651
- }
652
- return result;
653
- }
654
- /**
655
- * Merge 2 materials including texture
656
- * @param material1
657
- * @param material2
658
- * @returns
659
- */
660
- async function mergeMaterials(material1, material2) {
661
- if (material1.texture?.bufferView &&
662
- material2.texture?.bufferView &&
663
- material1.mergedMaterials &&
664
- material2.mergedMaterials) {
665
- const buffer1 = Buffer.from(material1.texture.bufferView.data);
666
- const buffer2 = Buffer.from(material2.texture.bufferView.data);
667
- try {
668
- // @ts-ignore
669
- const { joinImages } = await Promise.resolve().then(() => __importStar(require('join-images')));
670
- const sharpData = await joinImages([buffer1, buffer2], { direction: 'horizontal' });
671
- material1.texture.bufferView.data = await sharpData
672
- .toFormat(material1.texture.mimeType === 'image/png' ? 'png' : 'jpeg')
673
- .toBuffer();
674
- }
675
- catch (error) {
676
- 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)');
677
- throw error;
678
- }
679
- // @ts-ignore
680
- material1.material.pbrMetallicRoughness.baseColorTexture.textureSetDefinitionId = 1;
681
- }
682
- material1.mergedMaterials = material1.mergedMaterials.concat(material2.mergedMaterials);
683
- return material1;
684
- }
685
- /**
686
- * Convert texture and material from gltf 2.0 material object
687
- * @param sourceMaterial - material object
688
- * @returns I3S material definition and texture
689
- */
690
- function convertMaterial(sourceMaterial) {
691
- const material = {
692
- doubleSided: sourceMaterial.doubleSided,
693
- emissiveFactor: sourceMaterial.emissiveFactor?.map((c) => Math.round(c * 255)),
694
- // It is in upper case in GLTF: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#alpha-coverage
695
- // But it is in lower case in I3S: https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
696
- alphaMode: convertAlphaMode(sourceMaterial.alphaMode),
697
- pbrMetallicRoughness: {
698
- roughnessFactor: sourceMaterial?.pbrMetallicRoughness?.roughnessFactor || DEFAULT_ROUGHNESS_FACTOR,
699
- metallicFactor: sourceMaterial?.pbrMetallicRoughness?.metallicFactor || DEFAULT_METALLIC_FACTOR
700
- }
701
- };
702
- let texture;
703
- if (sourceMaterial?.pbrMetallicRoughness?.baseColorTexture) {
704
- texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
705
- material.pbrMetallicRoughness.baseColorTexture = {
706
- textureSetDefinitionId: 0
707
- };
708
- }
709
- else if (sourceMaterial.emissiveTexture) {
710
- texture = sourceMaterial.emissiveTexture.texture.source;
711
- // ArcGIS webscene doesn't show emissiveTexture but shows baseColorTexture
712
- material.pbrMetallicRoughness.baseColorTexture = {
713
- textureSetDefinitionId: 0
714
- };
715
- }
716
- sourceMaterial.id = Number.isFinite(sourceMaterial.id) ? sourceMaterial.id : (0, uuid_1.v4)();
717
- let mergedMaterials = [{ originalMaterialId: sourceMaterial.id }];
718
- if (!texture) {
719
- // Should use default baseColorFactor if it is not present in source material
720
- // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-pbrmetallicroughness
721
- const baseColorFactor = sourceMaterial?.pbrMetallicRoughness?.baseColorFactor;
722
- material.pbrMetallicRoughness.baseColorFactor =
723
- (baseColorFactor && baseColorFactor.map((c) => Math.round(c * 255))) || undefined;
724
- }
725
- else {
726
- mergedMaterials[0].textureSize = { width: texture.image.width, height: texture.image.height };
727
- }
728
- return { material, texture, mergedMaterials };
729
- }
730
- /**
731
- * Converts from `alphaMode` material property from GLTF to I3S format
732
- * @param gltfAlphaMode Gltf material `alphaMode` property
733
- * @returns I3SMaterialDefinition.alphaMode property
734
- */
735
- function convertAlphaMode(gltfAlphaMode) {
736
- switch (gltfAlphaMode) {
737
- case 'OPAQUE':
738
- return 'opaque';
739
- case 'MASK':
740
- return 'mask';
741
- case 'BLEND':
742
- return 'blend';
743
- default:
744
- return 'opaque';
745
- }
746
- }
747
- /**
748
- * Form default I3SMaterialDefinition
749
- * @returns I3S material definition
750
- */
751
- function getDefaultMaterial() {
752
- return {
753
- alphaMode: 'opaque',
754
- pbrMetallicRoughness: {
755
- metallicFactor: 1,
756
- roughnessFactor: 1
757
- }
758
- };
759
- }
760
- /**
761
- * Form "sharedResources" from gltf materials array
762
- * @param gltfMaterials - GLTF materials array
763
- * @param nodeId - I3S node ID
764
- * @returns {materialDefinitionInfos: Object[], textureDefinitionInfos: Object[]} -
765
- * 2 arrays in format of i3s sharedResources data https://github.com/Esri/i3s-spec/blob/master/docs/1.7/sharedResource.cmn.md
766
- */
767
- function getSharedResources(gltfMaterials, nodeId) {
768
- const i3sResources = {};
769
- if (!gltfMaterials || !gltfMaterials.length) {
770
- return i3sResources;
771
- }
772
- i3sResources.materialDefinitionInfos = [];
773
- for (const gltfMaterial of gltfMaterials) {
774
- const { materialDefinitionInfo, textureDefinitionInfo } = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId);
775
- i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
776
- if (textureDefinitionInfo) {
777
- i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
778
- i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
779
- }
780
- }
781
- return i3sResources;
782
- }
783
- /**
784
- * Convert gltf material into I3S sharedResources data
785
- * @param gltfMaterial - gltf material data
786
- * @param nodeId - I3S node ID
787
- * @returns - Couple {materialDefinitionInfo, textureDefinitionInfo} extracted from gltf material data
788
- */
789
- function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
790
- const texture = gltfMaterial?.pbrMetallicRoughness?.baseColorTexture || gltfMaterial.emissiveTexture;
791
- let textureDefinitionInfo = null;
792
- if (texture) {
793
- textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
794
- }
795
- const { baseColorFactor, metallicFactor } = gltfMaterial?.pbrMetallicRoughness || {};
796
- let colorFactor = baseColorFactor;
797
- // If alpha channel is 0 try to get emissive factor from gltf material.
798
- if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
799
- colorFactor = gltfMaterial.emissiveFactor;
800
- colorFactor[3] = colorFactor[3] || 1;
801
- }
802
- return {
803
- materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor || [1, 1, 1, 1], metallicFactor),
804
- textureDefinitionInfo
805
- };
806
- }
807
- /**
808
- * Form "materialDefinition" which is part of "sharedResouces"
809
- * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materials
810
- * See formulas in appendix "Appendix B: BRDF Implementation":
811
- * const dielectricSpecular = rgb(0.04, 0.04, 0.04)
812
- * const black = rgb(0, 0, 0)
813
- * cdiff = lerp(baseColor.rgb * (1 - dielectricSpecular.r), black, metallic)
814
- * F0 = lerp(dieletricSpecular, baseColor.rgb, metallic)
815
- *
816
- * Assumption: F0 - specular in i3s ("specular reflection" <-> "reflectance value at normal incidence")
817
- * cdiff - diffuse in i3s ("Diffuse color" <-> "'c' diffuse" (c means color?))
818
- * @param baseColorFactor - RGBA color in 0..1 format
819
- * @param metallicFactor - "metallicFactor" attribute of gltf material object
820
- * @returns material definition info for I3S shared resource
821
- */
822
- function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 1) {
823
- const matDielectricColorComponent = 0.04 / 255; // Color from rgb (255) to 0..1 resolution
824
- // All color resolutions are 0..1
825
- const black = new core_1.Vector4(0, 0, 0, 1);
826
- const unitVector = new core_1.Vector4(1, 1, 1, 1);
827
- const dielectricSpecular = new core_1.Vector4(matDielectricColorComponent, matDielectricColorComponent, matDielectricColorComponent, 0);
828
- const baseColorVector = new core_1.Vector4(baseColorFactor);
829
- // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
830
- // Formulas for Cdiff & F0
831
- const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);
832
- const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);
833
- dielectricSpecular[3] = 1;
834
- const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
835
- return {
836
- params: {
837
- // @ts-expect-error NumericArray
838
- diffuse: diffuse.toArray(),
839
- // @ts-expect-error NumericArray
840
- specular: specular.toArray(),
841
- renderMode: 'solid'
842
- }
843
- };
844
- }
845
- /**
846
- * Form "textureDefinition" which is part of "sharedResouces"
847
- * @param texture - texture image info
848
- * @param nodeId - I3S node ID
849
- * @returns texture definition infor for shared resource
850
- */
851
- function extractSharedResourcesTextureInfo(texture, nodeId) {
852
- return {
853
- encoding: texture?.source?.mimeType ? [texture.source.mimeType] : undefined,
854
- images: [
855
- {
856
- // 'i3s' has just size which is width of the image. Images are supposed to be square.
857
- // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/image.cmn.md
858
- id: generateImageId(texture, nodeId),
859
- size: texture.source?.image.width,
860
- length: texture.source?.image.data.length ? [texture.source?.image.data.length] : undefined
861
- }
862
- ]
863
- };
864
- }
865
- /**
866
- * Formula for calculating imageId:
867
- * https://github.com/Esri/i3s-spec/blob/0a6366a9249b831db8436c322f8d27521e86cf07/format/Indexed%203d%20Scene%20Layer%20Format%20Specification.md#generating-image-ids
868
- * @param texture - texture image info
869
- * @param nodeId - I3S node ID
870
- * @returns calculate image ID according to the spec
871
- */
872
- function generateImageId(texture, nodeId) {
873
- const { width, height } = texture.source?.image || {};
874
- if (!width || !height) {
875
- return '';
876
- }
877
- const levelCountOfTexture = 1;
878
- const indexOfLevel = 0;
879
- const indexOfTextureInStore = nodeId + 1;
880
- const zerosCount = 32 - indexOfTextureInStore.toString(2).length;
881
- const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));
882
- const shiftedLevelCountOfTexture = levelCountOfTexture << 28;
883
- const shiftedIndexOfLevel = indexOfLevel << 24;
884
- const shiftedWidth = (width - 1) << 12;
885
- const shiftedHeight = (height - 1) << 0;
886
- const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;
887
- const imageId = BigInt(`0b${leftHalf.toString(2)}${rightHalf}`);
888
- return imageId.toString();
889
- }
890
- /**
891
- * Make all feature ids unique through all nodes in layout.
892
- * @param featureIds
893
- * @param featureIndices
894
- * @param featuresHashArray
895
- * @param batchTable
896
- * @returns {void}
897
- */
898
- function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {
899
- const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);
900
- replaceIndicesByUnique(featureIndices, replaceMap);
901
- replaceIndicesByUnique(featureIds, replaceMap);
902
- }
903
- /**
904
- * Generate replace map to make featureIds unique.
905
- * @param featureIds
906
- * @param batchTable
907
- * @param featuresHashArray
908
- * @returns
909
- */
910
- function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
911
- const featureMap = {};
912
- for (let index = 0; index < featureIds.length; index++) {
913
- const oldFeatureId = featureIds[index];
914
- const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
915
- featureMap[oldFeatureId.toString()] = uniqueFeatureId;
916
- }
917
- return featureMap;
918
- }
919
- /**
920
- * Generates string for unique batch id creation.
921
- * @param batchTable
922
- * @param index
923
- * @returns
924
- */
925
- function generateStringFromBatchTableByIndex(batchTable, index) {
926
- let str = '';
927
- for (const key in batchTable) {
928
- str += batchTable[key][index];
929
- }
930
- return str;
931
- }
932
- /**
933
- * Return already exited featureId or creates and returns new to support unique feature ids throw nodes.
934
- * @param index
935
- * @param batchTable
936
- * @param featuresHashArray
937
- * @returns
938
- */
939
- function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
940
- const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
941
- const hash = (0, md5_1.default)(batchTableStr);
942
- if (featuresHashArray.includes(hash)) {
943
- return featuresHashArray.indexOf(hash);
944
- }
945
- return featuresHashArray.push(hash) - 1;
946
- }
947
- /**
948
- * Do replacement of indices for making them unique through all nodes.
949
- * @param indicesArray
950
- * @param featureMap
951
- * @returns
952
- */
953
- function replaceIndicesByUnique(indicesArray, featureMap) {
954
- for (let index = 0; index < indicesArray.length; index++) {
955
- indicesArray[index] = featureMap[indicesArray[index]];
956
- }
957
- }
958
- /**
959
- * Convert property table data to attribute buffers.
960
- * @param featureIds
961
- * @param propertyTable - table with metadata for particular feature.
962
- * @param attributeStorageInfo
963
- * @returns - Array of file buffers.
964
- */
965
- function convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo) {
966
- const attributeBuffers = [];
967
- const needFlattenPropertyTable = (0, feature_attributes_1.checkPropertiesLength)(featureIds, propertyTable);
968
- const properties = needFlattenPropertyTable
969
- ? (0, feature_attributes_1.flattenPropertyTableByFeatureIds)(featureIds, propertyTable)
970
- : propertyTable;
971
- const propertyTableWithObjectIds = {
972
- OBJECTID: featureIds,
973
- ...properties
974
- };
975
- for (const propertyName in propertyTableWithObjectIds) {
976
- const type = getAttributeType(propertyName, attributeStorageInfo);
977
- const value = propertyTableWithObjectIds[propertyName];
978
- const attributeBuffer = generateAttributeBuffer(type, value);
979
- attributeBuffers.push(attributeBuffer);
980
- }
981
- return attributeBuffers;
982
- }
983
- /**
984
- * Generates attribute buffer based on attribute type
985
- * @param type
986
- * @param value
987
- */
988
- function generateAttributeBuffer(type, value) {
989
- let attributeBuffer;
990
- switch (type) {
991
- case OBJECT_ID_TYPE:
992
- case SHORT_INT_TYPE:
993
- attributeBuffer = generateShortIntegerAttributeBuffer(value);
994
- break;
995
- case DOUBLE_TYPE:
996
- attributeBuffer = generateDoubleAttributeBuffer(value);
997
- break;
998
- case STRING_TYPE:
999
- attributeBuffer = generateStringAttributeBuffer(value);
1000
- break;
1001
- default:
1002
- attributeBuffer = generateStringAttributeBuffer(value);
1003
- }
1004
- return attributeBuffer;
1005
- }
1006
- /**
1007
- * Return attribute type.
1008
- * @param key
1009
- * @param attributeStorageInfo
1010
- * @returns attribute type.
1011
- */
1012
- function getAttributeType(key, attributeStorageInfo) {
1013
- const attribute = attributeStorageInfo.find((attr) => attr.name === key);
1014
- return attribute.attributeValues.valueType;
1015
- }
1016
- /**
1017
- * Convert short integer to attribute arrayBuffer.
1018
- * @param featureIds
1019
- * @returns - Buffer with objectId data.
1020
- */
1021
- function generateShortIntegerAttributeBuffer(featureIds) {
1022
- const count = new Uint32Array([featureIds.length]);
1023
- const valuesArray = new Uint32Array(featureIds);
1024
- return (0, loader_utils_1.concatenateArrayBuffers)(count.buffer, valuesArray.buffer);
1025
- }
1026
- /**
1027
- * Convert double to attribute arrayBuffer.
1028
- * @param featureIds
1029
- * @returns - Buffer with objectId data.
1030
- */
1031
- function generateDoubleAttributeBuffer(featureIds) {
1032
- const count = new Uint32Array([featureIds.length]);
1033
- const padding = new Uint8Array(4);
1034
- const valuesArray = new Float64Array(featureIds);
1035
- return (0, loader_utils_1.concatenateArrayBuffers)(count.buffer, padding.buffer, valuesArray.buffer);
1036
- }
1037
- /**
1038
- * Convert batch table attributes to array buffer with batch table data.
1039
- * @param batchAttributes
1040
- * @returns - Buffer with batch table data.
1041
- */
1042
- function generateStringAttributeBuffer(batchAttributes) {
1043
- const stringCountArray = new Uint32Array([batchAttributes.length]);
1044
- let totalNumberOfBytes = 0;
1045
- const stringSizesArray = new Uint32Array(batchAttributes.length);
1046
- const stringBufferArray = [];
1047
- for (let index = 0; index < batchAttributes.length; index++) {
1048
- const currentString = `${String(batchAttributes[index])}\0`;
1049
- const currentStringBuffer = Buffer.from(currentString);
1050
- const currentStringSize = currentStringBuffer.length;
1051
- totalNumberOfBytes += currentStringSize;
1052
- stringSizesArray[index] = currentStringSize;
1053
- stringBufferArray.push(currentStringBuffer);
1054
- }
1055
- const totalBytes = new Uint32Array([totalNumberOfBytes]);
1056
- return (0, loader_utils_1.concatenateArrayBuffers)(stringCountArray.buffer, totalBytes.buffer, stringSizesArray.buffer, ...stringBufferArray);
1057
- }
1058
- /**
1059
- * Convert featureIds to BigUint64Array.
1060
- * @param featureIds
1061
- * @returns - Array of feature ids in BigUint64 format.
1062
- */
1063
- function generateBigUint64Array(featureIds) {
1064
- const typedFeatureIds = new BigUint64Array(featureIds.length);
1065
- for (let index = 0; index < featureIds.length; index++) {
1066
- typedFeatureIds[index] = BigInt(featureIds[index]);
1067
- }
1068
- return typedFeatureIds;
1069
- }
1070
- /**
1071
- * Generates draco compressed geometry
1072
- * @param {Number} vertexCount
1073
- * @param {Object} convertedAttributes - get rid of this argument here
1074
- * @param {Object} attributes - geometry attributes to compress
1075
- * @param {string} dracoWorkerSoure - draco worker source code
1076
- * @returns {Promise<object>} - COmpressed geometry.
1077
- */
1078
- async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes, dracoWorkerSoure) {
1079
- const { positions, normals, texCoords, colors, uvRegions, featureIds, faceRange } = attributes;
1080
- const indices = new Uint32Array(vertexCount);
1081
- for (let index = 0; index < indices.length; index++) {
1082
- indices.set([index], index);
1083
- }
1084
- const featureIndices = new Uint32Array(convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount);
1085
- const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
1086
- const compressedAttributes = {
1087
- positions,
1088
- normals,
1089
- colors,
1090
- 'feature-index': featureIndex
1091
- };
1092
- if (texCoords.length) {
1093
- compressedAttributes.texCoords = texCoords;
1094
- }
1095
- const attributesMetadata = {
1096
- 'feature-index': {
1097
- 'i3s-attribute-type': 'feature-index',
1098
- 'i3s-feature-ids': new Int32Array(featureIds)
1099
- }
1100
- };
1101
- if (uvRegions.length) {
1102
- compressedAttributes['uv-region'] = uvRegions;
1103
- attributesMetadata['uv-region'] = {
1104
- 'i3s-attribute-type': 'uv-region'
1105
- };
1106
- }
1107
- return (0, core_2.encode)({ attributes: compressedAttributes, indices }, draco_1.DracoWriterWorker, {
1108
- ...draco_1.DracoWriterWorker.options,
1109
- source: dracoWorkerSoure,
1110
- reuseWorkers: true,
1111
- _nodeWorkers: true,
1112
- draco: {
1113
- method: 'MESH_SEQUENTIAL_ENCODING',
1114
- attributesMetadata
1115
- }
1116
- });
1117
- }
1118
- /**
1119
- * Generates ordered feature indices based on face range
1120
- * @param featureIndex
1121
- * @param faceRange
1122
- * @returns
1123
- */
1124
- function generateFeatureIndexAttribute(featureIndex, faceRange) {
1125
- const orderedFeatureIndices = new Uint32Array(featureIndex.length);
1126
- let fillIndex = 0;
1127
- let startIndex = 0;
1128
- for (let index = 1; index < faceRange.length; index += 2) {
1129
- const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
1130
- orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);
1131
- fillIndex++;
1132
- startIndex = endIndex + 1;
1133
- }
1134
- return orderedFeatureIndices;
1135
- }
1136
- /**
1137
- * Find property table in tile
1138
- * For example it can be batchTable for b3dm files or property table in gLTF extension.
1139
- * @param tileContent - 3DTiles tile content
1140
- * @return batch table from b3dm / feature properties from EXT_FEATURE_METADATA
1141
- */
1142
- function getPropertyTable(tileContent) {
1143
- if (!tileContent) {
1144
- return null;
1145
- }
1146
- const batchTableJson = tileContent?.batchTableJson;
1147
- if (batchTableJson) {
1148
- return batchTableJson;
1149
- }
1150
- const { extensionName, extension } = getPropertyTableExtension(tileContent);
1151
- switch (extensionName) {
1152
- case EXT_MESH_FEATURES: {
1153
- console.warn('The I3S converter does not yet support the EXT_mesh_features extension');
1154
- return null;
1155
- }
1156
- case EXT_FEATURE_METADATA: {
1157
- return getPropertyTableFromExtFeatureMetadata(extension);
1158
- }
1159
- default:
1160
- return null;
1161
- }
1162
- }
1163
- exports.getPropertyTable = getPropertyTable;
1164
- /**
1165
- * Check extensions which can be with property table inside.
1166
- * @param tileContent - 3DTiles tile content
1167
- */
1168
- function getPropertyTableExtension(tileContent) {
1169
- const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];
1170
- const extensionsUsed = tileContent?.gltf?.extensionsUsed;
1171
- if (!extensionsUsed) {
1172
- return { extensionName: null, extension: null };
1173
- }
1174
- let extensionName = '';
1175
- for (const extensionItem of tileContent?.gltf?.extensionsUsed || []) {
1176
- if (extensionsWithPropertyTables.includes(extensionItem)) {
1177
- extensionName = extensionItem;
1178
- break;
1179
- }
1180
- }
1181
- const extension = tileContent?.gltf?.extensions?.[extensionName];
1182
- return { extensionName, extension };
1183
- }
1184
- /**
1185
- * Handle EXT_feature_metadata to get property table
1186
- * @param extension
1187
- */
1188
- function getPropertyTableFromExtFeatureMetadata(extension) {
1189
- if (extension?.featureTables) {
1190
- /**
1191
- * Take only first feature table to generate attributes storage info object.
1192
- * TODO: Think about getting data from all feature tables?
1193
- * It can be tricky just because 3dTiles is able to have multiple featureId attributes and multiple feature tables.
1194
- * In I3S we should decide which featureIds attribute will be passed to geometry data.
1195
- */
1196
- const firstFeatureTableName = Object.keys(extension.featureTables)?.[0];
1197
- if (firstFeatureTableName) {
1198
- const featureTable = extension?.featureTables[firstFeatureTableName];
1199
- const propertyTable = {};
1200
- for (const propertyName in featureTable.properties) {
1201
- propertyTable[propertyName] = featureTable.properties[propertyName].data;
1202
- }
1203
- return propertyTable;
1204
- }
1205
- }
1206
- if (extension?.featureTextures) {
1207
- /**
1208
- * Take only first feature texture to generate attributes storage info object.
1209
- * TODO: Think about getting data from all feature textures?
1210
- * It can be tricky just because 3dTiles is able to have multiple featureTextures.
1211
- * In I3S we should decide which featureTextures will be passed to geometry data.
1212
- */
1213
- const firstTextureName = Object.keys(extension.featureTextures)?.[0];
1214
- if (firstTextureName) {
1215
- const featureTable = extension?.featureTextures[firstTextureName];
1216
- const propertyTable = {};
1217
- for (const propertyName in featureTable.properties) {
1218
- propertyTable[propertyName] = featureTable.properties[propertyName].data;
1219
- }
1220
- return propertyTable;
1221
- }
1222
- }
1223
- console.warn("The I3S converter couldn't handle EXT_feature_metadata extension: There is neither featureTables, no featureTextures in the extension.");
1224
- return null;
1225
- }