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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (502) hide show
  1. package/bin/converter.js +1 -1
  2. package/bin/slpk-extractor.js +4 -0
  3. package/dist/3d-tiles-attributes-worker.d.ts +28 -0
  4. package/dist/3d-tiles-attributes-worker.d.ts.map +1 -0
  5. package/dist/3d-tiles-attributes-worker.js +3 -0
  6. package/dist/3d-tiles-attributes-worker.js.map +7 -0
  7. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +90 -0
  8. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -0
  9. package/dist/3d-tiles-converter/3d-tiles-converter.js +275 -226
  10. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +71 -18
  11. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -0
  12. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +256 -236
  13. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +4 -7
  14. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts.map +1 -0
  15. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +22 -9
  16. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +9 -0
  17. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -0
  18. package/dist/3d-tiles-converter/helpers/texture-atlas.js +47 -28
  19. package/dist/3d-tiles-converter/json-templates/tileset.d.ts +15 -0
  20. package/dist/3d-tiles-converter/json-templates/tileset.d.ts.map +1 -0
  21. package/dist/3d-tiles-converter/json-templates/tileset.js +42 -36
  22. package/dist/bundle.d.ts +2 -0
  23. package/dist/bundle.d.ts.map +1 -0
  24. package/dist/bundle.js +2 -2
  25. package/dist/constants.d.ts +2 -0
  26. package/dist/constants.d.ts.map +1 -0
  27. package/dist/constants.js +4 -0
  28. package/dist/converter-cli.d.ts +2 -0
  29. package/dist/converter-cli.d.ts.map +1 -0
  30. package/dist/converter-cli.js +214 -0
  31. package/dist/converter.min.js +185 -190
  32. package/dist/deps-installer/deps-installer.d.ts +11 -3
  33. package/dist/deps-installer/deps-installer.d.ts.map +1 -0
  34. package/dist/deps-installer/deps-installer.js +61 -23
  35. package/dist/dist.min.js +64143 -0
  36. package/dist/es5/3d-tiles-attributes-worker.js +25 -0
  37. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -0
  38. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +467 -0
  39. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
  40. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +293 -0
  41. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
  42. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +18 -0
  43. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
  44. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +33 -0
  45. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  46. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +61 -0
  47. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -0
  48. package/dist/es5/bundle.js +6 -0
  49. package/dist/es5/bundle.js.map +1 -0
  50. package/dist/es5/constants.js +9 -0
  51. package/dist/es5/constants.js.map +1 -0
  52. package/dist/es5/converter-cli.js +244 -0
  53. package/dist/es5/converter-cli.js.map +1 -0
  54. package/dist/es5/deps-installer/deps-installer.js +124 -0
  55. package/dist/es5/deps-installer/deps-installer.js.map +1 -0
  56. package/dist/es5/i3s-attributes-worker.js +25 -0
  57. package/dist/es5/i3s-attributes-worker.js.map +1 -0
  58. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +116 -0
  59. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  60. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +89 -0
  61. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -0
  62. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +41 -0
  63. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
  64. package/dist/es5/i3s-converter/helpers/feature-attributes.js +174 -0
  65. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -0
  66. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +213 -0
  67. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -0
  68. package/dist/es5/i3s-converter/helpers/geometry-converter.js +1192 -0
  69. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -0
  70. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +113 -0
  71. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  72. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js +82 -0
  73. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js.map +1 -0
  74. package/dist/es5/i3s-converter/helpers/node-debug.js +76 -0
  75. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -0
  76. package/dist/es5/i3s-converter/helpers/node-index-document.js +521 -0
  77. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -0
  78. package/dist/es5/i3s-converter/helpers/node-pages.js +519 -0
  79. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -0
  80. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +111 -0
  81. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -0
  82. package/dist/es5/i3s-converter/helpers/tileset-traversal.js +82 -0
  83. package/dist/es5/i3s-converter/helpers/tileset-traversal.js.map +1 -0
  84. package/dist/es5/i3s-converter/i3s-converter.js +1541 -0
  85. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -0
  86. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js +107 -0
  87. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
  88. package/dist/es5/i3s-converter/json-templates/layers.js +163 -0
  89. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -0
  90. package/dist/es5/i3s-converter/json-templates/metadata.js +31 -0
  91. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -0
  92. package/dist/es5/i3s-converter/json-templates/node.js +99 -0
  93. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -0
  94. package/dist/es5/i3s-converter/json-templates/scene-server.js +39 -0
  95. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -0
  96. package/dist/es5/i3s-converter/json-templates/shared-resources.js +173 -0
  97. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -0
  98. package/dist/es5/i3s-converter/json-templates/store.js +107 -0
  99. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -0
  100. package/dist/es5/i3s-converter/types.js +18 -0
  101. package/dist/es5/i3s-converter/types.js.map +1 -0
  102. package/dist/es5/i3s-server/README.md +19 -0
  103. package/dist/es5/i3s-server/app.js +27 -0
  104. package/dist/es5/i3s-server/app.js.map +1 -0
  105. package/dist/es5/i3s-server/controllers/index-controller.js +55 -0
  106. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -0
  107. package/dist/es5/i3s-server/controllers/slpk-controller.js +84 -0
  108. package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -0
  109. package/dist/es5/i3s-server/routes/index.js +37 -0
  110. package/dist/es5/i3s-server/routes/index.js.map +1 -0
  111. package/dist/es5/i3s-server/routes/slpk-router.js +71 -0
  112. package/dist/es5/i3s-server/routes/slpk-router.js.map +1 -0
  113. package/dist/es5/i3s-server/utils/create-scene-server.js +17 -0
  114. package/dist/es5/i3s-server/utils/create-scene-server.js.map +1 -0
  115. package/dist/es5/index.js +21 -0
  116. package/dist/es5/index.js.map +1 -0
  117. package/dist/es5/lib/utils/cli-utils.js +57 -0
  118. package/dist/es5/lib/utils/cli-utils.js.map +1 -0
  119. package/dist/es5/lib/utils/compress-util.js +346 -0
  120. package/dist/es5/lib/utils/compress-util.js.map +1 -0
  121. package/dist/es5/lib/utils/file-utils.js +208 -0
  122. package/dist/es5/lib/utils/file-utils.js.map +1 -0
  123. package/dist/es5/lib/utils/geometry-utils.js +15 -0
  124. package/dist/es5/lib/utils/geometry-utils.js.map +1 -0
  125. package/dist/es5/lib/utils/lod-conversion-utils.js +44 -0
  126. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -0
  127. package/dist/es5/lib/utils/queue.js +47 -0
  128. package/dist/es5/lib/utils/queue.js.map +1 -0
  129. package/dist/es5/lib/utils/statistic-utills.d.ts +25 -0
  130. package/dist/es5/lib/utils/statistic-utills.js +147 -0
  131. package/dist/es5/lib/utils/statistic-utills.js.map +1 -0
  132. package/dist/es5/lib/utils/write-queue.js +214 -0
  133. package/dist/es5/lib/utils/write-queue.js.map +1 -0
  134. package/dist/es5/pgm-loader.js +41 -0
  135. package/dist/es5/pgm-loader.js.map +1 -0
  136. package/dist/es5/slpk-extractor/helpers/file-handle-provider.js +181 -0
  137. package/dist/es5/slpk-extractor/helpers/file-handle-provider.js.map +1 -0
  138. package/dist/es5/slpk-extractor/slpk-extractor.js +172 -0
  139. package/dist/es5/slpk-extractor/slpk-extractor.js.map +1 -0
  140. package/dist/es5/slpk-extractor-cli.js +117 -0
  141. package/dist/es5/slpk-extractor-cli.js.map +1 -0
  142. package/dist/es5/workers/3d-tiles-attributes-worker.js +28 -0
  143. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -0
  144. package/dist/es5/workers/i3s-attributes-worker.js +30 -0
  145. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -0
  146. package/dist/esm/3d-tiles-attributes-worker.js +16 -0
  147. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -0
  148. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +245 -0
  149. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
  150. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +218 -0
  151. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
  152. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +10 -0
  153. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
  154. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +27 -0
  155. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  156. package/dist/esm/3d-tiles-converter/json-templates/tileset.js +37 -0
  157. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -0
  158. package/dist/esm/bundle.js +4 -0
  159. package/dist/esm/bundle.js.map +1 -0
  160. package/dist/esm/constants.js +2 -0
  161. package/dist/esm/constants.js.map +1 -0
  162. package/dist/esm/converter-cli.js +187 -0
  163. package/dist/esm/converter-cli.js.map +1 -0
  164. package/dist/esm/deps-installer/deps-installer.js +45 -0
  165. package/dist/esm/deps-installer/deps-installer.js.map +1 -0
  166. package/dist/esm/i3s-attributes-worker.js +16 -0
  167. package/dist/esm/i3s-attributes-worker.js.map +1 -0
  168. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +105 -0
  169. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  170. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +79 -0
  171. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -0
  172. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +16 -0
  173. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
  174. package/dist/esm/i3s-converter/helpers/feature-attributes.js +147 -0
  175. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -0
  176. package/{src → dist/esm}/i3s-converter/helpers/geometry-attributes.js +80 -106
  177. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -0
  178. package/dist/esm/i3s-converter/helpers/geometry-converter.js +906 -0
  179. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -0
  180. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +110 -0
  181. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  182. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js +35 -0
  183. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js.map +1 -0
  184. package/{src → dist/esm}/i3s-converter/helpers/node-debug.js +20 -41
  185. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -0
  186. package/dist/esm/i3s-converter/helpers/node-index-document.js +201 -0
  187. package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -0
  188. package/dist/esm/i3s-converter/helpers/node-pages.js +206 -0
  189. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -0
  190. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +48 -0
  191. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -0
  192. package/dist/esm/i3s-converter/helpers/tileset-traversal.js +14 -0
  193. package/dist/esm/i3s-converter/helpers/tileset-traversal.js.map +1 -0
  194. package/dist/esm/i3s-converter/i3s-converter.js +778 -0
  195. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -0
  196. package/dist/esm/i3s-converter/json-templates/geometry-definitions.js +89 -0
  197. package/dist/esm/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
  198. package/dist/esm/i3s-converter/json-templates/layers.js +133 -0
  199. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -0
  200. package/dist/esm/i3s-converter/json-templates/metadata.js +22 -0
  201. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -0
  202. package/dist/esm/i3s-converter/json-templates/node.js +80 -0
  203. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -0
  204. package/dist/esm/i3s-converter/json-templates/scene-server.js +28 -0
  205. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -0
  206. package/dist/esm/i3s-converter/json-templates/shared-resources.js +123 -0
  207. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -0
  208. package/dist/esm/i3s-converter/json-templates/store.js +98 -0
  209. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -0
  210. package/dist/esm/i3s-converter/types.js +11 -0
  211. package/dist/esm/i3s-converter/types.js.map +1 -0
  212. package/dist/esm/i3s-server/README.md +19 -0
  213. package/dist/esm/i3s-server/app.js +26 -0
  214. package/dist/esm/i3s-server/app.js.map +1 -0
  215. package/dist/esm/i3s-server/bin/www +102 -0
  216. package/dist/esm/i3s-server/certs/cert.pem +19 -0
  217. package/dist/esm/i3s-server/certs/key.pem +27 -0
  218. package/dist/esm/i3s-server/controllers/index-controller.js +24 -0
  219. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -0
  220. package/dist/esm/i3s-server/controllers/slpk-controller.js +36 -0
  221. package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -0
  222. package/dist/esm/i3s-server/routes/index.js +16 -0
  223. package/dist/esm/i3s-server/routes/index.js.map +1 -0
  224. package/dist/esm/i3s-server/routes/slpk-router.js +33 -0
  225. package/dist/esm/i3s-server/routes/slpk-router.js.map +1 -0
  226. package/dist/esm/i3s-server/utils/create-scene-server.js +16 -0
  227. package/dist/esm/i3s-server/utils/create-scene-server.js.map +1 -0
  228. package/dist/esm/index.js +3 -0
  229. package/dist/esm/index.js.map +1 -0
  230. package/dist/esm/lib/utils/cli-utils.js +47 -0
  231. package/dist/esm/lib/utils/cli-utils.js.map +1 -0
  232. package/dist/esm/lib/utils/compress-util.js +168 -0
  233. package/dist/esm/lib/utils/compress-util.js.map +1 -0
  234. package/dist/esm/lib/utils/file-utils.js +87 -0
  235. package/dist/esm/lib/utils/file-utils.js.map +1 -0
  236. package/dist/esm/lib/utils/geometry-utils.js +8 -0
  237. package/dist/esm/lib/utils/geometry-utils.js.map +1 -0
  238. package/dist/esm/lib/utils/lod-conversion-utils.js +37 -0
  239. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -0
  240. package/dist/esm/lib/utils/queue.js +15 -0
  241. package/dist/esm/lib/utils/queue.js.map +1 -0
  242. package/dist/esm/lib/utils/statistic-utills.d.ts +25 -0
  243. package/dist/esm/lib/utils/statistic-utills.js +62 -0
  244. package/dist/esm/lib/utils/statistic-utills.js.map +1 -0
  245. package/dist/esm/lib/utils/write-queue.js +85 -0
  246. package/dist/esm/lib/utils/write-queue.js.map +1 -0
  247. package/dist/esm/pgm-loader.js +15 -0
  248. package/dist/esm/pgm-loader.js.map +1 -0
  249. package/dist/esm/slpk-extractor/helpers/file-handle-provider.js +43 -0
  250. package/dist/esm/slpk-extractor/helpers/file-handle-provider.js.map +1 -0
  251. package/dist/esm/slpk-extractor/slpk-extractor.js +63 -0
  252. package/dist/esm/slpk-extractor/slpk-extractor.js.map +1 -0
  253. package/dist/esm/slpk-extractor-cli.js +74 -0
  254. package/dist/esm/slpk-extractor-cli.js.map +1 -0
  255. package/dist/esm/workers/3d-tiles-attributes-worker.js +8 -0
  256. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -0
  257. package/dist/esm/workers/i3s-attributes-worker.js +7 -0
  258. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -0
  259. package/dist/i3s-attributes-worker.d.ts +45 -0
  260. package/dist/i3s-attributes-worker.d.ts.map +1 -0
  261. package/dist/i3s-attributes-worker.js +9 -0
  262. package/dist/i3s-attributes-worker.js.map +7 -0
  263. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +13 -0
  264. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -0
  265. package/dist/i3s-converter/helpers/batch-ids-extensions.js +138 -0
  266. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +39 -0
  267. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -0
  268. package/dist/i3s-converter/helpers/coordinate-converter.js +118 -42
  269. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +9 -0
  270. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -0
  271. package/dist/i3s-converter/helpers/create-scene-server-path.js +27 -15
  272. package/dist/i3s-converter/helpers/feature-attributes.d.ts +56 -0
  273. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -0
  274. package/dist/i3s-converter/helpers/feature-attributes.js +216 -0
  275. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +8 -0
  276. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -0
  277. package/dist/i3s-converter/helpers/geometry-attributes.js +188 -185
  278. package/dist/i3s-converter/helpers/geometry-converter.d.ts +41 -35
  279. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -0
  280. package/dist/i3s-converter/helpers/geometry-converter.js +1179 -650
  281. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +28 -0
  282. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -0
  283. package/dist/i3s-converter/helpers/gltf-attributes.js +129 -0
  284. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts +18 -0
  285. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts.map +1 -0
  286. package/dist/i3s-converter/helpers/load-3d-tiles.js +53 -0
  287. package/dist/i3s-converter/helpers/node-debug.d.ts +8 -0
  288. package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -0
  289. package/dist/i3s-converter/helpers/node-debug.js +106 -74
  290. package/dist/i3s-converter/helpers/node-index-document.d.ts +103 -0
  291. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -0
  292. package/dist/i3s-converter/helpers/node-index-document.js +268 -0
  293. package/dist/i3s-converter/helpers/node-pages.d.ts +125 -113
  294. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -0
  295. package/dist/i3s-converter/helpers/node-pages.js +313 -133
  296. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +22 -0
  297. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -0
  298. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +75 -0
  299. package/dist/i3s-converter/helpers/tileset-traversal.d.ts +25 -0
  300. package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -0
  301. package/dist/i3s-converter/helpers/tileset-traversal.js +29 -0
  302. package/dist/i3s-converter/i3s-converter.d.ts +267 -0
  303. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -0
  304. package/dist/i3s-converter/i3s-converter.js +891 -867
  305. package/dist/i3s-converter/json-templates/geometry-definitions.d.ts +7 -0
  306. package/dist/i3s-converter/json-templates/geometry-definitions.d.ts.map +1 -0
  307. package/dist/i3s-converter/json-templates/geometry-definitions.js +87 -0
  308. package/dist/i3s-converter/json-templates/layers.d.ts +70 -0
  309. package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -0
  310. package/dist/i3s-converter/json-templates/layers.js +138 -190
  311. package/dist/i3s-converter/json-templates/metadata.d.ts +22 -0
  312. package/dist/i3s-converter/json-templates/metadata.d.ts.map +1 -0
  313. package/dist/i3s-converter/json-templates/metadata.js +25 -22
  314. package/dist/i3s-converter/json-templates/node.d.ts +61 -0
  315. package/dist/i3s-converter/json-templates/node.d.ts.map +1 -0
  316. package/dist/i3s-converter/json-templates/node.js +88 -79
  317. package/dist/i3s-converter/json-templates/scene-server.d.ts +28 -0
  318. package/dist/i3s-converter/json-templates/scene-server.d.ts.map +1 -0
  319. package/dist/i3s-converter/json-templates/scene-server.js +31 -28
  320. package/dist/i3s-converter/json-templates/shared-resources.d.ts +14 -0
  321. package/dist/i3s-converter/json-templates/shared-resources.d.ts.map +1 -0
  322. package/dist/i3s-converter/json-templates/shared-resources.js +124 -125
  323. package/dist/i3s-converter/json-templates/store.d.ts +95 -0
  324. package/dist/i3s-converter/json-templates/store.d.ts.map +1 -0
  325. package/dist/i3s-converter/json-templates/store.js +100 -95
  326. package/dist/i3s-converter/types.d.ts +163 -0
  327. package/dist/i3s-converter/types.d.ts.map +1 -0
  328. package/dist/i3s-converter/types.js +17 -0
  329. package/dist/i3s-server/app.d.ts +3 -0
  330. package/dist/i3s-server/app.d.ts.map +1 -0
  331. package/dist/i3s-server/app.js +11 -10
  332. package/dist/i3s-server/controllers/index-controller.d.ts +2 -0
  333. package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -0
  334. package/dist/i3s-server/controllers/index-controller.js +16 -24
  335. package/dist/i3s-server/controllers/slpk-controller.d.ts +3 -0
  336. package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -0
  337. package/dist/i3s-server/controllers/slpk-controller.js +32 -0
  338. package/dist/i3s-server/routes/index.d.ts +3 -0
  339. package/dist/i3s-server/routes/index.d.ts.map +1 -0
  340. package/dist/i3s-server/routes/index.js +11 -15
  341. package/dist/i3s-server/routes/slpk-router.d.ts +3 -0
  342. package/dist/i3s-server/routes/slpk-router.d.ts.map +1 -0
  343. package/dist/i3s-server/routes/slpk-router.js +33 -0
  344. package/dist/i3s-server/utils/create-scene-server.d.ts +11 -0
  345. package/dist/i3s-server/utils/create-scene-server.d.ts.map +1 -0
  346. package/dist/i3s-server/utils/create-scene-server.js +14 -0
  347. package/dist/index.d.ts +3 -0
  348. package/dist/index.d.ts.map +1 -0
  349. package/dist/index.js +10 -5
  350. package/dist/lib/utils/cli-utils.d.ts +34 -0
  351. package/dist/lib/utils/cli-utils.d.ts.map +1 -0
  352. package/dist/lib/utils/cli-utils.js +82 -0
  353. package/dist/lib/utils/compress-util.d.ts +45 -0
  354. package/dist/lib/utils/compress-util.d.ts.map +1 -0
  355. package/dist/lib/utils/compress-util.js +238 -160
  356. package/dist/lib/utils/file-utils.d.ts +22 -14
  357. package/dist/lib/utils/file-utils.d.ts.map +1 -0
  358. package/dist/lib/utils/file-utils.js +134 -36
  359. package/dist/lib/utils/geometry-utils.d.ts +9 -0
  360. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  361. package/dist/lib/utils/geometry-utils.js +18 -0
  362. package/dist/lib/utils/lod-conversion-utils.d.ts +23 -13
  363. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -0
  364. package/dist/lib/utils/lod-conversion-utils.js +72 -39
  365. package/dist/lib/utils/queue.d.ts +7 -0
  366. package/dist/lib/utils/queue.d.ts.map +1 -0
  367. package/dist/lib/utils/queue.js +18 -0
  368. package/dist/lib/utils/statistic-utills.d.ts +3 -25
  369. package/dist/lib/utils/statistic-utills.d.ts.map +1 -0
  370. package/dist/lib/utils/statistic-utills.js +58 -67
  371. package/dist/lib/utils/write-queue.d.ts +39 -0
  372. package/dist/lib/utils/write-queue.d.ts.map +1 -0
  373. package/dist/lib/utils/write-queue.js +80 -0
  374. package/dist/pgm-loader.d.ts +6 -0
  375. package/dist/pgm-loader.d.ts.map +1 -0
  376. package/dist/pgm-loader.js +23 -14
  377. package/dist/slpk-extractor/helpers/file-handle-provider.d.ts +48 -0
  378. package/dist/slpk-extractor/helpers/file-handle-provider.d.ts.map +1 -0
  379. package/dist/slpk-extractor/helpers/file-handle-provider.js +71 -0
  380. package/dist/slpk-extractor/slpk-extractor.d.ts +23 -0
  381. package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -0
  382. package/dist/slpk-extractor/slpk-extractor.js +78 -0
  383. package/dist/slpk-extractor-cli.d.ts +17 -0
  384. package/dist/slpk-extractor-cli.d.ts.map +1 -0
  385. package/dist/slpk-extractor-cli.js +102 -0
  386. package/dist/slpk-extractor.min.js +189 -0
  387. package/dist/workers/3d-tiles-attributes-worker.d.ts +2 -0
  388. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +1 -0
  389. package/dist/workers/3d-tiles-attributes-worker.js +9 -0
  390. package/dist/workers/i3s-attributes-worker.d.ts +2 -0
  391. package/dist/workers/i3s-attributes-worker.d.ts.map +1 -0
  392. package/dist/workers/i3s-attributes-worker.js +5 -0
  393. package/package.json +36 -24
  394. package/src/3d-tiles-attributes-worker.ts +43 -0
  395. package/src/3d-tiles-converter/3d-tiles-converter.ts +131 -63
  396. package/src/3d-tiles-converter/helpers/{b3dm-converter.js → b3dm-converter.ts} +72 -53
  397. package/src/3d-tiles-converter/helpers/{i3s-obb-to-3d-tiles-obb.js → i3s-obb-to-3d-tiles-obb.ts} +16 -1
  398. package/src/3d-tiles-converter/helpers/texture-atlas.ts +4 -4
  399. package/src/3d-tiles-converter/json-templates/{tileset.js → tileset.ts} +9 -9
  400. package/src/constants.ts +2 -0
  401. package/src/converter-cli.ts +305 -0
  402. package/src/deps-installer/deps-installer.ts +72 -0
  403. package/src/i3s-attributes-worker.ts +59 -0
  404. package/src/i3s-converter/helpers/batch-ids-extensions.ts +202 -0
  405. package/src/i3s-converter/helpers/coordinate-converter.ts +94 -34
  406. package/src/i3s-converter/helpers/create-scene-server-path.ts +29 -0
  407. package/src/i3s-converter/helpers/feature-attributes.ts +247 -0
  408. package/src/i3s-converter/helpers/geometry-attributes.ts +267 -0
  409. package/src/i3s-converter/helpers/geometry-converter.ts +1667 -0
  410. package/src/i3s-converter/helpers/gltf-attributes.ts +162 -0
  411. package/src/i3s-converter/helpers/load-3d-tiles.ts +68 -0
  412. package/src/i3s-converter/helpers/node-debug.ts +146 -0
  413. package/src/i3s-converter/helpers/node-index-document.ts +335 -0
  414. package/src/i3s-converter/helpers/node-pages.ts +344 -0
  415. package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +79 -0
  416. package/src/i3s-converter/helpers/tileset-traversal.ts +51 -0
  417. package/src/i3s-converter/i3s-converter.ts +650 -669
  418. package/src/i3s-converter/json-templates/geometry-definitions.ts +83 -0
  419. package/src/i3s-converter/json-templates/layers.ts +137 -0
  420. package/src/i3s-converter/json-templates/{metadata.js → metadata.ts} +2 -2
  421. package/src/i3s-converter/json-templates/{node.js → node.ts} +12 -12
  422. package/src/i3s-converter/json-templates/{scene-server.js → scene-server.ts} +2 -2
  423. package/src/i3s-converter/json-templates/{shared-resources.js → shared-resources.ts} +17 -17
  424. package/src/i3s-converter/types.ts +185 -0
  425. package/src/i3s-server/README.md +19 -0
  426. package/src/i3s-server/app.js +8 -1
  427. package/src/i3s-server/controllers/slpk-controller.js +38 -0
  428. package/src/i3s-server/routes/slpk-router.js +33 -0
  429. package/src/i3s-server/utils/create-scene-server.js +15 -0
  430. package/src/index.ts +0 -4
  431. package/src/lib/utils/cli-utils.ts +78 -0
  432. package/src/lib/utils/{compress-util.js → compress-util.ts} +105 -18
  433. package/src/lib/utils/file-utils.ts +140 -0
  434. package/src/lib/utils/geometry-utils.ts +14 -0
  435. package/src/lib/utils/{lod-conversion-utils.js → lod-conversion-utils.ts} +31 -5
  436. package/src/lib/utils/queue.ts +17 -0
  437. package/src/lib/utils/write-queue.ts +110 -0
  438. package/src/pgm-loader.ts +3 -3
  439. package/src/slpk-extractor/helpers/file-handle-provider.ts +91 -0
  440. package/src/slpk-extractor/slpk-extractor.ts +102 -0
  441. package/src/slpk-extractor-cli.ts +128 -0
  442. package/src/workers/3d-tiles-attributes-worker.ts +6 -0
  443. package/src/workers/i3s-attributes-worker.ts +7 -0
  444. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
  445. package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
  446. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
  447. package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
  448. package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
  449. package/dist/bundle.js.map +0 -1
  450. package/dist/deps-installer/deps-installer.js.map +0 -1
  451. package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
  452. package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
  453. package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
  454. package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
  455. package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
  456. package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
  457. package/dist/i3s-converter/i3s-converter.js.map +0 -1
  458. package/dist/i3s-converter/json-templates/layers.js.map +0 -1
  459. package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
  460. package/dist/i3s-converter/json-templates/node.js.map +0 -1
  461. package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
  462. package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
  463. package/dist/i3s-converter/json-templates/store.js.map +0 -1
  464. package/dist/i3s-server/app.js.map +0 -1
  465. package/dist/i3s-server/controllers/index-controller.js.map +0 -1
  466. package/dist/i3s-server/routes/index.js.map +0 -1
  467. package/dist/index.js.map +0 -1
  468. package/dist/lib/geoid-height-model.d.ts +0 -41
  469. package/dist/lib/geoid-height-model.js +0 -140
  470. package/dist/lib/geoid-height-model.js.map +0 -1
  471. package/dist/lib/pgm-parser.d.ts +0 -14
  472. package/dist/lib/pgm-parser.js +0 -183
  473. package/dist/lib/pgm-parser.js.map +0 -1
  474. package/dist/lib/utils/compress-util.js.map +0 -1
  475. package/dist/lib/utils/compress-utils.d.ts +0 -53
  476. package/dist/lib/utils/file-utils.js.map +0 -1
  477. package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
  478. package/dist/lib/utils/statistic-utills.js.map +0 -1
  479. package/dist/pgm-loader.js.map +0 -1
  480. package/src/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  481. package/src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  482. package/src/deps-installer/deps-installer.d.ts +0 -10
  483. package/src/deps-installer/deps-installer.js +0 -22
  484. package/src/i3s-converter/helpers/create-scene-server-path.js +0 -25
  485. package/src/i3s-converter/helpers/geometry-converter.d.ts +0 -40
  486. package/src/i3s-converter/helpers/geometry-converter.js +0 -915
  487. package/src/i3s-converter/helpers/node-pages.d.ts +0 -144
  488. package/src/i3s-converter/helpers/node-pages.js +0 -208
  489. package/src/i3s-converter/json-templates/layers.js +0 -199
  490. package/src/lib/geoid-height-model.d.ts +0 -41
  491. package/src/lib/geoid-height-model.js +0 -239
  492. package/src/lib/pgm-parser.d.ts +0 -14
  493. package/src/lib/pgm-parser.js +0 -179
  494. package/src/lib/utils/compress-utils.d.ts +0 -53
  495. package/src/lib/utils/file-utils.d.ts +0 -43
  496. package/src/lib/utils/file-utils.js +0 -38
  497. package/src/lib/utils/lod-conversion-utils.d.ts +0 -32
  498. /package/dist/{i3s-server → es5/i3s-server}/bin/www +0 -0
  499. /package/dist/{i3s-server → es5/i3s-server}/certs/cert.pem +0 -0
  500. /package/dist/{i3s-server → es5/i3s-server}/certs/key.pem +0 -0
  501. /package/src/i3s-converter/json-templates/{store.js → store.ts} +0 -0
  502. /package/src/lib/utils/{statistic-utills.js → statistic-utills.ts} +0 -0
@@ -1,10 +1,49 @@
1
- import { Vector3, Matrix4, Vector4 } from '@math.gl/core';
2
- import { Ellipsoid } from '@math.gl/geospatial';
3
- import { DracoWriter } from '@loaders.gl/draco';
4
- import { encode, assert } from '@loaders.gl/core';
5
- import { concatenateArrayBuffers, concatenateTypedArrays } from '@loaders.gl/loader-utils';
6
- import md5 from 'md5';
7
- import { generateAttributes } from './geometry-attributes';
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;
8
47
  const VALUES_PER_VERTEX = 3;
9
48
  const VALUES_PER_TEX_COORD = 2;
10
49
  const VALUES_PER_COLOR_ELEMENT = 4;
@@ -12,685 +51,1175 @@ const STRING_TYPE = 'string';
12
51
  const SHORT_INT_TYPE = 'Int32';
13
52
  const DOUBLE_TYPE = 'Float64';
14
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
+ */
15
59
  const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
16
- export default async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco) {
17
- const materialAndTextureList = convertMaterials(tileContent);
18
- const convertedAttributesMap = convertAttributes(tileContent);
19
-
20
- if (convertedAttributesMap.has('default')) {
21
- materialAndTextureList.push({
22
- material: getDefaultMaterial()
23
- });
24
- }
25
-
26
- const result = [];
27
- let nodesCounter = nodeId;
28
- let {
29
- materials = []
30
- } = tileContent.gltf;
31
-
32
- if (!materials.length === 0) {
33
- materials.push({
34
- id: 'default'
35
- });
36
- }
37
-
38
- for (let i = 0; i < materials.length; i++) {
39
- const sourceMaterial = materials[i];
40
-
41
- if (!convertedAttributesMap.has(sourceMaterial.id)) {
42
- continue;
43
- }
44
-
45
- const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);
46
- const {
47
- material,
48
- texture
49
- } = materialAndTextureList[i];
50
- result.push(await _makeNodeResources({
51
- convertedAttributes,
52
- material,
53
- texture,
54
- tileContent,
55
- nodeId: nodesCounter,
56
- featuresHashArray,
57
- attributeStorageInfo,
58
- draco
59
- }));
60
- nodesCounter++;
61
- }
62
-
63
- if (!result.length) {
64
- return null;
65
- }
66
-
67
- return result;
68
- }
69
-
70
- async function _makeNodeResources({
71
- convertedAttributes,
72
- material,
73
- texture,
74
- tileContent,
75
- nodeId,
76
- featuresHashArray,
77
- attributeStorageInfo,
78
- draco
79
- }) {
80
- const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
81
- const triangleCount = vertexCount / 3;
82
- const {
83
- faceRange,
84
- featureIds,
85
- positions,
86
- normals,
87
- colors,
88
- texCoords,
89
- featureCount
90
- } = generateAttributes({
91
- triangleCount,
92
- ...convertedAttributes
93
- });
94
-
95
- if (tileContent.batchTableJson) {
96
- makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
97
- }
98
-
99
- const header = new Uint32Array(2);
100
- const typedFeatureIds = generateBigUint64Array(featureIds);
101
- header.set([vertexCount, featureCount], 0);
102
- const fileBuffer = new Uint8Array(concatenateArrayBuffers(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, typedFeatureIds.buffer, faceRange.buffer));
103
- const compressedGeometry = draco ? await generateCompressedGeometry(vertexCount, convertedAttributes, {
104
- positions,
105
- normals,
106
- texCoords: texture ? texCoords : new Float32Array(0),
107
- colors,
108
- featureIds,
109
- faceRange
110
- }) : null;
111
- const attributes = convertBatchTableToAttributeBuffers(tileContent.batchTableJson, featureIds, attributeStorageInfo);
112
- return {
113
- geometry: fileBuffer,
114
- compressedGeometry,
115
- texture,
116
- sharedResources: getSharedResources(tileContent, nodeId),
117
- meshMaterial: material,
118
- vertexCount,
119
- attributes,
120
- featureCount
121
- };
122
- }
123
-
124
- function convertAttributes(tileContent) {
125
- var _tileContent$gltf$sce;
126
-
127
- const attributesMap = new Map();
128
-
129
- for (const material of tileContent.gltf.materials || [{
130
- id: 'default'
131
- }]) {
132
- attributesMap.set(material.id, {
133
- positions: new Float32Array(0),
134
- normals: new Float32Array(0),
135
- texCoords: new Float32Array(0),
136
- colors: new Uint8Array(0),
137
- featureIndices: []
138
- });
139
- }
140
-
141
- const nodes = (tileContent.gltf.scene || ((_tileContent$gltf$sce = tileContent.gltf.scenes) === null || _tileContent$gltf$sce === void 0 ? void 0 : _tileContent$gltf$sce[0]) || tileContent.gltf).nodes;
142
- convertNodes(nodes, tileContent, attributesMap);
143
-
144
- for (const attrKey of attributesMap.keys()) {
145
- const attributes = attributesMap.get(attrKey);
146
-
147
- if (attributes.positions.length === 0) {
148
- attributesMap.delete(attrKey);
149
- continue;
150
- }
151
-
152
- const vertexCount = attributes.positions.length / VALUES_PER_VERTEX;
153
-
154
- if (!attributes.colors.length) {
155
- attributes.colors = new Uint8Array(vertexCount * VALUES_PER_COLOR_ELEMENT);
156
-
157
- for (let index = 0; index < attributes.colors.length; index += 4) {
158
- attributes.colors.set([255, 255, 255, 255], index);
159
- }
160
- }
161
-
162
- if (!attributes.texCoords.length) {
163
- attributes.texCoords = new Float32Array(vertexCount * VALUES_PER_TEX_COORD);
164
-
165
- for (let index = 0; index < attributes.texCoords.length; index += 2) {
166
- attributes.texCoords.set([1, 1], index);
167
- }
168
- }
169
-
170
- attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));
171
- }
172
-
173
- return attributesMap;
174
- }
175
-
176
- function convertNodes(nodes, tileContent, attributesMap, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
177
- if (nodes) {
178
- for (const node of nodes) {
179
- convertNode(node, tileContent, attributesMap, matrix);
180
- }
181
- }
182
- }
183
-
184
- function convertNode(node, tileContent, attributesMap, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
185
- const nodeMatrix = node.matrix;
186
- const compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;
187
- const mesh = node.mesh;
188
-
189
- if (mesh) {
190
- convertMesh(mesh, tileContent, attributesMap, compositeMatrix);
191
- }
192
-
193
- convertNodes(node.children, tileContent, attributesMap, compositeMatrix);
194
- }
195
-
196
- function convertMesh(mesh, content, attributesMap, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
197
- for (const primitive of mesh.primitives) {
198
- let outputAttributes = null;
199
-
200
- if (primitive.material) {
201
- outputAttributes = attributesMap.get(primitive.material.id);
202
- } else if (attributesMap.has('default')) {
203
- outputAttributes = attributesMap.get('default');
204
- }
205
-
206
- assert(outputAttributes !== null, 'Primitive - material mapping failed');
207
- const attributes = primitive.attributes;
208
- outputAttributes.positions = concatenateTypedArrays(outputAttributes.positions, transformVertexArray({
209
- vertices: attributes.POSITION.value,
210
- cartographicOrigin: content.cartographicOrigin,
211
- cartesianModelMatrix: content.cartesianModelMatrix,
212
- nodeMatrix: matrix,
213
- indices: primitive.indices.value,
214
- attributeSpecificTransformation: transformVertexPositions
215
- }));
216
- outputAttributes.normals = concatenateTypedArrays(outputAttributes.normals, transformVertexArray({
217
- vertices: attributes.NORMAL && attributes.NORMAL.value,
218
- cartographicOrigin: content.cartographicOrigin,
219
- cartesianModelMatrix: content.cartesianModelMatrix,
220
- nodeMatrix: matrix,
221
- indices: primitive.indices.value,
222
- attributeSpecificTransformation: transformVertexNormals
223
- }));
224
- outputAttributes.texCoords = concatenateTypedArrays(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices.value));
225
- outputAttributes.colors = concatenateTypedArrays(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices.value));
226
- outputAttributes.featureIndices.push(flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value));
227
- }
228
- }
229
-
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
+ */
230
427
  function transformVertexArray(args) {
231
- const {
232
- vertices,
233
- indices,
234
- attributeSpecificTransformation
235
- } = args;
236
- const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
237
-
238
- if (!vertices) {
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
+ }
239
442
  return newVertices;
240
- }
241
-
242
- for (let i = 0; i < indices.length; i++) {
243
- const coordIndex = indices[i] * VALUES_PER_VERTEX;
244
- const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
245
- let vertexVector = new Vector3(Array.from(vertex));
246
- vertexVector = attributeSpecificTransformation(vertexVector, args);
247
- newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;
248
- newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;
249
- newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;
250
- }
251
-
252
- return newVertices;
253
- }
254
-
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
+ */
255
454
  function transformVertexPositions(vertexVector, calleeArgs) {
256
- const {
257
- cartesianModelMatrix,
258
- cartographicOrigin,
259
- nodeMatrix
260
- } = calleeArgs;
261
-
262
- if (nodeMatrix) {
263
- vertexVector = vertexVector.transform(nodeMatrix);
264
- }
265
-
266
- vertexVector = vertexVector.transform(cartesianModelMatrix);
267
- Ellipsoid.WGS84.cartesianToCartographic([vertexVector[0], vertexVector[1], vertexVector[2]], vertexVector);
268
- vertexVector = vertexVector.subtract(cartographicOrigin);
269
- return vertexVector;
270
- }
271
-
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
+ */
272
475
  function transformVertexNormals(vertexVector, calleeArgs) {
273
- const {
274
- cartesianModelMatrix,
275
- nodeMatrix
276
- } = calleeArgs;
277
-
278
- if (nodeMatrix) {
279
- vertexVector = vertexVector.transformAsVector(nodeMatrix);
280
- }
281
-
282
- vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);
283
- return vertexVector;
284
- }
285
-
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
+ */
286
489
  function flattenTexCoords(texCoords, indices) {
287
- if (!texCoords) {
288
- return new Float32Array(0);
289
- }
290
-
291
- const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
292
-
293
- for (let i = 0; i < indices.length; i++) {
294
- const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
295
- const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
296
- newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];
297
- newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];
298
- }
299
-
300
- return newTexCoords;
301
- }
302
-
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
+ */
303
511
  function flattenColors(colorsAttribute, indices) {
304
- if (!colorsAttribute) {
305
- return new Uint8Array(0);
306
- }
307
-
308
- const components = colorsAttribute.components;
309
- const colors = colorsAttribute.value;
310
- const newColors = new Uint8Array(indices.length * components);
311
-
312
- for (let i = 0; i < indices.length; i++) {
313
- const colorIndex = indices[i] * components;
314
- const color = colors.subarray(colorIndex, colorIndex + components);
315
- const colorUint8 = new Uint8Array(components);
316
-
317
- for (let j = 0; j < color.length; j++) {
318
- colorUint8[j] = color[j] * 255;
319
- }
320
-
321
- newColors.set(colorUint8, i * components);
322
- }
323
-
324
- return newColors;
325
- }
326
-
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
+ */
327
550
  function flattenBatchIds(batchedIds, indices) {
328
- if (!batchedIds.length || !indices.length) {
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
+ }
329
579
  return [];
330
- }
331
-
332
- const newBatchIds = [];
333
-
334
- for (let i = 0; i < indices.length; i++) {
335
- const coordIndex = indices[i];
336
- newBatchIds.push(batchedIds[coordIndex]);
337
- }
338
-
339
- return newBatchIds;
340
- }
341
-
342
- function getBatchIdsByAttributeName(attributes) {
343
- let batchIds = [];
344
-
345
- for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
346
- const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
347
-
348
- if (attributes[possibleBatchIdAttributeName] && attributes[possibleBatchIdAttributeName].value) {
349
- batchIds = attributes[possibleBatchIdAttributeName].value;
350
- break;
351
- }
352
- }
353
-
354
- return batchIds;
355
- }
356
-
357
- function convertMaterials(tileContent) {
358
- const result = [];
359
- const sourceMaterials = tileContent.gltf.materials || [];
360
-
361
- for (const sourceMaterial of sourceMaterials) {
362
- result.push(convertMaterial(sourceMaterial));
363
- }
364
-
365
- return result;
366
- }
367
-
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
+ */
368
690
  function convertMaterial(sourceMaterial) {
369
- const material = {
370
- doubleSided: sourceMaterial.doubleSided,
371
- emissiveFactor: sourceMaterial.emissiveFactor.map(c => Math.round(c * 255)),
372
- alphaMode: (sourceMaterial.alphaMode || 'OPAQUE').toLowerCase(),
373
- pbrMetallicRoughness: {
374
- roughnessFactor: sourceMaterial.pbrMetallicRoughness.roughnessFactor,
375
- metallicFactor: sourceMaterial.pbrMetallicRoughness.metallicFactor
376
- }
377
- };
378
- let texture;
379
-
380
- if (sourceMaterial.pbrMetallicRoughness.baseColorTexture) {
381
- texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
382
- material.pbrMetallicRoughness.baseColorTexture = {
383
- textureSetDefinitionId: 0
384
- };
385
- } else if (sourceMaterial.emissiveTexture) {
386
- texture = sourceMaterial.emissiveTexture.texture.source;
387
- material.pbrMetallicRoughness.baseColorTexture = {
388
- textureSetDefinitionId: 0
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
+ }
389
701
  };
390
- }
391
-
392
- if (!texture) {
393
- const baseColorFactor = sourceMaterial.pbrMetallicRoughness.baseColorFactor;
394
- material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(c => Math.round(c * 255)) || undefined;
395
- }
396
-
397
- return {
398
- material,
399
- texture
400
- };
401
- }
402
-
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
+ */
403
751
  function getDefaultMaterial() {
404
- return {
405
- alphaMode: 'opaque',
406
- pbrMetallicRoughness: {}
407
- };
408
- }
409
-
410
- function getSharedResources(tileContent, nodeId) {
411
- const gltfMaterials = tileContent.gltf.materials;
412
- const i3sResources = {};
413
-
414
- if (!gltfMaterials || !gltfMaterials.length) {
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
+ }
415
781
  return i3sResources;
416
- }
417
-
418
- i3sResources.materialDefinitionInfos = [];
419
-
420
- for (const gltfMaterial of gltfMaterials) {
421
- const {
422
- materialDefinitionInfo,
423
- textureDefinitionInfo
424
- } = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId);
425
- i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
426
-
427
- if (textureDefinitionInfo) {
428
- i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
429
- i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
430
- }
431
- }
432
-
433
- return i3sResources;
434
- }
435
-
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
+ */
436
789
  function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
437
- const texture = gltfMaterial.pbrMetallicRoughness.baseColorTexture || gltfMaterial.emissiveTexture;
438
- let textureDefinitionInfo = null;
439
-
440
- if (texture) {
441
- textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
442
- }
443
-
444
- const {
445
- baseColorFactor,
446
- metallicFactor
447
- } = gltfMaterial.pbrMetallicRoughness;
448
- let colorFactor = baseColorFactor;
449
-
450
- if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
451
- colorFactor = gltfMaterial.emissiveFactor;
452
- colorFactor[3] = colorFactor[3] || 1;
453
- }
454
-
455
- return {
456
- materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor, metallicFactor),
457
- textureDefinitionInfo
458
- };
459
- }
460
-
461
- function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 0) {
462
- const matDielectricColorComponent = 0.04 / 255;
463
- const black = new Vector4(0, 0, 0, 1);
464
- const unitVector = new Vector4(1, 1, 1, 1);
465
- const dielectricSpecular = new Vector4(matDielectricColorComponent, matDielectricColorComponent, matDielectricColorComponent, 0);
466
- const baseColorVector = new Vector4(baseColorFactor);
467
- const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);
468
- const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);
469
- dielectricSpecular[3] = 1;
470
- const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
471
- return {
472
- diffuse: diffuse.toArray(),
473
- specular: specular.toArray()
474
- };
475
- }
476
-
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
+ */
477
851
  function extractSharedResourcesTextureInfo(texture, nodeId) {
478
- return {
479
- encoding: [texture.source.mimeType],
480
- images: [{
481
- id: generateImageId(texture, nodeId),
482
- size: texture.source.image.width,
483
- length: [texture.source.image.data.length]
484
- }]
485
- };
486
- }
487
-
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
+ */
488
872
  function generateImageId(texture, nodeId) {
489
- const {
490
- width,
491
- height
492
- } = texture.source.image;
493
- const levelCountOfTexture = 1;
494
- const indexOfLevel = 0;
495
- const indexOfTextureInStore = nodeId + 1;
496
- const zerosCount = 32 - indexOfTextureInStore.toString(2).length;
497
- const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));
498
- const shiftedLevelCountOfTexture = levelCountOfTexture << 28;
499
- const shiftedIndexOfLevel = indexOfLevel << 24;
500
- const shiftedWidth = width - 1 << 12;
501
- const shiftedHeight = height - 1 << 0;
502
- const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;
503
- const imageId = BigInt("0b".concat(leftHalf.toString(2)).concat(rightHalf));
504
- return imageId.toString();
505
- }
506
-
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
+ */
507
898
  function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {
508
- const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);
509
- replaceIndicesByUnique(featureIndices, replaceMap);
510
- replaceIndicesByUnique(featureIds, replaceMap);
899
+ const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);
900
+ replaceIndicesByUnique(featureIndices, replaceMap);
901
+ replaceIndicesByUnique(featureIds, replaceMap);
511
902
  }
512
-
903
+ /**
904
+ * Generate replace map to make featureIds unique.
905
+ * @param featureIds
906
+ * @param batchTable
907
+ * @param featuresHashArray
908
+ * @returns
909
+ */
513
910
  function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
514
- const featureMap = {};
515
-
516
- for (let index = 0; index < featureIds.length; index++) {
517
- const oldFeatureId = featureIds[index];
518
- const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
519
- featureMap[oldFeatureId.toString()] = uniqueFeatureId;
520
- }
521
-
522
- return featureMap;
523
- }
524
-
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
+ */
525
925
  function generateStringFromBatchTableByIndex(batchTable, index) {
526
- let str = '';
527
-
528
- for (const key in batchTable) {
529
- str += batchTable[key][index];
530
- }
531
-
532
- return str;
533
- }
534
-
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
+ */
535
939
  function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
536
- const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
537
- const hash = md5(batchTableStr);
538
-
539
- if (featuresHashArray.includes(hash)) {
540
- return featuresHashArray.indexOf(hash);
541
- }
542
-
543
- return featuresHashArray.push(hash) - 1;
544
- }
545
-
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
+ */
546
953
  function replaceIndicesByUnique(indicesArray, featureMap) {
547
- for (let index = 0; index < indicesArray.length; index++) {
548
- indicesArray[index] = featureMap[indicesArray[index]];
549
- }
550
- }
551
-
552
- function convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeStorageInfo) {
553
- const attributeBuffers = [];
554
-
555
- if (batchTable) {
556
- const batchTableWithFeatureIds = {
557
- OBJECTID: featureIds,
558
- ...batchTable
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
559
974
  };
560
-
561
- for (const key in batchTableWithFeatureIds) {
562
- const type = getAttributeType(key, attributeStorageInfo);
563
- let attributeBuffer = null;
564
-
565
- switch (type) {
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) {
566
991
  case OBJECT_ID_TYPE:
567
992
  case SHORT_INT_TYPE:
568
- attributeBuffer = generateShortIntegerAttributeBuffer(batchTableWithFeatureIds[key]);
569
- break;
570
-
993
+ attributeBuffer = generateShortIntegerAttributeBuffer(value);
994
+ break;
571
995
  case DOUBLE_TYPE:
572
- attributeBuffer = generateDoubleAttributeBuffer(batchTableWithFeatureIds[key]);
573
- break;
574
-
996
+ attributeBuffer = generateDoubleAttributeBuffer(value);
997
+ break;
575
998
  case STRING_TYPE:
576
- attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
577
- break;
578
-
999
+ attributeBuffer = generateStringAttributeBuffer(value);
1000
+ break;
579
1001
  default:
580
- attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
581
- }
582
-
583
- attributeBuffers.push(attributeBuffer);
1002
+ attributeBuffer = generateStringAttributeBuffer(value);
584
1003
  }
585
- }
586
-
587
- return attributeBuffers;
1004
+ return attributeBuffer;
588
1005
  }
589
-
1006
+ /**
1007
+ * Return attribute type.
1008
+ * @param key
1009
+ * @param attributeStorageInfo
1010
+ * @returns attribute type.
1011
+ */
590
1012
  function getAttributeType(key, attributeStorageInfo) {
591
- const attribute = attributeStorageInfo.find(attr => attr.name === key);
592
- return attribute.attributeValues.valueType;
1013
+ const attribute = attributeStorageInfo.find((attr) => attr.name === key);
1014
+ return attribute.attributeValues.valueType;
593
1015
  }
594
-
1016
+ /**
1017
+ * Convert short integer to attribute arrayBuffer.
1018
+ * @param featureIds
1019
+ * @returns - Buffer with objectId data.
1020
+ */
595
1021
  function generateShortIntegerAttributeBuffer(featureIds) {
596
- const count = new Uint32Array([featureIds.length]);
597
- const valuesArray = new Uint32Array(featureIds);
598
- return concatenateArrayBuffers(count.buffer, valuesArray.buffer);
1022
+ const count = new Uint32Array([featureIds.length]);
1023
+ const valuesArray = new Uint32Array(featureIds);
1024
+ return (0, loader_utils_1.concatenateArrayBuffers)(count.buffer, valuesArray.buffer);
599
1025
  }
600
-
1026
+ /**
1027
+ * Convert double to attribute arrayBuffer.
1028
+ * @param featureIds
1029
+ * @returns - Buffer with objectId data.
1030
+ */
601
1031
  function generateDoubleAttributeBuffer(featureIds) {
602
- const count = new Uint32Array([featureIds.length]);
603
- const padding = new Uint8Array(4);
604
- const valuesArray = new Float64Array(featureIds);
605
- return concatenateArrayBuffers(count.buffer, padding.buffer, valuesArray.buffer);
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);
606
1036
  }
607
-
1037
+ /**
1038
+ * Convert batch table attributes to array buffer with batch table data.
1039
+ * @param batchAttributes
1040
+ * @returns - Buffer with batch table data.
1041
+ */
608
1042
  function generateStringAttributeBuffer(batchAttributes) {
609
- const stringCountArray = new Uint32Array([batchAttributes.length]);
610
- let totalNumberOfBytes = 0;
611
- const stringSizesArray = new Uint32Array(batchAttributes.length);
612
- const stringBufferArray = [];
613
-
614
- for (let index = 0; index < batchAttributes.length; index++) {
615
- const currentString = "".concat(String(batchAttributes[index]), "\0");
616
- const currentStringBuffer = Buffer.from(currentString);
617
- const currentStringSize = currentStringBuffer.length;
618
- totalNumberOfBytes += currentStringSize;
619
- stringSizesArray[index] = currentStringSize;
620
- stringBufferArray.push(currentStringBuffer);
621
- }
622
-
623
- const totalBytes = new Uint32Array([totalNumberOfBytes]);
624
- return concatenateArrayBuffers(stringCountArray.buffer, totalBytes.buffer, stringSizesArray.buffer, ...stringBufferArray);
625
- }
626
-
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
+ */
627
1063
  function generateBigUint64Array(featureIds) {
628
- const typedFeatureIds = new BigUint64Array(featureIds.length);
629
-
630
- for (let index = 0; index < featureIds.length; index++) {
631
- typedFeatureIds[index] = BigInt(featureIds[index]);
632
- }
633
-
634
- return typedFeatureIds;
635
- }
636
-
637
- async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes) {
638
- const {
639
- positions,
640
- normals,
641
- texCoords,
642
- colors,
643
- featureIds,
644
- faceRange
645
- } = attributes;
646
- const indices = new Uint32Array(vertexCount);
647
-
648
- for (let index = 0; index < indices.length; index++) {
649
- indices.set([index], index);
650
- }
651
-
652
- const featureIndices = new Uint32Array(convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount);
653
- const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
654
- const compressedAttributes = {
655
- positions,
656
- normals,
657
- colors,
658
- 'feature-index': featureIndex
659
- };
660
-
661
- if (texCoords.length) {
662
- compressedAttributes.texCoords = texCoords;
663
- }
664
-
665
- const attributesMetadata = {
666
- 'feature-index': {
667
- 'i3s-attribute-type': 'feature-index',
668
- 'i3s-feature-ids': new Int32Array(featureIds)
669
- }
670
- };
671
- return new Uint8Array(await encode({
672
- attributes: compressedAttributes,
673
- indices
674
- }, DracoWriter, {
675
- draco: {
676
- method: 'MESH_SEQUENTIAL_ENCODING',
677
- attributesMetadata
678
- }
679
- }));
680
- }
681
-
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
+ */
682
1124
  function generateFeatureIndexAttribute(featureIndex, faceRange) {
683
- const orderedFeatureIndices = new Uint32Array(featureIndex.length);
684
- let fillIndex = 0;
685
- let startIndex = 0;
686
-
687
- for (let index = 1; index < faceRange.length; index += 2) {
688
- const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
689
- orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);
690
- fillIndex++;
691
- startIndex = endIndex + 1;
692
- }
693
-
694
- return orderedFeatureIndices;
695
- }
696
- //# sourceMappingURL=geometry-converter.js.map
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
+ }