leaflet-city-mapper 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (472) hide show
  1. package/README.md +15 -13
  2. package/cucumber.mjs +4 -0
  3. package/dist/leaflet-city-mapper.js +1 -1
  4. package/dist/leaflet-city-mapper.js.map +4 -4
  5. package/dist/utils/CELL.js +2 -0
  6. package/dist/utils/CELL.js.map +7 -0
  7. package/dist/utils/addBridges.js +2 -0
  8. package/dist/utils/addBridges.js.map +7 -0
  9. package/dist/utils/addRasterTile.js +2 -0
  10. package/dist/utils/addRasterTile.js.map +7 -0
  11. package/dist/utils/along.js +2 -0
  12. package/dist/utils/along.js.map +7 -0
  13. package/dist/utils/atmosphere.js +2 -0
  14. package/dist/utils/atmosphere.js.map +7 -0
  15. package/dist/utils/attach.js +2 -0
  16. package/dist/utils/attach.js.map +7 -0
  17. package/dist/utils/bindSunlight.js +2 -0
  18. package/dist/utils/bindSunlight.js.map +7 -0
  19. package/dist/utils/box.js +2 -0
  20. package/dist/utils/box.js.map +7 -0
  21. package/dist/utils/bridgeElevation.js +2 -0
  22. package/dist/utils/bridgeElevation.js.map +7 -0
  23. package/dist/utils/build.js +2 -0
  24. package/dist/utils/build.js.map +7 -0
  25. package/dist/utils/cameraControls.js +2 -0
  26. package/dist/utils/cameraControls.js.map +7 -0
  27. package/dist/utils/channel.js +2 -0
  28. package/dist/utils/channel.js.map +7 -0
  29. package/dist/utils/collider.js +2 -0
  30. package/dist/utils/collider.js.map +7 -0
  31. package/dist/utils/colliders.js +2 -0
  32. package/dist/utils/colliders.js.map +7 -0
  33. package/dist/utils/computeBounds.js +2 -0
  34. package/dist/utils/computeBounds.js.map +7 -0
  35. package/dist/utils/conformModelToTerrain.js +2 -0
  36. package/dist/utils/conformModelToTerrain.js.map +7 -0
  37. package/dist/utils/createMesh.js +2 -0
  38. package/dist/utils/createMesh.js.map +7 -0
  39. package/dist/utils/createProgram.js +3 -0
  40. package/dist/utils/createProgram.js.map +7 -0
  41. package/dist/utils/decodeDirectory.js +2 -0
  42. package/dist/utils/decodeDirectory.js.map +7 -0
  43. package/dist/utils/decodeHeader.js +2 -0
  44. package/dist/utils/decodeHeader.js.map +7 -0
  45. package/dist/utils/decodeModel.js +2 -0
  46. package/dist/utils/decodeModel.js.map +7 -0
  47. package/dist/utils/decompress.js +2 -0
  48. package/dist/utils/decompress.js.map +7 -0
  49. package/dist/utils/destroyTexture.js +2 -0
  50. package/dist/utils/destroyTexture.js.map +7 -0
  51. package/dist/utils/disposeMesh.js +2 -0
  52. package/dist/utils/disposeMesh.js.map +7 -0
  53. package/dist/utils/drawGeometry.js +2 -0
  54. package/dist/utils/drawGeometry.js.map +7 -0
  55. package/dist/utils/elevationWGSL.js +24 -0
  56. package/dist/utils/elevationWGSL.js.map +7 -0
  57. package/dist/utils/emptyNode.js +2 -0
  58. package/dist/utils/emptyNode.js.map +7 -0
  59. package/dist/utils/endZoom.js +2 -0
  60. package/dist/utils/endZoom.js.map +7 -0
  61. package/dist/utils/findFeature.js +2 -0
  62. package/dist/utils/findFeature.js.map +7 -0
  63. package/dist/utils/geometry.js +0 -1
  64. package/dist/utils/geometry.js.map +4 -4
  65. package/dist/utils/getElevation.js +2 -0
  66. package/dist/utils/getElevation.js.map +7 -0
  67. package/dist/utils/getHeader.js +2 -0
  68. package/dist/utils/getHeader.js.map +7 -0
  69. package/dist/utils/getZxy.js +2 -0
  70. package/dist/utils/getZxy.js.map +7 -0
  71. package/dist/utils/glass.js +2 -0
  72. package/dist/utils/glass.js.map +7 -0
  73. package/dist/utils/headlight.js +2 -0
  74. package/dist/utils/headlight.js.map +7 -0
  75. package/dist/utils/hit.js +2 -0
  76. package/dist/utils/hit.js.map +7 -0
  77. package/dist/utils/horizontalPosition.js +2 -0
  78. package/dist/utils/horizontalPosition.js.map +7 -0
  79. package/dist/utils/horizontalRay.js +2 -0
  80. package/dist/utils/horizontalRay.js.map +7 -0
  81. package/dist/utils/hull.js +2 -0
  82. package/dist/utils/hull.js.map +7 -0
  83. package/dist/utils/initSunlight.js +2 -0
  84. package/dist/utils/initSunlight.js.map +7 -0
  85. package/dist/utils/initTerrain.js +2 -0
  86. package/dist/utils/initTerrain.js.map +7 -0
  87. package/dist/utils/initTraffic.js +40 -0
  88. package/dist/utils/initTraffic.js.map +7 -0
  89. package/dist/utils/initWalk.js +2 -0
  90. package/dist/utils/initWalk.js.map +7 -0
  91. package/dist/utils/intersectMeshes.js +2 -0
  92. package/dist/utils/intersectMeshes.js.map +7 -0
  93. package/dist/utils/isClockWise.js +2 -0
  94. package/dist/utils/isClockWise.js.map +7 -0
  95. package/dist/utils/lampPostGeometry.js +2 -0
  96. package/dist/utils/lampPostGeometry.js.map +7 -0
  97. package/dist/utils/lightGeometry.js +2 -0
  98. package/dist/utils/lightGeometry.js.map +7 -0
  99. package/dist/utils/lightGrid.js +2 -0
  100. package/dist/utils/lightGrid.js.map +7 -0
  101. package/dist/utils/limbs.js +2 -0
  102. package/dist/utils/limbs.js.map +7 -0
  103. package/dist/utils/loadModel.js +2 -0
  104. package/dist/utils/loadModel.js.map +7 -0
  105. package/dist/utils/loadSource.js +2 -0
  106. package/dist/utils/loadSource.js.map +7 -0
  107. package/dist/utils/loadTerrain.js +2 -0
  108. package/dist/utils/loadTerrain.js.map +7 -0
  109. package/dist/utils/mapCamera.js +2 -0
  110. package/dist/utils/mapCamera.js.map +7 -0
  111. package/dist/utils/{shaders.js → materialShaders.js} +16 -8
  112. package/dist/utils/materialShaders.js.map +7 -0
  113. package/dist/utils/mirror.js +2 -0
  114. package/dist/utils/mirror.js.map +7 -0
  115. package/dist/utils/moonPosition.js +2 -0
  116. package/dist/utils/moonPosition.js.map +7 -0
  117. package/dist/utils/moves.js +2 -0
  118. package/dist/utils/moves.js.map +7 -0
  119. package/dist/utils/nativeEvents.js +2 -0
  120. package/dist/utils/nativeEvents.js.map +7 -0
  121. package/dist/utils/nativeGeometry.js +2 -0
  122. package/dist/utils/nativeGeometry.js.map +7 -0
  123. package/dist/utils/nativeLayer.js +2 -0
  124. package/dist/utils/nativeLayer.js.map +7 -0
  125. package/dist/utils/nodeMatrix.js +2 -0
  126. package/dist/utils/nodeMatrix.js.map +7 -0
  127. package/dist/utils/onAdd3DLayer.js +2 -0
  128. package/dist/utils/onAdd3DLayer.js.map +7 -0
  129. package/dist/utils/onAddSun.js +2 -0
  130. package/dist/utils/onAddSun.js.map +7 -0
  131. package/dist/utils/onClick.js +2 -0
  132. package/dist/utils/onClick.js.map +7 -0
  133. package/dist/utils/onMapChange.js +2 -0
  134. package/dist/utils/onMapChange.js.map +7 -0
  135. package/dist/utils/onPMTileAdd.js +2 -0
  136. package/dist/utils/onPMTileAdd.js.map +7 -0
  137. package/dist/utils/onPMTileRemove.js +2 -0
  138. package/dist/utils/onPMTileRemove.js.map +7 -0
  139. package/dist/utils/onPointerLeave.js +2 -0
  140. package/dist/utils/onPointerLeave.js.map +7 -0
  141. package/dist/utils/onPointerMove.js +2 -0
  142. package/dist/utils/onPointerMove.js.map +7 -0
  143. package/dist/utils/onRemove3DLayer.js +2 -0
  144. package/dist/utils/onRemove3DLayer.js.map +7 -0
  145. package/dist/utils/onRemoveSun.js +2 -0
  146. package/dist/utils/onRemoveSun.js.map +7 -0
  147. package/dist/utils/onTerrainAdd.js +2 -0
  148. package/dist/utils/onTerrainAdd.js.map +7 -0
  149. package/dist/utils/onTerrainChange.js +2 -0
  150. package/dist/utils/onTerrainChange.js.map +7 -0
  151. package/dist/utils/onTerrainRemove.js +2 -0
  152. package/dist/utils/onTerrainRemove.js.map +7 -0
  153. package/dist/utils/onZoomAnim.js +2 -0
  154. package/dist/utils/onZoomAnim.js.map +7 -0
  155. package/dist/utils/paints.js +2 -0
  156. package/dist/utils/paints.js.map +7 -0
  157. package/dist/utils/parseColor.js +2 -0
  158. package/dist/utils/parseColor.js.map +7 -0
  159. package/dist/utils/parts.js +2 -0
  160. package/dist/utils/parts.js.map +7 -0
  161. package/dist/utils/projectCelestialBody.js +2 -0
  162. package/dist/utils/projectCelestialBody.js.map +7 -0
  163. package/dist/utils/pump.js +2 -0
  164. package/dist/utils/pump.js.map +7 -0
  165. package/dist/utils/rasterTiles.js +2 -0
  166. package/dist/utils/rasterTiles.js.map +7 -0
  167. package/dist/utils/raycast.js +2 -0
  168. package/dist/utils/raycast.js.map +7 -0
  169. package/dist/utils/read.js +2 -0
  170. package/dist/utils/read.js.map +7 -0
  171. package/dist/utils/readAccessor.js +2 -0
  172. package/dist/utils/readAccessor.js.map +7 -0
  173. package/dist/utils/releaseArea.js +2 -0
  174. package/dist/utils/releaseArea.js.map +7 -0
  175. package/dist/utils/removeRasterTile.js +2 -0
  176. package/dist/utils/removeRasterTile.js.map +7 -0
  177. package/dist/utils/render.js +15 -0
  178. package/dist/utils/render.js.map +7 -0
  179. package/dist/utils/renderSunlight.js +13 -0
  180. package/dist/utils/renderSunlight.js.map +7 -0
  181. package/dist/utils/renderers.js +2 -0
  182. package/dist/utils/renderers.js.map +7 -0
  183. package/dist/utils/resizeSunlight.js +2 -0
  184. package/dist/utils/resizeSunlight.js.map +7 -0
  185. package/dist/utils/roofCoverage.js +2 -0
  186. package/dist/utils/roofCoverage.js.map +7 -0
  187. package/dist/utils/routeGeometry.js +2 -0
  188. package/dist/utils/routeGeometry.js.map +7 -0
  189. package/dist/utils/scheduledTrips.js +2 -0
  190. package/dist/utils/scheduledTrips.js.map +7 -0
  191. package/dist/utils/setGeoJSONData.js +2 -0
  192. package/dist/utils/setGeoJSONData.js.map +7 -0
  193. package/dist/utils/setHighlight.js +2 -0
  194. package/dist/utils/setHighlight.js.map +7 -0
  195. package/dist/utils/setPMTileOpacity.js +2 -0
  196. package/dist/utils/setPMTileOpacity.js.map +7 -0
  197. package/dist/utils/setPMTileZIndex.js +2 -0
  198. package/dist/utils/setPMTileZIndex.js.map +7 -0
  199. package/dist/utils/setParent.js +2 -0
  200. package/dist/utils/setParent.js.map +7 -0
  201. package/dist/utils/setTerrainHeight.js +2 -0
  202. package/dist/utils/setTerrainHeight.js.map +7 -0
  203. package/dist/utils/setVertexColor.js +2 -0
  204. package/dist/utils/setVertexColor.js.map +7 -0
  205. package/dist/utils/showFeature.js +2 -0
  206. package/dist/utils/showFeature.js.map +7 -0
  207. package/dist/utils/sizes.js +2 -0
  208. package/dist/utils/sizes.js.map +7 -0
  209. package/dist/utils/skin.js +2 -0
  210. package/dist/utils/skin.js.map +7 -0
  211. package/dist/utils/solarPosition.js +2 -0
  212. package/dist/utils/solarPosition.js.map +7 -0
  213. package/dist/utils/sortMeshes.js +2 -0
  214. package/dist/utils/sortMeshes.js.map +7 -0
  215. package/dist/utils/speed.js +2 -0
  216. package/dist/utils/speed.js.map +7 -0
  217. package/dist/utils/startZoom.js +2 -0
  218. package/dist/utils/startZoom.js.map +7 -0
  219. package/dist/utils/taillight.js +2 -0
  220. package/dist/utils/taillight.js.map +7 -0
  221. package/dist/utils/terrainAtlas.js +2 -0
  222. package/dist/utils/terrainAtlas.js.map +7 -0
  223. package/dist/utils/terrainElevation.js +2 -0
  224. package/dist/utils/terrainElevation.js.map +7 -0
  225. package/dist/utils/terrainGrid.js +2 -0
  226. package/dist/utils/terrainGrid.js.map +7 -0
  227. package/dist/utils/textureSampler.js +2 -0
  228. package/dist/utils/textureSampler.js.map +7 -0
  229. package/dist/utils/tileId.js +2 -0
  230. package/dist/utils/tileId.js.map +7 -0
  231. package/dist/utils/toLanes.js +2 -0
  232. package/dist/utils/toLanes.js.map +7 -0
  233. package/dist/utils/toSRGB.js +2 -0
  234. package/dist/utils/toSRGB.js.map +7 -0
  235. package/dist/utils/tooltip.js +3 -0
  236. package/dist/utils/tooltip.js.map +7 -0
  237. package/dist/utils/traffic.js +1 -1
  238. package/dist/utils/traffic.js.map +3 -3
  239. package/dist/utils/traverse.js +2 -0
  240. package/dist/utils/traverse.js.map +7 -0
  241. package/dist/utils/treeGeometry.js +2 -0
  242. package/dist/utils/treeGeometry.js.map +7 -0
  243. package/dist/utils/triangulate.js +2 -0
  244. package/dist/utils/triangulate.js.map +7 -0
  245. package/dist/utils/tripsAt.js +2 -0
  246. package/dist/utils/tripsAt.js.map +7 -0
  247. package/dist/utils/types.js +2 -0
  248. package/dist/utils/types.js.map +7 -0
  249. package/dist/utils/underEntry.js +2 -0
  250. package/dist/utils/underEntry.js.map +7 -0
  251. package/dist/utils/update.js +2 -0
  252. package/dist/utils/update.js.map +7 -0
  253. package/dist/utils/updateArea.js +2 -0
  254. package/dist/utils/updateArea.js.map +7 -0
  255. package/dist/utils/updateCamera.js +2 -0
  256. package/dist/utils/updateCamera.js.map +7 -0
  257. package/dist/utils/updatePointLights.js +2 -0
  258. package/dist/utils/updatePointLights.js.map +7 -0
  259. package/dist/utils/updateWorldMatrix.js +2 -0
  260. package/dist/utils/updateWorldMatrix.js.map +7 -0
  261. package/dist/utils/vehicleOffsets.js +2 -0
  262. package/dist/utils/vehicleOffsets.js.map +7 -0
  263. package/dist/utils/vehicles.js +1 -1
  264. package/dist/utils/vehicles.js.map +3 -3
  265. package/dist/utils/vertexNormals.js +2 -0
  266. package/dist/utils/vertexNormals.js.map +7 -0
  267. package/dist/utils/walk.js +1 -1
  268. package/dist/utils/walk.js.map +3 -3
  269. package/dist/utils/white.js +2 -0
  270. package/dist/utils/white.js.map +7 -0
  271. package/dist/utils/worldLights.js +2 -0
  272. package/dist/utils/worldLights.js.map +7 -0
  273. package/dist/utils/wrap.js +2 -0
  274. package/dist/utils/wrap.js.map +7 -0
  275. package/package.json +2 -4
  276. package/src/index.js +365 -50
  277. package/src/utils/CELL.js +4 -0
  278. package/src/utils/addBridges.js +66 -0
  279. package/src/utils/addRasterTile.js +112 -0
  280. package/src/utils/along.js +9 -0
  281. package/src/utils/atmosphere.js +20 -0
  282. package/src/utils/attach.js +255 -0
  283. package/src/utils/bindSunlight.js +12 -0
  284. package/src/utils/box.js +1 -0
  285. package/src/utils/bridgeElevation.js +18 -0
  286. package/src/utils/build.js +20 -0
  287. package/src/utils/cameraControls.js +287 -0
  288. package/src/utils/channel.js +4 -0
  289. package/src/utils/collider.js +62 -0
  290. package/src/utils/colliders.js +2 -0
  291. package/src/utils/computeBounds.js +17 -0
  292. package/src/utils/conformModelToTerrain.js +69 -0
  293. package/src/utils/createMesh.js +31 -0
  294. package/src/utils/createProgram.js +92 -0
  295. package/src/utils/decodeDirectory.js +40 -0
  296. package/src/utils/decodeHeader.js +15 -0
  297. package/src/utils/decodeModel.js +43 -0
  298. package/src/utils/decompress.js +5 -0
  299. package/src/utils/destroyTexture.js +7 -0
  300. package/src/utils/disposeMesh.js +13 -0
  301. package/src/utils/drawGeometry.js +122 -0
  302. package/src/utils/elevationWGSL.js +27 -0
  303. package/src/utils/emptyNode.js +9 -0
  304. package/src/utils/endZoom.js +15 -0
  305. package/src/utils/findFeature.js +49 -0
  306. package/src/utils/geometry.js +0 -254
  307. package/src/utils/getElevation.js +10 -0
  308. package/src/utils/getHeader.js +9 -0
  309. package/src/utils/getZxy.js +76 -0
  310. package/src/utils/glass.js +1 -0
  311. package/src/utils/headlight.js +1 -0
  312. package/src/utils/hit.js +41 -0
  313. package/src/utils/horizontalPosition.js +16 -0
  314. package/src/utils/horizontalRay.js +12 -0
  315. package/src/utils/hull.js +1 -0
  316. package/src/utils/initSunlight.js +9 -0
  317. package/src/utils/initTerrain.js +19 -0
  318. package/src/utils/initTraffic.js +93 -0
  319. package/src/utils/initWalk.js +72 -0
  320. package/src/utils/{picking.js → intersectMeshes.js} +121 -119
  321. package/src/utils/isClockWise.js +12 -0
  322. package/src/utils/lampPostGeometry.js +26 -0
  323. package/src/utils/lightGeometry.js +22 -0
  324. package/src/utils/{lighting.js → lightGrid.js} +50 -51
  325. package/src/utils/limbs.js +9 -0
  326. package/src/{scene/model.js → utils/loadModel.js} +37 -24
  327. package/src/utils/loadSource.js +17 -0
  328. package/src/utils/loadTerrain.js +65 -0
  329. package/src/utils/mapCamera.js +432 -0
  330. package/src/utils/{shaders.js → materialShaders.js} +243 -237
  331. package/src/utils/mirror.js +6 -0
  332. package/src/utils/moonPosition.js +17 -0
  333. package/src/utils/moves.js +11 -0
  334. package/src/utils/nativeEvents.js +77 -0
  335. package/src/utils/nativeGeometry.js +131 -0
  336. package/src/utils/nativeLayer.js +317 -0
  337. package/src/utils/nodeMatrix.js +22 -0
  338. package/src/utils/onAdd3DLayer.js +31 -0
  339. package/src/utils/onAddSun.js +147 -0
  340. package/src/utils/onClick.js +13 -0
  341. package/src/utils/onMapChange.js +16 -0
  342. package/src/utils/onPMTileAdd.js +15 -0
  343. package/src/utils/onPMTileRemove.js +8 -0
  344. package/src/utils/onPointerLeave.js +11 -0
  345. package/src/utils/onPointerMove.js +15 -0
  346. package/src/utils/onRemove3DLayer.js +78 -0
  347. package/src/utils/onRemoveSun.js +3 -0
  348. package/src/utils/onTerrainAdd.js +18 -0
  349. package/src/utils/onTerrainChange.js +13 -0
  350. package/src/utils/onTerrainRemove.js +40 -0
  351. package/src/utils/onZoomAnim.js +14 -0
  352. package/src/utils/paints.js +10 -0
  353. package/src/utils/parseColor.js +42 -0
  354. package/src/utils/parts.js +16 -0
  355. package/src/utils/projectCelestialBody.js +13 -0
  356. package/src/{scene/sources.js → utils/pump.js} +59 -98
  357. package/src/utils/rasterTiles.js +285 -0
  358. package/src/utils/raycast.js +60 -0
  359. package/src/utils/read.js +29 -0
  360. package/src/utils/readAccessor.js +68 -0
  361. package/src/utils/releaseArea.js +34 -0
  362. package/src/utils/removeRasterTile.js +13 -0
  363. package/src/{scene → utils}/render.js +112 -173
  364. package/src/utils/renderSunlight.js +170 -0
  365. package/src/utils/renderers.js +2 -0
  366. package/src/utils/resizeSunlight.js +15 -0
  367. package/src/utils/roofCoverage.js +47 -0
  368. package/src/utils/routeGeometry.js +22 -0
  369. package/src/utils/scheduledTrips.js +29 -0
  370. package/src/utils/setGeoJSONData.js +11 -0
  371. package/src/utils/setHighlight.js +13 -0
  372. package/src/utils/setPMTileOpacity.js +7 -0
  373. package/src/utils/setPMTileZIndex.js +7 -0
  374. package/src/utils/setParent.js +7 -0
  375. package/src/utils/setTerrainHeight.js +10 -0
  376. package/src/utils/setVertexColor.js +14 -0
  377. package/src/utils/showFeature.js +27 -0
  378. package/src/utils/sizes.js +1 -0
  379. package/src/utils/skin.js +2 -0
  380. package/src/utils/solarPosition.js +17 -0
  381. package/src/utils/sortMeshes.js +12 -0
  382. package/src/utils/speed.js +3 -0
  383. package/src/utils/startZoom.js +5 -0
  384. package/src/utils/taillight.js +1 -0
  385. package/src/utils/terrainAtlas.js +21 -0
  386. package/src/utils/terrainElevation.js +20 -0
  387. package/src/utils/terrainGrid.js +23 -0
  388. package/src/utils/textureSampler.js +10 -0
  389. package/src/utils/tileId.js +18 -0
  390. package/src/utils/toLanes.js +7 -0
  391. package/src/utils/toSRGB.js +1 -0
  392. package/src/utils/tooltip.js +6 -0
  393. package/src/utils/traffic.js +310 -85
  394. package/src/utils/traverse.js +6 -0
  395. package/src/utils/treeGeometry.js +45 -0
  396. package/src/utils/triangulate.js +100 -0
  397. package/src/utils/tripsAt.js +16 -0
  398. package/src/utils/types.js +8 -0
  399. package/src/utils/{control.js → underEntry.js} +1 -2
  400. package/src/utils/update.js +18 -0
  401. package/src/utils/updateArea.js +40 -0
  402. package/src/utils/updateCamera.js +32 -0
  403. package/src/utils/updatePointLights.js +38 -0
  404. package/src/utils/updateWorldMatrix.js +47 -0
  405. package/src/utils/vehicleOffsets.js +8 -0
  406. package/src/utils/vehicles.js +65 -69
  407. package/src/utils/vertexNormals.js +30 -0
  408. package/src/utils/walk.js +181 -66
  409. package/src/utils/white.js +1 -0
  410. package/src/utils/worldLights.js +25 -0
  411. package/src/utils/wrap.js +1 -0
  412. package/dist/scene/gpu.js +0 -3
  413. package/dist/scene/gpu.js.map +0 -7
  414. package/dist/scene/lighting.js +0 -9
  415. package/dist/scene/lighting.js.map +0 -7
  416. package/dist/scene/model.js +0 -2
  417. package/dist/scene/model.js.map +0 -7
  418. package/dist/scene/picking.js +0 -2
  419. package/dist/scene/picking.js.map +0 -7
  420. package/dist/scene/pmtiles.js +0 -2
  421. package/dist/scene/pmtiles.js.map +0 -7
  422. package/dist/scene/render.js +0 -15
  423. package/dist/scene/render.js.map +0 -7
  424. package/dist/scene/sources.js +0 -2
  425. package/dist/scene/sources.js.map +0 -7
  426. package/dist/types/3d.js +0 -2
  427. package/dist/types/3d.js.map +0 -7
  428. package/dist/types/geojson.js +0 -2
  429. package/dist/types/geojson.js.map +0 -7
  430. package/dist/types/pmtiles.js +0 -2
  431. package/dist/types/pmtiles.js.map +0 -7
  432. package/dist/types/sunlight.js +0 -2
  433. package/dist/types/sunlight.js.map +0 -7
  434. package/dist/types/terrain.js +0 -24
  435. package/dist/types/terrain.js.map +0 -7
  436. package/dist/types/traffic.js +0 -41
  437. package/dist/types/traffic.js.map +0 -7
  438. package/dist/types/walk.js +0 -2
  439. package/dist/types/walk.js.map +0 -7
  440. package/dist/utils/control.js +0 -2
  441. package/dist/utils/control.js.map +0 -7
  442. package/dist/utils/lighting.js +0 -2
  443. package/dist/utils/lighting.js.map +0 -7
  444. package/dist/utils/model.js +0 -2
  445. package/dist/utils/model.js.map +0 -7
  446. package/dist/utils/picking.js +0 -2
  447. package/dist/utils/picking.js.map +0 -7
  448. package/dist/utils/pmtiles.js +0 -2
  449. package/dist/utils/pmtiles.js.map +0 -7
  450. package/dist/utils/scene.js +0 -2
  451. package/dist/utils/scene.js.map +0 -7
  452. package/dist/utils/shaders.js.map +0 -7
  453. package/dist/utils/sun.js +0 -2
  454. package/dist/utils/sun.js.map +0 -7
  455. package/dist/utils/terrain.js +0 -2
  456. package/dist/utils/terrain.js.map +0 -7
  457. package/src/scene/gpu.js +0 -438
  458. package/src/scene/lighting.js +0 -193
  459. package/src/scene/picking.js +0 -150
  460. package/src/scene/pmtiles.js +0 -94
  461. package/src/types/3d.js +0 -337
  462. package/src/types/geojson.js +0 -42
  463. package/src/types/pmtiles.js +0 -143
  464. package/src/types/sunlight.js +0 -142
  465. package/src/types/terrain.js +0 -331
  466. package/src/types/traffic.js +0 -356
  467. package/src/types/walk.js +0 -219
  468. package/src/utils/model.js +0 -178
  469. package/src/utils/pmtiles.js +0 -79
  470. package/src/utils/scene.js +0 -102
  471. package/src/utils/sun.js +0 -71
  472. package/src/utils/terrain.js +0 -78
@@ -1,178 +0,0 @@
1
- const types = {
2
- 5120: Int8Array,
3
- 5121: Uint8Array,
4
- 5122: Int16Array,
5
- 5123: Uint16Array,
6
- 5125: Uint32Array,
7
- 5126: Float32Array,
8
- };
9
- const sizes = { SCALAR: 1, VEC2: 2, VEC3: 3, VEC4: 4 };
10
-
11
- /** Decode a static glTF JSON document or GLB v2 container. */
12
- export function decodeModel(data) {
13
- const view = new DataView(data),
14
- decoder = new TextDecoder();
15
- let description;
16
- if (view.getUint32(0, true) === 0x46546c67) {
17
- // Decode GLB v2 chunks; unknown types are skipped.
18
- if (view.getUint32(4, true) !== 2 || view.getUint32(8, true) !== data.byteLength) {
19
- throw new Error('Invalid GLB header');
20
- }
21
- let binary;
22
- for (let offset = 12; offset < data.byteLength;) {
23
- if (offset + 8 > data.byteLength) {
24
- throw new Error('Truncated GLB chunk');
25
- }
26
- const length = view.getUint32(offset, true), type = view.getUint32(offset + 4, true);
27
- offset += 8;
28
- if (offset + length > data.byteLength) {
29
- throw new Error('Truncated GLB data');
30
- }
31
- const chunk = data.slice(offset, offset + length);
32
- if (type === 0x4e4f534a) {
33
- description = JSON.parse(decoder.decode(chunk));
34
- }
35
- if (type === 0x004e4942) {
36
- binary = chunk;
37
- }
38
- offset += length;
39
- }
40
- if (!description) {
41
- throw new Error('Missing GLB JSON');
42
- }
43
- if (binary) {
44
- description.buffers[0].binary = binary;
45
- }
46
- } else {
47
- description = JSON.parse(decoder.decode(data));
48
- }
49
- if (description.skins?.length || description.animations?.length || description.extensionsRequired?.length || description.meshes?.some(mesh => mesh.primitives.some(primitive => primitive.targets || (primitive.mode !== undefined && primitive.mode !== 4)))) {
50
- throw new Error('Layer3D supports static triangle glTF models without required extensions');
51
- }
52
- return description;
53
- }
54
-
55
- /** Decode packed, interleaved, normalized or sparse glTF accessor data. */
56
- export function readAccessor(description, index) {
57
- const spec = description.accessors[index],
58
- Type = types[spec.componentType],
59
- size = sizes[spec.type];
60
- if (!Type || !size || !Number.isInteger(spec.count) || spec.count < 0) {
61
- throw new Error('Invalid glTF accessor');
62
- }
63
- const data = new Type(spec.count * size);
64
- // The destination callback is sequential for base data and sparse-indexed for overrides.
65
- const read = (viewIndex, offset, count, stride, output) => {
66
- const view = description.bufferViews[viewIndex], bytes = Type.BYTES_PER_ELEMENT;
67
- const buffer = description.buffers[view.buffer].binary;
68
- stride ||= size * bytes;
69
- if (!buffer || stride < size * bytes || offset < 0 ||
70
- (view.byteOffset || 0) + view.byteLength > buffer.byteLength ||
71
- (count - 1) * stride + size * bytes + offset > view.byteLength) throw new Error('glTF accessor outside buffer view');
72
- for (let i = 0; i < count; i++) {
73
- const values = new Type(buffer.slice((view.byteOffset || 0) + offset + i * stride,
74
- (view.byteOffset || 0) + offset + i * stride + size * bytes));
75
- data.set(values, output(i) * size);
76
- }
77
- };
78
- if (spec.bufferView !== undefined) {
79
- read(
80
- spec.bufferView,
81
- spec.byteOffset || 0,
82
- spec.count,
83
- description.bufferViews[spec.bufferView].byteStride,
84
- i => i
85
- );
86
- }
87
- if (spec.sparse) {
88
- const sparse = spec.sparse, Index = types[sparse.indices.componentType];
89
- if (![Uint8Array, Uint16Array, Uint32Array].includes(Index)) {
90
- throw new Error('Invalid sparse glTF indices');
91
- }
92
- const view = description.bufferViews[sparse.indices.bufferView];
93
- const offset = (view.byteOffset || 0) + (sparse.indices.byteOffset || 0);
94
- if (sparse.count > spec.count || (sparse.indices.byteOffset || 0) + sparse.count * Index.BYTES_PER_ELEMENT > view.byteLength) {
95
- throw new Error('Invalid sparse glTF indices');
96
- }
97
- const indices = new Index(description.buffers[view.buffer].binary.slice(offset, offset + sparse.count * Index.BYTES_PER_ELEMENT));
98
- read(
99
- sparse.values.bufferView,
100
- sparse.values.byteOffset || 0,
101
- sparse.count,
102
- 0,
103
- i => {
104
- if (indices[i] >= spec.count) throw new Error('Invalid sparse glTF index');
105
- return indices[i];
106
- }
107
- );
108
- }
109
- if (spec.componentType === 5126) {
110
- return { data, size };
111
- }
112
- const normalized = new Float32Array(data.length);
113
- // Normalization is a glTF accessor rule, not sRGB conversion; indices stay integers.
114
- for (let i = 0; i < data.length; i++) {
115
- normalized[i] = spec.normalized
116
- ? Math.max(-1, data[i] / (Type === Int8Array ? 127 : Type === Int16Array ? 32767 : Type === Uint8Array ? 255 : Type === Uint32Array ? 4294967295 : 65535))
117
- : data[i];
118
- }
119
- return { data: normalized, size, indices: data };
120
- }
121
-
122
- /** glTF quaternion/translation/scale to a column-major matrix. */
123
- export function nodeMatrix(spec) {
124
- if (spec.matrix) return Array.from(spec.matrix);
125
- // glTF stores quaternions [x,y,z,w]; convert directly to a scaled column-major matrix.
126
- const [x, y, z, w] = spec.rotation || [0, 0, 0, 1],
127
- [sx, sy, sz] = spec.scale || [1, 1, 1];
128
- return [
129
- (1 - 2 * (y * y + z * z)) * sx,
130
- 2 * (x * y + z * w) * sx,
131
- 2 * (x * z - y * w) * sx,
132
- 0,
133
- 2 * (x * y - z * w) * sy,
134
- (1 - 2 * (x * x + z * z)) * sy,
135
- 2 * (y * z + x * w) * sy, 0,
136
- 2 * (x * z + y * w) * sz,
137
- 2 * (y * z - x * w) * sz,
138
- (1 - 2 * (x * x + y * y)) * sz,
139
- 0,
140
- ...(spec.translation || [0, 0, 0]),
141
- 1,
142
- ];
143
- }
144
-
145
- /** Area-weighted vertex normals, for indexed or non-indexed triangles. */
146
- export function vertexNormals(p, indices) {
147
- // Accumulate area-weighted face normals for shared vertices, then normalize.
148
- const normals = new Float32Array(p.length);
149
- for (let i = 0; i < (indices?.length || p.length / 3); i += 3) {
150
- const a = indices ? indices[i] : i,
151
- b = indices ? indices[i + 1] : i + 1,
152
- c = indices ? indices[i + 2] : i + 2;
153
- const u = [0, 1, 2].map(j => p[b * 3 + j] - p[a * 3 + j]), v = [0, 1, 2].map(j => p[c * 3 + j] - p[a * 3 + j]);
154
- const n = [u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]];
155
- for (const index of [a, b, c]) {
156
- for (let j = 0; j < 3; j++) {
157
- normals[index * 3 + j] += n[j];
158
- }
159
- }
160
- }
161
- for (let i = 0; i < normals.length; i += 3) {
162
- const length = Math.hypot(...normals.subarray(i, i + 3)) || 1;
163
- for (let j = 0; j < 3; j++) {
164
- normals[i + j] /= length;
165
- }
166
- }
167
- return normals;
168
- }
169
-
170
- /** Translate glTF sampler constants into WebGPU sampler options. */
171
- export function textureSampler(sampler) {
172
- return {
173
- addressModeU: sampler.wrapS === 33071 ? 'clamp-to-edge' : sampler.wrapS === 33648 ? 'mirror-repeat' : 'repeat',
174
- addressModeV: sampler.wrapT === 33071 ? 'clamp-to-edge' : sampler.wrapT === 33648 ? 'mirror-repeat' : 'repeat',
175
- magFilter: sampler.magFilter === 9728 ? 'nearest' : 'linear',
176
- minFilter: sampler.minFilter === 9728 || sampler.minFilter === 9984 || sampler.minFilter === 9986 ? 'nearest' : 'linear',
177
- };
178
- }
@@ -1,79 +0,0 @@
1
- export async function decompress(data, compression) {
2
- if (compression === 1) return data;
3
- if (compression !== 2) throw new Error(`Unsupported PMTiles compression: ${compression}`);
4
- return new Response(new Blob([data]).stream().pipeThrough(new DecompressionStream('gzip'))).arrayBuffer();
5
- }
6
-
7
- /** Decode the PMTiles v3 header. */
8
- export function decodeHeader(data) {
9
- if (data.byteLength < 127 || new TextDecoder().decode(new Uint8Array(data, 0, 7)) !== 'PMTiles' ||
10
- new Uint8Array(data)[7] !== 3) throw new Error('Expected a PMTiles v3 archive');
11
- const view = new DataView(data);
12
- const header = {};
13
- ['rootDirectoryOffset', 'rootDirectoryLength', 'jsonMetadataOffset', 'jsonMetadataLength', 'leafDirectoryOffset', 'leafDirectoryLength', 'tileDataOffset', 'tileDataLength', 'numAddressedTiles', 'numTileEntries', 'numTileContents'].forEach((name, i) => { header[name] = Number(view.getBigUint64(8 + i * 8, true)); });
14
- ['clustered', 'internalCompression', 'tileCompression', 'tileType', 'minZoom', 'maxZoom'].forEach((name, i) => { header[name] = view.getUint8(96 + i); });
15
- ['minLon', 'minLat', 'maxLon', 'maxLat'].forEach((name, i) => { header[name] = view.getInt32(102 + i * 4, true) / 1e7; });
16
- header.centerZoom = view.getUint8(118);
17
- header.centerLon = view.getInt32(119, true) / 1e7;
18
- header.centerLat = view.getInt32(123, true) / 1e7;
19
- return header;
20
- }
21
-
22
- /** Cumulative Hilbert ID for an archive tile. */
23
- export function tileId(z, x, y) {
24
- if (![z, x, y].every(Number.isInteger) || z < 0 || z > 26 ||
25
- x < 0 || y < 0 || x >= 2 ** z || y >= 2 ** z) throw new Error('Invalid PMTiles tile coordinates');
26
- let id = (4 ** z - 1) / 3;
27
- const n = 2 ** z;
28
- // Same cumulative Hilbert ordering used by build/pmtiles.js.
29
- for (let s = n / 2; s >= 1; s /= 2) {
30
- const rx = (x & s) ? 1 : 0,
31
- ry = (y & s) ? 1 : 0;
32
- id += s * s * ((3 * rx) ^ ry);
33
- if (!ry) {
34
- if (rx) { x = n - 1 - x; y = n - 1 - y; }
35
- [x, y] = [y, x];
36
- }
37
- }
38
- return id;
39
- }
40
-
41
- /** Decode delta/varint directory columns, rejecting malformed entries. */
42
- export function decodeDirectory(data) {
43
- const bytes = new Uint8Array(data);
44
- let cursor = 0;
45
- const varint = () => {
46
- let value = 0;
47
- for (let factor = 1; factor <= 2 ** 49; factor *= 128) {
48
- if (cursor >= bytes.length) throw new Error('Truncated PMTiles directory');
49
- const byte = bytes[cursor++];
50
- value += (byte & 127) * factor;
51
- if (!Number.isSafeInteger(value)) throw new Error('Invalid PMTiles directory integer');
52
- if (byte < 128) return value;
53
- }
54
- throw new Error('Invalid PMTiles directory integer');
55
- };
56
- const count = varint();
57
- if (count > (bytes.length - cursor) / 4) throw new Error('Invalid PMTiles directory count');
58
- const entries = [];
59
- let tileId = 0;
60
- for (let i = 0; i < count; i++) {
61
- tileId += varint();
62
- if (!Number.isSafeInteger(tileId) || (i && tileId <= entries[i - 1].tileId)) {
63
- throw new Error('Invalid PMTiles directory tile IDs');
64
- }
65
- entries.push({ tileId });
66
- }
67
- for (const entry of entries) entry.runLength = varint();
68
- for (const entry of entries) {
69
- entry.length = varint();
70
- if (!entry.length) throw new Error('Invalid PMTiles directory length');
71
- }
72
- entries.forEach((entry, i) => {
73
- const value = varint();
74
- if (!value && !i) throw new Error('Invalid PMTiles directory offset');
75
- entry.offset = value ? value - 1 : entries[i - 1].offset + entries[i - 1].length;
76
- });
77
- if (cursor !== bytes.length) throw new Error('Trailing PMTiles directory data');
78
- return entries;
79
- }
@@ -1,102 +0,0 @@
1
- /** A fresh, empty scene-graph node. */
2
- export const emptyNode = () => ({
3
- position: [0, 0, 0],
4
- rotation: [0, 0, 0],
5
- scale: [1, 1, 1],
6
- worldMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
7
- children: [],
8
- visible: true,
9
- });
10
-
11
- /** Reparent/detach scene data without drawing or disposing GPU resources. */
12
- export function setParent(node, parent) {
13
- if (node.parent) node.parent.children.splice(node.parent.children.indexOf(node), 1);
14
- node.parent = parent;
15
- if (parent) parent.children.push(node);
16
- }
17
-
18
- /** Depth-first walk; a truthy callback result skips that node's descendants. */
19
- export function traverse(node, callback) {
20
- if (callback(node)) return;
21
- for (const child of node.children) traverse(child, callback);
22
- }
23
-
24
- /** Compose parent*local matrices; a node.matrix overrides its position/rotation/scale. */
25
- export function updateWorldMatrix(node) {
26
- const parent = node.parent;
27
- const parentVersion = parent?._worldMatrixVersion || 0;
28
- const matrixMode = Boolean(node.matrix);
29
- let changed = node._worldParent !== parent || node._parentWorldVersion !== parentVersion ||
30
- node._worldMatrixMode !== matrixMode;
31
- if (node.matrix) {
32
- const state = node._matrixState ||= new Float64Array(16);
33
- for (let i = 0; i < 16; i++) {
34
- if (state[i] !== node.matrix[i]) changed = true;
35
- state[i] = node.matrix[i];
36
- }
37
- } else {
38
- const state = node._transformState ||= new Float64Array(9);
39
- for (let i = 0; i < 9; i++) {
40
- const value = i < 3 ? node.position[i] : i < 6 ? node.rotation[i - 3] : node.scale[i - 6];
41
- if (state[i] !== value) changed = true;
42
- state[i] = value;
43
- }
44
- }
45
- if (!changed) {
46
- for (const child of node.children) updateWorldMatrix(child);
47
- return;
48
- }
49
- let local;
50
- if (node.matrix) local = node.matrix;
51
- else {
52
- const degrees = 180 / Math.PI;
53
- const matrix = new DOMMatrix().translate(...node.position);
54
- // Node rotations use YXZ, as did the previous renderer.
55
- matrix.rotateAxisAngleSelf(0, 1, 0, node.rotation[1] * degrees);
56
- matrix.rotateAxisAngleSelf(1, 0, 0, node.rotation[0] * degrees);
57
- matrix.rotateAxisAngleSelf(0, 0, 1, node.rotation[2] * degrees);
58
- local = matrix.scale(...node.scale).toFloat64Array();
59
- }
60
- const world = parent
61
- ? new DOMMatrix(parent.worldMatrix).multiply(new DOMMatrix(local)).toFloat64Array()
62
- : local;
63
- for (let i = 0; i < 16; i++) node.worldMatrix[i] = world[i];
64
- node._worldParent = parent;
65
- node._parentWorldVersion = parentVersion;
66
- node._worldMatrixMode = matrixMode;
67
- node._worldMatrixVersion = (node._worldMatrixVersion || 0) + 1;
68
- for (const child of node.children) updateWorldMatrix(child);
69
- }
70
-
71
- /** Orthonormal view basis plus perspective matrices, refreshed before projecting/drawing. */
72
- export function updateCamera(camera) {
73
- const z = camera.position.map((v, i) => v - camera.target[i]);
74
- const zLength = Math.hypot(...z) || 1;
75
- const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
76
- for (let i = 0; i < 3; i++) {
77
- z[i] /= zLength;
78
- }
79
- const x = cross(camera.up, z), xLength = Math.hypot(...x) || 1;
80
- for (let i = 0; i < 3; i++) {
81
- x[i] /= xLength;
82
- }
83
- const y = cross(z, x);
84
- const view = new DOMMatrix([x[0], x[1], x[2], 0, y[0], y[1], y[2], 0, z[0], z[1], z[2], 0, ...camera.position, 1]).inverse().toFloat64Array();
85
- if (![...view].every(Number.isFinite)) {
86
- throw new Error('Singular 3D transform');
87
- }
88
- for (let i = 0; i < 16; i++) {
89
- camera.viewMatrix[i] = view[i];
90
- }
91
- const f = 1 / Math.tan(camera.fov * Math.PI / 360),
92
- n = camera.near,
93
- r = camera.far;
94
- const projection = [f / camera.aspect, 0, 0, 0, 0, f, 0, 0, 0, 0, r / (n - r), -1, 0, 0, r * n / (n - r), 0];
95
- for (let i = 0; i < 16; i++) {
96
- camera.projectionMatrix[i] = projection[i];
97
- }
98
- const projectionView = new DOMMatrix(camera.projectionMatrix).multiply(new DOMMatrix(camera.viewMatrix)).toFloat64Array();
99
- for (let i = 0; i < 16; i++) {
100
- camera.projectionViewMatrix[i] = projectionView[i];
101
- }
102
- }
package/src/utils/sun.js DELETED
@@ -1,71 +0,0 @@
1
- // Solar centre, without atmospheric refraction.
2
- export function solarPosition(date, lat, lng) {
3
- const time = new Date(date).getTime();
4
- if (!Number.isFinite(time) || !Number.isFinite(lat) || Math.abs(lat) > 90 ||
5
- !Number.isFinite(lng) || Math.abs(lng) > 180) throw new Error('Invalid solar date or location');
6
- const rad = Math.PI / 180, d = time / 86400000 - 10957.5;
7
- const mean = (357.5291 + 0.98560028 * d) * rad;
8
- const longitude = mean + (1.9148 * Math.sin(mean) + 0.02 * Math.sin(2 * mean) +
9
- 0.0003 * Math.sin(3 * mean) + 102.9372 + 180) * rad;
10
- const obliquity = 23.4397 * rad;
11
- const declination = Math.asin(Math.sin(longitude) * Math.sin(obliquity));
12
- const ascension = Math.atan2(Math.sin(longitude) * Math.cos(obliquity), Math.cos(longitude));
13
- return horizontalPosition(d, lat, lng, ascension, declination);
14
- }
15
-
16
- function horizontalPosition(d, lat, lng, ascension, declination) {
17
- const rad = Math.PI / 180;
18
- const hourAngle = (280.16 + 360.9856235 * d + lng) * rad - ascension;
19
- const latitude = lat * rad;
20
- const altitude = Math.asin(Math.sin(latitude) * Math.sin(declination) +
21
- Math.cos(latitude) * Math.cos(declination) * Math.cos(hourAngle));
22
- const southAzimuth = Math.atan2(Math.sin(hourAngle),
23
- Math.cos(hourAngle) * Math.sin(latitude) - Math.tan(declination) * Math.cos(latitude));
24
- const azimuth = (southAzimuth / rad + 180 + 360) % 360;
25
- return { altitude: altitude / rad, azimuth,
26
- direction: [Math.sin(azimuth * rad) * Math.cos(altitude), Math.sin(altitude),
27
- -Math.cos(azimuth * rad) * Math.cos(altitude)] };
28
- }
29
-
30
- // Low-precision geocentric lunar orbit; no parallax or atmospheric refraction.
31
- export function moonPosition(date, lat, lng) {
32
- solarPosition(date, lat, lng);
33
- const rad = Math.PI / 180, d = new Date(date).getTime() / 86400000 - 10957.5;
34
- const anomaly = (134.963 + 13.064993 * d) * rad;
35
- const longitude = (218.316 + 13.176396 * d + 6.289 * Math.sin(anomaly)) * rad;
36
- const latitude = 5.128 * Math.sin((93.272 + 13.229350 * d) * rad) * rad;
37
- const obliquity = 23.4397 * rad;
38
- const x = Math.cos(latitude) * Math.cos(longitude);
39
- const y = Math.cos(latitude) * Math.sin(longitude) * Math.cos(obliquity) - Math.sin(latitude) * Math.sin(obliquity);
40
- const z = Math.cos(latitude) * Math.sin(longitude) * Math.sin(obliquity) + Math.sin(latitude) * Math.cos(obliquity);
41
- return horizontalPosition(d, lat, lng, Math.atan2(y, x), Math.asin(z));
42
- }
43
-
44
- export function atmosphere(altitude) {
45
- if (!Number.isFinite(altitude)) throw new Error('Invalid solar altitude');
46
- const stops = [
47
- [-18, [3, 7, 20], [17, 28, 54], [0.025, 0.04, 0.09]],
48
- [-6, [37, 53, 84], [182, 106, 86], [0.12, 0.10, 0.14]],
49
- [0, [101, 131, 171], [246, 170, 115], [0.38, 0.24, 0.18]],
50
- [10, [74, 147, 208], [197, 221, 237], [0.80, 0.75, 0.68]],
51
- [25, [53, 144, 213], [223, 238, 250], [1, 1, 1]],
52
- ];
53
- const upper = stops.findIndex(stop => stop[0] >= altitude);
54
- const b = stops[upper < 0 ? stops.length - 1 : upper], a = stops[Math.max(0, upper - 1)];
55
- const t = a === b || upper < 0 ? 1 : (altitude - a[0]) / (b[0] - a[0]);
56
- const mix = index => a[index].map((value, i) => value + (b[index][i] - value) * t);
57
- const rgb = values => `rgb(${values.map(Math.round).join(', ')})`;
58
- return { background: `linear-gradient(${rgb(mix(1))}, ${rgb(mix(2))})`, tint: mix(3) };
59
- }
60
-
61
- /** Perspective projection of a celestial direction; null when behind the camera. */
62
- export function projectCelestialBody(direction, size, pitch, bearing) {
63
- const [x, y, z] = direction;
64
- const right = x * Math.cos(bearing) - z * Math.sin(bearing);
65
- const up = -x * Math.sin(bearing) * Math.cos(pitch) + y * Math.sin(pitch) - z * Math.cos(bearing) * Math.cos(pitch);
66
- const forward = -x * Math.sin(bearing) * Math.sin(pitch) - y * Math.cos(pitch) - z * Math.cos(bearing) * Math.sin(pitch);
67
- if (forward <= 0) return null;
68
- const left = size.x / 2 + size.y * 1.5 * right / forward;
69
- const top = size.y / 2 - size.y * 1.5 * up / forward;
70
- return { left, top };
71
- }
@@ -1,78 +0,0 @@
1
- /** Height inside a bridge deck, or null outside its triangles. */
2
- export function bridgeElevation(point, bridges) {
3
- // Bridges bucketed by 64 DEM pixels.
4
- for (const bridge of bridges?.get(`${Math.floor(point.x / 64)}/${Math.floor(point.y / 64)}`) || []) {
5
- if (point.x < bridge.min[0] || point.x > bridge.max[0] || point.y < bridge.min[1] || point.y > bridge.max[1]) continue;
6
- for (const [a, b, c] of bridge.triangles) {
7
- const d = (b[1] - c[1]) * (a[0] - c[0]) + (c[0] - b[0]) * (a[1] - c[1]);
8
- const u = ((b[1] - c[1]) * (point.x - c[0]) + (c[0] - b[0]) * (point.y - c[1])) / d;
9
- const v = ((c[1] - a[1]) * (point.x - c[0]) + (a[0] - c[0]) * (point.y - c[1])) / d;
10
- if (u >= 0 && v >= 0 && u + v <= 1) return u * a[2] + v * b[2] + (1 - u - v) * c[2];
11
- }
12
- }
13
- return null;
14
- }
15
-
16
- /** Bilinear DEM sampling, with the original first-valid-neighbour no-data rule. */
17
- export function terrainElevation(point, tiles) {
18
- const x = point.x - 0.5, y = point.y - 0.5;
19
- const x0 = Math.floor(x), y0 = Math.floor(y);
20
- const fx = x - x0, fy = y - y0;
21
- const sample = (px, py) => {
22
- const tileX = Math.floor(px / 256), tileY = Math.floor(py / 256);
23
- const tile = tiles.get(`${tileX}/${tileY}`);
24
- if (!tile) return null;
25
- const elevation = tile[(py - tileY * 256) * 256 + px - tileX * 256];
26
- return Number.isFinite(elevation) && elevation > -1000 ? elevation : null;
27
- };
28
- const values = [sample(x0, y0), sample(x0 + 1, y0), sample(x0, y0 + 1), sample(x0 + 1, y0 + 1)];
29
- const valid = values.map((value, i) => Number.isFinite(value) ? i : -1).filter(i => i >= 0);
30
- if (!valid.length) return null;
31
- if (valid.length < 4) return values[valid[0]];
32
- return (values[0] * (1 - fx) + values[1] * fx) * (1 - fy) +
33
- (values[2] * (1 - fx) + values[3] * fx) * fy;
34
- }
35
-
36
- /** Unit tile grid; the vertex shader supplies the elevation. */
37
- export function terrainGrid(divisions) {
38
- const positions = [], normals = [], uvs = [], indices = [];
39
- for (let row = 0; row <= divisions; row++) {
40
- for (let column = 0; column <= divisions; column++) {
41
- positions.push(column / divisions, 0, row / divisions);
42
- normals.push(0, 1, 0);
43
- uvs.push(column / divisions, row / divisions);
44
- if (row < divisions && column < divisions) {
45
- const a = row * (divisions + 1) + column;
46
- const b = a + 1, c = a + divisions + 1, d = c + 1;
47
- indices.push(a, c, b, b, c, d);
48
- }
49
- }
50
- }
51
- return {
52
- position: { size: 3, data: new Float32Array(positions) },
53
- normal: { size: 3, data: new Float32Array(normals) },
54
- uv: { size: 2, data: new Float32Array(uvs) },
55
- index: { data: new Uint16Array(indices) },
56
- };
57
- }
58
-
59
- /** Float32 DEM atlas; missing samples retain the shader no-data sentinel. */
60
- export function terrainAtlas(tiles, bounds) {
61
- const columns = bounds.max.x - bounds.min.x + 1, rows = bounds.max.y - bounds.min.y + 1;
62
- const elevations = new Float32Array(columns * rows * 65536).fill(-1e9);
63
- let low = Infinity, high = -Infinity;
64
- for (const [key, values] of tiles) {
65
- const [x, y] = key.split('/').map(Number);
66
- const start = (y - bounds.min.y) * 256 * columns * 256 + (x - bounds.min.x) * 256;
67
- for (let row = 0; row < 256; row++) {
68
- for (let column = 0; column < 256; column++) {
69
- const value = values[row * 256 + column];
70
- if (!Number.isFinite(value) || value <= -1000) continue;
71
- elevations[start + row * columns * 256 + column] = value;
72
- low = Math.min(low, value);
73
- high = Math.max(high, value);
74
- }
75
- }
76
- }
77
- return { elevations, low, high };
78
- }