@loaders.gl/3d-tiles 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 (393) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/cesium-ion-loader.d.ts +6 -0
  5. package/dist/cesium-ion-loader.d.ts.map +1 -0
  6. package/dist/cesium-ion-loader.js +37 -32
  7. package/dist/dist.min.js +14805 -0
  8. package/dist/es5/bundle.js +6 -0
  9. package/dist/es5/bundle.js.map +1 -0
  10. package/dist/es5/cesium-ion-loader.js +77 -0
  11. package/dist/es5/cesium-ion-loader.js.map +1 -0
  12. package/dist/es5/index.js +63 -0
  13. package/dist/es5/index.js.map +1 -0
  14. package/dist/es5/lib/classes/helpers/tile-3d-accessor-utils.js +114 -0
  15. package/dist/es5/lib/classes/helpers/tile-3d-accessor-utils.js.map +1 -0
  16. package/dist/es5/lib/classes/tile-3d-batch-table-hierarchy.js +180 -0
  17. package/dist/es5/lib/classes/tile-3d-batch-table-hierarchy.js.map +1 -0
  18. package/dist/es5/lib/classes/tile-3d-batch-table.js +285 -0
  19. package/dist/es5/lib/classes/tile-3d-batch-table.js.map +1 -0
  20. package/dist/es5/lib/classes/tile-3d-feature-table.js +97 -0
  21. package/dist/es5/lib/classes/tile-3d-feature-table.js.map +1 -0
  22. package/dist/es5/lib/constants.js +32 -0
  23. package/dist/es5/lib/constants.js.map +1 -0
  24. package/dist/es5/lib/encoders/encode-3d-tile-batched-model.js +49 -0
  25. package/dist/es5/lib/encoders/encode-3d-tile-batched-model.js.map +1 -0
  26. package/dist/es5/lib/encoders/encode-3d-tile-composite.js +30 -0
  27. package/dist/es5/lib/encoders/encode-3d-tile-composite.js.map +1 -0
  28. package/dist/es5/lib/encoders/encode-3d-tile-instanced-model.js +47 -0
  29. package/dist/es5/lib/encoders/encode-3d-tile-instanced-model.js.map +1 -0
  30. package/dist/es5/lib/encoders/encode-3d-tile-point-cloud.js +48 -0
  31. package/dist/es5/lib/encoders/encode-3d-tile-point-cloud.js.map +1 -0
  32. package/dist/es5/lib/encoders/encode-3d-tile.js +35 -0
  33. package/dist/es5/lib/encoders/encode-3d-tile.js.map +1 -0
  34. package/dist/es5/lib/encoders/helpers/encode-3d-tile-header.js +35 -0
  35. package/dist/es5/lib/encoders/helpers/encode-3d-tile-header.js.map +1 -0
  36. package/dist/es5/lib/ion/ion.js +170 -0
  37. package/dist/es5/lib/ion/ion.js.map +1 -0
  38. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-colors.js +65 -0
  39. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-colors.js.map +1 -0
  40. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-normals.js +32 -0
  41. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-normals.js.map +1 -0
  42. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-positions.js +32 -0
  43. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-positions.js.map +1 -0
  44. package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js +280 -0
  45. package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -0
  46. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js +110 -0
  47. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -0
  48. package/dist/es5/lib/parsers/helpers/parse-3d-tile-header.js +22 -0
  49. package/dist/es5/lib/parsers/helpers/parse-3d-tile-header.js.map +1 -0
  50. package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js +145 -0
  51. package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -0
  52. package/dist/es5/lib/parsers/helpers/parse-3d-tile-tables.js +85 -0
  53. package/dist/es5/lib/parsers/helpers/parse-3d-tile-tables.js.map +1 -0
  54. package/dist/es5/lib/parsers/helpers/parse-utils.js +28 -0
  55. package/dist/es5/lib/parsers/helpers/parse-utils.js.map +1 -0
  56. package/dist/es5/lib/parsers/parse-3d-tile-batched-model.js +51 -0
  57. package/dist/es5/lib/parsers/parse-3d-tile-batched-model.js.map +1 -0
  58. package/dist/es5/lib/parsers/parse-3d-tile-composite.js +48 -0
  59. package/dist/es5/lib/parsers/parse-3d-tile-composite.js.map +1 -0
  60. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js +52 -0
  61. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js.map +1 -0
  62. package/dist/es5/lib/parsers/parse-3d-tile-header.js +289 -0
  63. package/dist/es5/lib/parsers/parse-3d-tile-header.js.map +1 -0
  64. package/dist/es5/lib/parsers/parse-3d-tile-instanced-model.js +163 -0
  65. package/dist/es5/lib/parsers/parse-3d-tile-instanced-model.js.map +1 -0
  66. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js +295 -0
  67. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -0
  68. package/dist/es5/lib/parsers/parse-3d-tile.js +74 -0
  69. package/dist/es5/lib/parsers/parse-3d-tile.js.map +1 -0
  70. package/dist/es5/lib/utils/obb/s2-corners-to-obb.js +30 -0
  71. package/dist/es5/lib/utils/obb/s2-corners-to-obb.js.map +1 -0
  72. package/dist/es5/lib/utils/s2/converters/s2-to-boundary.js +44 -0
  73. package/dist/es5/lib/utils/s2/converters/s2-to-boundary.js.map +1 -0
  74. package/dist/es5/lib/utils/s2/converters/s2-to-obb-points.js +30 -0
  75. package/dist/es5/lib/utils/s2/converters/s2-to-obb-points.js.map +1 -0
  76. package/dist/es5/lib/utils/s2/converters/s2-to-region.js +52 -0
  77. package/dist/es5/lib/utils/s2/converters/s2-to-region.js.map +1 -0
  78. package/dist/es5/lib/utils/s2/index.js +90 -0
  79. package/dist/es5/lib/utils/s2/index.js.map +1 -0
  80. package/dist/es5/lib/utils/s2/s2-geometry-functions.js +19 -0
  81. package/dist/es5/lib/utils/s2/s2-geometry-functions.js.map +1 -0
  82. package/dist/es5/lib/utils/s2/s2-token-functions.js +41 -0
  83. package/dist/es5/lib/utils/s2/s2-token-functions.js.map +1 -0
  84. package/dist/es5/lib/utils/s2/s2geometry/s2-cell-utils.js +22 -0
  85. package/dist/es5/lib/utils/s2/s2geometry/s2-cell-utils.js.map +1 -0
  86. package/dist/es5/lib/utils/s2/s2geometry/s2-geometry.js +207 -0
  87. package/dist/es5/lib/utils/s2/s2geometry/s2-geometry.js.map +1 -0
  88. package/dist/es5/lib/utils/version.js +9 -0
  89. package/dist/es5/lib/utils/version.js.map +1 -0
  90. package/dist/es5/tile-3d-subtree-loader.js +22 -0
  91. package/dist/es5/tile-3d-subtree-loader.js.map +1 -0
  92. package/dist/es5/tile-3d-writer.js +26 -0
  93. package/dist/es5/tile-3d-writer.js.map +1 -0
  94. package/dist/es5/tiles-3d-loader.js +133 -0
  95. package/dist/es5/tiles-3d-loader.js.map +1 -0
  96. package/dist/es5/types.js +2 -0
  97. package/dist/es5/types.js.map +1 -0
  98. package/dist/esm/bundle.js +4 -0
  99. package/dist/esm/bundle.js.map +1 -0
  100. package/dist/esm/cesium-ion-loader.js +36 -0
  101. package/dist/esm/cesium-ion-loader.js.map +1 -0
  102. package/dist/esm/index.js +9 -0
  103. package/dist/esm/index.js.map +1 -0
  104. package/dist/esm/lib/classes/helpers/tile-3d-accessor-utils.js +96 -0
  105. package/dist/esm/lib/classes/helpers/tile-3d-accessor-utils.js.map +1 -0
  106. package/dist/esm/lib/classes/tile-3d-batch-table-hierarchy.js +171 -0
  107. package/dist/esm/lib/classes/tile-3d-batch-table-hierarchy.js.map +1 -0
  108. package/dist/esm/lib/classes/tile-3d-batch-table.js +231 -0
  109. package/dist/esm/lib/classes/tile-3d-batch-table.js.map +1 -0
  110. package/dist/esm/lib/classes/tile-3d-feature-table.js +70 -0
  111. package/dist/esm/lib/classes/tile-3d-feature-table.js.map +1 -0
  112. package/dist/esm/lib/constants.js +22 -0
  113. package/dist/esm/lib/constants.js.map +1 -0
  114. package/dist/esm/lib/encoders/encode-3d-tile-batched-model.js +40 -0
  115. package/dist/esm/lib/encoders/encode-3d-tile-batched-model.js.map +1 -0
  116. package/dist/esm/lib/encoders/encode-3d-tile-composite.js +21 -0
  117. package/dist/esm/lib/encoders/encode-3d-tile-composite.js.map +1 -0
  118. package/dist/esm/lib/encoders/encode-3d-tile-instanced-model.js +36 -0
  119. package/dist/esm/lib/encoders/encode-3d-tile-instanced-model.js.map +1 -0
  120. package/dist/esm/lib/encoders/encode-3d-tile-point-cloud.js +39 -0
  121. package/dist/esm/lib/encoders/encode-3d-tile-point-cloud.js.map +1 -0
  122. package/dist/esm/lib/encoders/encode-3d-tile.js +29 -0
  123. package/dist/esm/lib/encoders/encode-3d-tile.js.map +1 -0
  124. package/dist/esm/lib/encoders/helpers/encode-3d-tile-header.js +28 -0
  125. package/dist/esm/lib/encoders/helpers/encode-3d-tile-header.js.map +1 -0
  126. package/dist/esm/lib/ion/ion.js +70 -0
  127. package/dist/esm/lib/ion/ion.js.map +1 -0
  128. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-colors.js +58 -0
  129. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-colors.js.map +1 -0
  130. package/{src → dist/esm}/lib/parsers/helpers/normalize-3d-tile-normals.js +5 -10
  131. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-normals.js.map +1 -0
  132. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-positions.js +26 -0
  133. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-positions.js.map +1 -0
  134. package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js +241 -0
  135. package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -0
  136. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js +67 -0
  137. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -0
  138. package/dist/esm/lib/parsers/helpers/parse-3d-tile-header.js +16 -0
  139. package/dist/esm/lib/parsers/helpers/parse-3d-tile-header.js.map +1 -0
  140. package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js +67 -0
  141. package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -0
  142. package/dist/esm/lib/parsers/helpers/parse-3d-tile-tables.js +80 -0
  143. package/dist/esm/lib/parsers/helpers/parse-3d-tile-tables.js.map +1 -0
  144. package/dist/esm/lib/parsers/helpers/parse-utils.js +20 -0
  145. package/dist/esm/lib/parsers/helpers/parse-utils.js.map +1 -0
  146. package/dist/esm/lib/parsers/parse-3d-tile-batched-model.js +25 -0
  147. package/dist/esm/lib/parsers/parse-3d-tile-batched-model.js.map +1 -0
  148. package/dist/esm/lib/parsers/parse-3d-tile-composite.js +15 -0
  149. package/dist/esm/lib/parsers/parse-3d-tile-composite.js.map +1 -0
  150. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js +20 -0
  151. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js.map +1 -0
  152. package/dist/esm/lib/parsers/parse-3d-tile-header.js +181 -0
  153. package/dist/esm/lib/parsers/parse-3d-tile-header.js.map +1 -0
  154. package/dist/esm/lib/parsers/parse-3d-tile-instanced-model.js +138 -0
  155. package/dist/esm/lib/parsers/parse-3d-tile-instanced-model.js.map +1 -0
  156. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js +232 -0
  157. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -0
  158. package/dist/esm/lib/parsers/parse-3d-tile.js +30 -0
  159. package/dist/esm/lib/parsers/parse-3d-tile.js.map +1 -0
  160. package/dist/esm/lib/utils/obb/s2-corners-to-obb.js +23 -0
  161. package/dist/esm/lib/utils/obb/s2-corners-to-obb.js.map +1 -0
  162. package/dist/esm/lib/utils/s2/converters/s2-to-boundary.js +40 -0
  163. package/dist/esm/lib/utils/s2/converters/s2-to-boundary.js.map +1 -0
  164. package/dist/esm/lib/utils/s2/converters/s2-to-obb-points.js +24 -0
  165. package/dist/esm/lib/utils/s2/converters/s2-to-obb-points.js.map +1 -0
  166. package/dist/esm/lib/utils/s2/converters/s2-to-region.js +42 -0
  167. package/dist/esm/lib/utils/s2/converters/s2-to-region.js.map +1 -0
  168. package/dist/esm/lib/utils/s2/index.js +7 -0
  169. package/dist/esm/lib/utils/s2/index.js.map +1 -0
  170. package/dist/esm/lib/utils/s2/s2-geometry-functions.js +12 -0
  171. package/dist/esm/lib/utils/s2/s2-geometry-functions.js.map +1 -0
  172. package/dist/esm/lib/utils/s2/s2-token-functions.js +32 -0
  173. package/dist/esm/lib/utils/s2/s2-token-functions.js.map +1 -0
  174. package/dist/esm/lib/utils/s2/s2geometry/s2-cell-utils.js +15 -0
  175. package/dist/esm/lib/utils/s2/s2geometry/s2-cell-utils.js.map +1 -0
  176. package/dist/esm/lib/utils/s2/s2geometry/s2-geometry.js +186 -0
  177. package/dist/esm/lib/utils/s2/s2geometry/s2-geometry.js.map +1 -0
  178. package/dist/esm/lib/utils/version.js +2 -0
  179. package/dist/esm/lib/utils/version.js.map +1 -0
  180. package/dist/esm/tile-3d-subtree-loader.js +14 -0
  181. package/dist/esm/tile-3d-subtree-loader.js.map +1 -0
  182. package/dist/esm/tile-3d-writer.js +19 -0
  183. package/dist/esm/tile-3d-writer.js.map +1 -0
  184. package/dist/esm/tiles-3d-loader.js +68 -0
  185. package/dist/esm/tiles-3d-loader.js.map +1 -0
  186. package/dist/esm/types.js +2 -0
  187. package/dist/esm/types.js.map +1 -0
  188. package/dist/index.d.ts +11 -0
  189. package/dist/index.d.ts.map +1 -0
  190. package/dist/index.js +26 -8
  191. package/dist/lib/classes/helpers/tile-3d-accessor-utils.d.ts +8 -0
  192. package/dist/lib/classes/helpers/tile-3d-accessor-utils.d.ts.map +1 -0
  193. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +106 -89
  194. package/dist/lib/classes/tile-3d-batch-table-hierarchy.d.ts +10 -0
  195. package/dist/lib/classes/tile-3d-batch-table-hierarchy.d.ts.map +1 -0
  196. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +184 -202
  197. package/dist/lib/classes/tile-3d-batch-table.d.ts +34 -0
  198. package/dist/lib/classes/tile-3d-batch-table.d.ts.map +1 -0
  199. package/dist/lib/classes/tile-3d-batch-table.js +223 -267
  200. package/dist/lib/classes/tile-3d-feature-table.d.ts +15 -0
  201. package/dist/lib/classes/tile-3d-feature-table.d.ts.map +1 -0
  202. package/dist/lib/classes/tile-3d-feature-table.js +64 -79
  203. package/dist/lib/constants.d.ts +22 -0
  204. package/dist/lib/constants.d.ts.map +1 -0
  205. package/dist/lib/constants.js +23 -18
  206. package/dist/lib/encoders/encode-3d-tile-batched-model.d.ts +2 -0
  207. package/dist/lib/encoders/encode-3d-tile-batched-model.d.ts.map +1 -0
  208. package/dist/lib/encoders/encode-3d-tile-batched-model.js +45 -45
  209. package/dist/lib/encoders/encode-3d-tile-composite.d.ts +2 -0
  210. package/dist/lib/encoders/encode-3d-tile-composite.d.ts.map +1 -0
  211. package/dist/lib/encoders/encode-3d-tile-composite.js +23 -24
  212. package/dist/lib/encoders/encode-3d-tile-instanced-model.d.ts +2 -0
  213. package/dist/lib/encoders/encode-3d-tile-instanced-model.d.ts.map +1 -0
  214. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +37 -37
  215. package/dist/lib/encoders/encode-3d-tile-point-cloud.d.ts +2 -0
  216. package/dist/lib/encoders/encode-3d-tile-point-cloud.d.ts.map +1 -0
  217. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +36 -38
  218. package/dist/lib/encoders/encode-3d-tile.d.ts +2 -0
  219. package/dist/lib/encoders/encode-3d-tile.d.ts.map +1 -0
  220. package/dist/lib/encoders/encode-3d-tile.js +30 -32
  221. package/dist/lib/encoders/helpers/encode-3d-tile-header.d.ts +3 -0
  222. package/dist/lib/encoders/helpers/encode-3d-tile-header.d.ts.map +1 -0
  223. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +28 -29
  224. package/dist/lib/ion/ion.d.ts +4 -0
  225. package/dist/lib/ion/ion.d.ts.map +1 -0
  226. package/dist/lib/ion/ion.js +60 -69
  227. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +9 -0
  228. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -0
  229. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +60 -62
  230. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +7 -0
  231. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -0
  232. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +26 -26
  233. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.d.ts +2 -0
  234. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.d.ts.map +1 -0
  235. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +39 -28
  236. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +57 -0
  237. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -0
  238. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +266 -0
  239. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +10 -0
  240. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -0
  241. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +90 -63
  242. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +3 -0
  243. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -0
  244. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +26 -15
  245. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +10 -0
  246. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -0
  247. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +104 -0
  248. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +5 -0
  249. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -0
  250. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +85 -81
  251. package/dist/lib/parsers/helpers/parse-utils.d.ts +4 -0
  252. package/dist/lib/parsers/helpers/parse-utils.d.ts.map +1 -0
  253. package/dist/lib/parsers/helpers/parse-utils.js +29 -16
  254. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +5 -0
  255. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -0
  256. package/dist/lib/parsers/parse-3d-tile-batched-model.js +30 -26
  257. package/dist/lib/parsers/parse-3d-tile-composite.d.ts +8 -0
  258. package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -0
  259. package/dist/lib/parsers/parse-3d-tile-composite.js +23 -16
  260. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +5 -0
  261. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -0
  262. package/dist/lib/parsers/parse-3d-tile-gltf.js +28 -0
  263. package/dist/lib/parsers/parse-3d-tile-header.d.ts +20 -0
  264. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -0
  265. package/dist/lib/parsers/parse-3d-tile-header.js +186 -71
  266. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +5 -0
  267. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -0
  268. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +165 -170
  269. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +6 -0
  270. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -0
  271. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +372 -184
  272. package/dist/lib/parsers/parse-3d-tile.d.ts +5 -0
  273. package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -0
  274. package/dist/lib/parsers/parse-3d-tile.js +32 -27
  275. package/dist/lib/utils/obb/s2-corners-to-obb.d.ts +15 -0
  276. package/dist/lib/utils/obb/s2-corners-to-obb.d.ts.map +1 -0
  277. package/dist/lib/utils/obb/s2-corners-to-obb.js +37 -0
  278. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +9 -0
  279. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -0
  280. package/dist/lib/utils/s2/converters/s2-to-boundary.js +61 -0
  281. package/dist/lib/utils/s2/converters/s2-to-obb-points.d.ts +15 -0
  282. package/dist/lib/utils/s2/converters/s2-to-obb-points.d.ts.map +1 -0
  283. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +36 -0
  284. package/dist/lib/utils/s2/converters/s2-to-region.d.ts +13 -0
  285. package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -0
  286. package/dist/lib/utils/s2/converters/s2-to-region.js +59 -0
  287. package/dist/lib/utils/s2/index.d.ts +8 -0
  288. package/dist/lib/utils/s2/index.d.ts.map +1 -0
  289. package/dist/lib/utils/s2/index.js +23 -0
  290. package/dist/lib/utils/s2/s2-geometry-functions.d.ts +14 -0
  291. package/dist/lib/utils/s2/s2-geometry-functions.d.ts.map +1 -0
  292. package/dist/lib/utils/s2/s2-geometry-functions.js +29 -0
  293. package/dist/lib/utils/s2/s2-token-functions.d.ts +23 -0
  294. package/dist/lib/utils/s2/s2-token-functions.d.ts.map +1 -0
  295. package/dist/lib/utils/s2/s2-token-functions.js +68 -0
  296. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +14 -0
  297. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -0
  298. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +32 -0
  299. package/dist/lib/utils/s2/s2geometry/s2-geometry.d.ts +52 -0
  300. package/dist/lib/utils/s2/s2geometry/s2-geometry.d.ts.map +1 -0
  301. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +260 -0
  302. package/dist/lib/utils/version.d.ts +2 -0
  303. package/dist/lib/utils/version.d.ts.map +1 -0
  304. package/dist/lib/utils/version.js +7 -2
  305. package/dist/tile-3d-subtree-loader.d.ts +7 -0
  306. package/dist/tile-3d-subtree-loader.d.ts.map +1 -0
  307. package/dist/tile-3d-subtree-loader.js +23 -0
  308. package/dist/tile-3d-writer.d.ts +6 -0
  309. package/dist/tile-3d-writer.d.ts.map +1 -0
  310. package/dist/tile-3d-writer.js +24 -17
  311. package/dist/tiles-3d-loader.d.ts +20 -0
  312. package/dist/tiles-3d-loader.d.ts.map +1 -0
  313. package/dist/tiles-3d-loader.js +69 -65
  314. package/dist/types.d.ts +335 -0
  315. package/dist/types.d.ts.map +1 -0
  316. package/dist/types.js +2 -2
  317. package/package.json +14 -13
  318. package/src/cesium-ion-loader.ts +1 -0
  319. package/src/index.ts +13 -1
  320. package/src/lib/classes/{tile-3d-batch-table.js → tile-3d-batch-table.ts} +14 -4
  321. package/src/lib/classes/{tile-3d-feature-table.js → tile-3d-feature-table.ts} +5 -2
  322. package/src/lib/{constants.js → constants.ts} +2 -1
  323. package/src/lib/parsers/helpers/{normalize-3d-tile-colors.js → normalize-3d-tile-colors.ts} +10 -4
  324. package/src/lib/parsers/helpers/normalize-3d-tile-normals.ts +35 -0
  325. package/src/lib/parsers/helpers/parse-3d-implicit-tiles.ts +396 -0
  326. package/src/lib/parsers/helpers/{parse-3d-tile-gltf-view.js → parse-3d-tile-gltf-view.ts} +40 -16
  327. package/src/lib/parsers/helpers/{parse-3d-tile-header.js → parse-3d-tile-header.ts} +7 -1
  328. package/src/lib/parsers/helpers/parse-3d-tile-subtree.ts +148 -0
  329. package/src/lib/parsers/helpers/{parse-3d-tile-tables.js → parse-3d-tile-tables.ts} +33 -12
  330. package/src/lib/parsers/{parse-3d-tile-batched-model.js → parse-3d-tile-batched-model.ts} +18 -3
  331. package/src/lib/parsers/{parse-3d-tile-composite.js → parse-3d-tile-composite.ts} +20 -8
  332. package/src/lib/parsers/parse-3d-tile-gltf.ts +33 -0
  333. package/src/lib/parsers/parse-3d-tile-header.ts +253 -0
  334. package/src/lib/parsers/{parse-3d-tile-instanced-model.js → parse-3d-tile-instanced-model.ts} +41 -30
  335. package/src/lib/parsers/{parse-3d-tile-point-cloud.js → parse-3d-tile-point-cloud.ts} +73 -14
  336. package/src/lib/parsers/{parse-3d-tile.js → parse-3d-tile.ts} +14 -1
  337. package/src/lib/utils/obb/s2-corners-to-obb.ts +51 -0
  338. package/src/lib/utils/s2/converters/s2-to-boundary.ts +67 -0
  339. package/src/lib/utils/s2/converters/s2-to-obb-points.ts +46 -0
  340. package/src/lib/utils/s2/converters/s2-to-region.ts +69 -0
  341. package/src/lib/utils/s2/index.ts +17 -0
  342. package/src/lib/utils/s2/s2-geometry-functions.ts +28 -0
  343. package/src/lib/utils/s2/s2-token-functions.ts +67 -0
  344. package/src/lib/utils/s2/s2geometry/s2-cell-utils.ts +33 -0
  345. package/src/lib/utils/s2/s2geometry/s2-geometry.ts +296 -0
  346. package/src/tile-3d-subtree-loader.ts +19 -0
  347. package/src/tiles-3d-loader.ts +68 -37
  348. package/src/types.ts +321 -13
  349. package/dist/bundle.js.map +0 -1
  350. package/dist/cesium-ion-loader.js.map +0 -1
  351. package/dist/index.js.map +0 -1
  352. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
  353. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
  354. package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
  355. package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
  356. package/dist/lib/constants.js.map +0 -1
  357. package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
  358. package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
  359. package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
  360. package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
  361. package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
  362. package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
  363. package/dist/lib/ion/ion.js.map +0 -1
  364. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
  365. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
  366. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
  367. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
  368. package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
  369. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
  370. package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
  371. package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
  372. package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
  373. package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
  374. package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
  375. package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
  376. package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
  377. package/dist/lib/utils/version.js.map +0 -1
  378. package/dist/tile-3d-writer.js.map +0 -1
  379. package/dist/tiles-3d-loader.js.map +0 -1
  380. package/dist/types.js.map +0 -1
  381. package/src/lib/parsers/parse-3d-tile-header.js +0 -69
  382. /package/src/lib/classes/helpers/{tile-3d-accessor-utils.js → tile-3d-accessor-utils.ts} +0 -0
  383. /package/src/lib/classes/{tile-3d-batch-table-hierarchy.js → tile-3d-batch-table-hierarchy.ts} +0 -0
  384. /package/src/lib/encoders/{encode-3d-tile-batched-model.js → encode-3d-tile-batched-model.ts} +0 -0
  385. /package/src/lib/encoders/{encode-3d-tile-composite.js → encode-3d-tile-composite.ts} +0 -0
  386. /package/src/lib/encoders/{encode-3d-tile-instanced-model.js → encode-3d-tile-instanced-model.ts} +0 -0
  387. /package/src/lib/encoders/{encode-3d-tile-point-cloud.js → encode-3d-tile-point-cloud.ts} +0 -0
  388. /package/src/lib/encoders/{encode-3d-tile.js → encode-3d-tile.ts} +0 -0
  389. /package/src/lib/encoders/helpers/{encode-3d-tile-header.js → encode-3d-tile-header.ts} +0 -0
  390. /package/src/lib/ion/{ion.js → ion.ts} +0 -0
  391. /package/src/lib/parsers/helpers/{normalize-3d-tile-positions.js → normalize-3d-tile-positions.ts} +0 -0
  392. /package/src/lib/parsers/helpers/{parse-utils.js → parse-utils.ts} +0 -0
  393. /package/src/lib/utils/{version.js → version.ts} +0 -0
@@ -12,8 +12,17 @@ import {parse3DTileTablesHeaderSync, parse3DTileTablesSync} from './helpers/pars
12
12
  import {normalize3DTileColorAttribute} from './helpers/normalize-3d-tile-colors';
13
13
  import {normalize3DTileNormalAttribute} from './helpers/normalize-3d-tile-normals';
14
14
  import {normalize3DTilePositionAttribute} from './helpers/normalize-3d-tile-positions';
15
-
16
- export async function parsePointCloud3DTile(tile, arrayBuffer, byteOffset, options, context) {
15
+ import {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
16
+ import {LoaderContext} from '@loaders.gl/loader-utils';
17
+ import {Tiles3DTileContent} from '../../types';
18
+
19
+ export async function parsePointCloud3DTile(
20
+ tile: Tiles3DTileContent,
21
+ arrayBuffer: ArrayBuffer,
22
+ byteOffset: number,
23
+ options?: Tiles3DLoaderOptions,
24
+ context?: LoaderContext
25
+ ): Promise<number> {
17
26
  byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
18
27
  byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
19
28
  byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options);
@@ -24,13 +33,14 @@ export async function parsePointCloud3DTile(tile, arrayBuffer, byteOffset, optio
24
33
  await parseDraco(tile, featureTable, batchTable, options, context);
25
34
 
26
35
  parsePositions(tile, featureTable, options);
36
+ // @ts-expect-error TODO - do we need to assert on the batch table?
27
37
  parseColors(tile, featureTable, batchTable);
28
38
  parseNormals(tile, featureTable);
29
39
 
30
40
  return byteOffset;
31
41
  }
32
42
 
33
- function initializeTile(tile) {
43
+ function initializeTile(tile: Tiles3DTileContent): void {
34
44
  // Initialize point cloud tile defaults
35
45
  tile.attributes = {
36
46
  positions: null,
@@ -44,7 +54,10 @@ function initializeTile(tile) {
44
54
  tile.isOctEncoded16P = false;
45
55
  }
46
56
 
47
- function parsePointCloudTables(tile) {
57
+ function parsePointCloudTables(tile: Tiles3DTileContent): {
58
+ featureTable: Tile3DFeatureTable;
59
+ batchTable: Tile3DBatchTable | null;
60
+ } {
48
61
  const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
49
62
 
50
63
  const pointsLength = featureTable.getGlobalProperty('POINTS_LENGTH');
@@ -64,7 +77,17 @@ function parsePointCloudTables(tile) {
64
77
  return {featureTable, batchTable};
65
78
  }
66
79
 
67
- function parsePositions(tile, featureTable, options) {
80
+ function parsePositions(
81
+ tile: Tiles3DTileContent,
82
+ featureTable: Tile3DFeatureTable,
83
+ options: Tiles3DLoaderOptions | undefined
84
+ ): void {
85
+ tile.attributes = tile.attributes || {
86
+ positions: null,
87
+ colors: null,
88
+ normals: null,
89
+ batchIds: null
90
+ };
68
91
  if (!tile.attributes.positions) {
69
92
  if (featureTable.hasProperty('POSITION')) {
70
93
  tile.attributes.positions = featureTable.getPropertyArray('POSITION', GL.FLOAT, 3);
@@ -101,7 +124,17 @@ function parsePositions(tile, featureTable, options) {
101
124
  }
102
125
  }
103
126
 
104
- function parseColors(tile, featureTable, batchTable) {
127
+ function parseColors(
128
+ tile: Tiles3DTileContent,
129
+ featureTable: Tile3DFeatureTable,
130
+ batchTable: Tile3DBatchTable
131
+ ): void {
132
+ tile.attributes = tile.attributes || {
133
+ positions: null,
134
+ colors: null,
135
+ normals: null,
136
+ batchIds: null
137
+ };
105
138
  if (!tile.attributes.colors) {
106
139
  let colors = null;
107
140
  if (featureTable.hasProperty('RGBA')) {
@@ -122,7 +155,13 @@ function parseColors(tile, featureTable, batchTable) {
122
155
  }
123
156
  }
124
157
 
125
- function parseNormals(tile, featureTable) {
158
+ function parseNormals(tile: Tiles3DTileContent, featureTable: Tile3DFeatureTable): void {
159
+ tile.attributes = tile.attributes || {
160
+ positions: null,
161
+ colors: null,
162
+ normals: null,
163
+ batchIds: null
164
+ };
126
165
  if (!tile.attributes.normals) {
127
166
  let normals = null;
128
167
  if (featureTable.hasProperty('NORMAL')) {
@@ -136,8 +175,11 @@ function parseNormals(tile, featureTable) {
136
175
  }
137
176
  }
138
177
 
139
- function parseBatchIds(tile, featureTable) {
140
- let batchTable = null;
178
+ function parseBatchIds(
179
+ tile: Tiles3DTileContent,
180
+ featureTable: Tile3DFeatureTable
181
+ ): Tile3DBatchTable | null {
182
+ let batchTable: Tile3DBatchTable | null = null;
141
183
  if (!tile.batchIds && featureTable.hasProperty('BATCH_ID')) {
142
184
  tile.batchIds = featureTable.getPropertyArray('BATCH_ID', GL.UNSIGNED_SHORT, 1);
143
185
 
@@ -154,7 +196,13 @@ function parseBatchIds(tile, featureTable) {
154
196
  }
155
197
 
156
198
  // eslint-disable-next-line complexity
157
- async function parseDraco(tile, featureTable, batchTable, options, context) {
199
+ async function parseDraco(
200
+ tile: Tiles3DTileContent,
201
+ featureTable: Tile3DFeatureTable,
202
+ batchTable,
203
+ options?: Tiles3DLoaderOptions,
204
+ context?: LoaderContext
205
+ ) {
158
206
  let dracoBuffer;
159
207
  let dracoFeatureTableProperties;
160
208
  let dracoBatchTableProperties;
@@ -175,7 +223,10 @@ async function parseDraco(tile, featureTable, batchTable, options, context) {
175
223
  throw new Error('Draco properties, byteOffset, and byteLength must be defined');
176
224
  }
177
225
 
178
- dracoBuffer = tile.featureTableBinary.slice(dracoByteOffset, dracoByteOffset + dracoByteLength);
226
+ dracoBuffer = (tile.featureTableBinary || []).slice(
227
+ dracoByteOffset,
228
+ dracoByteOffset + dracoByteLength
229
+ );
179
230
 
180
231
  tile.hasPositions = Number.isFinite(dracoFeatureTableProperties.POSITION);
181
232
  tile.hasColors =
@@ -202,12 +253,20 @@ async function parseDraco(tile, featureTable, batchTable, options, context) {
202
253
  }
203
254
 
204
255
  // eslint-disable-next-line complexity, max-statements
205
- export async function loadDraco(tile, dracoData, options, context) {
256
+ export async function loadDraco(
257
+ tile: Tiles3DTileContent,
258
+ dracoData,
259
+ options?: Tiles3DLoaderOptions,
260
+ context?: LoaderContext
261
+ ): Promise<void> {
262
+ if (!context) {
263
+ return;
264
+ }
206
265
  const {parse} = context;
207
266
  const dracoOptions = {
208
267
  ...options,
209
268
  draco: {
210
- ...options.draco,
269
+ ...options?.draco,
211
270
  extraAttributes: dracoData.batchTableProperties || {}
212
271
  }
213
272
  };
@@ -250,7 +309,7 @@ export async function loadDraco(tile, dracoData, options, context) {
250
309
 
251
310
  tile.attributes = {
252
311
  positions: decodedPositions,
253
- colors: normalize3DTileColorAttribute(tile, decodedColors),
312
+ colors: normalize3DTileColorAttribute(tile, decodedColors, undefined),
254
313
  normals: decodedNormals,
255
314
  batchIds: decodedBatchIds,
256
315
  ...batchTableAttributes
@@ -8,9 +8,19 @@ import {parsePointCloud3DTile} from './parse-3d-tile-point-cloud';
8
8
  import {parseBatchedModel3DTile} from './parse-3d-tile-batched-model';
9
9
  import {parseInstancedModel3DTile} from './parse-3d-tile-instanced-model';
10
10
  import {parseComposite3DTile} from './parse-3d-tile-composite';
11
+ import {parseGltf3DTile} from './parse-3d-tile-gltf';
12
+ import {LoaderContext} from '@loaders.gl/loader-utils';
13
+ import {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
14
+ import {Tiles3DTileContent} from '../../types';
11
15
 
12
16
  // Extracts
13
- export async function parse3DTile(arrayBuffer, byteOffset = 0, options, context, tile = {}) {
17
+ export async function parse3DTile(
18
+ arrayBuffer: ArrayBuffer,
19
+ byteOffset = 0,
20
+ options: Tiles3DLoaderOptions | undefined,
21
+ context: LoaderContext | undefined,
22
+ tile: Tiles3DTileContent = {}
23
+ ) {
14
24
  tile.byteOffset = byteOffset;
15
25
  tile.type = getMagicString(arrayBuffer, byteOffset);
16
26
 
@@ -29,6 +39,9 @@ export async function parse3DTile(arrayBuffer, byteOffset = 0, options, context,
29
39
  case TILE3D_TYPE.BATCHED_3D_MODEL:
30
40
  return await parseBatchedModel3DTile(tile, arrayBuffer, byteOffset, options, context);
31
41
 
42
+ case TILE3D_TYPE.GLTF:
43
+ return await parseGltf3DTile(tile, arrayBuffer, options, context);
44
+
32
45
  case TILE3D_TYPE.INSTANCED_3D_MODEL:
33
46
  return await parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context);
34
47
 
@@ -0,0 +1,51 @@
1
+ import {Vector3} from '@math.gl/core';
2
+ import {OrientedBoundingBox, makeOrientedBoundingBoxFromPoints} from '@math.gl/culling';
3
+
4
+ import type {S2HeightInfo} from '../../utils/s2/index';
5
+ import {getS2OrientedBoundingBoxCornerPoints} from '../../utils/s2/index';
6
+
7
+ import {getS2LngLat} from '../../utils/s2/index';
8
+ import {Ellipsoid} from '@math.gl/geospatial';
9
+
10
+ export type S2VolumeInfo = {
11
+ /** S2 key or token */
12
+ token: string;
13
+ /** minimum height in meters */
14
+ minimumHeight: number;
15
+ /** maximum height in meters */
16
+ maximumHeight: number;
17
+ };
18
+
19
+ /**
20
+ * Converts S2VolumeInfo to OrientedBoundingBox
21
+ * @param {S2VolumeInfo} s2VolumeInfo - s2 volume to convert
22
+ * @returns Oriented Bounding Box of type Box
23
+ */
24
+ export function convertS2BoundingVolumetoOBB(s2VolumeInfo: S2VolumeInfo): number[] {
25
+ const token: string = s2VolumeInfo.token;
26
+ const heightInfo: S2HeightInfo = {
27
+ minimumHeight: s2VolumeInfo.minimumHeight,
28
+ maximumHeight: s2VolumeInfo.maximumHeight
29
+ };
30
+
31
+ const corners: Vector3[] = getS2OrientedBoundingBoxCornerPoints(token, heightInfo);
32
+
33
+ // Add a point that doesn't allow the box dive under the Earth
34
+
35
+ const center = getS2LngLat(token);
36
+ const centerLng: number = center[0];
37
+ const centerLat: number = center[1];
38
+ const point = Ellipsoid.WGS84.cartographicToCartesian([
39
+ centerLng,
40
+ centerLat,
41
+ heightInfo.maximumHeight
42
+ ]);
43
+ const centerPointAdditional = new Vector3(point[0], point[1], point[2]);
44
+ corners.push(centerPointAdditional);
45
+
46
+ // corners should be an array of Vector3 (XYZ)
47
+ const obb: OrientedBoundingBox = makeOrientedBoundingBoxFromPoints(corners);
48
+ const box: number[] = [...obb.center, ...obb.halfAxes];
49
+
50
+ return box;
51
+ }
@@ -0,0 +1,67 @@
1
+ import type {S2Cell} from '../s2geometry/s2-geometry';
2
+ import {IJToST, STToUV, FaceUVToXYZ, XYZToLngLat} from '../s2geometry/s2-geometry';
3
+
4
+ const MAX_RESOLUTION = 100;
5
+
6
+ /**
7
+ * Get a polygon with corner coordinates for an S2 cell
8
+ * @param s2cell {S2Cell} S2 cell
9
+ * @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
10
+ * - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
11
+ */
12
+ // eslint-disable-next-line max-statements
13
+ export function getS2BoundaryFlatFromS2Cell(s2cell: S2Cell): Float64Array {
14
+ const {face, ij, level} = s2cell;
15
+ const offsets = [
16
+ [0, 0],
17
+ [0, 1],
18
+ [1, 1],
19
+ [1, 0],
20
+ [0, 0]
21
+ ];
22
+
23
+ // The S2 cell edge is curved: http://s2geometry.io/
24
+ // This is more prominent at lower levels
25
+ // resolution is the number of segments to generate per edge.
26
+ // We exponentially reduce resolution as level increases so it doesn't affect perf
27
+ // when there are a large number of cells
28
+ const resolution = Math.max(1, Math.ceil(MAX_RESOLUTION * Math.pow(2, -level)));
29
+ const result = new Float64Array(4 * resolution * 2 + 2);
30
+ let ptIndex = 0;
31
+ let prevLng = 0;
32
+
33
+ for (let i = 0; i < 4; i++) {
34
+ const offset = offsets[i].slice(0) as [number, number];
35
+ const nextOffset = offsets[i + 1];
36
+ const stepI = (nextOffset[0] - offset[0]) / resolution;
37
+ const stepJ = (nextOffset[1] - offset[1]) / resolution;
38
+
39
+ for (let j = 0; j < resolution; j++) {
40
+ offset[0] += stepI;
41
+ offset[1] += stepJ;
42
+ // Cell can be represented by coordinates IJ, ST, UV, XYZ
43
+ // http://s2geometry.io/devguide/s2cell_hierarchy#coordinate-systems
44
+ const st = IJToST(ij, level, offset);
45
+ const uv = STToUV(st);
46
+ const xyz = FaceUVToXYZ(face, uv);
47
+ const lngLat = XYZToLngLat(xyz);
48
+
49
+ // Adjust longitude for Web Mercator projection
50
+
51
+ if (Math.abs(lngLat[1]) > 89.999) {
52
+ lngLat[0] = prevLng;
53
+ }
54
+
55
+ const deltaLng = lngLat[0] - prevLng;
56
+ lngLat[0] += deltaLng > 180 ? -360 : deltaLng < -180 ? 360 : 0;
57
+
58
+ result[ptIndex++] = lngLat[0];
59
+ result[ptIndex++] = lngLat[1];
60
+ prevLng = lngLat[0];
61
+ }
62
+ }
63
+ // close the loop
64
+ result[ptIndex++] = result[0];
65
+ result[ptIndex++] = result[1];
66
+ return result;
67
+ }
@@ -0,0 +1,46 @@
1
+ import {getS2Cell} from '../s2geometry/s2-cell-utils';
2
+ import {getS2Region} from './s2-to-region';
3
+ import {Vector3} from '@math.gl/core';
4
+
5
+ export type S2HeightInfo = {
6
+ minimumHeight: number;
7
+ maximumHeight: number;
8
+ };
9
+
10
+ /**
11
+ * Converts S2HeightInfo to corner points of an oriented bounding box
12
+ * Can be used to constuct an OrientedBoundingBox instance
13
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
14
+ * @param heightInfo {S2HeightInfo} min and max height of the box
15
+ * @returns corner points of the oriented bounding box
16
+ */
17
+ export function getS2OrientedBoundingBoxCornerPoints(
18
+ tokenOrKey: string, // This can be an S2 key or token
19
+ heightInfo?: S2HeightInfo
20
+ ): Vector3[] {
21
+ const min: number = heightInfo?.minimumHeight || 0;
22
+ const max: number = heightInfo?.maximumHeight || 0;
23
+
24
+ const s2cell = getS2Cell(tokenOrKey);
25
+ const region = getS2Region(s2cell);
26
+
27
+ // region lng/lat are in degrees
28
+ const W = region.west;
29
+ const S = region.south;
30
+ const E = region.east;
31
+ const N = region.north;
32
+
33
+ const points: Vector3[] = [];
34
+
35
+ points.push(new Vector3(W, N, min));
36
+ points.push(new Vector3(E, N, min));
37
+ points.push(new Vector3(E, S, min));
38
+ points.push(new Vector3(W, S, min));
39
+
40
+ points.push(new Vector3(W, N, max));
41
+ points.push(new Vector3(E, N, max));
42
+ points.push(new Vector3(E, S, max));
43
+ points.push(new Vector3(W, S, max));
44
+
45
+ return points;
46
+ }
@@ -0,0 +1,69 @@
1
+ import type {S2Cell} from '../s2geometry/s2-geometry';
2
+ import {getS2BoundaryFlatFromS2Cell} from './s2-to-boundary';
3
+ import {getS2Cell} from '../s2geometry/s2-cell-utils';
4
+
5
+ /**
6
+ * Converts S2 cell to the 2D region
7
+ * @param s2cell {S2Cell} S2 cell to convert to 2D region
8
+ * @returns 2D region as an object containing: west, north, east, south in degrees
9
+ */
10
+ export function getS2Region(s2cell: S2Cell): {
11
+ west: number;
12
+ east: number;
13
+ north: number;
14
+ south: number;
15
+ } {
16
+ let region;
17
+ if (s2cell.face === 2 || s2cell.face === 5) {
18
+ // let corners: Float64Array;
19
+ let corners: any = null;
20
+ let len = 0;
21
+ for (let i = 0; i < 4; i++) {
22
+ const key = `${s2cell.face}/${i}`;
23
+ const cell = getS2Cell(key);
24
+ const corns: Float64Array = getS2BoundaryFlatFromS2Cell(cell);
25
+ if (typeof corners === 'undefined' || corners === null)
26
+ corners = new Float64Array(4 * corns.length);
27
+ corners.set(corns, len);
28
+ len += corns.length;
29
+ }
30
+ region = get2DRegionFromS2Corners(corners);
31
+ } else {
32
+ const corners: Float64Array = getS2BoundaryFlatFromS2Cell(s2cell);
33
+ region = get2DRegionFromS2Corners(corners);
34
+ }
35
+ return region;
36
+ }
37
+
38
+ /**
39
+ * Converts the S2 cell defined by its corners to the 2D region
40
+ * @param corners {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
41
+ * @returns 2D region as an object containing: west, north, east, south in degrees
42
+ */
43
+ function get2DRegionFromS2Corners(corners: Float64Array): {
44
+ west: number;
45
+ east: number;
46
+ north: number;
47
+ south: number;
48
+ } {
49
+ if (corners.length % 2 !== 0) {
50
+ throw new Error('Invalid corners');
51
+ }
52
+ const longitudes: number[] = [];
53
+ const latitudes: number[] = [];
54
+ for (let i = 0; i < corners.length; i += 2) {
55
+ longitudes.push(corners[i]);
56
+ latitudes.push(corners[i + 1]);
57
+ }
58
+
59
+ longitudes.sort((a, b) => a - b);
60
+ latitudes.sort((a, b) => a - b);
61
+
62
+ // Return the region in degrees
63
+ return {
64
+ west: longitudes[0],
65
+ east: longitudes[longitudes.length - 1],
66
+ north: latitudes[latitudes.length - 1],
67
+ south: latitudes[0]
68
+ };
69
+ }
@@ -0,0 +1,17 @@
1
+ // math.gl MIT license
2
+
3
+ export {getS2CellIdFromToken, getS2TokenFromCellId, getS2ChildCellId} from './s2-token-functions';
4
+ export {getS2BoundaryFlat, getS2LngLat} from './s2-geometry-functions';
5
+
6
+ export {getS2Cell, getS2QuadKey} from './s2geometry/s2-cell-utils';
7
+ export {
8
+ getS2QuadkeyFromCellId,
9
+ getS2CellFromQuadKey,
10
+ getS2CellIdFromQuadkey,
11
+ getS2LngLatFromS2Cell
12
+ } from './s2geometry/s2-geometry';
13
+
14
+ export {getS2Region} from './converters/s2-to-region';
15
+
16
+ export type {S2HeightInfo} from './converters/s2-to-obb-points';
17
+ export {getS2OrientedBoundingBoxCornerPoints} from './converters/s2-to-obb-points';
@@ -0,0 +1,28 @@
1
+ // math.gl, MIT license
2
+
3
+ import {getS2BoundaryFlatFromS2Cell} from './converters/s2-to-boundary';
4
+ import {getS2LngLatFromS2Cell} from './s2geometry/s2-geometry';
5
+ import {getS2Cell} from './s2geometry/s2-cell-utils';
6
+
7
+ // GEOMETRY
8
+
9
+ /**
10
+ * Retrieve S2 geometry center
11
+ * @param s2Token {string} A string that is the cell's hex token
12
+ * @returns {[number, number]} Longitude and Latitude coordinates of the S2 cell's center
13
+ */
14
+ export function getS2LngLat(s2Token: string): [number, number] {
15
+ const s2cell = getS2Cell(s2Token);
16
+ return getS2LngLatFromS2Cell(s2cell);
17
+ }
18
+
19
+ /**
20
+ * Get a polygon with corner coordinates for an s2 cell
21
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
22
+ * @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
23
+ * - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
24
+ */
25
+ export function getS2BoundaryFlat(tokenOrKey: string): Float64Array {
26
+ const s2cell = getS2Cell(tokenOrKey);
27
+ return getS2BoundaryFlatFromS2Cell(s2cell);
28
+ }
@@ -0,0 +1,67 @@
1
+ // loaders.gl, MIT license
2
+
3
+ import Long from 'long';
4
+
5
+ const MAXIMUM_TOKEN_LENGTH = 16;
6
+
7
+ /**
8
+ * Convert the S2 token to the S2 cell ID
9
+ * @param token {string} A string that is the cell's hex token. Zero cell ID is represented as 'X'.
10
+ * @returns {Long} Cell id that is a 64-bit encoding of a face and a Hilbert curve parameter on that face.
11
+ * See {@link https://github.com/google/s2-geometry-library-java/blob/c04b68bf3197a9c34082327eeb3aec7ab7c85da1/src/com/google/common/geometry/S2CellId.java#L439} for more information
12
+ */
13
+ export function getS2CellIdFromToken(token: string): Long {
14
+ if (token === 'X') {
15
+ token = '';
16
+ }
17
+ // pad token with zeros to make the length 16 that is defined in MAXIMUM_TOKEN_LENGTH
18
+ const paddedToken = token.padEnd(MAXIMUM_TOKEN_LENGTH, '0');
19
+ return Long.fromString(paddedToken, true, 16); // Hex base
20
+ }
21
+
22
+ /**
23
+ * Convert the S2 cell ID to the S2 token
24
+ * @param cellId {Long} A 64-bit encoding of a face and a Hilbert curve parameter on that face.
25
+ * @returns {string} A string that is the cell's hex token. Zero cell ID is represented as 'X'.
26
+ */
27
+ export function getS2TokenFromCellId(cellId: Long): string {
28
+ if (cellId.isZero()) {
29
+ return 'X';
30
+ }
31
+ let numZeroDigits = cellId.countTrailingZeros();
32
+
33
+ const remainder = numZeroDigits % 4;
34
+ numZeroDigits = (numZeroDigits - remainder) / 4;
35
+ const trailingZeroHexChars = numZeroDigits;
36
+ numZeroDigits *= 4;
37
+
38
+ const x = cellId.shiftRightUnsigned(numZeroDigits);
39
+ const hexString = x.toString(16).replace(/0+$/, '');
40
+ const zeroString = Array(17 - trailingZeroHexChars - hexString.length).join('0');
41
+ return zeroString + hexString;
42
+ }
43
+
44
+ /**
45
+ * Get one of four S2 cell's children.
46
+ * @param cellId {Long} A 64-bit encoding of a face and a Hilbert curve parameter on that face.
47
+ * The cell must NOT be a leaf one. So, the cell's level is in the range [0-29].
48
+ * @param index {number} Child index defines one of four S2 cell's children. Must be in the range [0-3].
49
+ * @returns The ID of the cell's child.
50
+ */
51
+ export function getS2ChildCellId(cellId: Long, index: number): Long {
52
+ // Shift sentinel bit 2 positions to the right.
53
+ const newLsb = lsb(cellId).shiftRightUnsigned(2);
54
+ // Insert child index before the sentinel bit.
55
+ const childCellId: Long = cellId.add(Long.fromNumber(2 * index + 1 - 4).multiply(newLsb));
56
+ return childCellId;
57
+ }
58
+
59
+ /**
60
+ * Return the lowest-numbered bit that is on for this cell id.
61
+ * @private
62
+ * @param cellId {Long} Cell id.
63
+ * @returns {Long} The lowest-numbered bit that is on for this cell id.
64
+ */
65
+ function lsb(cellId: Long): Long {
66
+ return cellId.and(cellId.not().add(1)); // eslint-disable-line
67
+ }
@@ -0,0 +1,33 @@
1
+ // math.gl, MIT license
2
+
3
+ import type {S2Cell} from './s2-geometry';
4
+ import {getS2CellFromQuadKey, getS2QuadkeyFromCellId} from './s2-geometry';
5
+ import {getS2CellIdFromToken} from '../s2-token-functions';
6
+
7
+ import Long from 'long';
8
+
9
+ /**
10
+ * Return the S2Cell from the cell's hex token or the Hilbert quad key
11
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
12
+ * @returns {@link S2Cell}
13
+ */
14
+ export function getS2Cell(tokenOrKey: string): S2Cell {
15
+ const key = getS2QuadKey(tokenOrKey);
16
+ const s2cell = getS2CellFromQuadKey(key);
17
+ return s2cell;
18
+ }
19
+
20
+ /**
21
+ * Get the underlying Hilbert quad key
22
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
23
+ * @returns Hilbert quad key
24
+ */
25
+ export function getS2QuadKey(tokenOrKey: string): string {
26
+ if (tokenOrKey.indexOf('/') > 0) {
27
+ // is Hilbert quad key
28
+ return tokenOrKey;
29
+ }
30
+ // is S2 cell's hex token
31
+ const id: Long = getS2CellIdFromToken(tokenOrKey);
32
+ return getS2QuadkeyFromCellId(id);
33
+ }