@loaders.gl/tile-converter 4.0.0-alpha.5 → 4.0.0-alpha.7

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 (368) hide show
  1. package/bin/converter.js +1 -1
  2. package/dist/3d-tiles-attributes-worker.d.ts +28 -0
  3. package/dist/3d-tiles-attributes-worker.d.ts.map +1 -0
  4. package/dist/3d-tiles-attributes-worker.js +3 -0
  5. package/dist/3d-tiles-attributes-worker.js.map +7 -0
  6. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +13 -1
  7. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  8. package/dist/3d-tiles-converter/3d-tiles-converter.js +274 -233
  9. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +9 -16
  10. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  11. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +256 -246
  12. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +22 -9
  13. package/dist/3d-tiles-converter/helpers/texture-atlas.js +47 -28
  14. package/dist/3d-tiles-converter/json-templates/tileset.js +38 -35
  15. package/dist/bundle.js +2 -2
  16. package/dist/constants.d.ts +2 -0
  17. package/dist/constants.d.ts.map +1 -0
  18. package/dist/constants.js +4 -0
  19. package/dist/converter-cli.d.ts +2 -0
  20. package/dist/converter-cli.d.ts.map +1 -0
  21. package/dist/converter-cli.js +280 -0
  22. package/dist/converter.min.js +185 -190
  23. package/dist/deps-installer/deps-installer.d.ts +11 -3
  24. package/dist/deps-installer/deps-installer.d.ts.map +1 -1
  25. package/dist/deps-installer/deps-installer.js +59 -18
  26. package/dist/dist.min.js +15153 -37895
  27. package/dist/es5/3d-tiles-attributes-worker.js +25 -0
  28. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -0
  29. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +467 -0
  30. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
  31. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +293 -0
  32. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
  33. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +18 -0
  34. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
  35. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +33 -0
  36. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  37. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +61 -0
  38. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -0
  39. package/dist/es5/bundle.js +6 -0
  40. package/dist/es5/bundle.js.map +1 -0
  41. package/dist/es5/constants.js +9 -0
  42. package/dist/es5/constants.js.map +1 -0
  43. package/dist/es5/converter-cli.js +289 -0
  44. package/dist/es5/converter-cli.js.map +1 -0
  45. package/dist/es5/deps-installer/deps-installer.js +123 -0
  46. package/dist/es5/deps-installer/deps-installer.js.map +1 -0
  47. package/dist/es5/i3s-attributes-worker.js +25 -0
  48. package/dist/es5/i3s-attributes-worker.js.map +1 -0
  49. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +116 -0
  50. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  51. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +90 -0
  52. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -0
  53. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +41 -0
  54. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
  55. package/dist/es5/i3s-converter/helpers/feature-attributes.js +174 -0
  56. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -0
  57. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +213 -0
  58. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -0
  59. package/dist/es5/i3s-converter/helpers/geometry-converter.js +1181 -0
  60. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -0
  61. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +80 -0
  62. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  63. package/dist/es5/i3s-converter/helpers/node-debug.js +76 -0
  64. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -0
  65. package/dist/es5/i3s-converter/helpers/node-index-document.js +492 -0
  66. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -0
  67. package/dist/es5/i3s-converter/helpers/node-pages.js +519 -0
  68. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -0
  69. package/dist/es5/i3s-converter/i3s-converter.js +1512 -0
  70. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -0
  71. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js +107 -0
  72. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
  73. package/dist/es5/i3s-converter/json-templates/layers.js +163 -0
  74. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -0
  75. package/dist/es5/i3s-converter/json-templates/metadata.js +31 -0
  76. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -0
  77. package/dist/es5/i3s-converter/json-templates/node.js +99 -0
  78. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -0
  79. package/dist/es5/i3s-converter/json-templates/scene-server.js +39 -0
  80. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -0
  81. package/dist/es5/i3s-converter/json-templates/shared-resources.js +173 -0
  82. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -0
  83. package/dist/es5/i3s-converter/json-templates/store.js +107 -0
  84. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -0
  85. package/dist/es5/i3s-converter/types.js +2 -0
  86. package/dist/es5/i3s-converter/types.js.map +1 -0
  87. package/dist/es5/i3s-server/app.js +18 -0
  88. package/dist/es5/i3s-server/app.js.map +1 -0
  89. package/dist/es5/i3s-server/controllers/index-controller.js +55 -0
  90. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -0
  91. package/dist/es5/i3s-server/routes/index.js +37 -0
  92. package/dist/es5/i3s-server/routes/index.js.map +1 -0
  93. package/dist/es5/index.js +21 -0
  94. package/dist/es5/index.js.map +1 -0
  95. package/dist/es5/lib/utils/compress-util.js +346 -0
  96. package/dist/es5/lib/utils/compress-util.js.map +1 -0
  97. package/dist/es5/lib/utils/file-utils.js +208 -0
  98. package/dist/es5/lib/utils/file-utils.js.map +1 -0
  99. package/dist/es5/lib/utils/geometry-utils.js +15 -0
  100. package/dist/es5/lib/utils/geometry-utils.js.map +1 -0
  101. package/dist/es5/lib/utils/lod-conversion-utils.js +44 -0
  102. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -0
  103. package/dist/es5/lib/utils/queue.js +47 -0
  104. package/dist/es5/lib/utils/queue.js.map +1 -0
  105. package/dist/es5/lib/utils/statistic-utills.d.ts +25 -0
  106. package/dist/es5/lib/utils/statistic-utills.js +147 -0
  107. package/dist/es5/lib/utils/statistic-utills.js.map +1 -0
  108. package/dist/es5/lib/utils/write-queue.js +214 -0
  109. package/dist/es5/lib/utils/write-queue.js.map +1 -0
  110. package/dist/es5/pgm-loader.js +41 -0
  111. package/dist/es5/pgm-loader.js.map +1 -0
  112. package/dist/es5/workers/3d-tiles-attributes-worker.js +28 -0
  113. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -0
  114. package/dist/es5/workers/i3s-attributes-worker.js +30 -0
  115. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -0
  116. package/dist/esm/3d-tiles-attributes-worker.js +16 -0
  117. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -0
  118. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +245 -0
  119. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
  120. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +218 -0
  121. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
  122. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +10 -0
  123. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
  124. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +27 -0
  125. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  126. package/dist/esm/3d-tiles-converter/json-templates/tileset.js +37 -0
  127. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -0
  128. package/dist/esm/bundle.js +4 -0
  129. package/dist/esm/bundle.js.map +1 -0
  130. package/dist/esm/constants.js +2 -0
  131. package/dist/esm/constants.js.map +1 -0
  132. package/dist/esm/converter-cli.js +232 -0
  133. package/dist/esm/converter-cli.js.map +1 -0
  134. package/dist/esm/deps-installer/deps-installer.js +44 -0
  135. package/dist/esm/deps-installer/deps-installer.js.map +1 -0
  136. package/dist/esm/i3s-attributes-worker.js +16 -0
  137. package/dist/esm/i3s-attributes-worker.js.map +1 -0
  138. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +105 -0
  139. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  140. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +80 -0
  141. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -0
  142. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +16 -0
  143. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
  144. package/dist/esm/i3s-converter/helpers/feature-attributes.js +147 -0
  145. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -0
  146. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +190 -0
  147. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -0
  148. package/dist/esm/i3s-converter/helpers/geometry-converter.js +895 -0
  149. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -0
  150. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +73 -0
  151. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  152. package/dist/esm/i3s-converter/helpers/node-debug.js +72 -0
  153. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -0
  154. package/dist/esm/i3s-converter/helpers/node-index-document.js +188 -0
  155. package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -0
  156. package/dist/esm/i3s-converter/helpers/node-pages.js +206 -0
  157. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -0
  158. package/dist/esm/i3s-converter/i3s-converter.js +764 -0
  159. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -0
  160. package/dist/esm/i3s-converter/json-templates/geometry-definitions.js +89 -0
  161. package/dist/esm/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
  162. package/dist/esm/i3s-converter/json-templates/layers.js +133 -0
  163. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -0
  164. package/dist/esm/i3s-converter/json-templates/metadata.js +22 -0
  165. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -0
  166. package/dist/esm/i3s-converter/json-templates/node.js +80 -0
  167. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -0
  168. package/dist/esm/i3s-converter/json-templates/scene-server.js +28 -0
  169. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -0
  170. package/dist/esm/i3s-converter/json-templates/shared-resources.js +123 -0
  171. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -0
  172. package/dist/esm/i3s-converter/json-templates/store.js +98 -0
  173. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -0
  174. package/dist/esm/i3s-converter/types.js +2 -0
  175. package/dist/esm/i3s-converter/types.js.map +1 -0
  176. package/dist/esm/i3s-server/app.js +16 -0
  177. package/dist/esm/i3s-server/app.js.map +1 -0
  178. package/dist/esm/i3s-server/bin/www +102 -0
  179. package/dist/esm/i3s-server/certs/cert.pem +19 -0
  180. package/dist/esm/i3s-server/certs/key.pem +27 -0
  181. package/dist/esm/i3s-server/controllers/index-controller.js +24 -0
  182. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -0
  183. package/dist/esm/i3s-server/routes/index.js +16 -0
  184. package/dist/esm/i3s-server/routes/index.js.map +1 -0
  185. package/dist/esm/index.js +3 -0
  186. package/dist/esm/index.js.map +1 -0
  187. package/dist/esm/lib/utils/compress-util.js +168 -0
  188. package/dist/esm/lib/utils/compress-util.js.map +1 -0
  189. package/dist/esm/lib/utils/file-utils.js +87 -0
  190. package/dist/esm/lib/utils/file-utils.js.map +1 -0
  191. package/dist/esm/lib/utils/geometry-utils.js +8 -0
  192. package/dist/esm/lib/utils/geometry-utils.js.map +1 -0
  193. package/dist/esm/lib/utils/lod-conversion-utils.js +37 -0
  194. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -0
  195. package/dist/esm/lib/utils/queue.js +15 -0
  196. package/dist/esm/lib/utils/queue.js.map +1 -0
  197. package/dist/esm/lib/utils/statistic-utills.d.ts +25 -0
  198. package/dist/esm/lib/utils/statistic-utills.js +62 -0
  199. package/dist/esm/lib/utils/statistic-utills.js.map +1 -0
  200. package/dist/esm/lib/utils/write-queue.js +85 -0
  201. package/dist/esm/lib/utils/write-queue.js.map +1 -0
  202. package/dist/esm/pgm-loader.js +15 -0
  203. package/dist/esm/pgm-loader.js.map +1 -0
  204. package/dist/esm/workers/3d-tiles-attributes-worker.js +8 -0
  205. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -0
  206. package/dist/esm/workers/i3s-attributes-worker.js +7 -0
  207. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -0
  208. package/dist/i3s-attributes-worker.d.ts +45 -0
  209. package/dist/i3s-attributes-worker.d.ts.map +1 -0
  210. package/dist/i3s-attributes-worker.js +9 -0
  211. package/dist/i3s-attributes-worker.js.map +7 -0
  212. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +13 -0
  213. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -0
  214. package/dist/i3s-converter/helpers/batch-ids-extensions.js +141 -0
  215. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +9 -9
  216. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
  217. package/dist/i3s-converter/helpers/coordinate-converter.js +118 -72
  218. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +5 -5
  219. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -1
  220. package/dist/i3s-converter/helpers/create-scene-server-path.js +27 -15
  221. package/dist/i3s-converter/helpers/feature-attributes.d.ts +56 -0
  222. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -0
  223. package/dist/i3s-converter/helpers/feature-attributes.js +216 -0
  224. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +4 -19
  225. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  226. package/dist/i3s-converter/helpers/geometry-attributes.js +188 -185
  227. package/dist/i3s-converter/helpers/geometry-converter.d.ts +36 -39
  228. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  229. package/dist/i3s-converter/helpers/geometry-converter.js +1150 -689
  230. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +9 -0
  231. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -0
  232. package/dist/i3s-converter/helpers/gltf-attributes.js +85 -0
  233. package/dist/i3s-converter/helpers/node-debug.d.ts +7 -1
  234. package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -1
  235. package/dist/i3s-converter/helpers/node-debug.js +106 -72
  236. package/dist/i3s-converter/helpers/node-index-document.d.ts +95 -0
  237. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -0
  238. package/dist/i3s-converter/helpers/node-index-document.js +250 -0
  239. package/dist/i3s-converter/helpers/node-pages.d.ts +81 -41
  240. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  241. package/dist/i3s-converter/helpers/node-pages.js +313 -144
  242. package/dist/i3s-converter/i3s-converter.d.ts +60 -113
  243. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  244. package/dist/i3s-converter/i3s-converter.js +858 -951
  245. package/dist/i3s-converter/json-templates/geometry-definitions.d.ts +7 -0
  246. package/dist/i3s-converter/json-templates/geometry-definitions.d.ts.map +1 -0
  247. package/dist/i3s-converter/json-templates/geometry-definitions.js +87 -0
  248. package/dist/i3s-converter/json-templates/layers.d.ts +5 -30
  249. package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -1
  250. package/dist/i3s-converter/json-templates/layers.js +132 -194
  251. package/dist/i3s-converter/json-templates/metadata.js +24 -21
  252. package/dist/i3s-converter/json-templates/node.js +82 -77
  253. package/dist/i3s-converter/json-templates/scene-server.js +30 -27
  254. package/dist/i3s-converter/json-templates/shared-resources.js +116 -122
  255. package/dist/i3s-converter/json-templates/store.js +100 -95
  256. package/dist/i3s-converter/types.d.ts +137 -6
  257. package/dist/i3s-converter/types.d.ts.map +1 -1
  258. package/dist/i3s-converter/types.js +2 -2
  259. package/dist/i3s-server/app.js +2 -9
  260. package/dist/i3s-server/controllers/index-controller.js +16 -24
  261. package/dist/i3s-server/routes/index.js +11 -15
  262. package/dist/index.d.ts +0 -2
  263. package/dist/index.d.ts.map +1 -1
  264. package/dist/index.js +10 -5
  265. package/dist/lib/utils/compress-util.d.ts +12 -20
  266. package/dist/lib/utils/compress-util.d.ts.map +1 -1
  267. package/dist/lib/utils/compress-util.js +238 -160
  268. package/dist/lib/utils/file-utils.d.ts +22 -14
  269. package/dist/lib/utils/file-utils.d.ts.map +1 -1
  270. package/dist/lib/utils/file-utils.js +133 -36
  271. package/dist/lib/utils/geometry-utils.d.ts +9 -0
  272. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  273. package/dist/lib/utils/geometry-utils.js +18 -0
  274. package/dist/lib/utils/lod-conversion-utils.d.ts +21 -12
  275. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -1
  276. package/dist/lib/utils/lod-conversion-utils.js +72 -39
  277. package/dist/lib/utils/queue.d.ts +7 -0
  278. package/dist/lib/utils/queue.d.ts.map +1 -0
  279. package/dist/lib/utils/queue.js +18 -0
  280. package/dist/lib/utils/statistic-utills.d.ts +3 -25
  281. package/dist/lib/utils/statistic-utills.d.ts.map +1 -1
  282. package/dist/lib/utils/statistic-utills.js +58 -67
  283. package/dist/lib/utils/write-queue.d.ts +39 -0
  284. package/dist/lib/utils/write-queue.d.ts.map +1 -0
  285. package/dist/lib/utils/write-queue.js +80 -0
  286. package/dist/pgm-loader.d.ts.map +1 -1
  287. package/dist/pgm-loader.js +23 -14
  288. package/dist/workers/3d-tiles-attributes-worker.d.ts +2 -0
  289. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +1 -0
  290. package/dist/workers/3d-tiles-attributes-worker.js +9 -0
  291. package/dist/workers/i3s-attributes-worker.d.ts +2 -0
  292. package/dist/workers/i3s-attributes-worker.d.ts.map +1 -0
  293. package/dist/workers/i3s-attributes-worker.js +5 -0
  294. package/package.json +32 -24
  295. package/src/3d-tiles-attributes-worker.ts +43 -0
  296. package/src/3d-tiles-converter/3d-tiles-converter.ts +102 -40
  297. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +39 -44
  298. package/src/constants.ts +2 -0
  299. package/src/converter-cli.ts +370 -0
  300. package/src/deps-installer/deps-installer.ts +71 -0
  301. package/src/i3s-attributes-worker.ts +59 -0
  302. package/src/i3s-converter/helpers/batch-ids-extensions.ts +205 -0
  303. package/src/i3s-converter/helpers/coordinate-converter.ts +33 -26
  304. package/src/i3s-converter/helpers/create-scene-server-path.ts +9 -5
  305. package/src/i3s-converter/helpers/feature-attributes.ts +247 -0
  306. package/src/i3s-converter/helpers/geometry-attributes.ts +98 -47
  307. package/src/i3s-converter/helpers/geometry-converter.ts +1635 -0
  308. package/src/i3s-converter/helpers/gltf-attributes.ts +100 -0
  309. package/src/i3s-converter/helpers/node-debug.ts +68 -16
  310. package/src/i3s-converter/helpers/node-index-document.ts +315 -0
  311. package/src/i3s-converter/helpers/node-pages.ts +222 -101
  312. package/src/i3s-converter/i3s-converter.ts +408 -555
  313. package/src/i3s-converter/json-templates/geometry-definitions.ts +83 -0
  314. package/src/i3s-converter/json-templates/layers.ts +27 -91
  315. package/src/i3s-converter/json-templates/shared-resources.ts +3 -3
  316. package/src/i3s-converter/types.ts +156 -5
  317. package/src/index.ts +0 -4
  318. package/src/lib/utils/{compress-util.js → compress-util.ts} +105 -18
  319. package/src/lib/utils/file-utils.ts +139 -0
  320. package/src/lib/utils/geometry-utils.ts +14 -0
  321. package/src/lib/utils/{lod-conversion-utils.js → lod-conversion-utils.ts} +27 -5
  322. package/src/lib/utils/queue.ts +17 -0
  323. package/src/lib/utils/write-queue.ts +110 -0
  324. package/src/pgm-loader.ts +2 -2
  325. package/src/workers/3d-tiles-attributes-worker.ts +6 -0
  326. package/src/workers/i3s-attributes-worker.ts +7 -0
  327. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
  328. package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
  329. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
  330. package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
  331. package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
  332. package/dist/bundle.js.map +0 -1
  333. package/dist/deps-installer/deps-installer.js.map +0 -1
  334. package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
  335. package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
  336. package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
  337. package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
  338. package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
  339. package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
  340. package/dist/i3s-converter/i3s-converter.js.map +0 -1
  341. package/dist/i3s-converter/json-templates/layers.js.map +0 -1
  342. package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
  343. package/dist/i3s-converter/json-templates/node.js.map +0 -1
  344. package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
  345. package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
  346. package/dist/i3s-converter/json-templates/store.js.map +0 -1
  347. package/dist/i3s-converter/types.js.map +0 -1
  348. package/dist/i3s-server/app.js.map +0 -1
  349. package/dist/i3s-server/controllers/index-controller.js.map +0 -1
  350. package/dist/i3s-server/routes/index.js.map +0 -1
  351. package/dist/index.js.map +0 -1
  352. package/dist/lib/utils/compress-util.js.map +0 -1
  353. package/dist/lib/utils/file-utils.js.map +0 -1
  354. package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
  355. package/dist/lib/utils/statistic-utills.js.map +0 -1
  356. package/dist/pgm-loader.js.map +0 -1
  357. package/src/deps-installer/deps-installer.d.ts +0 -10
  358. package/src/deps-installer/deps-installer.js +0 -22
  359. package/src/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  360. package/src/i3s-converter/helpers/geometry-converter.js +0 -992
  361. package/src/lib/utils/compress-util.d.ts +0 -53
  362. package/src/lib/utils/file-utils.d.ts +0 -43
  363. package/src/lib/utils/file-utils.js +0 -38
  364. package/src/lib/utils/lod-conversion-utils.d.ts +0 -32
  365. /package/dist/{i3s-server → es5/i3s-server}/bin/www +0 -0
  366. /package/dist/{i3s-server → es5/i3s-server}/certs/cert.pem +0 -0
  367. /package/dist/{i3s-server → es5/i3s-server}/certs/key.pem +0 -0
  368. /package/src/lib/utils/{statistic-utills.js → statistic-utills.ts} +0 -0
@@ -1,992 +0,0 @@
1
- import {Vector3, Matrix4, Vector4} from '@math.gl/core';
2
- import {Ellipsoid} from '@math.gl/geospatial';
3
-
4
- import {DracoWriter} from '@loaders.gl/draco';
5
- import {encode, assert} from '@loaders.gl/core';
6
- import {concatenateArrayBuffers, concatenateTypedArrays} from '@loaders.gl/loader-utils';
7
- import md5 from 'md5';
8
- import {generateAttributes} from './geometry-attributes';
9
- import {createBoundingVolumesFromGeometry} from './coordinate-converter';
10
-
11
- const VALUES_PER_VERTEX = 3;
12
- const VALUES_PER_TEX_COORD = 2;
13
- const VALUES_PER_COLOR_ELEMENT = 4;
14
-
15
- const STRING_TYPE = 'string';
16
- const SHORT_INT_TYPE = 'Int32';
17
- const DOUBLE_TYPE = 'Float64';
18
- const OBJECT_ID_TYPE = 'Oid32';
19
- /*
20
- * 'CUSTOM_ATTRIBUTE_2' - Attribute name which includes batch info and used by New York map.
21
- * _BATCHID - Default attribute name which includes batch info.
22
- * BATCHID - Legacy attribute name which includes batch info.
23
- */
24
- const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
25
-
26
- let scratchVector = new Vector3();
27
-
28
- export default async function convertB3dmToI3sGeometry(
29
- tileContent,
30
- nodeId,
31
- featuresHashArray,
32
- attributeStorageInfo,
33
- draco,
34
- generateBoundingVolumes,
35
- geoidHeightModel
36
- ) {
37
- const useCartesianPositions = generateBoundingVolumes;
38
- const materialAndTextureList = convertMaterials(tileContent);
39
- const convertedAttributesMap = convertAttributes(tileContent, useCartesianPositions);
40
-
41
- if (generateBoundingVolumes) {
42
- _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
43
- }
44
-
45
- if (convertedAttributesMap.has('default')) {
46
- materialAndTextureList.push({
47
- material: getDefaultMaterial()
48
- });
49
- }
50
-
51
- const result = [];
52
- let nodesCounter = nodeId;
53
- let {materials = []} = tileContent.gltf;
54
- if (!materials?.length) {
55
- materials.push({id: 'default'});
56
- }
57
- for (let i = 0; i < materials.length; i++) {
58
- const sourceMaterial = materials[i];
59
- if (!convertedAttributesMap.has(sourceMaterial.id)) {
60
- continue; // eslint-disable-line no-continue
61
- }
62
- const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);
63
- const {material, texture} = materialAndTextureList[i];
64
- result.push(
65
- await _makeNodeResources({
66
- convertedAttributes,
67
- material,
68
- texture,
69
- tileContent,
70
- nodeId: nodesCounter,
71
- featuresHashArray,
72
- attributeStorageInfo,
73
- draco
74
- })
75
- );
76
- nodesCounter++;
77
- }
78
-
79
- if (!result.length) {
80
- return null;
81
- }
82
- return result;
83
- }
84
-
85
- /**
86
- * Create bounding volumes based on positions
87
- * @param convertedAttributesMap
88
- * @param geoidHeightModel
89
- */
90
- function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {
91
- for (const attributes of convertedAttributesMap.values()) {
92
- const boundingVolumes = createBoundingVolumesFromGeometry(
93
- attributes.positions,
94
- geoidHeightModel
95
- );
96
-
97
- attributes.boundingVolumes = boundingVolumes;
98
- const cartographicOrigin = boundingVolumes.obb.center;
99
-
100
- for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {
101
- const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);
102
- Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
103
- scratchVector[2] =
104
- scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);
105
- scratchVector = scratchVector.subtract(cartographicOrigin);
106
- attributes.positions.set(scratchVector, index);
107
- }
108
- }
109
- }
110
-
111
- async function _makeNodeResources({
112
- convertedAttributes,
113
- material,
114
- texture,
115
- tileContent,
116
- nodeId,
117
- featuresHashArray,
118
- attributeStorageInfo,
119
- draco
120
- }) {
121
- const boundingVolumes = convertedAttributes.boundingVolumes;
122
- const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
123
- const triangleCount = vertexCount / 3;
124
- const {faceRange, featureIds, positions, normals, colors, texCoords, featureCount} =
125
- generateAttributes({triangleCount, ...convertedAttributes});
126
-
127
- if (tileContent.batchTableJson) {
128
- makeFeatureIdsUnique(
129
- featureIds,
130
- convertedAttributes.featureIndices,
131
- featuresHashArray,
132
- tileContent.batchTableJson
133
- );
134
- }
135
-
136
- const header = new Uint32Array(2);
137
- const typedFeatureIds = generateBigUint64Array(featureIds);
138
-
139
- header.set([vertexCount, featureCount], 0);
140
- const fileBuffer = new Uint8Array(
141
- concatenateArrayBuffers(
142
- header.buffer,
143
- positions.buffer,
144
- normals.buffer,
145
- texture ? texCoords.buffer : new ArrayBuffer(0),
146
- colors.buffer,
147
- typedFeatureIds.buffer,
148
- faceRange.buffer
149
- )
150
- );
151
- const compressedGeometry = draco
152
- ? await generateCompressedGeometry(vertexCount, convertedAttributes, {
153
- positions,
154
- normals,
155
- texCoords: texture ? texCoords : new Float32Array(0),
156
- colors,
157
- featureIds,
158
- faceRange
159
- })
160
- : null;
161
-
162
- const attributes = convertBatchTableToAttributeBuffers(
163
- tileContent.batchTableJson,
164
- featureIds,
165
- attributeStorageInfo
166
- );
167
-
168
- return {
169
- geometry: fileBuffer,
170
- compressedGeometry,
171
- texture,
172
- sharedResources: getSharedResources(tileContent, nodeId),
173
- meshMaterial: material,
174
- vertexCount,
175
- attributes,
176
- featureCount,
177
- boundingVolumes
178
- };
179
- }
180
-
181
- /**
182
- * Convert attributes from the gltf nodes tree to i3s plain geometry
183
- * @param {Object} tileContent - 3d tile content
184
- * @returns {Map}
185
- * Map<{
186
- * positions: Float32Array,
187
- * normals: Float32Array,
188
- * colors: Uint8Array,
189
- * texCoords: Float32Array
190
- * }>
191
- * @todo implement colors support (if applicable for gltf format)
192
- */
193
- function convertAttributes(tileContent, useCartesianPositions) {
194
- const attributesMap = new Map();
195
-
196
- for (const material of tileContent.gltf.materials || [{id: 'default'}]) {
197
- attributesMap.set(material.id, {
198
- positions: new Float32Array(0),
199
- normals: new Float32Array(0),
200
- texCoords: new Float32Array(0),
201
- colors: new Uint8Array(0),
202
- featureIndices: [],
203
- boundingVolumes: null
204
- });
205
- }
206
-
207
- const nodes = (tileContent.gltf.scene || tileContent.gltf.scenes?.[0] || tileContent.gltf).nodes;
208
- convertNodes(nodes, tileContent, attributesMap, useCartesianPositions);
209
-
210
- for (const attrKey of attributesMap.keys()) {
211
- const attributes = attributesMap.get(attrKey);
212
- if (attributes.positions.length === 0) {
213
- attributesMap.delete(attrKey);
214
- continue; // eslint-disable-line no-continue
215
- }
216
- attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));
217
- }
218
-
219
- return attributesMap;
220
- }
221
-
222
- /**
223
- * Gltf has hierarchical structure of nodes. This function converts nodes starting from those which are in gltf scene object.
224
- * The goal is applying tranformation matrix for all children. Functions "convertNodes" and "convertNode" work together recursively.
225
- * @param {Object[]} nodes - gltf nodes array
226
- * @param {Object} tileContent - 3d tile content
227
- * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: UInt8Array, featureIndices: Array}> - for recursive concatenation of
228
- * attributes
229
- * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices
230
- * @returns {void}
231
- */
232
- function convertNodes(
233
- nodes,
234
- tileContent,
235
- attributesMap,
236
- useCartesianPositions,
237
- matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])
238
- ) {
239
- if (nodes) {
240
- for (const node of nodes) {
241
- convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix);
242
- }
243
- }
244
- }
245
-
246
- /**
247
- * Generate transformation matrix for node
248
- * Aapply all gltf transformations to initial transformation matrix.
249
- * @param node
250
- * @param matrix
251
- */
252
- function getCompositeTransformationMatrix(node, matrix) {
253
- let transformationMatrix = matrix;
254
-
255
- const {matrix: nodeMatrix, rotation, scale, translation} = node;
256
-
257
- if (nodeMatrix) {
258
- transformationMatrix = matrix.multiplyRight(nodeMatrix);
259
- }
260
-
261
- if (rotation) {
262
- transformationMatrix = transformationMatrix.rotateXYZ(rotation);
263
- }
264
-
265
- if (scale) {
266
- transformationMatrix = transformationMatrix.scale(scale);
267
- }
268
-
269
- if (translation) {
270
- transformationMatrix = transformationMatrix.translate(translation);
271
- }
272
-
273
- return transformationMatrix;
274
- }
275
-
276
- /**
277
- * Convert all primitives of node and all children nodes
278
- * @param {Object} node - gltf node
279
- * @param {Object} tileContent - 3d tile content
280
- * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of
281
- * attributes
282
- * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices
283
- * @todo: optimize arrays concatenation
284
- */
285
- function convertNode(
286
- node,
287
- tileContent,
288
- attributesMap,
289
- useCartesianPositions,
290
- matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])
291
- ) {
292
- const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
293
-
294
- const mesh = node.mesh;
295
- if (mesh) {
296
- convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, transformationMatrix);
297
- }
298
-
299
- convertNodes(
300
- node.children,
301
- tileContent,
302
- attributesMap,
303
- useCartesianPositions,
304
- transformationMatrix
305
- );
306
- }
307
-
308
- /**
309
- * Convert all primitives of node and all children nodes
310
- * @param {Object} mesh - gltf node
311
- * @param {Object} content - 3d tile content
312
- * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of
313
- * attributes
314
- * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices
315
- * @todo: optimize arrays concatenation
316
- */
317
- function convertMesh(
318
- mesh,
319
- content,
320
- attributesMap,
321
- useCartesianPositions = false,
322
- matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])
323
- ) {
324
- for (const primitive of mesh.primitives) {
325
- let outputAttributes = null;
326
- if (primitive.material) {
327
- outputAttributes = attributesMap.get(primitive.material.id);
328
- } else if (attributesMap.has('default')) {
329
- outputAttributes = attributesMap.get('default');
330
- }
331
- assert(outputAttributes !== null, 'Primitive - material mapping failed');
332
- const attributes = primitive.attributes;
333
-
334
- outputAttributes.positions = concatenateTypedArrays(
335
- outputAttributes.positions,
336
- transformVertexArray({
337
- vertices: attributes.POSITION.value,
338
- cartographicOrigin: content.cartographicOrigin,
339
- cartesianModelMatrix: content.cartesianModelMatrix,
340
- nodeMatrix: matrix,
341
- indices: primitive.indices.value,
342
- attributeSpecificTransformation: transformVertexPositions,
343
- useCartesianPositions
344
- })
345
- );
346
- outputAttributes.normals = concatenateTypedArrays(
347
- outputAttributes.normals,
348
- transformVertexArray({
349
- vertices: attributes.NORMAL && attributes.NORMAL.value,
350
- cartographicOrigin: content.cartographicOrigin,
351
- cartesianModelMatrix: content.cartesianModelMatrix,
352
- nodeMatrix: matrix,
353
- indices: primitive.indices.value,
354
- attributeSpecificTransformation: transformVertexNormals,
355
- useCartesianPositions: false
356
- })
357
- );
358
- outputAttributes.texCoords = concatenateTypedArrays(
359
- outputAttributes.texCoords,
360
- flattenTexCoords(
361
- attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value,
362
- primitive.indices.value
363
- )
364
- );
365
-
366
- outputAttributes.colors = concatenateTypedArrays(
367
- outputAttributes.colors,
368
- flattenColors(attributes.COLOR_0, primitive.indices.value)
369
- );
370
-
371
- outputAttributes.featureIndices.push(
372
- flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value)
373
- );
374
- }
375
- }
376
-
377
- /**
378
- * Convert vertices attributes (POSITIONS or NORMALS) to i3s compatible format
379
- * @param {object} args - source tile (3DTile)
380
- * @param {Float32Array} args.vertices - gltf primitive POSITION or NORMAL attribute
381
- * @param {Object} args.cartographicOrigin - cartographic origin coordinates
382
- * @param {Object} args.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format
383
- * @param {Matrix4} args.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices
384
- * @param {Uint8Array} args.indices - gltf primitive indices
385
- * @param {Function} args.attributeSpecificTransformation - function to do attribute - specific transformations
386
- * @param {Boolean} args.useCartesianPositions - use coordinates as it is.
387
- * @returns {Float32Array}
388
- */
389
- function transformVertexArray(args) {
390
- const {vertices, indices, attributeSpecificTransformation} = args;
391
- const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
392
- if (!vertices) {
393
- return newVertices;
394
- }
395
- for (let i = 0; i < indices.length; i++) {
396
- const coordIndex = indices[i] * VALUES_PER_VERTEX;
397
- const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
398
- let vertexVector = new Vector3(Array.from(vertex));
399
-
400
- vertexVector = attributeSpecificTransformation(vertexVector, args);
401
-
402
- newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;
403
- newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;
404
- newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;
405
- }
406
- return newVertices;
407
- }
408
-
409
- function transformVertexPositions(vertexVector, calleeArgs) {
410
- const {cartesianModelMatrix, cartographicOrigin, nodeMatrix, useCartesianPositions} = calleeArgs;
411
-
412
- if (nodeMatrix) {
413
- vertexVector = vertexVector.transform(nodeMatrix);
414
- }
415
-
416
- vertexVector = vertexVector.transform(cartesianModelMatrix);
417
-
418
- if (useCartesianPositions) {
419
- return vertexVector;
420
- }
421
-
422
- Ellipsoid.WGS84.cartesianToCartographic(
423
- [vertexVector[0], vertexVector[1], vertexVector[2]],
424
- vertexVector
425
- );
426
- vertexVector = vertexVector.subtract(cartographicOrigin);
427
- return vertexVector;
428
- }
429
-
430
- function transformVertexNormals(vertexVector, calleeArgs) {
431
- const {cartesianModelMatrix, nodeMatrix} = calleeArgs;
432
-
433
- if (nodeMatrix) {
434
- vertexVector = vertexVector.transformAsVector(nodeMatrix);
435
- }
436
-
437
- vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);
438
- return vertexVector;
439
- }
440
-
441
- /**
442
- * Convert uv0 (texture coordinates) from coords based on indices to plain arrays, compatible with i3s
443
- * @param {Float32Array} texCoords - gltf primitive TEXCOORD_0 attribute
444
- * @param {Uint8Array} indices - gltf primitive indices
445
- * @returns {Float32Array}
446
- */
447
- function flattenTexCoords(texCoords, indices) {
448
- const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
449
- if (!texCoords) {
450
- // We need dummy UV0s because it is required in 1.6
451
- // https://github.com/Esri/i3s-spec/blob/master/docs/1.6/vertexAttribute.cmn.md
452
- newTexCoords.fill(1);
453
- return newTexCoords;
454
- }
455
- for (let i = 0; i < indices.length; i++) {
456
- const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
457
- const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
458
- newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];
459
- newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];
460
- }
461
- return newTexCoords;
462
- }
463
-
464
- /**
465
- * Convert color from COLOR_0 based on indices to plain arrays, compatible with i3s
466
- * @param {object} colorsAttribute - gltf primitive COLOR_0 attribute
467
- * @param {Uint8Array} indices - gltf primitive indices
468
- * @returns {Uint8Array}
469
- */
470
- function flattenColors(colorsAttribute, indices) {
471
- const components = colorsAttribute?.components || VALUES_PER_COLOR_ELEMENT;
472
- const newColors = new Uint8Array(indices.length * components);
473
- if (!colorsAttribute) {
474
- // Vertex color multiplies by material color so it must be normalized 1 by default
475
- newColors.fill(255);
476
- return newColors;
477
- }
478
- const colors = colorsAttribute.value;
479
- for (let i = 0; i < indices.length; i++) {
480
- const colorIndex = indices[i] * components;
481
- const color = colors.subarray(colorIndex, colorIndex + components);
482
- const colorUint8 = new Uint8Array(components);
483
- for (let j = 0; j < color.length; j++) {
484
- colorUint8[j] = color[j] * 255;
485
- }
486
- newColors.set(colorUint8, i * components);
487
- }
488
- return newColors;
489
- }
490
-
491
- /**
492
- * Flatten batchedIds list based on indices to right ordered array, compatible with i3s
493
- * @param {Array} batchedIds - gltf primitive
494
- * @param {Uint8Array} indices - gltf primitive indices
495
- * @returns {Array}
496
- */
497
- function flattenBatchIds(batchedIds, indices) {
498
- if (!batchedIds.length || !indices.length) {
499
- return [];
500
- }
501
- const newBatchIds = [];
502
- for (let i = 0; i < indices.length; i++) {
503
- const coordIndex = indices[i];
504
- newBatchIds.push(batchedIds[coordIndex]);
505
- }
506
- return newBatchIds;
507
- }
508
- /**
509
- * Return batchIds based on possible attribute names for different kind of maps.
510
- * @param {Object} attributes {attributeName: Float32Array}
511
- * @returns {Array}
512
- */
513
- function getBatchIdsByAttributeName(attributes) {
514
- let batchIds = [];
515
-
516
- for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
517
- const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
518
- if (
519
- attributes[possibleBatchIdAttributeName] &&
520
- attributes[possibleBatchIdAttributeName].value
521
- ) {
522
- batchIds = attributes[possibleBatchIdAttributeName].value;
523
- break;
524
- }
525
- }
526
-
527
- return batchIds;
528
- }
529
-
530
- function convertMaterials(tileContent) {
531
- const result = [];
532
- const sourceMaterials = tileContent.gltf.materials || [];
533
- for (const sourceMaterial of sourceMaterials) {
534
- result.push(convertMaterial(sourceMaterial));
535
- }
536
- return result;
537
- }
538
-
539
- /**
540
- * Convert texture and material from gltf 2.0 material object
541
- * @param {Object} sourceMaterial - material object
542
- * @returns {Object}
543
- */
544
- function convertMaterial(sourceMaterial) {
545
- const material = {
546
- doubleSided: sourceMaterial.doubleSided,
547
- emissiveFactor: sourceMaterial.emissiveFactor.map((c) => Math.round(c * 255)),
548
- // It is in upper case in GLTF: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#alpha-coverage
549
- // But it is in lower case in I3S: https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
550
- alphaMode: (sourceMaterial.alphaMode || 'OPAQUE').toLowerCase(),
551
- pbrMetallicRoughness: {
552
- roughnessFactor: sourceMaterial.pbrMetallicRoughness.roughnessFactor,
553
- metallicFactor: sourceMaterial.pbrMetallicRoughness.metallicFactor
554
- }
555
- };
556
-
557
- let texture;
558
- if (sourceMaterial.pbrMetallicRoughness.baseColorTexture) {
559
- texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
560
- material.pbrMetallicRoughness.baseColorTexture = {
561
- textureSetDefinitionId: 0
562
- };
563
- } else if (sourceMaterial.emissiveTexture) {
564
- texture = sourceMaterial.emissiveTexture.texture.source;
565
- // ArcGIS webscene doesn't show emissiveTexture but shows baseColorTexture
566
- material.pbrMetallicRoughness.baseColorTexture = {
567
- textureSetDefinitionId: 0
568
- };
569
- }
570
-
571
- if (!texture) {
572
- // Should use default baseColorFactor if it is not present in source material
573
- // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-pbrmetallicroughness
574
- const baseColorFactor = sourceMaterial.pbrMetallicRoughness.baseColorFactor;
575
- material.pbrMetallicRoughness.baseColorFactor =
576
- (baseColorFactor && baseColorFactor.map((c) => Math.round(c * 255))) || undefined;
577
- }
578
-
579
- return {material, texture};
580
- }
581
-
582
- function getDefaultMaterial() {
583
- return {
584
- alphaMode: 'opaque',
585
- pbrMetallicRoughness: {}
586
- };
587
- }
588
-
589
- /**
590
- * Form "sharedResources" from gltf materials array
591
- * @param {Object} tileContent - 3d tile content
592
- * @returns {Object} {materialDefinitionInfos: Object[], textureDefinitionInfos: Object[]} -
593
- * 2 arrays in format of i3s sharedResources data https://github.com/Esri/i3s-spec/blob/master/docs/1.7/sharedResource.cmn.md
594
- */
595
- function getSharedResources(tileContent, nodeId) {
596
- const gltfMaterials = tileContent.gltf.materials;
597
- const i3sResources = {};
598
-
599
- if (!gltfMaterials || !gltfMaterials.length) {
600
- return i3sResources;
601
- }
602
-
603
- i3sResources.materialDefinitionInfos = [];
604
- for (const gltfMaterial of gltfMaterials) {
605
- const {materialDefinitionInfo, textureDefinitionInfo} = convertGLTFMaterialToI3sSharedResources(
606
- gltfMaterial,
607
- nodeId
608
- );
609
- i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
610
- if (textureDefinitionInfo) {
611
- i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
612
- i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
613
- }
614
- }
615
- return i3sResources;
616
- }
617
-
618
- /**
619
- * Convert gltf material into I3S sharedResources data
620
- * @param {Object} gltfMaterial - gltf material data
621
- * @returns {Object} - Couple {materialDefinitionInfo, textureDefinitionInfo} extracted from gltf material data
622
- */
623
- function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
624
- const texture =
625
- gltfMaterial.pbrMetallicRoughness.baseColorTexture || gltfMaterial.emissiveTexture;
626
- let textureDefinitionInfo = null;
627
- if (texture) {
628
- textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
629
- }
630
- const {baseColorFactor, metallicFactor} = gltfMaterial.pbrMetallicRoughness;
631
- let colorFactor = baseColorFactor;
632
- // If alpha channel is 0 try to get emissive factor from gltf material.
633
- if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
634
- colorFactor = gltfMaterial.emissiveFactor;
635
- colorFactor[3] = colorFactor[3] || 1;
636
- }
637
-
638
- return {
639
- materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor, metallicFactor),
640
- textureDefinitionInfo
641
- };
642
- }
643
-
644
- /**
645
- * Form "materialDefinition" which is part of "sharedResouces"
646
- * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materials
647
- * See formulas in appendix "Appendix B: BRDF Implementation":
648
- * const dielectricSpecular = rgb(0.04, 0.04, 0.04)
649
- * const black = rgb(0, 0, 0)
650
- * cdiff = lerp(baseColor.rgb * (1 - dielectricSpecular.r), black, metallic)
651
- * F0 = lerp(dieletricSpecular, baseColor.rgb, metallic)
652
- *
653
- * Assumption: F0 - specular in i3s ("specular reflection" <-> "reflectance value at normal incidence")
654
- * cdiff - diffuse in i3s ("Diffuse color" <-> "'c' diffuse" (c means color?))
655
- * @param {number[]} baseColorFactor - RGBA color in 0..1 format
656
- * @param {number} metallicFactor - "metallicFactor" attribute of gltf material object
657
- * @returns {Object}
658
- */
659
- function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 0) {
660
- const matDielectricColorComponent = 0.04 / 255; // Color from rgb (255) to 0..1 resolution
661
- // All color resolutions are 0..1
662
- const black = new Vector4(0, 0, 0, 1);
663
- const unitVector = new Vector4(1, 1, 1, 1);
664
- const dielectricSpecular = new Vector4(
665
- matDielectricColorComponent,
666
- matDielectricColorComponent,
667
- matDielectricColorComponent,
668
- 0
669
- );
670
- const baseColorVector = new Vector4(baseColorFactor);
671
- // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
672
- // Formulas for Cdiff & F0
673
- const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);
674
- const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);
675
- dielectricSpecular[3] = 1;
676
- const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
677
- return {
678
- diffuse: diffuse.toArray(),
679
- specular: specular.toArray()
680
- };
681
- }
682
-
683
- /**
684
- * Form "textureDefinition" which is part of "sharedResouces"
685
- * @param {Object} texture - texture image info
686
- * @returns {Object}
687
- */
688
- function extractSharedResourcesTextureInfo(texture, nodeId) {
689
- return {
690
- encoding: [texture.source.mimeType],
691
- images: [
692
- {
693
- // 'i3s' has just size which is width of the image. Images are supposed to be square.
694
- // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/image.cmn.md
695
- id: generateImageId(texture, nodeId),
696
- size: texture.source.image.width,
697
- length: [texture.source.image.data.length]
698
- }
699
- ]
700
- };
701
- }
702
- /*
703
- * Formula for counting imageId:
704
- * https://github.com/Esri/i3s-spec/blob/0a6366a9249b831db8436c322f8d27521e86cf07/format/Indexed%203d%20Scene%20Layer%20Format%20Specification.md#generating-image-ids
705
- * @param {Object} texture - texture image info
706
- * @returns {string}
707
- */
708
- function generateImageId(texture, nodeId) {
709
- const {width, height} = texture.source.image;
710
- const levelCountOfTexture = 1;
711
- const indexOfLevel = 0;
712
- const indexOfTextureInStore = nodeId + 1;
713
-
714
- const zerosCount = 32 - indexOfTextureInStore.toString(2).length;
715
- const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));
716
-
717
- const shiftedLevelCountOfTexture = levelCountOfTexture << 28;
718
- const shiftedIndexOfLevel = indexOfLevel << 24;
719
- const shiftedWidth = (width - 1) << 12;
720
- const shiftedHeight = (height - 1) << 0;
721
-
722
- const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;
723
- const imageId = BigInt(`0b${leftHalf.toString(2)}${rightHalf}`);
724
- return imageId.toString();
725
- }
726
-
727
- /**
728
- * Make all feature ids unique through all nodes in layout.
729
- * @param {Array} featureIds
730
- * @param {Array} featureIndices
731
- * @param {Array} featuresHashArray
732
- * @param {Object} batchTable
733
- * @returns {void}
734
- */
735
- function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {
736
- const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);
737
- replaceIndicesByUnique(featureIndices, replaceMap);
738
- replaceIndicesByUnique(featureIds, replaceMap);
739
- }
740
-
741
- /**
742
- * Generate replace map to make featureIds unique.
743
- * @param {Array} featureIds
744
- * @param {Object} batchTable
745
- * @param {Array} featuresHashArray
746
- * @returns {Object}
747
- */
748
- function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
749
- const featureMap = {};
750
-
751
- for (let index = 0; index < featureIds.length; index++) {
752
- const oldFeatureId = featureIds[index];
753
- const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
754
- featureMap[oldFeatureId.toString()] = uniqueFeatureId;
755
- }
756
-
757
- return featureMap;
758
- }
759
-
760
- /**
761
- * Generates string for unique batch id creation.
762
- * @param {Object} batchTable
763
- * @param {Number} index
764
- * @returns {String}
765
- */
766
- function generateStringFromBatchTableByIndex(batchTable, index) {
767
- let str = '';
768
- for (const key in batchTable) {
769
- str += batchTable[key][index];
770
- }
771
- return str;
772
- }
773
-
774
- /**
775
- * Return already exited featureId or creates and returns new to support unique feature ids throw nodes.
776
- * @param {Number} index
777
- * @param {Object} batchTable
778
- * @param {Array} featuresHashArray
779
- * @returns {Number}
780
- */
781
- function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
782
- const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
783
- const hash = md5(batchTableStr);
784
-
785
- if (featuresHashArray.includes(hash)) {
786
- return featuresHashArray.indexOf(hash);
787
- }
788
- return featuresHashArray.push(hash) - 1;
789
- }
790
-
791
- /**
792
- * Do replacement of indices for making them unique through all nodes.
793
- * @param {Array} indicesArray
794
- * @param {Object} featureMap
795
- * @returns {void}
796
- */
797
- function replaceIndicesByUnique(indicesArray, featureMap) {
798
- for (let index = 0; index < indicesArray.length; index++) {
799
- indicesArray[index] = featureMap[indicesArray[index]];
800
- }
801
- }
802
-
803
- /**
804
- * Convert batch table data to attribute buffers.
805
- * @param {Object} batchTable - table with metadata for particular feature.
806
- * @param {Array} featureIds
807
- * @param {Array} attributeStorageInfo
808
- * @returns {Array} - Array of file buffers.
809
- */
810
- function convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeStorageInfo) {
811
- const attributeBuffers = [];
812
-
813
- if (batchTable) {
814
- const batchTableWithFeatureIds = {
815
- OBJECTID: featureIds,
816
- ...batchTable
817
- };
818
-
819
- for (const key in batchTableWithFeatureIds) {
820
- const type = getAttributeType(key, attributeStorageInfo);
821
-
822
- let attributeBuffer = null;
823
-
824
- switch (type) {
825
- case OBJECT_ID_TYPE:
826
- case SHORT_INT_TYPE:
827
- attributeBuffer = generateShortIntegerAttributeBuffer(batchTableWithFeatureIds[key]);
828
- break;
829
- case DOUBLE_TYPE:
830
- attributeBuffer = generateDoubleAttributeBuffer(batchTableWithFeatureIds[key]);
831
- break;
832
- case STRING_TYPE:
833
- attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
834
- break;
835
- default:
836
- attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
837
- }
838
-
839
- attributeBuffers.push(attributeBuffer);
840
- }
841
- }
842
-
843
- return attributeBuffers;
844
- }
845
- /**
846
- * Return attribute type.
847
- * @param {String} key
848
- * @param {Array} attributeStorageInfo
849
- * @returns {String} attribute type.
850
- */
851
- function getAttributeType(key, attributeStorageInfo) {
852
- const attribute = attributeStorageInfo.find((attr) => attr.name === key);
853
- return attribute.attributeValues.valueType;
854
- }
855
-
856
- /**
857
- * Convert short integer to attribute arrayBuffer.
858
- * @param {Array} featureIds
859
- * @returns {ArrayBuffer} - Buffer with objectId data.
860
- */
861
- function generateShortIntegerAttributeBuffer(featureIds) {
862
- const count = new Uint32Array([featureIds.length]);
863
- const valuesArray = new Uint32Array(featureIds);
864
- return concatenateArrayBuffers(count.buffer, valuesArray.buffer);
865
- }
866
-
867
- /**
868
- * Convert double to attribute arrayBuffer.
869
- * @param {Array} featureIds
870
- * @returns {ArrayBuffer} - Buffer with objectId data.
871
- */
872
- function generateDoubleAttributeBuffer(featureIds) {
873
- const count = new Uint32Array([featureIds.length]);
874
- const padding = new Uint8Array(4);
875
- const valuesArray = new Float64Array(featureIds);
876
-
877
- return concatenateArrayBuffers(count.buffer, padding.buffer, valuesArray.buffer);
878
- }
879
-
880
- /**
881
- * Convert batch table attributes to array buffer with batch table data.
882
- * @param {Array} batchAttributes
883
- * @returns {ArrayBuffer} - Buffer with batch table data.
884
- */
885
- function generateStringAttributeBuffer(batchAttributes) {
886
- const stringCountArray = new Uint32Array([batchAttributes.length]);
887
- let totalNumberOfBytes = 0;
888
- const stringSizesArray = new Uint32Array(batchAttributes.length);
889
- const stringBufferArray = [];
890
-
891
- for (let index = 0; index < batchAttributes.length; index++) {
892
- const currentString = `${String(batchAttributes[index])}\0`;
893
- const currentStringBuffer = Buffer.from(currentString);
894
- const currentStringSize = currentStringBuffer.length;
895
- totalNumberOfBytes += currentStringSize;
896
- stringSizesArray[index] = currentStringSize;
897
- stringBufferArray.push(currentStringBuffer);
898
- }
899
-
900
- const totalBytes = new Uint32Array([totalNumberOfBytes]);
901
-
902
- return concatenateArrayBuffers(
903
- stringCountArray.buffer,
904
- totalBytes.buffer,
905
- stringSizesArray.buffer,
906
- ...stringBufferArray
907
- );
908
- }
909
-
910
- /**
911
- * Convert featureIds to BigUint64Array.
912
- * @param {Array} featureIds
913
- * @returns {BigUint64Array} - Array of feature ids in BigUint64 format.
914
- */
915
- function generateBigUint64Array(featureIds) {
916
- const typedFeatureIds = new BigUint64Array(featureIds.length);
917
- for (let index = 0; index < featureIds.length; index++) {
918
- typedFeatureIds[index] = BigInt(featureIds[index]);
919
- }
920
- return typedFeatureIds;
921
- }
922
-
923
- /**
924
- * Generates draco compressed geometry
925
- * @param {Number} vertexCount
926
- * @param {Object} convertedAttributes
927
- * @returns {Promise<object>} - COmpressed geometry.
928
- */
929
- async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes) {
930
- const {positions, normals, texCoords, colors, featureIds, faceRange} = attributes;
931
- const indices = new Uint32Array(vertexCount);
932
-
933
- for (let index = 0; index < indices.length; index++) {
934
- indices.set([index], index);
935
- }
936
-
937
- const featureIndices = new Uint32Array(
938
- convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount
939
- );
940
-
941
- const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
942
-
943
- const compressedAttributes = {
944
- positions,
945
- normals,
946
- colors,
947
- 'feature-index': featureIndex
948
- };
949
-
950
- if (texCoords.length) {
951
- compressedAttributes.texCoords = texCoords;
952
- }
953
-
954
- const attributesMetadata = {
955
- 'feature-index': {
956
- 'i3s-attribute-type': 'feature-index',
957
- 'i3s-feature-ids': new Int32Array(featureIds)
958
- }
959
- };
960
-
961
- return new Uint8Array(
962
- await encode({attributes: compressedAttributes, indices}, DracoWriter, {
963
- draco: {
964
- method: 'MESH_SEQUENTIAL_ENCODING',
965
- attributesMetadata
966
- }
967
- })
968
- );
969
- }
970
-
971
- /**
972
- * Generates ordered feature indices based on face range
973
- * @param {Uint32Array} featureIndex
974
- * @param {Uint32Array} faceRange
975
- * @returns {Uint32Array}
976
- */
977
- function generateFeatureIndexAttribute(featureIndex, faceRange) {
978
- const orderedFeatureIndices = new Uint32Array(featureIndex.length);
979
- let fillIndex = 0;
980
- let startIndex = 0;
981
-
982
- for (let index = 1; index < faceRange.length; index += 2) {
983
- const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
984
-
985
- orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);
986
-
987
- fillIndex++;
988
- startIndex = endIndex + 1;
989
- }
990
-
991
- return orderedFeatureIndices;
992
- }